quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * 支付
 */
export const pay = (result, self, success, fail) => {
    if (result.code === -10) {
        self.showError(result.msg);
        return false;
    }
 
    // 发起微信支付
    if (result.data.pay_type == 20) {
        //小程序支付
        // #ifdef  MP-WEIXIN    
        uni.requestPayment({
            provider: 'wxpay',
            timeStamp: result.data.payment.timeStamp,
            nonceStr: result.data.payment.nonceStr,
            package: 'prepay_id=' + result.data.payment.prepay_id,
            signType: 'MD5',
            paySign: result.data.payment.paySign,
            success: res => {
                paySuccess(result, self, success);
            },
            fail: res => {
                self.showError('订单未支付成功', () => {
                    payError(result, fail);
                });
            },
        });
        // #endif
        //公众号支付
        // #ifdef  H5
        if (self.isWeixin()) {
            WeixinJSBridge.invoke('getBrandWCPayRequest', JSON.parse(result.data.payment),
                function(res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                        paySuccess(result, self, success);
                    } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                        self.showSuccess('支付取消', () => {
                            payError(result, fail);
                        });
                    } else {
                        self.showError('订单未支付成功', () => {
                            payError(result, fail);
                        });
                    }
                }
            );
        } else {
            window.location.href = result.data.payment.mweb_url + '&redirect_url=' + result.data.return_Url;
            return;
        }
        // #endif
        // #ifdef  APP-PLUS
        //微信支付
        wxAppPay(result, self, success, fail);
        return;
        // #endif
    }
    // 余额支付
    if (result.data.pay_type == 10) {
        paySuccess(result, self, success);
    }
    // 激活码支付
    if (result.data.pay_type == 50) {
        paySuccess(result, self, success);
    }
    // 联盟币支付
    if (result.data.pay_type == 60) {
        paySuccess(result, self, success);
    }
    // 支付宝支付
    if (result.data.pay_type == 30) {
        // #ifdef  APP-PLUS
        aliAppPay(result, self, success, fail);
        // #endif
        // #ifdef  H5
        const div = document.createElement('formdiv');
        div.innerHTML = result.data.payment;
        document.body.appendChild(div);
        document.forms[0].submit();
        div.remove();
        // #endif
    }
}
 
/*跳到支付成功页*/
function paySuccess(result, self, success) {
    if (success) {
        success(result);
        return;
    }
    gotoSuccess(result);
}
/*跳到支付成功页*/
function gotoSuccess(result) {
    if (result.data.order_type == 100) {
        uni.reLaunch({
            url: '/pages/plus/business/detail?business_card_id=' + result.data.business_card_id
        });
    } else {
        uni.reLaunch({
            url: '/pages/order/pay-success/pay-success?order_id=' + result.data.order_id
        });
    }
 
}
 
/*支付失败跳订单详情*/
function payError(result, fail) {
    if (fail) {
        fail(result);
        return;
    }
    uni.redirectTo({
        url: '/pages/order/order-detail?order_id=' + result.data.order_id
    });
}
 
function wxAppPay(result, self, success, fail) {
    // 获取支付通道  
    plus.payment.getChannels(function(channels) {
        self.channel = channels[0];
        console.log(self.channel);
        uni.requestPayment({
            provider: 'wxpay',
            orderInfo: result.data.payment,
            success(res) {
                paySuccess(result, self, success);
            },
            fail(error) {
                console.log(error);
                self.showError('订单未支付成功', () => {
                    payError(result, fail);
                });
            },
        });
    }, function(e) {
        console.log("获取支付通道失败:" + e.message);
    });
}
 
function aliAppPay(result, self, success, fail) {
    console.log(result.data.payment);
    uni.requestPayment({
        provider: 'alipay',
        orderInfo: result.data.payment,
        success(res) {
            paySuccess(result, self, success);
        },
        fail(error) {
            console.log(error);
            self.showError('订单未支付成功', () => {
                payError(result, fail);
            });
        },
    });
}