PogHttp.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Http from "../utils/Http";
  2. export interface PogResp {
  3. protocolId: number;
  4. requestId: number;
  5. code: number;
  6. success: boolean;
  7. data: any;
  8. msg: string;
  9. }
  10. export interface PogLoginResp {
  11. token: string;
  12. expire: number;
  13. wsUrl: string;
  14. }
  15. export default class PogHttp {
  16. private static readonly client = "YbVHPrXS";
  17. private static readonly HTTP_HEAD = "https://zombies.telgather.com/platform";
  18. private static _ins: PogHttp;
  19. public static get ins(): PogHttp {
  20. return (this._ins ??= new PogHttp());
  21. }
  22. public lastError: string = "";
  23. public async _apiRequest(path: string, params: any): Promise<any> {
  24. const headers = {
  25. client: PogHttp.client,
  26. };
  27. const resp = await Http.get(PogHttp.HTTP_HEAD + path, params, headers);
  28. const pogResp = resp as PogResp;
  29. if (pogResp.code !== 200) {
  30. this.lastError = pogResp.msg;
  31. return null;
  32. }
  33. return pogResp.data;
  34. }
  35. public async loginByWalletAddress(address: string): Promise<PogLoginResp> {
  36. const path = "/pog-service/login/wallet";
  37. const res = await this._apiRequest(path, { address });
  38. return res;
  39. }
  40. async loginByTgParams(
  41. initDataRaw: string,
  42. tgWebAppStartParam: string
  43. ): Promise<PogLoginResp> {
  44. const path = "/pog-service/login/tg";
  45. if (!tgWebAppStartParam) {
  46. tgWebAppStartParam = "ABC";
  47. }
  48. const res = await this._apiRequest(path, {
  49. params: initDataRaw,
  50. inviteCode: tgWebAppStartParam,
  51. });
  52. return res;
  53. }
  54. async allConfig(): Promise<any> {
  55. const path = "/pog-service/login/config";
  56. const res = await this._apiRequest(path, {});
  57. return res;
  58. }
  59. }