只用POST
,只封裝了POST
,等有用到GET
再重寫,接口用的ThinkPHP5.0
前端
主要代碼api
var apiurl = "xxxxx"; function http_post(controller,data,cb){ wx.request({ url:apiurl+controller, data:data, method:'post', header:{'Content-Type':'application/x-www-form-urlencoded'}, success:function(res){ return typeof cb == "function" && cb(res.data) }, fail:function(res){ return typeof cb == "function" && cb(false) } }) } module.exports = { http_post:http_post,//post請求 }
var wxq = require('../../utils/wxrequest.js'); var openid = wx.getStorageSync('openid');//獲取緩存裏面的openid wxq.http_post('這裏是控制器/方法',{'openid':openid},function(res){ console.info('回調',res) })