Happy New Year!

uni-app 支付宝支付

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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//封装全局APP支付方法
import {weixinPay} from "@/utils/api/api.js"; //微信支付
import {aliPay} from "@/utils/api/api.js"; //支付宝支付
//封装APP支付方法
/**
 * 参数1 必传 log_id
 * 参数2  money  价格
 * 参数3  e 1微信支付 2支付宝支付
 * 参数4 order_id  订单id
 * 参数5  type  订单类型
 * **/
const apppay =  (log_id,money,e,order_id,type,isshowmode=true)=>{
    return new Promise((resolve,reject)=>{
        if(e==1){ //微信支付
            weixinPay({
                log_id:log_id,//=》支付日志id
                amount:money,//=》支付金额
                //区分是什么设备  wechat  app
                // #ifdef APP-PLUS
                user_type:"app",
                // #endif
                // #ifndef APP-PLUS
                user_type:"wechat",
                // #endif
                 
            }).then(res=>{
                console.info("111",res);
                uni.hideLoading();
                if(res.code ==1){
                     
                    // #ifdef APP-PLUS
                    let orderInfo = res.data.result;
                    console.info("orderInfo",orderInfo);
                    uni.requestPayment({
                        provider:"wxpay" ,
                        orderInfo:orderInfo,
                        success: (e) => {
                            if(isshowmode){
                                uni.showToast({
                                    title:'支付成功',
                                    icon:'none'
                                });
                            }
                             
                            resolve(res);
                        },
                        fail: (e) => {
                            console.info("支付错误",e);
                            uni.showToast({
                                title:'取消支付',
                                icon:'none'
                            })
                            reject(false);
                        },
                        complete: (e) => {
                            console.info("e",e);
                            reject(false);
                        }
                    })
                     
                    // #endif
                     
                     
                    //小程序支付
                    // #ifndef APP-PLUS
                    let objinfo = {
                        timeStamp: res.data.result.timeStamp,
                        nonceStr: res.data.result.nonceStr,
                        package: res.data.result.package,
                        signType: res.data.result.signType,
                        paySign: res.data.result.paySign,
                    };
                    wx.requestPayment({
                        provider: "wxpay",
                        // orderInfo: objinfo,
                        ...objinfo,
                        success: (e) => {
                            resolve(true);
                        },
                        fail: (e) => {
                            console.info(e,"错误");
                            uni.showToast({
                                title: '取消支付',
                                icon: 'none'
                            })
                            reject(false);
                        },
                        complete: (e) => {
                            reject(false);
                        }
                    })
                    // #endif
                    //----------------小程序微信支付-------------------
                     
                     
                     
                }else{
                    uni.showToast({
                        title:res.msg,
                        icon:'none'
                    })
                }
                 
            }).catch(err=>{
                console.info("err",err);
                uni.hideLoading();
                reject(false);
            })
             
        }else{ //支付宝支付
            aliPay({
                log_id:log_id,
                amount:money,
            }).then(res=>{
                console.info(res,"res");
                uni.hideLoading();
                 
                // https://segmentfault.com/q/1010000022492163?bd_source_light=4746641
                //--------------H5 PLUS --------------------------------
                 
                // try{
                //  let channel;
                //  plus.payment.getChannels((channels) =>{
                //          channel = channels[1];
                //          let payserve = res.data.response;
                //          // 手机调用请求
                //          plus.payment.request(channel,payserve,(result)=>{
                //                  // plus.nativeUI.alert("支付成功!", function() {
                //                  //  back();
                //                  // });
                //                  reject(true);
                //              },(error)=>{
                //                  let err = JSON.stringify(
                //                      "支付失败:" + error.code + error.message
                //                  );
                //                  uni.showToast({
                //                      title:'取消支付',
                //                      icon:'none'
                //                  })
                //                  console.info(err);
                //                  reject(false);
                //              }
                //          );
                             
                //      },function(e) {
                //          console.info("获取支付通道失败:" + e.message);
                //          uni.showToast({
                //              title:'取消支付',
                //              icon:'none'
                //          })
                //          reject(false);
                //      }
                //  );
                // }catch(e){
                //  console.info("catch e:" + e);
                //  uni.showToast({
                //      title:'取消支付',
                //      icon:'none'
                //  })
                //  reject(false);
                // }
                 
                //----------------------------------------------
                 
                 
                //-------------------------uni-APP ALIAPY-------------------------------------
                try{
                    console.info("----------5555555555-----");
                    uni.requestPayment({
                        provider:"alipay" ,
                        orderInfo:res.data.response,//params,//res.data,
                        success: (e) => {
                            if(isshowmode){
                                uni.showToast({
                                    title:'支付成功',
                                    icon:'none'
                                });
                            }
                            resolve(res);
                        },
                        fail: (err) => {
                            console.info("支付错误",err);
                            uni.showToast({
                                title:'取消支付',
                                icon:'none'
                            })
                            reject(false);
                        },
                        complete: (e) => {
                            console.info("err",e);
                            reject(false);
                        }
                    })
                }catch(e){
                    console.info('e',e);
                }
                 
                //--------------------------------------------------------------
                 
            }).catch(err=>{
                console.info("err",err);
                uni.hideLoading();
                reject(false);
            })
        }
         
    });
 
}
 
export {apppay}

  

posted @   义美-小义  阅读(468)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Blazor Hybrid适配到HarmonyOS系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
· 分享4款.NET开源、免费、实用的商城系统
历史上的今天:
2021-05-07 CenterOS linux 下node的安装以及环境配置 linux配置node环境 pm2 常用命令
返回顶部小火箭
世界很公平,想要最好,就一定得付出!
x
github主页
点击右上角即可分享
微信分享提示