协议修改
This commit is contained in:
@@ -37,6 +37,7 @@ import MachineInfoService from "db://assets/Scripts/chat18x/foundation/identity/
|
|||||||
import { AuthService } from "db://assets/Scripts/chat18x/network/services/AuthService";
|
import { AuthService } from "db://assets/Scripts/chat18x/network/services/AuthService";
|
||||||
import { PlayerDataService } from "db://assets/Scripts/chat18x/network/services/PlayerDataService";
|
import { PlayerDataService } from "db://assets/Scripts/chat18x/network/services/PlayerDataService";
|
||||||
import { ApiCode } from "db://assets/Scripts/chat18x/network/client/types";
|
import { ApiCode } from "db://assets/Scripts/chat18x/network/client/types";
|
||||||
|
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -260,38 +261,36 @@ export class PreloadUI extends Component {
|
|||||||
const deviceId = DeviceIdService.I.id;
|
const deviceId = DeviceIdService.I.id;
|
||||||
const machineIdentifier = MachineInfoService.I.getMachineIdentifier();
|
const machineIdentifier = MachineInfoService.I.getMachineIdentifier();
|
||||||
const reqData = {
|
const reqData = {
|
||||||
GameName: ConfigManager.tables.TbGlobalConfig.GameName,
|
platType: 'guset',
|
||||||
Identifier: deviceId,
|
userId: deviceId,
|
||||||
IdentityType: 1,
|
device: deviceId,
|
||||||
OperateType: 1,
|
os: 3,
|
||||||
ShareDeposit: '',
|
|
||||||
MachineIdentifier: machineIdentifier,
|
|
||||||
SdkUid: '',
|
|
||||||
};
|
};
|
||||||
console.log("登录请求数据:", reqData);
|
console.log("登录请求数据:", reqData);
|
||||||
let res = await AuthService.I.login(reqData);
|
let res = await AuthService.I.login(reqData);
|
||||||
console.log("登录响应数据:", res);
|
console.log("登录响应数据:", res);
|
||||||
if (res && res.code === ApiCode.OK) {
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||||
const resData = res.data;
|
const resData = res.data;
|
||||||
// 保存数据
|
// 保存数据
|
||||||
const loginData = DataManager.I.getDataById<LoginData>(DataId.Login);
|
const loginData = DataManager.I.getDataById<LoginData>(DataId.Login);
|
||||||
loginData.operateType = resData.OperateType;
|
// loginData.operateType = resData.OperateType;
|
||||||
loginData.token = resData.Token;
|
loginData.token = resData.token;
|
||||||
loginData.ip = resData.Ip;
|
// loginData.refreshToken = resData.refreshToken;
|
||||||
loginData.machineIdentifier = resData.MachineIdentifier;
|
// loginData.ip = resData.Ip;
|
||||||
loginData.sdkUid = resData.SdkUid;
|
// loginData.machineIdentifier = resData.MachineIdentifier;
|
||||||
loginData.lastLoginTime = resData.LastLoginTime;
|
// loginData.sdkUid = resData.SdkUid;
|
||||||
const accountData = DataManager.I.getDataById<AccountData>(DataId.Account);
|
// loginData.lastLoginTime = resData.LastLoginTime;
|
||||||
accountData.identifier = resData.Identifier;
|
// const accountData = DataManager.I.getDataById<AccountData>(DataId.Account);
|
||||||
accountData.identityType = resData.IdentityType;
|
// accountData.identifier = resData.Identifier;
|
||||||
accountData.uid = resData.Uid;
|
// accountData.identityType = resData.IdentityType;
|
||||||
accountData.isNewGuide = resData.IsNewGuide;
|
// accountData.uid = resData.Uid;
|
||||||
accountData.isNewRegist = resData.IsNewRegist;
|
// accountData.isNewGuide = resData.IsNewGuide;
|
||||||
const metaData = DataManager.I.getDataById<MetaData>(DataId.Meta);
|
// accountData.isNewRegist = resData.IsNewRegist;
|
||||||
metaData.gameName = resData.GameName;
|
// const metaData = DataManager.I.getDataById<MetaData>(DataId.Meta);
|
||||||
const netTimeData = DataManager.I.getDataById<NetTimeData>(DataId.NetTime);
|
// metaData.gameName = resData.GameName;
|
||||||
netTimeData.serverTime = resData.ServerTime;
|
// const netTimeData = DataManager.I.getDataById<NetTimeData>(DataId.NetTime);
|
||||||
netTimeData.timezoneOffset = resData.TimezoneOffset;
|
// netTimeData.serverTime = resData.ServerTime;
|
||||||
|
// netTimeData.timezoneOffset = resData.TimezoneOffset;
|
||||||
|
|
||||||
this.loginFinish = true;
|
this.loginFinish = true;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import { AppConfigShape, Env } from "./env";
|
|||||||
export const devConfig: AppConfigShape = {
|
export const devConfig: AppConfigShape = {
|
||||||
env: Env.Dev,
|
env: Env.Dev,
|
||||||
endpoints: {
|
endpoints: {
|
||||||
httpBase: "http://43.139.27.67:8081/",
|
httpBase: "http://120.25.215.205:20600/",
|
||||||
socketBase: "ws://127.0.0.1:9001/ws/",
|
socketBase: "ws://127.0.0.1:9001/ws/",
|
||||||
cdn: {
|
cdn: {
|
||||||
bgm: "http://127.0.0.1:8081/BGM/",
|
bgm: "http://127.0.0.1:8081/BGM/",
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import { AppConfigShape, Env } from "./env";
|
|||||||
export const testConfig: AppConfigShape = {
|
export const testConfig: AppConfigShape = {
|
||||||
env: Env.Test,
|
env: Env.Test,
|
||||||
endpoints: {
|
endpoints: {
|
||||||
httpBase: "http://43.139.27.67:8081/",
|
httpBase: "http://120.25.215.205:20600/",
|
||||||
socketBase: "wss://www.confessioncontract.com/test/game/ai/response/",
|
socketBase: "wss://www.confessioncontract.com/test/game/ai/response/",
|
||||||
cdn: {
|
cdn: {
|
||||||
bgm: "https://test-cdn.example.com/BGM/",
|
bgm: "https://test-cdn.example.com/BGM/",
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ export class LoginData extends BaseData {
|
|||||||
private _loginState = 0;
|
private _loginState = 0;
|
||||||
// token
|
// token
|
||||||
private _token = "";
|
private _token = "";
|
||||||
|
// refresh token
|
||||||
|
private _refreshToken = "";
|
||||||
// 操作类型,1:登录界面;2:断线重连;3:其他
|
// 操作类型,1:登录界面;2:断线重连;3:其他
|
||||||
private _operateType = 1;
|
private _operateType = 1;
|
||||||
// 公网IP
|
// 公网IP
|
||||||
@@ -43,6 +45,17 @@ export class LoginData extends BaseData {
|
|||||||
public get token(): string {
|
public get token(): string {
|
||||||
return this._token;
|
return this._token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 设置登录refresh token */
|
||||||
|
public set refreshToken(value: string) {
|
||||||
|
this._refreshToken = value;
|
||||||
|
console.log("设置登录refresh token", this._refreshToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取登录refresh token */
|
||||||
|
public get refreshToken(): string {
|
||||||
|
return this._refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
/** 设置操作类型 */
|
/** 设置操作类型 */
|
||||||
public set operateType(value: number) {
|
public set operateType(value: number) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class ApiClient {
|
|||||||
}
|
}
|
||||||
private constructor(private http = HttpManager.I) {}
|
private constructor(private http = HttpManager.I) {}
|
||||||
private get baseUrl() { return AppConfig.I.getHttpBase() }
|
private get baseUrl() { return AppConfig.I.getHttpBase() }
|
||||||
private get token() { return DataManager.I.getDataById<LoginData>(DataId.Login).getToken();}
|
private get token() { return DataManager.I.getDataById<LoginData>(DataId.Login).token;}
|
||||||
|
|
||||||
public async call<Req, Res>(ep: Endpoint<Req, Res>, req: Req): Promise<ApiResponse<Res>> {
|
public async call<Req, Res>(ep: Endpoint<Req, Res>, req: Req): Promise<ApiResponse<Res>> {
|
||||||
const url = `${this.baseUrl}/${ep.path.replace(/^\/+/, "")}`;
|
const url = `${this.baseUrl}/${ep.path.replace(/^\/+/, "")}`;
|
||||||
@@ -67,12 +67,12 @@ export class ApiClient {
|
|||||||
if (parsed && typeof parsed === "object" && typeof parsed.code === "number") {
|
if (parsed && typeof parsed === "object" && typeof parsed.code === "number") {
|
||||||
return {
|
return {
|
||||||
code: parsed.code,
|
code: parsed.code,
|
||||||
msg: parsed.msg ?? (parsed.code === 1 ? "ok" : "error"),
|
msg: parsed.msg ?? (parsed.code === 0 ? "ok" : "error"),
|
||||||
data: parsed.Data as Res
|
data: parsed.data as Res
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// 否则我们包一层
|
// 否则我们包一层
|
||||||
return { code: ApiCode.OK, msg: "ok", data: parsed.Data as Res };
|
return { code: ApiCode.OK, msg: "ok", data: parsed.data as Res };
|
||||||
} else if (ep.codec === "proto") {
|
} else if (ep.codec === "proto") {
|
||||||
const data = ProtoCodec.decode<Res>(ep.resType!, r.body);
|
const data = ProtoCodec.decode<Res>(ep.resType!, r.body);
|
||||||
// proto 场景一般没有 {code,msg} 包装,我们统一包一层
|
// proto 场景一般没有 {code,msg} 包装,我们统一包一层
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export interface ApiResponse<T = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ApiCode = {
|
export const ApiCode = {
|
||||||
OK: 1,
|
OK: 0,
|
||||||
AUTH_EXPIRED: -401,
|
AUTH_EXPIRED: -401,
|
||||||
HTTP_ERROR: -400,
|
HTTP_ERROR: -400,
|
||||||
TIMEOUT: -408,
|
TIMEOUT: -408,
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ export class AuthService {
|
|||||||
private constructor(private api = ApiClient.I) {}
|
private constructor(private api = ApiClient.I) {}
|
||||||
|
|
||||||
// 登录
|
// 登录
|
||||||
public async login(req: proto.ProtoMsg.ILoginReq): Promise<ApiResponse<proto.ProtoMsg.ILoginRsp>> {
|
public async login(req: proto.cs.ICSLoginReq): Promise<ApiResponse<proto.cs.ICSLoginRes>> {
|
||||||
let epData: Endpoint<proto.ProtoMsg.ILoginReq, proto.ProtoMsg.ILoginRsp> = {
|
let epData: Endpoint<proto.cs.ICSLoginReq, proto.cs.ICSLoginRes> = {
|
||||||
path: "login",
|
path: "api/acc/login",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
codec: "json",
|
codec: "json",
|
||||||
needsAuth: false
|
needsAuth: false
|
||||||
|
|||||||
@@ -48,13 +48,10 @@ export class HttpManager {
|
|||||||
xhr.open(method, url, true);
|
xhr.open(method, url, true);
|
||||||
if (sys.isNative) {
|
if (sys.isNative) {
|
||||||
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
|
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
|
||||||
xhr.setRequestHeader("content-type", "text/html;charset=utf-8");
|
xhr.setRequestHeader("Content-type", "text/html;charset=utf-8");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xhr.open(method, url, true);
|
xhr.open(method, url, true);
|
||||||
if (!opt.rawBody) {
|
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (opt.headers) {
|
if (opt.headers) {
|
||||||
Object.keys(opt.headers).forEach(k => xhr.setRequestHeader(k, opt.headers![k]));
|
Object.keys(opt.headers).forEach(k => xhr.setRequestHeader(k, opt.headers![k]));
|
||||||
|
|||||||
Vendored
+1664
-4665
File diff suppressed because it is too large
Load Diff
+4820
-17231
File diff suppressed because it is too large
Load Diff
+1
-1
Submodule proto_cs updated: c1936f3323...596a85ecea
Reference in New Issue
Block a user