-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathPayPage.js
94 lines (81 loc) · 3.15 KB
/
PayPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* User: puti.
* Time: 2018/2/7 下午8:22.
* GitHub:https://github.com/puti94
* Email:guoquanxie@foxmail.com
*/
import React, {Component} from 'react';
import {ScrollView} from 'react-native'
import {observer} from 'mobx-react'
import {ListRow, Toast} from 'teaset'
import {appStateStore} from '../store'
import {BaseContainer} from "../components";
import XPay from 'react-native-puti-pay'
@observer
export default class PayPage extends Component {
constructor(props) {
super(props);
this.state = {
modelShow: false
};
XPay.setWxId('wxb4ba3c02aa476ea1');
//设置 支付宝URL Schemes
XPay.setAlipayScheme('ap2017102209453437')
}
componentDidMount() {
console.log('参数',this.props)
}
wxPay = async () => {
if (!appStateStore.isWXInstall) {
alert('微信未安装');
return;
}
const res = await fetch('https://wxpay.wxutil.com/pub_v2/app/app_pay.php');
const params = await res.json();
console.log('支付参数', params);
const {partnerid, noncestr, timestamp, prepayid, sign} = params;
XPay.wxPay({
partnerId: partnerid,
prepayId: prepayid,
packageValue: params.package,
nonceStr: noncestr,
timeStamp: String(timestamp),
sign: sign
},
res => {
console.log('回调', res);
const {errCode} = res;
if (errCode === 0 || errCode === '0') {
Toast.success('充值成功')
} else {
Toast.fail('充值失败')
}
})
};
aliPay = () => {
XPay.alipay('app_id=2015052600090779&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_trade_no%22%3A%22IQJZSRC1YMQB5HU%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fdomain.merchant.com%2Fpayment_notify&sign_type=RSA2×tamp=2016-08-25%2020%3A26%3A31&version=1.0&sign=cYmuUnKi5QdBsoZEAbMXVMmRWjsuUj%2By48A2DvWAVVBuYkiBj13CFDHu2vZQvmOfkjE0YqCUQE04kqm9Xg3tIX8tPeIGIFtsIyp%2FM45w1ZsDOiduBbduGfRo1XRsvAyVAv2hCrBLLrDI5Vi7uZZ77Lo5J0PpUUWwyQGt0M4cj8g%3D',
res => {
console.log('回调', res);
const {result, memo, resultStatus} = res;
if (resultStatus === '9000') {
Toast.success('充值成功')
} else {
Toast.fail('充值失败')
}
})
};
render() {
return (<BaseContainer title={'支付'}>
<ScrollView style={{flex: 1}}>
<ListRow
title="微信支付"
onPress={this.wxPay}
/>
<ListRow
title="支付宝支付"
onPress={this.aliPay}
/>
</ScrollView>
</BaseContainer>);
}
}