feat 对接微信支付接口
This commit is contained in:
parent
9d350dbb53
commit
08cc768f73
@ -1,7 +1,11 @@
|
|||||||
// pages/login/login.js
|
// pages/login/login.js
|
||||||
|
import Toast from '~/miniprogram_npm/@vant/weapp/toast/toast';
|
||||||
import {
|
import {
|
||||||
login
|
login
|
||||||
} from '~/services/login/login';
|
} from '~/services/login/login';
|
||||||
|
import {
|
||||||
|
getOpenId
|
||||||
|
} from '~/services/login/getOpenId';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
/**
|
/**
|
||||||
@ -14,9 +18,23 @@ Page({
|
|||||||
code: ""
|
code: ""
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 获取手机号
|
// 获取手机号
|
||||||
getPhoneNumber(e) {
|
getPhoneNumber(e) {
|
||||||
let that = this
|
let that = this
|
||||||
|
console.log(that.data.checked,'asdasdas');
|
||||||
|
if(that.data.checked == false){
|
||||||
|
Toast({
|
||||||
|
context: this,
|
||||||
|
selector: '#t-toast',
|
||||||
|
message: '请勾选同意按钮',
|
||||||
|
duration: 2000,
|
||||||
|
icon: '',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.detail.code) {
|
if (e.detail.code) {
|
||||||
let phoneCode = e.detail.code
|
let phoneCode = e.detail.code
|
||||||
let data = {
|
let data = {
|
||||||
@ -54,12 +72,17 @@ Page({
|
|||||||
*/
|
*/
|
||||||
onLoad() {
|
onLoad() {
|
||||||
let that = this
|
let that = this
|
||||||
// 获取OpenId
|
// 获取OpenId的code
|
||||||
wx.login({
|
wx.login({
|
||||||
success(res) {
|
success(res) {
|
||||||
that.setData({
|
that.setData({
|
||||||
code: res.code
|
code: res.code
|
||||||
})
|
})
|
||||||
|
getOpenId({
|
||||||
|
code: res.code
|
||||||
|
}).then((res) => {
|
||||||
|
wx.setStorageSync('openId', res.data)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -384,8 +384,10 @@ Page({
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.payLock = true;
|
// this.payLock = true;
|
||||||
const resSubmitCouponList = this.handleCouponList(submitCouponList);
|
const resSubmitCouponList = this.handleCouponList(submitCouponList);
|
||||||
|
const openId = wx.getStorageSync('openId')
|
||||||
|
console.log(openId,'我的openId');
|
||||||
const params = {
|
const params = {
|
||||||
userAddressReq: settleDetailData.userAddress || userAddressReq,
|
userAddressReq: settleDetailData.userAddress || userAddressReq,
|
||||||
goodsRequestList: goodsRequestList,
|
goodsRequestList: goodsRequestList,
|
||||||
@ -394,10 +396,12 @@ Page({
|
|||||||
invoiceRequest: null,
|
invoiceRequest: null,
|
||||||
storeInfoList,
|
storeInfoList,
|
||||||
couponList: resSubmitCouponList,
|
couponList: resSubmitCouponList,
|
||||||
|
openId: openId
|
||||||
};
|
};
|
||||||
if (invoiceData && invoiceData.email) {
|
if (invoiceData && invoiceData.email) {
|
||||||
params.invoiceRequest = invoiceData;
|
params.invoiceRequest = invoiceData;
|
||||||
}
|
}
|
||||||
|
console.log(params,'下单参数!');
|
||||||
/** 提交订单方法(接口) */
|
/** 提交订单方法(接口) */
|
||||||
commitPay(params).then(
|
commitPay(params).then(
|
||||||
(res) => {
|
(res) => {
|
||||||
@ -408,7 +412,7 @@ Page({
|
|||||||
if (this.isInvalidOrder(data)) {
|
if (this.isInvalidOrder(data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (res.code === 'Success') {
|
if (res.code === 200) {
|
||||||
console.log("正在调起支付");
|
console.log("正在调起支付");
|
||||||
this.handlePay(data, settleDetailData);
|
this.handlePay(data, settleDetailData);
|
||||||
} else {
|
} else {
|
||||||
@ -481,22 +485,22 @@ Page({
|
|||||||
|
|
||||||
// 处理支付
|
// 处理支付
|
||||||
handlePay(data, settleDetailData) {
|
handlePay(data, settleDetailData) {
|
||||||
const { channel, payInfo, tradeNo, interactId, transactionId } = data;
|
const { channel, jsApiUiPackage, outTradeNo, interactId, transactionId } = data;
|
||||||
const { totalAmount, totalPayAmount } = settleDetailData;
|
const { totalAmount, totalPayAmount } = settleDetailData;
|
||||||
const payOrderInfo = {
|
const payOrderInfo = {
|
||||||
payInfo: payInfo,
|
payInfo: jsApiUiPackage,
|
||||||
orderId: tradeNo,
|
orderId: outTradeNo,
|
||||||
orderAmt: totalAmount,
|
orderAmt: totalAmount,
|
||||||
payAmt: totalPayAmount,
|
payAmt: totalPayAmount,
|
||||||
interactId: interactId,
|
interactId: interactId,
|
||||||
tradeNo: tradeNo,
|
tradeNo: outTradeNo,
|
||||||
transactionId: transactionId,
|
transactionId: transactionId,
|
||||||
};
|
};
|
||||||
console.log(payOrderInfo,'支付信息');
|
console.log(payOrderInfo,'支付信息');
|
||||||
|
|
||||||
if (channel === 'wechat') {
|
// if (channel === 'wechat') {
|
||||||
wechatPayOrder(payOrderInfo);
|
wechatPayOrder(payOrderInfo);
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
|
@ -3,7 +3,7 @@ import Toast from 'tdesign-miniprogram/toast/index';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
dispatchCommitPay
|
dispatchCommitPay
|
||||||
} from '../../../services/order/orderConfirm';
|
} from '~/services/order/orderConfirm';
|
||||||
|
|
||||||
// 真实的提交支付
|
// 真实的提交支付
|
||||||
export const commitPay = (params) => {
|
export const commitPay = (params) => {
|
||||||
@ -24,6 +24,7 @@ export const commitPay = (params) => {
|
|||||||
storeInfoList: params.storeInfoList, //备注信息列表
|
storeInfoList: params.storeInfoList, //备注信息列表
|
||||||
couponList: params.couponList,
|
couponList: params.couponList,
|
||||||
groupInfo: params.groupInfo,
|
groupInfo: params.groupInfo,
|
||||||
|
openId: params.openId, // openId
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,18 +106,18 @@ export const payFail = (payOrderInfo, resultMsg) => {
|
|||||||
|
|
||||||
// 微信支付方式
|
// 微信支付方式
|
||||||
export const wechatPayOrder = (payOrderInfo) => {
|
export const wechatPayOrder = (payOrderInfo) => {
|
||||||
const payInfo = JSON.parse(payOrderInfo.payInfo);
|
// const payInfo = JSON.parse(payOrderInfo.payInfo);
|
||||||
const { timeStamp, nonceStr, signType, paySign } = payInfo;
|
const { timestamp, nonceStr, prepayIdPackage , signType, signature } = payOrderInfo.payInfo;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// demo 中直接走支付成功
|
// demo 中直接走支付成功
|
||||||
// paySuccess(payOrderInfo);
|
// paySuccess(payOrderInfo);
|
||||||
// resolve();
|
// resolve();
|
||||||
wx.requestPayment({
|
wx.requestPayment({
|
||||||
timeStamp,
|
timeStamp: timestamp,
|
||||||
nonceStr,
|
nonceStr,
|
||||||
package: payInfo.package,
|
package: prepayIdPackage,
|
||||||
signType,
|
signType: "MD5",
|
||||||
paySign,
|
paySign: signature,
|
||||||
success: function () {
|
success: function () {
|
||||||
paySuccess(payOrderInfo);
|
paySuccess(payOrderInfo);
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import { fetchUserCenter } from '~/services/usercenter/fetchUsercenter';
|
import {
|
||||||
|
fetchUserCenter
|
||||||
|
} from '~/services/usercenter/fetchUsercenter';
|
||||||
|
import {
|
||||||
|
getOpenId
|
||||||
|
} from '~/services/login/getOpenId';
|
||||||
import Toast from 'tdesign-miniprogram/toast/index';
|
import Toast from 'tdesign-miniprogram/toast/index';
|
||||||
|
|
||||||
const menuData = [
|
const menuData = [
|
||||||
[
|
[{
|
||||||
{
|
|
||||||
title: '申请开店',
|
title: '申请开店',
|
||||||
tit: '',
|
tit: '',
|
||||||
url: '',
|
url: '',
|
||||||
@ -34,8 +38,7 @@ const menuData = [
|
|||||||
type: 'set',
|
type: 'set',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[{
|
||||||
{
|
|
||||||
title: '帮助中心',
|
title: '帮助中心',
|
||||||
tit: '',
|
tit: '',
|
||||||
url: '',
|
url: '',
|
||||||
@ -51,8 +54,7 @@ const menuData = [
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
const orderTagInfos = [
|
const orderTagInfos = [{
|
||||||
{
|
|
||||||
title: '待付款',
|
title: '待付款',
|
||||||
iconName: 'wallet',
|
iconName: 'wallet',
|
||||||
orderNum: 0,
|
orderNum: 0,
|
||||||
@ -158,16 +160,24 @@ Page({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
onClickCell({ currentTarget }) {
|
onClickCell({
|
||||||
const { type } = currentTarget.dataset;
|
currentTarget
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
type
|
||||||
|
} = currentTarget.dataset;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'apply-shop': {
|
case 'apply-shop': {
|
||||||
wx.navigateTo({ url: '/pages/usercenter/apply-shop/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/usercenter/apply-shop/index'
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'address': {
|
case 'address': {
|
||||||
wx.navigateTo({ url: '/pages/usercenter/address/list/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/usercenter/address/list/index'
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'service': {
|
case 'service': {
|
||||||
@ -195,11 +205,15 @@ Page({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'coupon': {
|
case 'coupon': {
|
||||||
wx.navigateTo({ url: '/pages/coupon/coupon-list/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/coupon/coupon-list/index'
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'set': {
|
case 'set': {
|
||||||
wx.navigateTo({ url: '/pages/usercenter/set/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/usercenter/set/index'
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -219,22 +233,32 @@ Page({
|
|||||||
const status = e.detail.tabType;
|
const status = e.detail.tabType;
|
||||||
|
|
||||||
if (status === 0) {
|
if (status === 0) {
|
||||||
wx.navigateTo({ url: '/pages/order/after-service-list/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/order/after-service-list/index'
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
wx.navigateTo({ url: `/pages/order/order-list/index?status=${status}` });
|
wx.navigateTo({
|
||||||
|
url: `/pages/order/order-list/index?status=${status}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
jumpAllOrder() {
|
jumpAllOrder() {
|
||||||
wx.navigateTo({ url: '/pages/order/order-list/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/order/order-list/index'
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
openMakePhone() {
|
openMakePhone() {
|
||||||
this.setData({ showMakePhone: true });
|
this.setData({
|
||||||
|
showMakePhone: true
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
closeMakePhone() {
|
closeMakePhone() {
|
||||||
this.setData({ showMakePhone: false });
|
this.setData({
|
||||||
|
showMakePhone: false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
call() {
|
call() {
|
||||||
@ -243,10 +267,28 @@ Page({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getOpenIdFun() {
|
||||||
|
wx.login({
|
||||||
|
success(res) {
|
||||||
|
getOpenId({
|
||||||
|
code: res.code
|
||||||
|
}).then((res) => {
|
||||||
|
wx.setStorageSync('openId', res.data)
|
||||||
|
console.log(res.data, '获取来的OpenId');
|
||||||
|
})
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
gotoUserEditPage() {
|
gotoUserEditPage() {
|
||||||
const { currAuthStep } = this.data;
|
const {
|
||||||
|
currAuthStep
|
||||||
|
} = this.data;
|
||||||
if (currAuthStep === 2) {
|
if (currAuthStep === 2) {
|
||||||
wx.navigateTo({ url: '/pages/usercenter/person-info/index' });
|
wx.navigateTo({
|
||||||
|
url: '/pages/usercenter/person-info/index'
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// this.fetUseriInfoHandle();
|
// this.fetUseriInfoHandle();
|
||||||
}
|
}
|
||||||
@ -254,7 +296,10 @@ Page({
|
|||||||
|
|
||||||
getVersionInfo() {
|
getVersionInfo() {
|
||||||
const versionInfo = wx.getAccountInfoSync();
|
const versionInfo = wx.getAccountInfoSync();
|
||||||
const { version, envVersion = __wxConfig } = versionInfo.miniProgram;
|
const {
|
||||||
|
version,
|
||||||
|
envVersion = __wxConfig
|
||||||
|
} = versionInfo.miniProgram;
|
||||||
this.setData({
|
this.setData({
|
||||||
versionNo: envVersion === 'release' ? version : envVersion,
|
versionNo: envVersion === 'release' ? version : envVersion,
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
bind:gotoUserEditPage="gotoUserEditPage"
|
bind:gotoUserEditPage="gotoUserEditPage"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<view class="content-wrapper">
|
<view class="content-wrapper">
|
||||||
|
<button type="primary" bind:tap="getOpenIdFun">获取OpenID</button>
|
||||||
<view class="order-group-wrapper">
|
<view class="order-group-wrapper">
|
||||||
<t-order-group orderTagInfos="{{orderTagInfos}}" bind:onClickTop="jumpAllOrder" bind:onClickItem="jumpNav" />
|
<t-order-group orderTagInfos="{{orderTagInfos}}" bind:onClickTop="jumpAllOrder" bind:onClickItem="jumpNav" />
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"description": "Project configuration file, more information: https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
||||||
"packOptions": {
|
"packOptions": {
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"include": []
|
"include": []
|
||||||
|
24
services/login/getOpenId.js
Normal file
24
services/login/getOpenId.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {
|
||||||
|
request
|
||||||
|
} from '../_utils/request';
|
||||||
|
import {
|
||||||
|
setStorage,
|
||||||
|
getStorage
|
||||||
|
} from '~/utils/storage'
|
||||||
|
|
||||||
|
/** 获取OpenId */
|
||||||
|
export function getOpenId(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request({
|
||||||
|
url: `WeChatLogin/getOpenId`,
|
||||||
|
method: 'POST',
|
||||||
|
data: data,
|
||||||
|
success: async function (res) {
|
||||||
|
wx.setStorageSync("openId",res);
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
import { config } from '../../config/index';
|
import { config } from '../../config/index';
|
||||||
import { mockIp, mockReqId } from '../../utils/mock';
|
import { mockIp, mockReqId } from '../../utils/mock';
|
||||||
|
import {
|
||||||
|
request
|
||||||
|
} from '../_utils/request';
|
||||||
|
|
||||||
/** 获取结算mock数据 */
|
/** 获取结算mock数据 */
|
||||||
function mockFetchSettleDetail(params) {
|
function mockFetchSettleDetail(params) {
|
||||||
@ -47,12 +50,27 @@ export function fetchSettleDetail(params) {
|
|||||||
|
|
||||||
/* 提交订单 */
|
/* 提交订单 */
|
||||||
export function dispatchCommitPay(params) {
|
export function dispatchCommitPay(params) {
|
||||||
if (config.useMock) {
|
// if (config.useMock) {
|
||||||
return mockDispatchCommitPay(params);
|
// return mockDispatchCommitPay(params);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
// return new Promise((resolve) => {
|
||||||
resolve('real api');
|
// resolve('real api');
|
||||||
|
// });
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request({
|
||||||
|
url: `WxPay/wxPay`,
|
||||||
|
method: 'POST',
|
||||||
|
data: params,
|
||||||
|
success: function (res) {
|
||||||
|
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail: function (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user