|
@@ -1,27 +1,92 @@
|
|
|
-const httpService= async ()=>{
|
|
|
+// get请求
|
|
|
+const httpServiceGet= async (path,params)=>{
|
|
|
+ const {cloud} = getApp();
|
|
|
+ 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.alert({
|
|
|
+// content: JSON.stringify(result)
|
|
|
+// });
|
|
|
+
|
|
|
+if(result.errno=='0'){
|
|
|
+ return result.data;
|
|
|
+}
|
|
|
+
|
|
|
+// return new Promise((resolve,reject) => {
|
|
|
+// if(result.errno=='0'){
|
|
|
+// resolve(result.data);
|
|
|
+// }else{
|
|
|
+// my.alert({
|
|
|
+// content: result.errmsg
|
|
|
+// });
|
|
|
+// reject('error')
|
|
|
+// }
|
|
|
+
|
|
|
+ // })
|
|
|
+
|
|
|
+ } catch(e) {
|
|
|
+ console.log(e);
|
|
|
+ my.alert({
|
|
|
+
|
|
|
+ // content: 'error'+e.message
|
|
|
+ content: e.msg
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+// post请求
|
|
|
+const httpServicePost= async (path,params)=>{
|
|
|
const {cloud} = getApp();
|
|
|
try {
|
|
|
console.log('request begin');
|
|
|
const result = await cloud.application.httpRequest({
|
|
|
//不需要完整域名,只需要接口访问路径即可
|
|
|
- 'path' : '/servantappletservice/getKey',
|
|
|
- 'method':'GET',
|
|
|
- 'headers':{ "mc-dd":"test", },
|
|
|
- 'params':{"key":1},
|
|
|
- 'body':{ "xftest":"hhh", "id":"1234", },
|
|
|
+ // '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(result);
|
|
|
console.log('response');
|
|
|
- console.log(JSON.stringify(result));
|
|
|
+ // console.log(JSON.stringify(result));
|
|
|
my.alert({
|
|
|
content: JSON.stringify(result)
|
|
|
});
|
|
|
+ console.log(result);
|
|
|
+if(result.errno=='0'){
|
|
|
+ return result.data;
|
|
|
+}
|
|
|
+// return new Promise((resolve) => {
|
|
|
+// if(result.errno=='0'){
|
|
|
+// resolve(result.data);
|
|
|
+// }else{
|
|
|
+// my.alert({
|
|
|
+// content: result.errmsg
|
|
|
+// });
|
|
|
+// }
|
|
|
+// })
|
|
|
} catch(e) {
|
|
|
+ console.log(e);
|
|
|
my.alert({
|
|
|
- content: 'error'+e.message
|
|
|
+ content: 'false'+JSON.stringify(e)
|
|
|
+ // content: 'error'+e.msg
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
export default{
|
|
|
- httpService
|
|
|
+ httpServiceGet,
|
|
|
+ httpServicePost
|
|
|
}
|