微信小程序开发(二)支付接入
浏览量:382
发起微信支付。
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
timeStamp | String | 是 | 时间戳从1970年1月1日00:00:00至今的秒数,即当前的时间 |
nonceStr | String | 是 | 随机字符串,长度为32个字符以下。 |
package | String | 是 | 统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=* |
signType | String | 是 | 签名算法,暂支持 MD5 |
paySign | String | 是 | 签名,具体签名方案参见小程序支付接口文档; |
success | Function | 否 | 接口调用成功的回调函数 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
了解更多信息,请查看微信支付接口文档
<view class="pay-choices-item">
<view class="pay-icon-wrap">
<view class="pay-icon"></view>
<text class="pay-choice-name">微信支付</text>
</view>
<view class="pay-radio-choice">
<radio checked="true"></radio>
</view>
</view>
<view class='tip-font'>付款后请分享,24小时内达到成团人数才能购买成功哦~</view>
<view>
<button class="settle-buy-sure" bindtap="toPay">购买</button>
</view>
</view>
1、购买绑定事件,先下单
toPay: function () { var that = this; that.makeOrderData();//下单接口 }, makeOrderData: function () { var that = this, order_data = that.post_order_data.order_data[0], item = that.post_order_data.order_data[0].items[0], info = that.data.orderInfo, uinfo = that.data.userInfo, address = that.post_order_data.user_address; //购买商品属性 order_data.shop_id = info.shop_id; item.product_id = info.product_id; item.sku_id = info.sku_id; item.count = info.count; item.price = info.price; item.buy_type = info.buy_type; item.team_sign = info.team_sign; //收货地址 address.area_list = uinfo.area_list; address.mobilephone = uinfo.mobilephone; address.name = uinfo.name; address.street = uinfo.street; util.request({ isLogin: true, url: DATAURL + '/app.php?c=Order&m=makeOrder',//下单接口 data: { "data": JSON.stringify(that.post_order_data) }, method: 'POST', success: function (res) { if (res.data.errno == 0) { that.data.orderInfo.team_sign = res.data.data.team_sign; that.data.orderInfo.order_sn = res.data.data.order_sn; that.makePayData(res.data.data); } else { wx.showModal({ title: '提示', content: res.data.msg, success: function (res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) } }, fail: function () { } }); }, //拿着下单的数据 呼起支付接口 makePayData: function (data) { var that = this; util.request({ isLogin: true, url: DATAURL + '/app.php?c=order&m=payRequestInterface',//调用支付接口 data: { "data": JSON.stringify(data) }, method: 'POST', success: function (res) { if (res.data.errno == 0) { var payData = res.data.data; wx.requestPayment({ 'timeStamp': payData.timeStamp, 'nonceStr': payData.nonceStr, 'package': payData.package, 'signType': 'MD5', 'paySign': payData.paySign, 'success': function (res) { var url = '../shareteam/shareteam?team_sign=' + that.data.orderInfo.team_sign + '&id=' + that.data.orderInfo.product_id; util.pageTo(url); }, 'fail': function (res) { var url = '../orderdetail/orderdetail?order_sn=' + that.data.orderInfo.order_sn; util.pageTo(url); } }) } else { wx.showModal({ title: '提示', content: res.data.msg, success: function (res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) } }, fail: function () { } }); },
神回复
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。