|
|
@@ -6,13 +6,15 @@ import { StorageKey } from "./StorageData";
|
|
|
*/
|
|
|
export class LoginData {
|
|
|
|
|
|
- public loadResCompelete: boolean = false;
|
|
|
+ public loadResCompelete: boolean = false;
|
|
|
|
|
|
/** 是否登录 */
|
|
|
public isLogin: boolean = false;
|
|
|
|
|
|
public sessionKey: string = '';
|
|
|
|
|
|
+ public randomKey: string = "abcdefghijklopqrstuvwxyzabcdefgh";
|
|
|
+
|
|
|
/** 玩家唯一id */
|
|
|
public uin: string = '';
|
|
|
|
|
|
@@ -53,20 +55,20 @@ export class LoginData {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 登录流程 initApp-->initAd-->connect-->wxLogin-->checkLogin-->getAccountInfo
|
|
|
+ * 初始化
|
|
|
*/
|
|
|
- public async login() {
|
|
|
- mk.pool.init(gData.gameData.pools);
|
|
|
- gData.appData.init();
|
|
|
- gData.adData.init();
|
|
|
+ public init() {
|
|
|
+ let uin = mk.storage.getStorage(StorageKey.uin);
|
|
|
+ this.uin = uin ? uin : "";
|
|
|
+ let sessionKey = mk.storage.getStorage(StorageKey.sessionKey);
|
|
|
+ this.sessionKey = sessionKey ? sessionKey : "";
|
|
|
+ }
|
|
|
|
|
|
- //测试参数
|
|
|
- if (cc.sys.os == cc.sys.OS_ANDROID) {
|
|
|
- mk.ad.ifShowAd = true;
|
|
|
- }
|
|
|
- else {
|
|
|
- mk.ad.ifShowAd = false;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 登录流程
|
|
|
+ * @description initApp-->initAd-->connect-->wxLogin-->checkLogin-->getAccountInfo
|
|
|
+ */
|
|
|
+ public async login() {
|
|
|
|
|
|
//有登录记录直接跳转到登录流程最后一步
|
|
|
if (this.sessionKey != '' && this.uin != '') {
|
|
|
@@ -74,40 +76,58 @@ export class LoginData {
|
|
|
this.getAccountInfo();
|
|
|
return;
|
|
|
}
|
|
|
- console.log("=== login 无登录记录");
|
|
|
-
|
|
|
- let ranKey = mk.encrypt.randomString();
|
|
|
+ else {
|
|
|
+ console.log("=== login 无登录记录");
|
|
|
+ this.connect();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 链接
|
|
|
+ * @description 获取临时的uin
|
|
|
+ */
|
|
|
+ private async connect() {
|
|
|
+ //connect
|
|
|
+ this.randomKey = mk.encrypt.randomString();
|
|
|
let data: any = {
|
|
|
"mac": gData.appData.mac,
|
|
|
- "psk": ranKey,
|
|
|
+ "psk": this.randomKey,
|
|
|
"appId": gData.appData.appId
|
|
|
}
|
|
|
|
|
|
- //connect
|
|
|
let response = await mk.http.sendRequest('connectTest', 'POST', JSON.stringify(data));
|
|
|
if (response.errcode != 0) {
|
|
|
return;
|
|
|
}
|
|
|
- data = mk.encrypt.decrypt(response.encrypt, ranKey, gData.appData.appId);
|
|
|
+ data = mk.encrypt.decrypt(response.encrypt, this.randomKey, gData.appData.appId);
|
|
|
+ console.log("[FC]connectTest decryptData", data);
|
|
|
this.tempUin = JSON.parse(data).tmp_uin;
|
|
|
+ mk.storage.setStorage(StorageKey.uin, this.tempUin);
|
|
|
+ this.wxLogin();
|
|
|
+ }
|
|
|
|
|
|
+ public async wxLogin() {
|
|
|
//wxLogin
|
|
|
+ let data;
|
|
|
let encode;
|
|
|
- if (gData.wechatData.code != null) {//微信登录
|
|
|
+ if (gData.wechatData.code != null) {
|
|
|
+ //微信登录
|
|
|
encode = mk.encrypt.encrypt(JSON.stringify({ "code": gData.wechatData.code }), this.sessionKey, gData.appData.appId);
|
|
|
data = {
|
|
|
"uin": this.uin,
|
|
|
"encrypt": encode
|
|
|
};
|
|
|
}
|
|
|
- else {//游客登录
|
|
|
- encode = mk.encrypt.encrypt(JSON.stringify({ "code": '' }), ranKey, gData.appData.appId);
|
|
|
+ else {
|
|
|
+ //游客登录
|
|
|
+ encode = mk.encrypt.encrypt(JSON.stringify({ "code": '' }), this.randomKey, gData.appData.appId);
|
|
|
data = {
|
|
|
"uin": this.tempUin,
|
|
|
"encrypt": encode
|
|
|
};
|
|
|
}
|
|
|
- response = await mk.http.sendRequest('wxlogin', 'POST', JSON.stringify(data), false, false);
|
|
|
+ let response = await mk.http.sendRequest('wxlogin', 'POST', JSON.stringify(data), false, false);
|
|
|
if (response.errcode != 0) {
|
|
|
if (response.errcode == -10003 || response.errcode == -20003) {
|
|
|
//清除缓存
|
|
|
@@ -119,13 +139,14 @@ export class LoginData {
|
|
|
data = mk.encrypt.decrypt(response.encrypt, this.sessionKey, gData.appData.appId);
|
|
|
}
|
|
|
else {
|
|
|
- data = mk.encrypt.decrypt(response.encrypt, ranKey, gData.appData.appId);
|
|
|
+ data = mk.encrypt.decrypt(response.encrypt, this.randomKey, gData.appData.appId);
|
|
|
}
|
|
|
data = JSON.parse(data);
|
|
|
this.loginTicket = data.login_ticket;
|
|
|
+ console.log("[FC]wxLoginTest decrypt", data);
|
|
|
mk.storage.setStorage(StorageKey.loginTicket, this.loginTicket);
|
|
|
|
|
|
- let isFirstIn = mk.storage.getStorage('isFirstIn');
|
|
|
+ let isFirstIn = mk.storage.getStorage(StorageKey.isFirstIn);
|
|
|
if (isFirstIn == null) {
|
|
|
this.isFirstIn = true;
|
|
|
mk.storage.setStorage(StorageKey.isFirstIn, 1);
|
|
|
@@ -138,11 +159,15 @@ export class LoginData {
|
|
|
else {
|
|
|
this.isNew = true;
|
|
|
}
|
|
|
- mk.console.log("uin:", this.uin);
|
|
|
mk.storage.setStorage(StorageKey.uin, this.uin);
|
|
|
+ this.checkLogin();
|
|
|
+ }
|
|
|
|
|
|
- console.log('uin ', this.uin)
|
|
|
- console.log('tempUin ', this.tempUin)
|
|
|
+ /**
|
|
|
+ * 检测登录
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ private async checkLogin() {
|
|
|
//checkLogin
|
|
|
let tmp_key = '';
|
|
|
if (gData.wechatData.code != null) {
|
|
|
@@ -152,49 +177,56 @@ export class LoginData {
|
|
|
tmp_key = mk.encrypt.randomString();
|
|
|
}
|
|
|
|
|
|
- data = {
|
|
|
+ let data = {
|
|
|
"tmp_key": tmp_key,
|
|
|
"uin": this.uin,
|
|
|
"login_ticket": this.loginTicket,
|
|
|
"appId": gData.appData.appId
|
|
|
}
|
|
|
- response = await mk.http.sendRequest('checklogin', 'POST', JSON.stringify(data));
|
|
|
+ let response = await mk.http.sendRequest('checklogin', 'POST', JSON.stringify(data));
|
|
|
if (response.errcode != 0) {
|
|
|
return;
|
|
|
}
|
|
|
+ let decryptData;
|
|
|
if (gData.wechatData.code != null) {
|
|
|
- data = mk.encrypt.decrypt(response.encrypt, this.sessionKey, gData.appData.appId);
|
|
|
+ decryptData = mk.encrypt.decrypt(response.encrypt, this.sessionKey, gData.appData.appId);
|
|
|
}
|
|
|
else {
|
|
|
- data = mk.encrypt.decrypt(response.encrypt, tmp_key, gData.appData.appId);
|
|
|
+ decryptData = mk.encrypt.decrypt(response.encrypt, tmp_key, gData.appData.appId);
|
|
|
}
|
|
|
|
|
|
- data = JSON.parse(data);
|
|
|
- this.sessionKey = data.session_key;
|
|
|
-
|
|
|
- mk.storage.setStorage('sessionKey', this.sessionKey);
|
|
|
+ let parseData = JSON.parse(decryptData);
|
|
|
+ this.sessionKey = parseData.session_key;
|
|
|
+ console.log("[FC]checkLogin decrypt", parseData);
|
|
|
+ mk.storage.setStorage(StorageKey.sessionKey, this.sessionKey);
|
|
|
+ this.getUserInfo();
|
|
|
+ }
|
|
|
|
|
|
- if (gData.wechatData.code != null) {
|
|
|
- if (this.isNew) {//玩过此游戏并且本地数据是本机的
|
|
|
- this.getAccountInfo();
|
|
|
- }
|
|
|
- else {//玩过此游戏 但 本地数据不是本账户的 清空数据 重新登录游戏
|
|
|
- this.isNew = false;
|
|
|
- gData.wechatData.code = null;
|
|
|
- this.reload();
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- this.getAccountInfo();
|
|
|
- }
|
|
|
+ private async getUserInfo() {
|
|
|
+
|
|
|
+ // if (gData.wechatData.code != null) {
|
|
|
+ // if (this.isNew) {//玩过此游戏并且本地数据是本机的
|
|
|
+ // this.getAccountInfo();
|
|
|
+ // }
|
|
|
+ // else {//玩过此游戏 但 本地数据不是本账户的 清空数据 重新登录游戏
|
|
|
+ // this.isNew = false;
|
|
|
+ // gData.wechatData.code = null;
|
|
|
+ // this.reload();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // this.getAccountInfo();
|
|
|
+ // }
|
|
|
+
|
|
|
+ this.getAccountInfo();
|
|
|
}
|
|
|
|
|
|
private async getAccountInfo() {
|
|
|
- let nickname = mk.storage.getStorage(StorageKey.nickname);
|
|
|
- if (nickname) {
|
|
|
- gData.wechatData.nickName = nickname;
|
|
|
- }
|
|
|
- else {
|
|
|
+ // let nickname = mk.storage.getStorage(StorageKey.nickname);
|
|
|
+ // if (nickname) {
|
|
|
+ // gData.wechatData.nickName = nickname;
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
let aa = {
|
|
|
"uin": this.uin,
|
|
|
"login_ticket": this.loginTicket
|
|
|
@@ -215,22 +247,23 @@ export class LoginData {
|
|
|
}
|
|
|
response = mk.http.checkData(response, true);
|
|
|
data = response.data;
|
|
|
+ mk.console.logSingle("[FC] getAccountInfo decrypt", data);
|
|
|
this.isAuth = data.is_auth;
|
|
|
if (this.isAuth) {
|
|
|
gData.wechatData.nickName = data.nickname;
|
|
|
gData.wechatData.avatar = data.headimgurl;
|
|
|
+ gData.gameData.init_head = true;
|
|
|
mk.storage.setStorage(StorageKey.isAuth, 1);
|
|
|
mk.storage.setStorage(StorageKey.nickname, gData.wechatData.nickName, false);
|
|
|
mk.storage.setStorage(StorageKey.avatar, gData.wechatData.avatar, false);
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ // }
|
|
|
|
|
|
//获取游戏数据
|
|
|
gData.gameData.init();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 本地数据不是本账户的 清空数据 重新登录游戏
|
|
|
*/
|