LoginApi.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const Api = require('./Api')
  2. class LoginApi {
  3. static login(js_code, wxRes, cb) {
  4. let url = "/auth/loginByGame.do";
  5. let data = {
  6. nick: wxRes.userInfo.nickName,
  7. head: wxRes.userInfo.avatarUrl,
  8. gender: wxRes.userInfo.gender,
  9. js_code: js_code,
  10. encryptedData: wxRes.encryptedData,
  11. iv: wxRes.iv
  12. }
  13. let requestBody = {
  14. url: url,
  15. data: data,
  16. success: (response) => {
  17. console.log('login response: ' + JSON.stringify(response));
  18. var user = response.user;
  19. Global.user = {
  20. token: response.token,
  21. uid: user.id,
  22. openId: user.openId,
  23. nick: wxRes.userInfo.nickName,
  24. avatarUrl: wxRes.userInfo.avatarUrl,
  25. gender: wxRes.userInfo.gender,
  26. };
  27. cc.sys.localStorage.setItem('GlobalUser', Global.user);
  28. cb();
  29. },
  30. fail: (errMsg) => {
  31. console.log(errMsg);
  32. },
  33. }
  34. Api.httpGet(requestBody);
  35. }
  36. static getUserInfoPromise() {
  37. return Api.httpGetPromise('/user/me.do');
  38. }
  39. static getUserInfo(success, fail) {
  40. let requestBody = {
  41. url: '/user/me.do',
  42. data: {},
  43. success: success,
  44. fail: fail,
  45. }
  46. Api.httpGet(requestBody);
  47. }
  48. }
  49. module.exports = LoginApi;