Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何自定义apiRequest #217

Open
kongdemin opened this issue Apr 15, 2024 · 1 comment
Open

如何自定义apiRequest #217

kongdemin opened this issue Apr 15, 2024 · 1 comment

Comments

@kongdemin
Copy link

文档写的有点不清楚,是要返回对象吗 还是要怎么的

@xiangyuecn
Copy link
Owner

success({ appkey:"", token:"" });
fail("错误消息")
自己处理完,回调一下就可以了

参考微信小程序:

/**实现apiRequest接口,tokenApi的请求实现方法**/
var wx_ApiRequest=function(url,args,success,fail){
wx.setStorageSync("page_asr_asrTokenApi", url); //测试用的存起来
wx.request({
url:url, data:args, method:"POST", dataType:"text"
,header:{"content-type":"application/x-www-form-urlencoded"}
,success:(e)=>{
if(e.statusCode!=200){
fail("请求出错["+e.statusCode+"]");
return;
}
try{
var data=JSON.parse(e.data);
}catch(e){
fail("请求结果不是json格式:"+e.data);
return;
}
//【自行修改】根据自己的接口格式提取出数据并回调
if(data.c!==0){
fail("接口调用错误:"+data.m);
return;
}
data=data.v;
success({ appkey:data.appkey, token:data.token });
}
,fail:(e)=>{
fail(e.errMsg||"请求出错");
}
});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants