uniapp 让支付触手可及,封装了微信支付、QQ支付、支付宝支付、京东支付、银联支付常用的支付方式以及各种常用的接口
生活随笔
收集整理的這篇文章主要介紹了
uniapp 让支付触手可及,封装了微信支付、QQ支付、支付宝支付、京东支付、银联支付常用的支付方式以及各种常用的接口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載地址?https://gitee.com/zscat/mallplus
1.uniapp 接入各種h5支付
// 用戶點擊支付方式處理async toPayHandler(code) {let params = {'orderId':this.orderId};let data = {payment_code: code,payment_type: this.type}data['orderId'] = (this.type == 1 || this.type == 5 || this.type == 6) ? this.orderId : this.uidswitch (code) {case 'alipay':/*** 支付寶支付需要模擬GET提交數據*/if (this.type == 1 && this.orderId) {data['params'] = {trade_type: 'WAP',return_url: baseUrl +'wap/#/pages/order/payment/result'}} else if (this.type == 2 && this.recharge) {data['params'] = {money: this.recharge,return_url: baseUrl + 'wap/#/pages/order/payment/result'}} else if ((this.type == 5 || this.type == 6) && this.recharge) {data['params'] = {orderId: this.orderId}}let res = await Api.apiCall('get',Api.order.aliWapPay,params);console.log('============================')console.log(res);console.log('success:' + JSON.stringify(res));if (res) {document.body.appendChild(JSON.stringify(res))let testForm = document.getElementsByName('punchout_form')testForm.dispatchEvent(new Event('submit'))console.log(tempForm);testForm.submit()document.body.removeChild(testForm)}breakcase 'wechatpay':/*** 微信支付有兩種* 判斷是否在微信瀏覽器* 微信jsapi支付*/let isWeiXin = this.$common.isWeiXinBrowser()if (isWeiXin) {var transitUrl =baseUrl +'wap/#/pages/order/payment/auth?order_id=' +this.orderId +'&type=' +this.type;if (this.type == 1 && this.orderId) {data['params'] = {trade_type: 'JSAPI_OFFICIAL',url: transitUrl}} else if (this.type == 2 && this.recharge) {data['params'] = {trade_type: 'JSAPI_OFFICIAL',money: this.recharge,url: transitUrl + '&uid=' + this.uid + '&money=' + this.recharge}} else if ((this.type == 5 || this.type == 6) && this.recharge) {data['params'] = {orderId: this.orderId}}let res = await Api.apiCall('get',Api.order.webPay,params);console.log(res);if (res) {const data = res.datathis.checkWXJSBridge(data)}else{window.location.href = res.msgreturn;}} else {// 微信 H5支付if (this.type == 1 && this.orderId) {data['params'] = {trade_type: 'MWEB',return_url: baseUrl +'wap/#/pages/order/payment/result'}} else if (this.type == 2 && this.recharge) {data['params'] = {trade_type: 'MWEB',money: this.recharge,return_url: baseUrl + 'wap/#/pages/order/payment/result'}} else if ((this.type == 5 || this.type == 6) && this.recharge) {data['params'] = {orderId: this.orderId}}console.log(data);// 微信h5支付let res = await Api.apiCall('get',Api.order.wapPay,params);console.log(res);if (res) {if (res) {location.href = res} else {this.$common.errorToShow(res)}}}breakcase 'balancepay':/*** 用戶余額支付**/if ((this.type == 5 || this.type == 6) && this.recharge) {data['params'] = {orderId: this.orderId}}let params1 = {'orderId':this.orderId};let data1 = await Api.apiCall('post',Api.order.balancePay,params1);console.log(data1)if (data1) {uni.redirectTo({url: '/pages/order/payment/result?order=' + JSON.stringify(data1)})}else {this.$api.msg('余額支付失敗');}breakcase 'offline':/*** 線下支付*/this.$common.modelShow('線下支付說明','請聯系客服進行線下支付qq:951449465',() => {},false,'取消','確定')break}2.uniapp支持各種微信環境的支付
// 用戶點擊支付方式處理async toPayHandler (code) {let params = {'orderId':this.orderId,payment_type: this.type};// 判斷訂單支付類型if (this.type == 2 && this.recharge) {}else if ((this.type == 5 || this.type == 6) && this.recharge) {}let _this = thisswitch (code) {case 'wechatpay':let res = await Api.apiCall('post',Api.order.weixinAppletPay,params);console.log(res);if (res) {uni.requestPayment({provider: 'wxpay',timeStamp: res.timeStamp,nonceStr: res.nonceStr,package: res.package,signType: res.signType,paySign: res.paySign,success: function (e) {if (e.errMsg === 'requestPayment:ok') {_this.$common.successToShow(res.msg, () => {_this.$common.redirectTo('/pages/order/payment/result?id=' + res.id)})}}});} else {this.$common.errorToShow(res.msg)}breakcase 'balancepay':/*** 用戶余額支付**/let params1 = {'orderId':this.orderId};let data1 = await Api.apiCall('post',Api.order.balancePay,params1);console.log(data1)if (data1) {uni.redirectTo({url: '/pages/order/payment/result?order=' + JSON.stringify(data1)})}else {this.$api.msg('余額支付失敗');}breakcase 'offline':/*** 線下支付*/this.$common.modelShow('線下支付說明', '請聯系客服進行線下支付', () => {},false, '取消', '確定')break}3.uniapp支持app環境的支付方式
// 用戶點擊支付方式處理async toPayHandler (code) {let _this = thislet params = {'orderId':this.orderId};let data = {payment_code: code,payment_type: _this.type}data['ids'] = (this.type == 1 || this.type == 5 || this.type == 6) ? this.orderId : this.uidif ((this.type == 5 || this.type == 6) && this.recharge) {data['params'] = {trade_type: 'APP',formid: this.orderId}}switch (code) {case 'alipay':/*** 支付寶支付需要模擬GET提交數據*/if (_this.type == 1 && _this.orderId) {data['params'] = {trade_type: 'APP'}} else if (_this.type == 2 && _this.recharge) {data['params'] = {trade_type: 'APP',money: _this.recharge}}let res = await Api.apiCall('get',Api.order.aliAppPay,params);console.log(res);if (res) {uni.requestPayment({provider: "alipay",orderInfo: res,success: function(data){console.log(data);_this.$common.successToShow('支付成功', () => {_this.redirectHandler(res.data.payment_id)})}});} else {_this.$comon.errorToShow(res.msg)}breakcase 'wechatpay':// 微信 H5支付if (_this.type == 1 && _this.orderId) {data['params'] = {trade_type: 'APP'}} else if (_this.type == 2 && _this.recharge) {data['params'] = {trade_type: 'APP',money: _this.recharge}}// 微信app支付let res1 = await Api.apiCall('get',Api.order.appPay,params);if (res1) {// 調用微信支付uni.requestPayment({provider: "wxpay",orderInfo: res1,success: function(data){_this.$common.successToShow('支付成功', () => {_this.redirectHandler(data)})},fail:function(res){console.log(JSON.stringify(res));}});} else {_this.$common.errorToShow(res.msg)}breakcase 'balancepay':/*** 用戶余額支付**/let params1 = {'orderId':this.orderId};let data1 = await Api.apiCall('post',Api.order.balancePay,params1);console.log(data1)if (data1) {uni.redirectTo({url: '/pages/order/payment/result?order=' + JSON.stringify(data1)})}else {this.$api.msg('余額支付失敗');}breakcase 'offline':/*** 線下支付*/_this.$common.modelShow('線下支付說明', '請聯系客服進行線下支付',() => {}, false, '取消', '確定')break}},?
4.uniapp支持各種 支付寶環境的支付方式
// 用戶點擊支付方式處理async toPayHandler (code) {let params = {'orderId':this.orderId};let data = {payment_code: code,payment_type: this.type}data['ids'] = (this.type == 1 || this.type == 5 || this.type == 6) ? this.orderId : this.uid// 判斷訂單支付類型if (this.type == 2 && this.recharge) {data['params'] = {money: this.recharge,trade_type: 'JSAPI'}} else if ((this.type == 5 || this.type == 6) && this.recharge) {data['params'] = {trade_type: 'JSAPI',formid: this.orderId}}else {data['params'] = {trade_type: 'JSAPI'}}let _this = this;switch (code) {case 'alipay':let res = await Api.apiCall('get',Api.order.webPay,params);console.log(res);if (res) {uni.requestPayment({provider: 'alipay',tradeNO:res.data.trade_no,success: function (e) {if (e.errMsg === 'requestPayment:ok') {_this.$common.successToShow(res.msg, () => {_this.$common.redirectTo('/pages/order/payment/result?id=' + res.data.id);});}}});} else {this.$common.errorToShow(res.msg);}breakcase 'balancepay'://用戶余額支付let params1 = {'orderId':this.orderId};let data1 = await Api.apiCall('post',Api.order.balancePay,params1);console.log(data1)if (data1) {uni.redirectTo({url: '/pages/order/payment/result?order=' + JSON.stringify(data1)})}else {this.$api.msg('余額支付失敗');}break;case 'offline'://線下支付this.$common.modelShow('線下支付說明', '請聯系客服進行線下支付',() => {}, false, '取消', '確定')break;}}下載 地址?https://gitee.com/zscat/mallplus???????
關注公眾號獲取微服務版本下載和部署方式
總結
以上是生活随笔為你收集整理的uniapp 让支付触手可及,封装了微信支付、QQ支付、支付宝支付、京东支付、银联支付常用的支付方式以及各种常用的接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 算法9---二叉树的遍历不用栈和递归
- 下一篇: 【转】彻底搞清计算结构体大小和数据对齐原