1.新增支付宝支付

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

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

@ -32,6 +32,11 @@ export const getH5AccessToken = params => {
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 => {
return POST('POST', `${base}/sms/getLoginSMSCode`, params).then(res => res.data);

File diff suppressed because it is too large Load Diff

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

@ -7,6 +7,7 @@
<script>
import {
getH5AccessToken,
getAlipayUserId
} from '../../Utils/Api.js';
let app = getApp();
export default {
@ -18,7 +19,7 @@
onLoad(options) {
var arr1 = window.location.href;
var arr2 = arr1.split('=');
if (app.globalData.platformType == 'WECHAT') {
if (app.globalData.platformType == 'WECHAT' || app.globalData.platformType == 'ALIPAY') {
if (arr2[1].length == 12) {
var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0];
@ -29,20 +30,30 @@
this.jumpWeb();
} else {
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];
uni.getStorage({
key: 'snNumber',
success(e) {
app.globalData.snNo = e.data;
// that.getQrCodeDetail();
}
})
}
if (app.globalData.code) {
if (app.globalData.code && app.globalData.platformType == 'WECHAT') {
this.getH5AccessToken();
}
if (app.globalData.code && app.globalData.platformType == 'ALIPAY') {
this.getAlipayUserId();
}
} else {
var arr1 = window.location.href;
var arr2 = arr1.split('=');
var arr3 = arr2[1].split('#/');
app.globalData.snNo = arr3[0];
uni.setStorage({
@ -53,11 +64,10 @@
url: '../index/index'
})
}
},
methods: {
//H5 openId
//H5 openId
getH5AccessToken() {
let params = {
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() {
location.href =
'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';
if (app.globalData.platformType == 'WECHAT') {
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