request只使用POST,只封装POST,有GET时重写,接口中使用的ThinkPHP5.0主要代码varapiurl="xxxxx";functionhttp_post(controller,data,cb){wx.request({url:apiurl+controller,data:data,method:'post',header:{'Content-Type':'application/x-www-form-urlencoded'},success:function(res){returntypeofcb=="function"&&cb(res.data)},fail:function(res){returntypeofcb=="function"&&cb(false)}})}module.exports={http_post:http_post,//postrequest}前端js使用varwxq=require('../../utils/wxrequest.js');varopenid=wx.getStorageSync('openid');//获取缓存中的openidwxq。http_post('这里是控制器/方法',{'openid':openid},function(res){console.info('callback',res)})
