1.对接支付宝支付、对接微信支付

dev
杨杰 2 years ago
parent aeba6f0ab4
commit ba900b6440
  1. 18
      App.vue
  2. 29
      index.html
  3. 192
      pages/index/index.vue
  4. 51
      pages/welcome/welcome.vue

@ -13,19 +13,27 @@
appId: 'wxa075e8509802f826', appId: 'wxa075e8509802f826',
code: '', //codeopenid code: '', //codeopenid
snNo: '', // sn snNo: '', // sn
platformType: '', //
// //
url: 'https://hsg.dctpay.com/user', url: 'https://hsg.dctpay.com/user',
graurl:'https://pay.dctpay.com/crest', graurl: 'https://pay.dctpay.com/crest',
imgUrl: 'https://pay.dctpay.com/filesystem/', imgUrl: 'https://pay.dctpay.com/filesystem/',
imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/',
// //
// url: 'https://hsgcs.dctpay.com/user', // url: 'https://hsgcs.dctpay.com/user',
// graurl:'https://gratia-pay.dctpay.com/crest', // graurl:'https://gratia-pay.dctpay.com/crest',
// imgUrl: 'https://hsgcs.dctpay.com/filesystem/', // imgUrl: 'https://hsgcs.dctpay.com/filesystem/',
// imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', // imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/',
}, },
onLaunch: function() { onLaunch: function() {
console.log('App Launch'); var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.match(/Alipay/i) == "alipay") {
this.platformType = 'ALIPAY';
} else if (userAgent.match(/MicroMessenger/i) == "micromessenger") {
this.platformType = 'WECHAT';
} else {
this.platformType = 'UQRCODEPAY';
}
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
@ -64,4 +72,4 @@
<style> <style>
/*每个页面公共css */ /*每个页面公共css */
</style> </style>

@ -1,14 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" /> <meta name="viewport"
<title></title> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<!--preload-links--> <title></title>
<!--app-context--> <!--preload-links-->
</head> <!--app-context-->
<body> </head>
<div id="app"><!--app-html--></div> <body>
<script type="module" src="/main.js"></script> <div id="app"><!--app-html--></div>
</body> <script type="module" src="/main.js"></script>
</html> </body>
</html>

@ -656,8 +656,8 @@
icon: 'none' icon: 'none'
}) })
this.payPrice = 0; this.payPrice = 0;
this.plateNumberList = []; this.plateNumberList = [];
this.plateNumberList1 = []; this.plateNumberList1 = [];
this.storediscountType = ''; // this.storediscountType = ''; //
this.storediscountCondition = ''; // this.storediscountCondition = ''; //
this.storediscountPrice = ''; // this.storediscountPrice = ''; //
@ -671,7 +671,7 @@
// if (userAgent.match(/Alipay/i) == "alipay") { // if (userAgent.match(/Alipay/i) == "alipay") {
// this.createJSAPIOrder('ALIPAY'); // this.createJSAPIOrder('ALIPAY');
// } else if (userAgent.match(/MicroMessenger/i) == "micromessenger") { // } else if (userAgent.match(/MicroMessenger/i) == "micromessenger") {
this.createJSAPIOrder('WECHAT'); this.createJSAPIOrder();
// } // }
}, },
// //
@ -684,7 +684,7 @@
let datas = { let datas = {
"qrCodeSN": app.globalData.snNo, "qrCodeSN": app.globalData.snNo,
"payUserId": app.globalData.openId, "payUserId": app.globalData.openId,
"payMode": item, "payMode": app.globalData.platformType,
"totalAmount": this.inputPrice, "totalAmount": this.inputPrice,
"storeDiscountId": this.storeDiscountId, "storeDiscountId": this.storeDiscountId,
"userDiscountId": this.memDiscountId, "userDiscountId": this.memDiscountId,
@ -709,15 +709,24 @@
} }
jsapiPay(datas).then(res => { jsapiPay(datas).then(res => {
if (res.return_code == '000000') { if (res.return_code == '000000') {
if (res.return_data.payParam) { if (res.return_data.payParam && app.globalData.platformType == 'WECHAT') {
this.payRequest(res.return_data.payParam); this.wechatpayRequest(res.return_data);
} else { return;
uni.showToast({ }
title: '单比金额最多10000000元', if (res.return_data.payParam && app.globalData.platformType == 'ALIPAY') {
icon: 'none', this.alipayRequest(res.return_data.acc_resp_fields.paepay_id);
duration: 2000 return;
}) }
if (res.return_data.payParam && app.globalData.platformType == 'UQRCODEPAY') {
// this.unionPayRequest(res.return_data);
window.location.href = res.return_data.acc_resp_fields.redirect_url;
return;
} }
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
} else { } else {
uni.showToast({ uni.showToast({
title: res.return_msg, title: res.return_msg,
@ -833,52 +842,133 @@
}, },
// //
payRequest: function(self) { wechatpayRequest: function(self) {
uni.showLoading({ uni.showLoading({
title: '支付中...' title: '支付中...'
}) })
jweixin.config({ if (self.platformType == 1) {
debug: false, // ,apialertpclogpc jweixin.config({
appId: self.appId, // debug: true, // ,apialertpclogpc
timestamp: self.timeStamp, // appId: self.acc_resp_fields.app_id, //
nonceStr: self.nonceStr, // timestamp: self.acc_resp_fields.time_stamp, //
signature: self.sign, // 1 nonceStr: self.acc_resp_fields.nonce_str, //
jsApiList: ['chooseWXPay'] // 使JSJS2 signature: self.acc_resp_fields.pay_sign, // 1
}); jsApiList: ['chooseWXPay'] // 使JSJS2
uni.hideLoading();
jweixin.ready(function() {
jweixin.checkJsApi({
jsApiList: ['chooseWXPay'], // JSJS2,
success: function(res) {},
fail: function(res) {}
}); });
jweixin.chooseWXPay({ uni.hideLoading();
appId: self.appId, jweixin.ready(function() {
timestamp: self jweixin.checkJsApi({
.timeStamp, // jssdk使timestamp使timeStampS jsApiList: ['chooseWXPay'], // JSJS2,
nonceStr: self.nonceStr, // 32 success: function(res) {},
package: self.package, // prepay_idprepay_id=*** fail: function(res) {}
signType: self.signType, // 'SHA1'使'MD5' });
paySign: self.sign, // jweixin.chooseWXPay({
success: function(res) { appId: self.acc_resp_fields.app_id,
// timestamp: self.acc_resp_fields
uni.showToast({ .time_stamp, // jssdk使timestamp使timeStampS
title: '支付成功' nonceStr: self.acc_resp_fields.nonce_str, // 32
}) package: self.acc_resp_fields
}, .package, // prepay_idprepay_id=***
cancel: function(r) {}, signType: self.acc_resp_fields.sign_type, // 'SHA1'使'MD5'
fail: function(res) {} paySign: self.acc_resp_fields.pay_sign, //
success: function(res) {
//
uni.showToast({
title: '支付成功'
})
},
cancel: function(r) {},
fail: function(res) {}
});
}); });
}); jweixin.error(function(res) {
uni.showToast({
jweixin.error(function(res) { icon: 'none',
uni.showToast({ title: '支付失败了',
icon: 'none', duration: 4000
title: '支付失败了', });
duration: 4000 });
} else {
jweixin.config({
debug: false, // ,apialertpclogpc
appId: self.appId, //
timestamp: self.timeStamp, //
nonceStr: self.nonceStr, //
signature: self.sign, // 1
jsApiList: ['chooseWXPay'] // 使JSJS2
});
uni.hideLoading();
jweixin.ready(function() {
jweixin.checkJsApi({
jsApiList: ['chooseWXPay'], // JSJS2,
success: function(res) {},
fail: function(res) {}
});
jweixin.chooseWXPay({
appId: self.appId,
timestamp: self
.timeStamp, // jssdk使timestamp使timeStampS
nonceStr: self.nonceStr, // 32
package: self.package, // prepay_idprepay_id=***
signType: self.signType, // 'SHA1'使'MD5'
paySign: self.sign, //
success: function(res) {
//
uni.showToast({
title: '支付成功'
})
},
cancel: function(r) {},
fail: function(res) {}
});
});
jweixin.error(function(res) {
uni.showToast({
icon: 'none',
title: '支付失败了',
duration: 2000
});
}); });
}
},
//
alipayRequest(item) {
// // provideralipay
uni.requestPayment({ // uniapp
provider: 'alipay', // wxpay
orderInfo: item, //
success: function(res) {
this.show1 = false
uni.showToast({
title: "支付成功",
icon: 'success',
duration: 2000
// success: () => {
// setTimeout(() => {
// uni.switchTab({
// url: '/pages/index/index'
// })
// }, 500)
// }
})
},
fail: function(err) {
uni.showToast({
title: "支付失败请稍后再试",
icon: 'none',
duration: 2000
// success: () => {
// setTimeout(() => {
// uni.switchTab({
// url: '/pages/my/my'
// })
// }, 500)
// }
})
}
}); });
}, },
} }
} }
@ -1086,4 +1176,4 @@
} }
} }
</style> </style>

