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',
code: '', //codeopenid
snNo: '', // sn
platformType: '', //
//
url: 'https://hsg.dctpay.com/user',
graurl:'https://pay.dctpay.com/crest',
graurl: 'https://pay.dctpay.com/crest',
imgUrl: 'https://pay.dctpay.com/filesystem/',
imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/',
//
@ -25,7 +26,14 @@
// imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/',
},
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() {
console.log('App Show')

@ -2,7 +2,8 @@
<html lang="en">
<head>
<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>
<!--preload-links-->
<!--app-context-->

@ -671,7 +671,7 @@
// if (userAgent.match(/Alipay/i) == "alipay") {
// this.createJSAPIOrder('ALIPAY');
// } else if (userAgent.match(/MicroMessenger/i) == "micromessenger") {
this.createJSAPIOrder('WECHAT');
this.createJSAPIOrder();
// }
},
//
@ -684,7 +684,7 @@
let datas = {
"qrCodeSN": app.globalData.snNo,
"payUserId": app.globalData.openId,
"payMode": item,
"payMode": app.globalData.platformType,
"totalAmount": this.inputPrice,
"storeDiscountId": this.storeDiscountId,
"userDiscountId": this.memDiscountId,
@ -709,15 +709,24 @@
}
jsapiPay(datas).then(res => {
if (res.return_code == '000000') {
if (res.return_data.payParam) {
this.payRequest(res.return_data.payParam);
} else {
if (res.return_data.payParam && app.globalData.platformType == 'WECHAT') {
this.wechatpayRequest(res.return_data);
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({
title: '单比金额最多10000000元',
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
} else {
uni.showToast({
title: res.return_msg,
@ -833,10 +842,53 @@
},
//
payRequest: function(self) {
wechatpayRequest: function(self) {
uni.showLoading({
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({
debug: false, // ,apialertpclogpc
appId: self.appId, //
@ -870,15 +922,53 @@
fail: function(res) {}
});
});
jweixin.error(function(res) {
uni.showToast({
icon: 'none',
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) {
var arr1 = window.location.href;
var arr2 = arr1.split('=');
if (app.globalData.platformType == 'WECHAT') {
if (arr2[1].length == 12) {
var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0];
@ -41,6 +42,18 @@
if (app.globalData.code) {
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: {
@ -57,7 +70,7 @@
data: res.return_data.openid
})
uni.reLaunch({
url:'../index/index'
url: '../index/index'
})
} else {
this.jumpWeb();

Loading…
Cancel
Save