// get请求 const httpServiceGet= async (path,params)=>{ const {cloud} = getApp(); my.showLoading({ content: '加载中...', delay: 0, }); try { console.log('request begin'); const result = await cloud.application.httpRequest({ //不需要完整域名,只需要接口访问路径即可 // 'path' : '/servantappletservice/auth/registerUser', 'path' : path, 'method':'GET', 'headers':{ }, 'params':params, // 'body':{ }, //对于一个小程序关联多个云应用的场景,调用非默认云应用,需要指定对应的云应用Id,超时时间单位ms 'exts':{ "cloudAppId":"21907" ,"timeout":60000} }); console.log('response'); console.log(result); my.hideLoading({ }); if(result.errno=='0'){ return result.data; }else{ my.alert({ content: result.errmsg }); return Promise.reject(result); } } catch(e) { console.log(e); my.hideLoading({ }); my.alert({ content: 'error'+e.message // content: e.msg }); return Promise.reject(e); } } // post请求 const httpServicePost= async (path,params)=>{ const {cloud} = getApp(); my.showLoading({ content: '加载中...', delay: 0, }); try { console.log('request begin'); const result = await cloud.application.httpRequest({ //不需要完整域名,只需要接口访问路径即可 // 'path' : '/servantappletservice/auth/registerUser', 'path' : path, 'method':'POST', 'headers':{ 'Content-type': 'application/json' }, 'params':{}, 'body':params, //对于一个小程序关联多个云应用的场景,调用非默认云应用,需要指定对应的云应用Id,超时时间单位ms 'exts':{ "cloudAppId":"21907" ,"timeout":60000} }); console.log('response'); // console.log(JSON.stringify(result)); // my.alert({ // content: JSON.stringify(result) // }); console.log(result); my.hideLoading({ }); if(result.errno=='0'){ return result.data; }else{ my.alert({ content: result.errmsg }); return Promise.reject(result); } } catch(e) { console.log(e); my.hideLoading({ }); my.alert({ content: 'error'+e.message }); return Promise.reject(e); // throw new Error(e) } } export default{ httpServiceGet, httpServicePost }