From 8ab026529ea464e47c3a6025f60b47e7f7aaeed5 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sun, 6 May 2018 10:56:59 +0800 Subject: [PATCH] =?UTF-8?q?update[litemall-wx]:=20=E5=B0=8F=E5=95=86?= =?UTF-8?q?=E5=9C=BA=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=AB=AF=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E3=80=82=201.=20=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8E=9F=E6=9D=A5pay.js=EF=BC=8C=E8=80=8C=E6=98=AF?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=9C=A8=E4=B8=8B=E5=8D=95=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=92=8C=E8=AE=A2=E5=8D=95=E4=BB=98=E6=AC=BE=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=9B=B4=E5=BC=95=E5=85=A5=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?api=202.=20=E5=B0=8F=E5=95=86=E5=9F=8E=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=9A=84=E8=AE=A2=E5=8D=95=E9=A2=84=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E4=BC=9A=E8=AF=9Dapi=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- litemall-wx/config/api.js | 4 +- litemall-wx/pages/payResult/payResult.js | 78 ++++++++++------- .../pages/shopping/checkout/checkout.js | 85 ++++++++++++------- litemall-wx/services/pay.js | 56 ------------ 4 files changed, 103 insertions(+), 120 deletions(-) delete mode 100644 litemall-wx/services/pay.js diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index 05a2fc17..8c3fdea8 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -48,8 +48,6 @@ module.exports = { CartGoodsCount: WxApiRoot + 'cart/goodscount', // 获取购物车商品件数 CartCheckout: WxApiRoot + 'cart/checkout', // 下单前信息确认 - PayPrepayId: WxApiRoot + 'pay/prepay', //获取微信统一下单prepay_id - CollectList: WxApiRoot + 'collect/list', //收藏列表 CollectAddOrDelete: WxApiRoot + 'collect/addordelete', //添加或取消收藏 @@ -74,7 +72,7 @@ module.exports = { RegionList: WxApiRoot + 'region/list', //获取区域列表 OrderSubmit: WxApiRoot + 'order/submit', // 提交订单 - OrderPay: WxApiRoot + 'order/pay', // 支付订单 + OrderPrepay: WxApiRoot + 'order/prepay', // 订单的预支付会话 OrderList: WxApiRoot + 'order/list', //订单列表 OrderDetail: WxApiRoot + 'order/detail', //订单详情 OrderCancel: WxApiRoot + 'order/cancel', //取消订单 diff --git a/litemall-wx/pages/payResult/payResult.js b/litemall-wx/pages/payResult/payResult.js index a164e38e..7906d9c0 100644 --- a/litemall-wx/pages/payResult/payResult.js +++ b/litemall-wx/pages/payResult/payResult.js @@ -1,6 +1,5 @@ var util = require('../../utils/util.js'); var api = require('../../config/api.js'); -const pay = require('../../services/pay.js'); var app = getApp(); Page({ @@ -32,36 +31,57 @@ Page({ }, payOrder() { let that = this; - // 目前不能支持微信支付,这里仅仅是模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已 - wx.showModal({ - title: '目前不能微信支付', - content: '点击确定模拟支付成功,点击取消模拟未支付成功', - success: function (res) { - if (res.confirm) { - util.request(api.OrderPay, { orderId: that.data.orderId }, 'POST').then(res => { - if (res.errno === 0) { - that.setData({ - status: true - }); - } - else { - util.showErrorToast('支付失败'); - } - }); - } - else if (res.cancel) { - util.showErrorToast('支付失败'); - } + // 模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已 + // wx.showModal({ + // title: '目前不能微信支付', + // content: '点击确定模拟支付成功,点击取消模拟未支付成功', + // success: function (res) { + // if (res.confirm) { + // util.request(api.OrderPrepay, { orderId: that.data.orderId }, 'POST').then(res => { + // if (res.errno === 0) { + // that.setData({ + // status: true + // }); + // } + // else { + // util.showErrorToast('支付失败'); + // } + // }); + // } + // else if (res.cancel) { + // util.showErrorToast('支付失败'); + // } + // } + // }); + + util.request(api.OrderPrepay, { + orderId: that.data.orderId + }, 'POST').then(function (res) { + if (res.errno === 0) { + const payParam = res.data; + console.log("支付过程开始") + wx.requestPayment({ + 'timeStamp': payParam.timeStamp, + 'nonceStr': payParam.nonceStr, + 'package': payParam.packageValue, + 'signType': payParam.signType, + 'paySign': payParam.paySign, + 'success': function (res) { + console.log("支付过程成功") + that.setData({ + status: true + }); + }, + 'fail': function (res) { + console.log("支付过程失败") + util.showErrorToast('支付失败'); + }, + 'complete': function (res) { + console.log("支付过程结束") + } + }); } }); - - // pay.payOrder(this.data.orderId).then(res => { - // this.setData({ - // status: true - // }); - // }).catch(res => { - // util.showErrorToast('支付失败'); - // }); } }) \ No newline at end of file diff --git a/litemall-wx/pages/shopping/checkout/checkout.js b/litemall-wx/pages/shopping/checkout/checkout.js index b1b97d21..371a507f 100644 --- a/litemall-wx/pages/shopping/checkout/checkout.js +++ b/litemall-wx/pages/shopping/checkout/checkout.js @@ -1,6 +1,5 @@ var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); -const pay = require('../../../services/pay.js'); var app = getApp(); @@ -106,47 +105,69 @@ Page({ if (res.errno === 0) { const orderId = res.data.orderId; - // 目前不能支持微信支付,这里仅仅是模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已 - wx.showModal({ - title: '目前不能微信支付', - content: '点击确定模拟支付成功,点击取消模拟未支付成功', - success: function(res) { - if (res.confirm) { - util.request(api.OrderPay, { orderId: orderId }, 'POST').then(res => { - if (res.errno === 0) { + // 模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已 + // wx.showModal({ + // title: '目前不能微信支付', + // content: '点击确定模拟支付成功,点击取消模拟未支付成功', + // success: function(res) { + // if (res.confirm) { + // util.request(api.OrderPrepay, { orderId: orderId }, 'POST').then(res => { + // if (res.errno === 0) { + // wx.redirectTo({ + // url: '/pages/payResult/payResult?status=1&orderId=' + orderId + // }); + // } + // else{ + // wx.redirectTo({ + // url: '/pages/payResult/payResult?status=0&orderId=' + orderId + // }); + // } + // }); + // } + // else if (res.cancel) { + // wx.redirectTo({ + // url: '/pages/payResult/payResult?status=0&orderId=' + orderId + // }); + // } + + // } + // }); + + util.request(api.OrderPrepay, { + orderId: orderId + }, 'POST').then(function (res) { + if (res.errno === 0) { + const payParam = res.data; + console.log("支付过程开始") + wx.requestPayment({ + 'timeStamp': payParam.timeStamp, + 'nonceStr': payParam.nonceStr, + 'package': payParam.packageValue, + 'signType': payParam.signType, + 'paySign': payParam.paySign, + 'success': function (res) { + console.log("支付过程成功") wx.redirectTo({ url: '/pages/payResult/payResult?status=1&orderId=' + orderId }); - } - else{ + }, + 'fail': function (res) { + console.log("支付过程失败") wx.redirectTo({ url: '/pages/payResult/payResult?status=0&orderId=' + orderId }); + }, + 'complete': function (res) { + console.log("支付过程结束") } }); } - else if (res.cancel) { - wx.redirectTo({ - url: '/pages/payResult/payResult?status=0&orderId=' + orderId - }); - } + }); - } - }); - - // pay.payOrder(orderId).then(res => { - // wx.redirectTo({ - // url: '/pages/payResult/payResult?status=1&orderId=' + orderId - // }); - // }).catch(res => { - // wx.redirectTo({ - // url: '/pages/payResult/payResult?status=0&orderId=' + orderId - // }); - // }); - // } else { - // wx.redirectTo({ - // url: '/pages/payResult/payResult?status=0&orderId=' + orderId - // }); + } else { + wx.redirectTo({ + url: '/pages/payResult/payResult?status=0&orderId=' + orderId + }); } }); } diff --git a/litemall-wx/services/pay.js b/litemall-wx/services/pay.js deleted file mode 100644 index 65f23639..00000000 --- a/litemall-wx/services/pay.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 支付相关服务 - */ - -const util = require('../utils/util.js'); -const api = require('../config/api.js'); - -/** - * 判断用户是否登录 - */ -function payOrder(orderId) { - return new Promise(function (resolve, reject) { - util.request(api.PayPrepayId, { - orderId: orderId - }).then((res) => { - console.log(res) - if (res.errno === 0) { - const payParam = res.data; - wx.requestPayment({ - 'timeStamp': payParam.timeStamp, - 'nonceStr': payParam.nonceStr, - 'package': payParam.package, - 'signType': payParam.signType, - 'paySign': payParam.paySign, - 'success': function (res) { - resolve(res); - }, - 'fail': function (res) { - reject(res); - }, - 'complete': function (res) { - reject(res); - } - }); - } else { - reject(res); - } - }); - }); -} - - -module.exports = { - payOrder, -}; - - - - - - - - - - -