diff --git a/packageA/pages/myGift/myGift.js b/packageA/pages/myGift/myGift.js index a96d9c9..b491e8b 100644 --- a/packageA/pages/myGift/myGift.js +++ b/packageA/pages/myGift/myGift.js @@ -2,6 +2,7 @@ const app = getApp(); let self = null; var os = app.globalData.setting; +var t_pay = require("../../../utils/pay2.js"); Page({ @@ -288,34 +289,40 @@ Page({ "store_id": os.stoid, //商家Id "user_id": user.user_id, //用户ID }; - var url = "/api/weshop/libao/libaoFormvip/libaoOrder"; - getApp().request.post(url, - { - data:json, - success:function(res) { - if (res.data.code == 0 && res.data.data) { - res = res.data.data; - - getApp().globalData.no_clear=1; - - wx.requestPayment({ - timeStamp: String(res.timeStamp), - nonceStr: res.nonceStr, - package: res.packageValue, - signType: res.signType, - paySign: res.paySign, - success: function(res) { - getApp().my_warnning("支付成功", 1, th); - }, - fail: function(res) { - getApp().my_warnning("取消支付", 0, th); - } - }); - } else { - getApp().my_warnning(res.data.msg, 0, th); - } - } - }) + t_pay.set_pay_url("/api/weshop/libao/libaoFormvip/libaoOrder"); + t_pay.pay(json,function (){ + getApp().my_warnning("支付成功", 1, th); + },function (e){ + getApp().my_warnning(e, 0, th); + }) + // var url = "/api/weshop/libao/libaoFormvip/libaoOrder"; + // getApp().request.post(url, + // { + // data:json, + // success:function(res) { + // if (res.data.code == 0 && res.data.data) { + // res = res.data.data; + // + // getApp().globalData.no_clear=1; + // + // wx.requestPayment({ + // timeStamp: String(res.timeStamp), + // nonceStr: res.nonceStr, + // package: res.packageValue, + // signType: res.signType, + // paySign: res.paySign, + // success: function(res) { + // getApp().my_warnning("支付成功", 1, th); + // }, + // fail: function(res) { + // getApp().my_warnning("取消支付", 0, th); + // } + // }); + // } else { + // getApp().my_warnning(res.data.msg, 0, th); + // } + // } + // }) }) }, diff --git a/packageA/pages/myGiftDetails/myGiftDetails.js b/packageA/pages/myGiftDetails/myGiftDetails.js index a031e86..58f26ce 100644 --- a/packageA/pages/myGiftDetails/myGiftDetails.js +++ b/packageA/pages/myGiftDetails/myGiftDetails.js @@ -3,6 +3,7 @@ const app = getApp(); let self = null; var os = app.globalData.setting; var ut = require("../../../utils/util.js"); +var t_pay = require("../../../utils/pay2.js"); Page({ @@ -228,37 +229,48 @@ Page({ "store_id": os.stoid, //商家Id "user_id": user.user_id, //用户ID }; - var url = "/api/weshop/libao/libaoFormvip/libaoOrder"; - getApp().request.post(url, - { - data:json, - success:function(res) { - if (res.data.code == 0 && res.data.data) { - res = res.data.data; - - getApp().globalData.no_clear=1; - - wx.requestPayment({ - timeStamp: String(res.timeStamp), - nonceStr: res.nonceStr, - package: res.packageValue, - signType: res.signType, - paySign: res.paySign, - success: function(res) { - getApp().my_warnning("支付成功", 1, th); - setTimeout(function (){ - getApp().goto("/packageA/pages/libao_payment/payment?type=2"); - },1000) - }, - fail: function(res) { - getApp().my_warnning("取消支付", 0, th); - } - }); - } else { - getApp().my_warnning(res.data.msg, 0, th); - } - } - }) + + t_pay.set_pay_url("/api/weshop/libao/libaoFormvip/libaoOrder"); + t_pay.pay(json,function (){ + getApp().my_warnning("支付成功", 1, th); + setTimeout(function (){ + getApp().goto("/packageA/pages/libao_payment/payment?type=2"); + },1000) + },function (msg){ + getApp().my_warnning(msg, 0, th); + }) + + // var url = "/api/weshop/libao/libaoFormvip/libaoOrder"; + // getApp().request.post(url, + // { + // data:json, + // success:function(res) { + // if (res.data.code == 0 && res.data.data) { + // res = res.data.data; + // + // getApp().globalData.no_clear=1; + // + // wx.requestPayment({ + // timeStamp: String(res.timeStamp), + // nonceStr: res.nonceStr, + // package: res.packageValue, + // signType: res.signType, + // paySign: res.paySign, + // success: function(res) { + // getApp().my_warnning("支付成功", 1, th); + // setTimeout(function (){ + // getApp().goto("/packageA/pages/libao_payment/payment?type=2"); + // },1000) + // }, + // fail: function(res) { + // getApp().my_warnning("取消支付", 0, th); + // } + // }); + // } else { + // getApp().my_warnning(res.data.msg, 0, th); + // } + // } + // }) }) }, diff --git a/packageE/pages/user/monthgiftbag/public/buy_com.js b/packageE/pages/user/monthgiftbag/public/buy_com.js index 11e0832..bfbf241 100644 --- a/packageE/pages/user/monthgiftbag/public/buy_com.js +++ b/packageE/pages/user/monthgiftbag/public/buy_com.js @@ -1,3 +1,5 @@ +//-- const subscribe = require("../../../../../../MdUNIApp_new2/packageD/pages/subscribe/subscribe"); -- +const t_pay = require("../../../../../utils/pay2.js"); module.exports = { //开启定位 wait_for_store_config: function (th) { @@ -253,27 +255,37 @@ module.exports = { break; case 2://立即购买 var order_sn = res.data.data.orderSn; - res = res.data.data.result; - if (!res) return false; + //res = res.data.data.result; + //if (!res) return false; var money=that.data.payMoney; var url = "/packageE/pages/user/monthgiftbag/payment/payment?money=" + money + "&order_sn=" + order_sn; getApp().globalData.no_clear=1; - wx.requestPayment({ - timeStamp: String(res.timeStamp), - nonceStr: res.nonceStr, - package: res.packageValue, - signType: res.signType, - paySign: res.paySign, - success: function (res) { - th.setData({submit:0}) - getApp().goto(url); - }, - fail: function (res) { - th.setData({submit:0}) - getApp().my_warnning("取消支付", 0, th); - then1.reduce(order_sn,that.data.getStorageID) - } - }); + + t_pay.pay_data(res,function (){ + th.setData({submit:0}) + getApp().goto(url); + },function (){ + th.setData({submit:0}) + getApp().my_warnning("取消支付", 0, th); + then1.reduce(order_sn,that.data.getStorageID) + }) + + // wx.requestPayment({ + // timeStamp: String(res.timeStamp), + // nonceStr: res.nonceStr, + // package: res.packageValue, + // signType: res.signType, + // paySign: res.paySign, + // success: function (res) { + // th.setData({submit:0}) + // getApp().goto(url); + // }, + // fail: function (res) { + // th.setData({submit:0}) + // getApp().my_warnning("取消支付", 0, th); + // then1.reduce(order_sn,that.data.getStorageID) + // } + // }); break; case 3://立即领取 th.setData({submit:0}) @@ -295,7 +307,7 @@ module.exports = { }, - //每月礼包减少购买数量 + //每月礼包补回减少购买数量 reduce(order_sn,stoid){ wx.showLoading({ title: '加载中.' diff --git a/pages/giftpack/public/buy_com.js b/pages/giftpack/public/buy_com.js index 810c50f..a646f31 100644 --- a/pages/giftpack/public/buy_com.js +++ b/pages/giftpack/public/buy_com.js @@ -1,3 +1,4 @@ +const t_pay = require("../../../utils/pay2.js"); module.exports = { //开启定位 wait_for_store_config: function (th) { @@ -251,54 +252,22 @@ module.exports = { break; case 2://立即购买 var order_sn = res.data.data.orderSn; - res = res.data.data.result; - if (!res) return false; var money=that.data.payMoney; var url = "/pages/giftpack/payment/payment?money=" + money + "&order_sn=" + order_sn; getApp().globalData.no_clear=1; - //--- 如果是富友支付的时候 -- - if(t.data.data.is_fuioupay){ - const plugin = requirePlugin('fuiou-pay') - - var paramsJson={ - reqType:"11",//必填 01-商户模式,11-机构模式 - reqData:t.data.data.reqData,//必填 富友加密参数 - } - console.log(plugin, plugin.fuioupay) - plugin.fuioupay(parseInt(t.data.data.amt),paramsJson,function (res){ - th.setData({submit:0}) - getApp().goto(url); - },function (error){ - console.log("插件支付错误",error); - //支付失败的时候 - //getApp().confirmBox(error.code+error.message); - //fail(error.code+":"+error.message) - //wx_paying=0; - th.setData({submit:0}) - getApp().my_warnning(error.code+":"+error.message, 0, th); - + t_pay.pay_data(res,function (){ + th.setData({submit:0}) + getApp().goto(url); + },function (e){ + th.setData({submit:0}) + wx.showToast({ + title:e, + icon:'none', + duration:2500 }) - }else{ - wx.requestPayment({ - timeStamp: String(res.timeStamp), - nonceStr: res.nonceStr, - package: res.packageValue, - signType: res.signType, - paySign: res.paySign, - success: function (res) { - th.setData({submit:0}) - getApp().goto(url); - }, - fail: function (res) { - th.setData({submit:0}) - getApp().my_warnning("取消支付", 0, th); - } - }); - } - - + }) break; case 3://立即领取 diff --git a/utils/pay2.js b/utils/pay2.js index ee49f3f..58f4668 100644 --- a/utils/pay2.js +++ b/utils/pay2.js @@ -44,7 +44,7 @@ module.exports = { } }else{ wx_paying=0; - "function" == typeof fail && fail(); + "function" == typeof fail && fail(t.data.msg); } return false; }, @@ -61,6 +61,36 @@ module.exports = { }); }, + //-- 这里是专享礼包的调用 -- + pay_data:function (t,succ,fail){ + var ob=t.data.data.result; + if(!ob){ + fail('支付参数错误'); + return false; + } + if(ob.is_fuioupay){ + const plugin = requirePlugin('fuiou-pay') + + var paramsJson={ + reqType:"11",//必填 01-商户模式,11-机构模式 + reqData:ob.reqData,//必填 富友加密参数 + } + console.log(plugin, plugin.fuioupay) + plugin.fuioupay(parseInt(ob.amt),paramsJson,function (res){ + console.log(res); + wx_paying=0; + "function" == typeof succ && succ(); + },function (error){ + console.log("插件支付错误",error); + //支付失败的时候 + //getApp().confirmBox(error.code+error.message); + fail(error.code+":"+error.message) + wx_paying=0; + }) + }else { + this.weixinPay(ob, succ, fail); + } + }, weixinPay: function(n, succ,fail) { if(!n) return false;