payUtil.js
2.2 KB
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
import api from '../common/api.js';
import config from '../config';
function pay(data) {
let orderCode = data.order_code;
let param = {
order_code: orderCode,
payment_code: config.payment_code,
openid: "4g0Q-X0ny9uLHASv",
}
api.get({data: param,url:"/payment/alipay_data"})
.then(json=>{
let data = json.data;
if(data){
let payParams = data.payParams;
ttPayment(payParams);
}
})
}
//支付确认接口
function payConfirm(orderCode){
if(!orderCode||orderCode==0){
return
}
let param = {
method:'app.SpaceOrders.payConfirm',
order_code:orderCode,
payment_id:45,
// uid:"",
}
api.get({data: param})
.then(json=>{
})
}
function ttPayment(data){
let paymentData = JSON.parse(data);
let timestampStr = paymentData.timestamp+"";
let total_amount = parseFloat(paymentData.total_amount);
//头条需要该字段为String
paymentData.timestamp = timestampStr;
//头条需要该字段为数字
paymentData.total_amount = total_amount;
// let aliPayParam = paymentData.params;
// let aliParam = JSON.parse(aliPayParam);
// let testUrl = '_input_charset=\"utf-8\"&body=\"novel\"&it_b_pay=\"30m\"¬ify_url=\"https://tp-pay-test.snssdk.com/callback/ali_pay\"&out_trade_no=\"201808211755020406852103\"&partner=\"2088801374045154\"&payment_type=\"1\"&seller_id=\"adsense@bytedance.com\"&service=\"mobile.securitypay.pay\"&subject=\"测试的商品\"&total_fee=\"0.01\"&sign=\"RGdwAoCy5DsjdFBdtrN9WzdYtyZGlUHn8dbAQVQsIPidLTR9s%2BCVtAj%2BtYzL8oAHP0IXJZw8U6EGlyA2MG2ZxhJRI1N1RhDMZOz56eAXO%2FITZYiGSB01hkhx9yhqmWAUJQfUMRHJZswS1DEpwam1JfaoahZ%2Bf%2FEE%2FkvG6ma67t4%3D\"&sign_type=\"RSA\"'
// let testparam = {
// url: testUrl,
// }
// let url = JSON.stringify(testparam);
tt.requestPayment({
data:paymentData,
success (res) {
//支付成功以后跳转到支付成功页
console.log("pay success"+res.errMsg);
},
fail (res) {
console.log("pay fail"+res.errMsg);
}
})
}
module.exports = {
aliPay: pay,
}