@ -18,29 +18,42 @@
onLoad(options) { onLoad(options) {
var arr1 = window.location.href; var arr1 = window.location.href;
var arr2 = arr1.split('='); var arr2 = arr1.split('=');
if (arr2[1].length == 12) { if (app.globalData.platformType == 'WECHAT') {
if (arr2[1].length == 12) {
var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0];
uni.setStorage({
key: "snNumber",
data: arr3[0]
})
this.jumpWeb();
} else {
let that = this;
var arr4 = arr2[2].split('&');
app.globalData.code = arr4[0];
uni.getStorage({
key: 'snNumber',
success(e) {
app.globalData.snNo = e.data;
// that.getQrCodeDetail();
}
})
}
if (app.globalData.code) {
this.getH5AccessToken();
}
} else {
var arr3 = arr2[1].split('#/'); var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0]; app.globalData.snNo = arr3[0];
uni.setStorage({ uni.setStorage({
key: "snNumber", key: "snNumber",
data: arr3[0] data: arr3[0]
}) })
this.jumpWeb(); uni.reLaunch({
} else { url: '../index/index'
let that = this;
var arr4 = arr2[2].split('&');
app.globalData.code = arr4[0];
uni.getStorage({
key: 'snNumber',
success(e) {
app.globalData.snNo = e.data;
// that.getQrCodeDetail();
}
}) })
} }
if (app.globalData.code) {
this.getH5AccessToken();
}
}, },
methods: { methods: {
@ -55,9 +68,9 @@
uni.setStorage({ uni.setStorage({
key: "openId", key: "openId",
data: res.return_data.openid data: res.return_data.openid
}) })
uni.reLaunch({ uni.reLaunch({
url:'../index/index' url: '../index/index'
}) })
} else { } else {
this.jumpWeb(); this.jumpWeb();
@ -75,4 +88,4 @@
<style> <style>
</style> </style>
Loading…
Cancel
Save