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',
code: '', //codeopenid
snNo: '', // sn
platformType: '', //
//
url: 'https://hsg.dctpay.com/user',
graurl:'https://pay.dctpay.com/crest',
url: 'https://hsg.dctpay.com/user',
graurl: 'https://pay.dctpay.com/crest',
imgUrl: 'https://pay.dctpay.com/filesystem/',
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',
// imgUrl: 'https://hsgcs.dctpay.com/filesystem/',
// 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')
@ -64,4 +72,4 @@
<style>
/*每个页面公共css */
</style>
</style>

@ -1,14 +1,15 @@
<!DOCTYPE html>
<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" />
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script>
</body>
</html>
<!DOCTYPE html>
<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" />
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script>
</body>
</html>

@ -656,8 +656,8 @@
icon: 'none'
})
this.payPrice = 0;
this.plateNumberList = [];
this.plateNumberList1 = [];
this.plateNumberList = [];
this.plateNumberList1 = [];
this.storediscountType = ''; //
this.storediscountCondition = ''; //
this.storediscountPrice = ''; //
@ -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 {
uni.showToast({
title: '单比金额最多10000000元',
icon: 'none',
duration: 2000
})
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: res.return_msg,
icon: 'none',
duration: 2000
})
} else {
uni.showToast({
title: res.return_msg,
@ -833,52 +842,133 @@
},
//
payRequest: function(self) {
wechatpayRequest: function(self) {
uni.showLoading({
title: '支付中...'
})
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) {}
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
});
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) {}
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
jweixin.error(function(res) {
uni.showToast({
icon: 'none',
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) {
var arr1 = window.location.href;
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('#/');
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();
}
uni.reLaunch({
url: '../index/index'
})
}
if (app.globalData.code) {
this.getH5AccessToken();
}
},
methods: {
@ -55,9 +68,9 @@
uni.setStorage({
key: "openId",
data: res.return_data.openid
})
uni.reLaunch({
url:'../index/index'
})
uni.reLaunch({
url: '../index/index'
})
} else {
this.jumpWeb();
@ -75,4 +88,4 @@
<style>
</style>
</style>
Loading…
Cancel
Save