1.新增支付宝支付

2.优化微信支付
dev
杨杰 2 years ago
parent ba900b6440
commit 578ff3f9df
  1. 21
      App.vue
  2. 5
      Utils/Api.js
  3. 1998
      Utils/js/alipay.js
  4. 2
      index.html
  5. 79
      pages/index/index.vue
  6. 52
      pages/welcome/welcome.vue

@ -26,18 +26,21 @@
// imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', // imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/',
}, },
onLaunch: function() { onLaunch: function() {
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')
let that = this; let that = this;
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.match(/Alipay/i) == "alipay") {
that.globalData.platformType = 'ALIPAY';
} else if (userAgent.match(/MicroMessenger/i) == "micromessenger") {
that.globalData.platformType = 'WECHAT';
} else {
that.globalData.platformType = 'UQRCODEPAY';
}
uni.getStorage({ uni.getStorage({
key: 'openId', key: 'openId',
success(e) { success(e) {

@ -31,6 +31,11 @@ export const calculation = params => {
export const getH5AccessToken = params => { export const getH5AccessToken = params => {
return POST('GET', `${base}/wechat/getH5AccessToken`, params).then(res => res.data); return POST('GET', `${base}/wechat/getH5AccessToken`, params).then(res => res.data);
} }
//支付宝获取openid
export const getAlipayUserId = params => {
return POST('GET', `${grabase}/login/getAlipayUserId`, params).then(res => res.data);
}
//获取登录验证码 //获取登录验证码
export const getLoginSMSCode = params => { export const getLoginSMSCode = params => {

File diff suppressed because it is too large Load Diff

@ -6,7 +6,7 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" /> 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-->
</head> </head>
<body> <body>
<div id="app"><!--app-html--></div> <div id="app"><!--app-html--></div>

@ -207,6 +207,7 @@
import passwordInput from "../../components/password-input/password-input.vue"; import passwordInput from "../../components/password-input/password-input.vue";
import cjSlider from '../../components/cj-slider/cj-slider.vue'; import cjSlider from '../../components/cj-slider/cj-slider.vue';
import wybPopup from '../../components/wyb-popup/wyb-popup.vue'; import wybPopup from '../../components/wyb-popup/wyb-popup.vue';
import alipayApi from '../../Utils/js/alipay.js';
import { import {
getQrCodeDetail, getQrCodeDetail,
getH5AccessToken, getH5AccessToken,
@ -714,12 +715,12 @@
return; return;
} }
if (res.return_data.payParam && app.globalData.platformType == 'ALIPAY') { if (res.return_data.payParam && app.globalData.platformType == 'ALIPAY') {
this.alipayRequest(res.return_data.acc_resp_fields.paepay_id); this.alipayRequest(res.return_data.payParam.acc_resp_fields.prepay_id);
return; return;
} }
if (res.return_data.payParam && app.globalData.platformType == 'UQRCODEPAY') { if (res.return_data.payParam && app.globalData.platformType == 'UQRCODEPAY') {
// this.unionPayRequest(res.return_data); // this.unionPayRequest(res.return_data);
window.location.href = res.return_data.acc_resp_fields.redirect_url; location.href = res.return_data.payParam.acc_resp_fields.redirect_url;
return; return;
} }
uni.showToast({ uni.showToast({
@ -848,11 +849,11 @@
}) })
if (self.platformType == 1) { if (self.platformType == 1) {
jweixin.config({ jweixin.config({
debug: true, // ,apialertpclogpc debug: false, // ,apialertpclogpc
appId: self.acc_resp_fields.app_id, // appId: self.payParam.acc_resp_fields.app_id, //
timestamp: self.acc_resp_fields.time_stamp, // timestamp: self.payParam.acc_resp_fields.time_stamp, //
nonceStr: self.acc_resp_fields.nonce_str, // nonceStr: self.payParam.acc_resp_fields.nonce_str, //
signature: self.acc_resp_fields.pay_sign, // 1 signature: self.payParam.acc_resp_fields.pay_sign, // 1
jsApiList: ['chooseWXPay'] // 使JSJS2 jsApiList: ['chooseWXPay'] // 使JSJS2
}); });
uni.hideLoading(); uni.hideLoading();
@ -863,14 +864,15 @@
fail: function(res) {} fail: function(res) {}
}); });
jweixin.chooseWXPay({ jweixin.chooseWXPay({
appId: self.acc_resp_fields.app_id, appId: self.payParam.acc_resp_fields.app_id,
timestamp: self.acc_resp_fields timestamp: self.payParam.acc_resp_fields
.time_stamp, // jssdk使timestamp使timeStampS .time_stamp, // jssdk使timestamp使timeStampS
nonceStr: self.acc_resp_fields.nonce_str, // 32 nonceStr: self.payParam.acc_resp_fields.nonce_str, // 32
package: self.acc_resp_fields package: self.payParam.acc_resp_fields
.package, // prepay_idprepay_id=*** .package, // prepay_idprepay_id=***
signType: self.acc_resp_fields.sign_type, // 'SHA1'使'MD5' signType: self.payParam.acc_resp_fields
paySign: self.acc_resp_fields.pay_sign, // .sign_type, // 'SHA1'使'MD5'
paySign: self.payParam.acc_resp_fields.pay_sign, //
success: function(res) { success: function(res) {
// //
uni.showToast({ uni.showToast({
@ -891,10 +893,10 @@
} else { } else {
jweixin.config({ jweixin.config({
debug: false, // ,apialertpclogpc debug: false, // ,apialertpclogpc
appId: self.appId, // appId: self.payParam.appId, //
timestamp: self.timeStamp, // timestamp: self.payParam.timeStamp, //
nonceStr: self.nonceStr, // nonceStr: self.payParam.nonceStr, //
signature: self.sign, // 1 signature: self.payParam.sign, // 1
jsApiList: ['chooseWXPay'] // 使JSJS2 jsApiList: ['chooseWXPay'] // 使JSJS2
}); });
uni.hideLoading(); uni.hideLoading();
@ -933,40 +935,13 @@
}, },
// //
alipayRequest(item) { alipayRequest(item) {
// // provideralipay alipayApi.tradePay({
uni.requestPayment({ // uniapp tradeNO: item
provider: 'alipay', // wxpay }, function(res) {
orderInfo: item, // // alert(JSON.stringify(res));
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)
// }
})
}
}); });
}, },
} }
@ -975,6 +950,10 @@
</script> </script>
<style lang="scss"> <style lang="scss">
page {
background-color: #ffffff;
}
.form { .form {
width: 100%; width: 100%;
border-radius: 8px; border-radius: 8px;

@ -7,6 +7,7 @@
<script> <script>
import { import {
getH5AccessToken, getH5AccessToken,
getAlipayUserId
} from '../../Utils/Api.js'; } from '../../Utils/Api.js';
let app = getApp(); let app = getApp();
export default { export default {
@ -18,7 +19,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 (app.globalData.platformType == 'WECHAT' || app.globalData.platformType == 'ALIPAY') {
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];
@ -29,20 +30,30 @@
this.jumpWeb(); this.jumpWeb();
} else { } else {
let that = this; let that = this;
var arr4 = arr2[2].split('&'); var arr4;
if (app.globalData.platformType == 'WECHAT') {
arr4 = arr2[2].split('&');
} else {
arr4 = arr2[1].split('&');
}
app.globalData.code = arr4[0]; app.globalData.code = arr4[0];
uni.getStorage({ uni.getStorage({
key: 'snNumber', key: 'snNumber',
success(e) { success(e) {
app.globalData.snNo = e.data; app.globalData.snNo = e.data;
// that.getQrCodeDetail();
} }
}) })
} }
if (app.globalData.code) {
if (app.globalData.code && app.globalData.platformType == 'WECHAT') {
this.getH5AccessToken(); this.getH5AccessToken();
} }
if (app.globalData.code && app.globalData.platformType == 'ALIPAY') {
this.getAlipayUserId();
}
} else { } else {
var arr1 = window.location.href;
var arr2 = arr1.split('=');
var arr3 = arr2[1].split('#/'); var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0]; app.globalData.snNo = arr3[0];
uni.setStorage({ uni.setStorage({
@ -53,11 +64,10 @@
url: '../index/index' url: '../index/index'
}) })
} }
}, },
methods: { methods: {
//H5 openId //H5 openId
getH5AccessToken() { getH5AccessToken() {
let params = { let params = {
code: app.globalData.code code: app.globalData.code
@ -77,10 +87,36 @@
} }
}); });
}, },
//openid
getAlipayUserId() {
let params = {
code: app.globalData.code
}
getAlipayUserId(params).then(res => {
if (res.return_code == '000000' && res.return_data.userId) {
app.globalData.openId = res.return_data.userId;
uni.setStorage({
key: "openId",
data: res.return_data.userId
})
uni.reLaunch({
url: '../index/index'
})
} else {
this.jumpWeb();
}
});
},
// //
jumpWeb() { jumpWeb() {
location.href = if (app.globalData.platformType == 'WECHAT') {
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa075e8509802f826&redirect_uri=https://hsg.dctpay.com/wechat_authorize/?redirect_uri=https://hsg.dctpay.com/scanPay&response_type=code&scope=snsapi_base#wechat_redirect'; location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa075e8509802f826&redirect_uri=https://hsg.dctpay.com/wechat_authorize/?redirect_uri=https://pay.dctpay.com/scanPay&response_type=code&scope=snsapi_base#wechat_redirect';
}
if (app.globalData.platformType == 'ALIPAY') {
location.href =
'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021003176605875&scope=auth_base&redirect_uri=https%3A%2F%2Fpay.dctpay.com%2FscanPay';
}
}, },
} }
} }

Loading…
Cancel
Save