小程序request请求包装
2019-04-03 15:16:50
如何看待微信公开课小程序热门讨论「小程序request请求包装」
摘要:小程序request请求包装
展开://请求包装varmyrequestfunction(requestobj){if((!requestobj.header||requestobj.header.authnull)){console.log(没有请求权限代码,默认无权限要求请求);}else{if((requestobj.header.auth1||requestobj.header.auth2)!token){//需要登录且未登录console.log(需要登录且未登录);login(myrequest,requestobj);//调用登录,登录完成后回调请求return;}elseif(requestobj.header.auth2){//需绑定手机号且未绑定手机号console.log(需认证且未认证);bind();//调用绑定手机号弹出框return;}else{console.log(通过验证,准备向服务器发送请求);}}wx.request({url:requestobj.url,data:requestobj.data,header:Object.assign({contenttype:application/json,token:token},requestobj.header),method:requestobj.method!null?requestobj.method:GET,success:function(res){console.log(res.data);if(res.statusCode200||res.statusCode304){if(res.data.errcode0){typeofrequestobj.successfunctionrequestobj.success(res)}else{wx.showToast({title:res.data.errmsg,image:/images/icon/error.png,duration:3000})}}else{wx.showToast({title:服务器响应失败,image:/images/icon/error.png,duration:3000})}},fail:function(res){wx.showToast({title:请求失败,image:/images/icon/error.png,duration:3000})typeofrequestobj.failfunctionrequestobj.fail(res)},complete:function(){typeofrequestobj.completefunctionrequestobj.complete()}})}//登录varloginfunction(cb,requestobj){if(token){console.log(已登录);}else{console.log(调用登录);wx.login({success:function(res){if(res.code){console.log(res.code);myrequest({url:requestUrl.loginUrl,data:{code:res.code},method:POST,success:function(res){tokenres.data.data.openid;console.log(token);typeofcbfunctioncb(requestobj)}})}else{console.log(获取用户登录态失败!+res.errMsg)}}})}}//一般请求myrequest({url:requestUrl.indexRequestUrl,data:{showAgent:1},header:{//0、直接请求1、需登录请求2.需登录且绑定手机后请求auth:1},success:function(res){console.log(私success);that.setData({Carousel:res.data.data.Carousel,Menu:res.data.data.Menu})}});
摘要:小程序request请求包装
展开://请求包装varmyrequestfunction(requestobj){if((!requestobj.header||requestobj.header.authnull)){console.log(没有请求权限代码,默认无权限要求请求);}else{if((requestobj.header.auth1||requestobj.header.auth2)!token){//需要登录且未登录console.log(需要登录且未登录);login(myrequest,requestobj);//调用登录,登录完成后回调请求return;}elseif(requestobj.header.auth2){//需绑定手机号且未绑定手机号console.log(需认证且未认证);bind();//调用绑定手机号弹出框return;}else{console.log(通过验证,准备向服务器发送请求);}}wx.request({url:requestobj.url,data:requestobj.data,header:Object.assign({contenttype:application/json,token:token},requestobj.header),method:requestobj.method!null?requestobj.method:GET,success:function(res){console.log(res.data);if(res.statusCode200||res.statusCode304){if(res.data.errcode0){typeofrequestobj.successfunctionrequestobj.success(res)}else{wx.showToast({title:res.data.errmsg,image:/images/icon/error.png,duration:3000})}}else{wx.showToast({title:服务器响应失败,image:/images/icon/error.png,duration:3000})}},fail:function(res){wx.showToast({title:请求失败,image:/images/icon/error.png,duration:3000})typeofrequestobj.failfunctionrequestobj.fail(res)},complete:function(){typeofrequestobj.completefunctionrequestobj.complete()}})}//登录varloginfunction(cb,requestobj){if(token){console.log(已登录);}else{console.log(调用登录);wx.login({success:function(res){if(res.code){console.log(res.code);myrequest({url:requestUrl.loginUrl,data:{code:res.code},method:POST,success:function(res){tokenres.data.data.openid;console.log(token);typeofcbfunctioncb(requestobj)}})}else{console.log(获取用户登录态失败!+res.errMsg)}}})}}//一般请求myrequest({url:requestUrl.indexRequestUrl,data:{showAgent:1},header:{//0、直接请求1、需登录请求2.需登录且绑定手机后请求auth:1},success:function(res){console.log(私success);that.setData({Carousel:res.data.data.Carousel,Menu:res.data.data.Menu})}});
标签:小程序
「小程序request请求包装」热门讨论订阅
方法1:微信扫描微信公开课小程序码即可订阅热门讨论「小程序request请求包装」
方法2:微信搜索微信公开课小程序名称进入,即可订阅热门讨论「小程序request请求包装」
方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热门讨论「小程序request请求包装」
微信公开课小程序热门讨论「小程序request请求包装」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。
微信公开课热门讨论「小程序request请求包装」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。
微信公开课小程序
更新时间:2019-04-03 15:16:50
>
__methodCallerx27;ofundefined
>-404011cloudfunctionexecutionerror
>,请补充选择商家自营-预付卡销售-发行方类目,并在基础信息处申请该类目,通过
>:host在模拟器中显示无效
>:请在小程序服务页面上架正式(非测试)内容或商品后重新提交审核
>.net 微信小程序 上传图片
>'setTimeout'的问题
>‘三朵里熙SPA主题减压空间’为什么搜索关键词‘三朵里‘搜不到
>‘扫普通链接二维码打开小程序‘中设置为体验版,扫码打开是线上版本
>“cloudfunctions**indexjs”gitignore
>“NO ULINK DEVICE FOUND”是怎么回事
>“万马掌上校园”的类目审核
>“上线了”公司开发的微信小程序怎么样?
>“产品是否一定需要条形码”
>