|
@@ -1,92 +1,27 @@
|
|
-// 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 httpService= async ()=>{
|
|
const {cloud} = getApp();
|
|
const {cloud} = getApp();
|
|
try {
|
|
try {
|
|
console.log('request begin');
|
|
console.log('request begin');
|
|
const result = await cloud.application.httpRequest({
|
|
const result = await cloud.application.httpRequest({
|
|
//不需要完整域名,只需要接口访问路径即可
|
|
//不需要完整域名,只需要接口访问路径即可
|
|
- // 'path' : '/servantappletservice/auth/registerUser',
|
|
|
|
- 'path' : path,
|
|
|
|
- 'method':'POST',
|
|
|
|
- 'headers':{ 'Content-type': 'application/json' },
|
|
|
|
- 'params':{},
|
|
|
|
- 'body':params,
|
|
|
|
|
|
+ 'path' : '/servantappletservice/getKey',
|
|
|
|
+ 'method':'GET',
|
|
|
|
+ 'headers':{ "mc-dd":"test", },
|
|
|
|
+ 'params':{"key":1},
|
|
|
|
+ 'body':{ "xftest":"hhh", "id":"1234", },
|
|
//对于一个小程序关联多个云应用的场景,调用非默认云应用,需要指定对应的云应用Id,超时时间单位ms
|
|
//对于一个小程序关联多个云应用的场景,调用非默认云应用,需要指定对应的云应用Id,超时时间单位ms
|
|
'exts':{ "cloudAppId":"21907" ,"timeout":60000} });
|
|
'exts':{ "cloudAppId":"21907" ,"timeout":60000} });
|
|
- console.log(result);
|
|
|
|
console.log('response');
|
|
console.log('response');
|
|
- // console.log(JSON.stringify(result));
|
|
|
|
|
|
+ console.log(JSON.stringify(result));
|
|
my.alert({
|
|
my.alert({
|
|
content: JSON.stringify(result)
|
|
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) {
|
|
} catch(e) {
|
|
- console.log(e);
|
|
|
|
my.alert({
|
|
my.alert({
|
|
- content: 'false'+JSON.stringify(e)
|
|
|
|
- // content: 'error'+e.msg
|
|
|
|
|
|
+ content: 'error'+e.message
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
export default{
|
|
export default{
|
|
- httpServiceGet,
|
|
|
|
- httpServicePost
|
|
|
|
|
|
+ httpService
|
|
}
|
|
}
|