uniapp 支付(支付宝,微信支付)
生活随笔
收集整理的这篇文章主要介绍了
uniapp 支付(支付宝,微信支付)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
uniapp 支付前端处理:
// 发送到后台的数据 var payData = {"isUpgrade": 'N',"lavel": level,"userid": this.user.id // 用户id } uni.getProvider({service: 'payment',success: function (res) {if(res.provider && res.provider.length > 0){if(_self.isWxPay){ // 微信支付if(res.provider.indexOf('wxpay') > -1){uni.request({url: "https://www.xxx.com/pay/wxpay", // 后台请求微信服务器data: payData,method: 'POST',success: (result) => {if(result.data.code == 200){var data = result.data;var obj = {"partnerid": data.app_result.partnerid,"prepayid": data.app_result.prepayid,"package": "Sign=WXPay","appid": data.app_result.appid,"noncestr": data.app_result.noncestr,"timestamp": data.app_result.timestamp,"sign": data.app_result.sign}uni.requestPayment({provider: 'wxpay',orderInfo: obj,success: function (res) {// 支付成功回调console.log('success:' + JSON.stringify(res));// 支付成功通知。。。},fail: function (err) {// 支付失败回调console.log('fail:' + JSON.stringify(err));}});}else{// 失败回调}},fail: (e) => {console.log(e);}});}else{// 没有安装微信uni.showToast({icon: "none",title: "请先安装微信"})}}else{ // 支付宝支付if(res.provider.indexOf('alipay') > -1){uni.request({url: "https://www.xxx.com/pay/alipay",data: payData,method: 'POST',success: (result) => {console.log(result);if(result.data){if(result.data.code && result.data.code != 200){// 后台请求支付宝失败}else{uni.requestPayment({provider: 'alipay',orderInfo: result.data,success: function (res) {// 支付成功回调console.log('success:' + JSON.stringify(res));},fail: function (err) {// 支付失败回调console.log('fail:' + JSON.stringify(err));}});}}else{uni.showToast({icon: "none",title: "请求失败"})}},fail: (e) => {console.log(e);}});}else{// 没有安装支付宝uni.showToast({icon: "none",title: "请先安装支付宝"})}}}else{uni.showToast({icon: "none",title: "获取支付通道失败,请先安装微信或支付宝"})}} });总结
以上是生活随笔为你收集整理的uniapp 支付(支付宝,微信支付)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: html百度天气api,百度API 免费
- 下一篇: 【ES6(2015)】Set