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