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