進(jìn)入小程序,下單,請(qǐng)求下單支付,調(diào)用小程序登錄API來(lái)獲取Openid(https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html#wxloginobject),生成商戶訂單,這些都是在小程序端完成的業(yè)務(wù)。
// pages/pay/pay.js
var app = getApp();
Page({
data: {},
onLoad: function (options) {
// 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來(lái)的參數(shù)
},
/* 微信支付 */
wxpay: function () {
var that = this
//登陸獲取code
wx.login({
success: function (res) {
console.log(res.code)
//獲取openid
that.getOpenId(res.code)
}
});
},
getOpenId: function (code) {
var that = this;
wx.request({
url: "https://api.weixin.qq.com/sns/jscode2session?appid=wxa142513e524e496c&secret=5d6a7d86048884e7c60f84f7aa85253c&js_code=" + code + "&grant_type=authorization_code",
data: {},
method: 'GET',
success: function (res) {
console.log('返回openId')
console.log(res.data)
that.generateOrder(res.data.openid)
},
fail: function () {
// fail
},
complete: function () {
// complete
}
})
},
/**生成商戶訂單 */
generateOrder: function (openid) {
var that = this
//統(tǒng)一支付
wx.request({
|