Skip to content

Commit 92bc75b

Browse files
committed
增加支付宝APP支付
1 parent c24b1a5 commit 92bc75b

File tree

128 files changed

+9161
-4407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+9161
-4407
lines changed

App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
merchantId: '951', // 42151
1010
version: '0.0.2',
1111
sysconfigkeys: 'mallName,shopMod,share_profile,recharge_amount_min,open_growth,shopping_cart_vop_open',
12-
wxpayOpenAppId: 'wx9b04553fd8c7b9c3' // 微信开放平台的移动端应用appID
12+
wxpayOpenAppId: 'wx9b04553fd8c7b9c3', // 微信开放平台的移动端应用appID
13+
openAlipayProvider: true, // 是否开通支付宝支付
1314
},
1415
onLaunch: function() {
1516
// https://www.yuque.com/apifm/nu0f75/cdqz1n

common/pay.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
const WXAPI = require('apifm-uniapp')
2+
import store from '@/store'
3+
4+
/**
5+
* provider 支付通道 alipay wxpay baidu appleiap
6+
* postDataExt 需要额外提交的参数放这里,如果没有额外提交参数,填 {}
7+
* money: 发起支付的金额
8+
* payName: 弹起用户观看的付款信息
9+
* remark 本次支付的备注信息,记录在后台支付记录的备注字段
10+
* nextAction 下一步需要做的工作,充值请填 null
11+
* successFuc 支付成功的回调函数
12+
* failFuc 支付失败的回调函数
13+
*/
14+
function pay(provider, postDataExt, money, payName, remark, nextAction, successFuc, failFuc) {
15+
const postData = {
16+
token: store.state.token,
17+
money,
18+
payName,
19+
remark,
20+
...postDataExt
21+
}
22+
if (nextAction) {
23+
postData.nextAction = JSON.stringify(nextAction)
24+
}
25+
// #ifdef H5
26+
const ua = window.navigator.userAgent.toLowerCase();
27+
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
28+
// 微信浏览器
29+
WXAPI.wxpayJsapi(postData).then(res => {
30+
if (res.code != 0) {
31+
uni.showToast({
32+
title: res.msg,
33+
icon: 'none'
34+
})
35+
return
36+
}
37+
window.WeixinJSBridge.invoke(
38+
'getBrandWCPayRequest', {
39+
'appId': res.data.appid,
40+
'timeStamp': res.data.timeStamp,
41+
'nonceStr': res.data.nonceStr,
42+
'package': 'prepay_id=' + res.data.prepayId,
43+
'signType': 'MD5',
44+
'paySign': res.data.sign
45+
},
46+
function(res) {
47+
if (res.err_msg === 'get_brand_wcpay_request:ok') {
48+
successFuc()
49+
} else {
50+
failFuc()
51+
}
52+
})
53+
})
54+
return
55+
} else {
56+
// 普通浏览器
57+
WXAPI.wxpayH5(postData).then(res => {
58+
if (res.code != 0) {
59+
uni.showToast({
60+
title: res.msg,
61+
icon: 'none'
62+
})
63+
return
64+
}
65+
window.location.href = res.data.mweb_url
66+
})
67+
return
68+
}
69+
// #endif
70+
// #ifdef MP-WEIXIN
71+
if (provider == 'wxpay') {
72+
WXAPI.wxpay(postData).then(res => {
73+
if (res.code != 0) {
74+
uni.showToast({
75+
title: res.msg,
76+
icon: 'none'
77+
})
78+
return
79+
}
80+
uni.requestPayment({
81+
timeStamp: res.data.timeStamp,
82+
nonceStr: res.data.nonceStr,
83+
package: res.data.package,
84+
signType: res.data.signType,
85+
paySign: res.data.paySign,
86+
fail: (err) => {
87+
console.error(err);
88+
failFuc(err)
89+
},
90+
success: () => {
91+
successFuc()
92+
}
93+
})
94+
})
95+
}
96+
// #endif
97+
// #ifdef APP-PLUS
98+
if (provider == 'wxpay') {
99+
const res = WXAPI.wxpayApp(postData).then(res => {
100+
if (res.code != 0) {
101+
uni.showToast({
102+
title: res.msg,
103+
icon: 'none'
104+
})
105+
return
106+
}
107+
uni.requestPayment({
108+
provider: 'wxpay', // alipay wxpay baidu appleiap
109+
orderInfo: res.data, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
110+
success: () => {
111+
successFuc()
112+
},
113+
fail: (err) => {
114+
console.error(err);
115+
failFuc(err)
116+
}
117+
})
118+
})
119+
return
120+
}
121+
if (provider == 'alipay') {
122+
const res = WXAPI.alipayAPP(postData).then(res => {
123+
if (res.code != 0) {
124+
uni.showToast({
125+
title: res.msg,
126+
icon: 'none'
127+
})
128+
return
129+
}
130+
uni.requestPayment({
131+
provider: 'alipay', // alipay wxpay baidu appleiap
132+
orderInfo: res.data.url, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
133+
success: () => {
134+
successFuc()
135+
},
136+
fail: (err) => {
137+
console.error(err);
138+
failFuc(err)
139+
}
140+
})
141+
})
142+
return
143+
}
144+
// #endif
145+
}
146+
147+
module.exports = {
148+
pay: pay
149+
}

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
},
8282
"payment" : {
8383
"weixin" : {
84-
"__platform__" : [ "ios", "android" ],
84+
"__platform__" : [ "android" ],
8585
"appid" : "wx9b04553fd8c7b9c3",
8686
"UniversalLinks" : "https://static-80ab3332-a88f-4a44-8486-06fa7fc6392f.bspapp.com/uni-universallinks/__UNI__151F11E/"
8787
}

node_modules/apifm-uniapp/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/apifm-uniapp/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"test": "eslint . --fix"
55
},
66
"devDependencies": {
7-
"apifm-uniapp": "^3.51.0",
7+
"apifm-uniapp": "^3.53.0",
88
"eslint": "^8.2.0",
99
"eslint-config-airbnb": "^19.0.0",
1010
"vue-i18n": "^8.20.0",

pages/asset/recharge.vue

Lines changed: 9 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</template>
1717

1818
<script>
19-
const wxpay = require('@/common/wxpay.js')
19+
const PAY = require('@/common/pay.js')
2020
export default {
2121
data() {
2222
return {
@@ -62,85 +62,16 @@
6262
return
6363
}
6464
// 发起在线支付
65-
// #ifdef MP-WEIXIN
66-
wxpay.wxpay('recharge', this.amount, 0, '/pages/asset/balance')
67-
// #endif
68-
// #ifdef H5
69-
const ua = window.navigator.userAgent.toLowerCase();
70-
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
71-
// https://www.yuque.com/apifm/nu0f75/mghxuo
72-
res = await this.$wxapi.wxpayJsapi({
73-
token: this.token,
74-
money: this.amount,
75-
remark: '在线充值',
76-
payName: '在线充值'
65+
PAY.pay('wxpay', {
66+
appid: getApp().globalData.wxpayOpenAppId
67+
}, this.amount, '在线充值', '在线充值', null, () => {
68+
uni.navigateBack()
69+
}, () => {
70+
uni.showToast({
71+
title: '支付失败',
72+
icon: 'none'
7773
})
78-
if(res.code != 0) {
79-
uni.showToast({
80-
title: res.msg,
81-
icon: 'none'
82-
})
83-
return
84-
}
85-
window.WeixinJSBridge.invoke(
86-
'getBrandWCPayRequest', {
87-
'appId': res.data.appid,
88-
'timeStamp': res.data.timeStamp,
89-
'nonceStr': res.data.nonceStr,
90-
'package': 'prepay_id=' + res.data.prepayId,
91-
'signType': 'MD5',
92-
'paySign': res.data.sign
93-
},
94-
function(res) {
95-
if (res.err_msg === 'get_brand_wcpay_request:ok') {
96-
uni.navigateBack()
97-
}
98-
})
99-
} else {
100-
// 普通浏览器,调用h5支付
101-
// https://www.yuque.com/apifm/nu0f75/pv7gll
102-
const res = await this.$wxapi.wxpayH5({
103-
token: this.token,
104-
money: this.amount,
105-
remark: '在线充值',
106-
payName: '在线充值'
107-
})
108-
if(res.code != 0) {
109-
uni.showToast({
110-
title: res.msg,
111-
icon: 'none'
112-
})
113-
uni.navigateBack()
114-
return
115-
}
116-
location.href = res.data.mweb_url
117-
}
118-
// #endif
119-
// #ifdef APP-PLUS
120-
// https://www.yuque.com/apifm/nu0f75/uvauoz
121-
const res = await this.$wxapi.wxpayApp({
122-
token: this.token,
123-
appid: getApp().globalData.wxpayOpenAppId,
124-
money: this.amount,
125-
remark: '在线充值',
126-
payName: '在线充值'
127-
})
128-
uni.requestPayment({
129-
provider: 'wxpay', // alipay wxpay baidu appleiap
130-
orderInfo: res.data, // https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
131-
success: res => {
132-
uni.navigateTo({
133-
url: "/pages/asset/balance"
134-
})
135-
},
136-
fail: err => {
137-
uni.showToast({
138-
title: '支付失败',
139-
icon: 'none'
140-
})
141-
}
14274
})
143-
// #endif
14475
}
14576
}
14677
}

0 commit comments

Comments
 (0)