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

dev
杨杰 2 years ago
parent aeba6f0ab4
commit ba900b6440
  1. 12
      App.vue
  2. 3
      index.html
  3. 110
      pages/index/index.vue
  4. 15
      pages/welcome/welcome.vue

@ -13,9 +13,10 @@
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/',
// //
@ -25,7 +26,14 @@
// 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')

@ -2,7 +2,8 @@
<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"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<title></title> <title></title>
<!--preload-links--> <!--preload-links-->
<!--app-context--> <!--app-context-->

@ -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;
}
if (res.return_data.payParam && app.globalData.platformType == 'ALIPAY') {
this.alipayRequest(res.return_data.acc_resp_fields.paepay_id);
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({ uni.showToast({
title: '单比金额最多10000000元', title: res.return_msg,
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}) })
}
} else { } else {
uni.showToast({ uni.showToast({
title: res.return_msg, title: res.return_msg,
@ -833,10 +842,53 @@
}, },
// //
payRequest: function(self) { wechatpayRequest: function(self) {
uni.showLoading({ uni.showLoading({
title: '支付中...' title: '支付中...'
}) })
if (self.platformType == 1) {
jweixin.config({
debug: true, // ,apialertpclogpc
appId: self.acc_resp_fields.app_id, //
timestamp: self.acc_resp_fields.time_stamp, //
nonceStr: self.acc_resp_fields.nonce_str, //
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({
appId: self.acc_resp_fields.app_id,
timestamp: self.acc_resp_fields
.time_stamp, // jssdk使timestamp使timeStampS
nonceStr: self.acc_resp_fields.nonce_str, // 32
package: self.acc_resp_fields
.package, // prepay_idprepay_id=***
signType: self.acc_resp_fields.sign_type, // 'SHA1'使'MD5'
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({
icon: 'none',
title: '支付失败了',
duration: 4000
});
});
} else {
jweixin.config({ jweixin.config({
debug: false, // ,apialertpclogpc debug: false, // ,apialertpclogpc
appId: self.appId, // appId: self.appId, //
@ -870,15 +922,53 @@
fail: function(res) {} fail: function(res) {}
}); });
}); });
jweixin.error(function(res) { jweixin.error(function(res) {
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '支付失败了', title: '支付失败了',
duration: 4000 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)
// }
})
}
});
}, },
} }
} }

@ -18,6 +18,7 @@
onLoad(options) { onLoad(options) {
var arr1 = window.location.href; var arr1 = window.location.href;
var arr2 = arr1.split('='); var arr2 = arr1.split('=');
if (app.globalData.platformType == 'WECHAT') {
if (arr2[1].length == 12) { if (arr2[1].length == 12) {
var arr3 = arr2[1].split('#/'); var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0]; app.globalData.snNo = arr3[0];
@ -41,6 +42,18 @@
if (app.globalData.code) { if (app.globalData.code) {
this.getH5AccessToken(); this.getH5AccessToken();
} }
} else {
var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0];
uni.setStorage({
key: "snNumber",
data: arr3[0]
})
uni.reLaunch({
url: '../index/index'
})
}
}, },
methods: { methods: {
@ -57,7 +70,7 @@
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();

Loading…
Cancel
Save