123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const Api = require('./Api')
- class LoginApi {
- static login(js_code, wxRes, cb) {
- let url = "/auth/loginByGame.do";
- let data = {
- nick: wxRes.userInfo.nickName,
- head: wxRes.userInfo.avatarUrl,
- gender: wxRes.userInfo.gender,
- js_code: js_code,
- encryptedData: wxRes.encryptedData,
- iv: wxRes.iv
- }
- let requestBody = {
- url: url,
- data: data,
- success: (response) => {
- console.log('login response: ' + JSON.stringify(response));
- var user = response.user;
- Global.user = {
- token: response.token,
- uid: user.id,
- openId: user.openId,
- nick: wxRes.userInfo.nickName,
- avatarUrl: wxRes.userInfo.avatarUrl,
- gender: wxRes.userInfo.gender,
- };
- cc.sys.localStorage.setItem('GlobalUser', Global.user);
- cb();
- },
- fail: (errMsg) => {
- console.log(errMsg);
- },
- }
- Api.httpGet(requestBody);
- }
- static getUserInfoPromise() {
- return Api.httpGetPromise('/user/me.do');
- }
- static getUserInfo(success, fail) {
- let requestBody = {
- url: '/user/me.do',
- data: {},
- success: success,
- fail: fail,
- }
- Api.httpGet(requestBody);
- }
- }
- module.exports = LoginApi;
|