123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class HTTPS {
- private static _instance = null;
- public static get Instance(): HTTPS {
- if (this._instance == null) {
- this._instance = new HTTPS();
- }
- return this._instance;
- }
- token = null;
- // private _URL = "http://120.79.5.67:7000";
- //得到现在的时间
- private GetNowTime(): string {
- const date = new Date(cc.sys.now());
- const hours = date.getHours();
- const minutes = date.getMinutes();
- const seconds = date.getSeconds();
- return `${hours}:${minutes}:${seconds} `;
- }
- post(action: string, data: object | string): Promise<any> {
- if (CC_DEBUG) {
- cc.error(this.GetNowTime() + "发送消息 >>>>>> :" + action, data);
- // cc.error(this.GetNowTime() + "消息内容 >>>>>> :", data);
- }
- const promise: Promise<any> = new Promise((resolve, reject) => {
- var timeoutKey: number;
- var retry = 5;//失败重试次数
- const send = () => {
- const httpRequest = new XMLHttpRequest();
- const method = 'POST'
- httpRequest.onreadystatechange = (event: Event): void => {
- const readyState = httpRequest.readyState;
- if (readyState !== 4) return;
- if (!timeoutKey) return;//已通知超时,之后收到数据后也不处理
- clearTimeout(timeoutKey);
- timeoutKey = null;
- const requestStatus = httpRequest.status;
- if (requestStatus >= 200 && requestStatus < 400) {
- let resp = JSON.parse(httpRequest.responseText);
- resolve(resp);
- if (CC_DEBUG) {
- cc.error(this.GetNowTime() + `收到消息(${retry}) >>>>>> :` + action, resp);
- // cc.error(httpRequest.responseText);
- }
- }
- else if (retry-- > 0) send();
- else reject(new Error('全部超时'));
- }
- httpRequest.open(method, Url + action, true);
- // httpRequest.setRequestHeader("Access-Control-Allow-Origin", "*");
- httpRequest.setRequestHeader("Content-Type", "application/json;charset=utf-8");
- httpRequest.setRequestHeader("Authorization", this.token != null ? this.token : "");
- var text = typeof (data) == "string" ? data : JSON.stringify(data);
- data ? httpRequest.send(text) : httpRequest.send();
- timeoutKey = setTimeout(() => {
- timeoutKey = null;
- httpRequest.abort();
- reject(new Error(`Timeout`));
- }, 12000);//超时时间(毫秒)
- }
- send();
- })
- return promise;
- }
- get(action: string): Promise<any> {
- if (CC_DEBUG) {
- cc.error(this.GetNowTime() + "发送消息 >>>>>> :" + action);
- }
- const promise: Promise<any> = new Promise((resolve, reject) => {
- var timeoutKey: number;
- var retry = 5;//失败重试次数
- const send = () => {
- const httpRequest = new XMLHttpRequest();
- const method = 'GET'
- httpRequest.onreadystatechange = (event: Event): void => {
- const readyState = httpRequest.readyState;
- if (readyState !== 4) return;
- if (!timeoutKey) return;//已通知超时,之后收到数据后也不处理
- clearTimeout(timeoutKey);
- timeoutKey = null;
- const requestStatus = httpRequest.status;
- if (requestStatus >= 200 && requestStatus < 400) {
- let resp = JSON.parse(httpRequest.responseText);
- resolve(resp);
- if (CC_DEBUG) {
- cc.error(this.GetNowTime() + `收到消息(${retry}) >>>>>> :` + action, resp);
- }
- }
- else if (retry-- > 0) send();
- else reject(new Error('全部超时'));
- }
- httpRequest.open(method, action, true);
- httpRequest.setRequestHeader("Authorization", this.token != null ? this.token : "");
- httpRequest.send();
- timeoutKey = setTimeout(() => {
- timeoutKey = null;
- httpRequest.abort();
- reject(new Error(`Timeout`));
- }, 12000);//超时时间(毫秒)
- }
- send();
- })
- return promise;
- }
- }
- export var Url = "https://api.sheishishangbanwang.top";
- export var NetGet = {
- /**获取地图数据 */
- Map: Url + "/api/tokenpass/Login/Map",
- /**收藏装扮Id 玩家穿戴收藏装 */
- UserWearCollect: Url + "/api/User/UserWearCollect?collectId=",
- /**玩家穿戴荣誉 */
- UserWearHonor: Url + "/api/User/UserWearHonor?honorId=",
- /**每日总数记录 */
- DailyRecord: Url + "/api/tokenpass/Login/DailyRecord",
- }
- export var NetPost = {
- /**登录 */
- Login: "/api/tokenpass/Login/UserInfo",
- TestLogin: "/api/tokenpass/Login/Login",
- /**用户授权 */
- Authorisation: "/api/User/Authorisation",
- /**获取玩家荣誉表 */
- GetUserHonorList: "/api/User/GetUserHonorList",
- /**获取玩家收藏列表 */
- GetUserCollectList: "/api/User/GetUserCollectList",
- /**查询邀请申请 */
- InvitationRecord: "/api/User/InvitationRecord",
- /**领取邀请奖励 */
- ReceiveInvitation: "/api/User/ReceiveInvitation",
-
- /**获取用户信息 */
- GetUserInfo: "/api/User/GetUserInfo",
- /**添加登录游玩记录 */
- AddRecord: "/api/User/AddRecord",
- /**结束本局游戏 */
- EndThisGam: "/api/User/EndThisGame",
- /**消息通知 */
- GetToBenotifiedList: "/api/User/GetToBenotifiedList",
- /**修改消息通知为已读 */
- EditToBenotified: "/api/User/EditToBenotified",
- /**新增消息通知 */
- AddToBenotified: "/api/User/AddToBenotified",
- /**查询职级排行 */
- GetPositionLevelRanking: "/api/User/GetPositionLevelRanking",
- /**获取省份排行 */
- GetProvinceRanking: "/api/User/GetProvinceRanking",
-
- /**获取玩家道具 */
- GetUserProp: "/api/User/GetUserProp",
-
- }
|