index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // 云函数入口文件
  2. const cloud = require('wx-server-sdk')
  3. const request = require('request');
  4. cloud.init()
  5. // 云函数入口函数
  6. exports.main = async (event, context) => {
  7. const wxContext = cloud.getWXContext()
  8. var data=event.message;
  9. return new Promise((resolve, reject) => {
  10. try {
  11. request({
  12. method: 'POST',
  13. headers: {
  14. Authorization: event.message.token || '',
  15. "content-type": "application/json",
  16. },
  17. body: JSON.stringify(data),
  18. url: 'https://wash.nanodreamtech.com/api/user/getPhoneNumber',
  19. }, function (error, response, body) {
  20. if (error) {
  21. return reject(error);
  22. }
  23. return resolve(JSON.parse(body));
  24. })
  25. } catch (e) {
  26. return reject(e)
  27. }
  28. });
  29. }
  30. // request({
  31. // url: 'https://wash.nanodreamtech.com/api/user/getPhoneNumber', // 云端正式服
  32. // body:data,
  33. // method:'POST',
  34. // headers: {
  35. // Authorization: event.message.token || '',
  36. // 'content-type': 'application/json',
  37. // },
  38. // json: true, // 添加这个配置
  39. // },function (error,response,body){
  40. // if(!error&&response.statusCode==200){
  41. // return body
  42. // }
  43. // })