123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- import { _decorator, Component, Node, sys } from 'cc';
- import { config } from './config';
- const { ccclass, property } = _decorator;
- @ccclass('http')
- export class http {
- public static domain = config.debug ? "https://tstzcapi.hainanmlwl.com" : "https://zcapi.hainanmlwl.com";
- public static static_domain = config.debug ? "https://tstzcapi.hainanmlwl.com" : "https://static.hainanmlwl.com"
- public static statistics_domain = config.debug ? "http://logads.xwrun.com" : "https://logads.hainanmlwl.com";
- static post(url, data, call_back) {
- var xml = new XMLHttpRequest()
- xml.open('POST', http.domain + url)
- xml.setRequestHeader('Content-Type', 'application/json');
- xml.send(JSON.stringify(data));
- var array: String[] = ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'];
- array.forEach(function (eventName) {
- xml[('on' + eventName) as 'onloadstart' | 'onabort' | 'onerror' | 'onload' | 'onloadend' | 'ontimeout'] = function () {
- var str = '\nEvent : ' + eventName;
- var lstr = ""
- if (eventName === 'timeout') {
- lstr += '(timeout)';
- }
- else if (eventName === 'loadend') {
- lstr += '...loadend!';
- } else if (eventName === 'onerror') {
- }
- console.log("str==", str)
- console.log("lstr==", lstr)
- };
- });
- // Special event
- xml.onreadystatechange = function () {
- if (xml.readyState === 4 && xml.status >= 200) {
- //label.string = handler(xml.responseText);
- // console.log("xml.responseText==",xml.responseText)
- call_back(null, xml.responseText);
- } else if (xml.status === 404) {
- call_back('404 page not found!', null);
- console.log("status ==", '404 page not found!')
- } else if (xml.readyState === 3) {
- call_back('Request dealing!', null);
- console.log("status ==", 'Request dealing!')
- } else if (xml.readyState === 2) {
- call_back('Request received!', null);
- console.log("status ==", 'Request received!')
- } else if (xml.readyState === 1) {
- call_back('Server connection established! Request hasn\'t been received', null);
- console.log("status ==", 'Server connection established! Request hasn\'t been received')
- } else if (xml.readyState === 0) {
- call_back('Request hasn\'t been initiated!', null);
- console.log("status ==", 'Request hasn\'t been initiated!')
- }
- };
- }
- public static getLongStoryList(page: number, limit: number = 20): string {
- return `/smistatic/long_story/${limit}_${page}.json`
- }
- public static getPlatformLevelsList(level_type:number, long_story_id:number, platform:string, page: number, limit: number = 6): string {
- return `/smistatic/platform_levels/${level_type}/${long_story_id}/${platform}_${limit}_${page}.json`
- }
- public static getGameList(page: number, limit: number = 6): string {
- return `/smistatic/levels/${limit}_${page}.json`
- }
- public static get_dyopen_id(): string {
- return `/note/user/get_dyopen_id`
- }
- public static get_wxopen_id(): string {
- return `/note/user/get_wxopen_id`
- }
- public static get_ksopen_id(): string {
- return `/note/user/get_ksopen_id`
- }
- public static get_zbopen_id():string {
- return '/user/anchor'
- }
- public static get_login(): string {
- return `/note/user/login`
- }
- public static get_game_config(game_id:number,platform:string):string {
- return `/smistatic/game_config/${game_id}_${platform}.json`
- }
- public static get_sys_config(): string {
- return `/smistatic/sys_config.json`
- }
- public static get_level_info(id: number): string {
- return `/smistatic/level_info/${id}.json`
- }
- //场景 scene 0=共用 1 = 场景1 2 = 场景2,
- public static get_level_resource(id: number, scene: number): string {
- return `/smistatic/resource/${id}_${scene}.json`
- }
- public static get_test_user_list(): string {
- return `/smistatic/user_test.json`
- }
- public static sync_data() {
- return `/note/user/sync_data`
- }
- public static statistics_ads() {
- return `/smadspush`
- }
- public static sync_user_level() {
- return `/note/user/sync_level_log`
- }
- public static user_unlock_number_status() {
- return `/note/user/unlock_number_status`
- }
- public static run_get(url, call_back) {
- var xml = new XMLHttpRequest()
- xml.open('GET', url)
- xml.setRequestHeader('Content-Type', 'application/json');
- xml.send();
- var array: String[] = ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'];
- array.forEach(function (eventName) {
- xml[('on' + eventName) as 'onloadstart' | 'onabort' | 'onerror' | 'onload' | 'onloadend' | 'ontimeout'] = function () {
- // var str = '\nEvent : ' + eventName;
- var lstr = ""
- if (eventName === 'timeout') {
- lstr += '(timeout)';
- }
- else if (eventName === 'loadend') {
- lstr += '...loadend!';
- } else if (eventName === 'onerror') {
- }
- };
- });
- // Special event
- xml.onreadystatechange = function () {
- if (xml.readyState === 4 && xml.status >= 200) {
- call_back(null, xml.responseText);
- } else if (xml.status === 404) {
- call_back('404 page not found!', null);
- }
- };
- }
- public static run_get_static(url, call_back) {
- var xml = new XMLHttpRequest()
- // let request_url = http.static_domain + url + "?" + Date.now()
- let request_url = http.static_domain + url
- xml.open('GET', request_url)
- xml.setRequestHeader('Content-Type', 'application/json');
- xml.send();
- var array: String[] = ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'];
- array.forEach(function (eventName) {
- xml[('on' + eventName) as 'onloadstart' | 'onabort' | 'onerror' | 'onload' | 'onloadend' | 'ontimeout'] = function () {
- // var str = '\nEvent : ' + eventName;
- var lstr = ""
- if (eventName === 'timeout') {
- lstr += '(timeout)';
- }
- else if (eventName === 'loadend') {
- lstr += '...loadend!';
- } else if (eventName === 'onerror') {
- }
- };
- });
- // Special event
- xml.onreadystatechange = function () {
- if (xml.readyState === 4 && xml.status >= 200) {
- call_back(null, xml.responseText);
- } else if (xml.status === 404) {
- call_back('404 page not found!', null);
- }
- };
- }
- public static run_post(url, data, call_back) {
- var xml = new XMLHttpRequest()
- xml.open('POST', http.domain + url)
- xml.setRequestHeader('Content-Type', 'application/json');
- xml.setRequestHeader('token', config.TOKEN);
- xml.send(JSON.stringify(data));
- var array: String[] = ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'];
- array.forEach(function (eventName) {
- xml[('on' + eventName) as 'onloadstart' | 'onabort' | 'onerror' | 'onload' | 'onloadend' | 'ontimeout'] = function () {
- var str = '\nEvent : ' + eventName;
- var lstr = ""
- if (eventName === 'timeout') {
- lstr += '(timeout)';
- }
- else if (eventName === 'loadend') {
- lstr += '...loadend!';
- } else if (eventName === 'onerror') {
- }
- };
- });
- // Special event
- xml.onreadystatechange = function () {
- if (xml.readyState === 4 && xml.status >= 200) {
- call_back(null, xml.responseText);
- } else if (xml.status === 404) {
- call_back('404 page not found!', null);
- }
- };
- }
- static statistics_post(url, data, call_back) {
- if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
- const options = {
- url: http.statistics_domain + url,
- data: data,
- header: {
- "content": "application/x-www-form-urlencoded",
- },
- method: "POST", //指定对应的网络请求方法,详见文档中method枚举值
- enableCache: false, //是否开启 cache ,不填默认为false
- timeout: 60000, //超时时间,单位为毫秒(最大值 60000ms)
- }
- // console.log('tt_options=',options)
- let task = tt.request({
- ...options,
- success(res) { //请求成功回调
- // console.log("请求成功", res.data);
- call_back(null, JSON.stringify(res.data));
- },
- fail(res) {//请求失败回调
- // console.log("请求失败", res);
- call_back(-1, null);
- },
- complete(res) { //请求结束回调
- console.log("调用接口结束", res.data)
- }
- });
- } else {
- var xml = new XMLHttpRequest()
- xml.open('POST', http.statistics_domain + url)
- xml.setRequestHeader('Content-Type', 'application/json');
- xml.setRequestHeader('token', config.TOKEN);
- xml.send(JSON.stringify(data));
- var array: String[] = ['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'];
- array.forEach(function (eventName) {
- xml[('on' + eventName) as 'onloadstart' | 'onabort' | 'onerror' | 'onload' | 'onloadend' | 'ontimeout'] = function () {
- var str = '\nEvent : ' + eventName;
- var lstr = ""
- if (eventName === 'timeout') {
- lstr += '(timeout)';
- }
- else if (eventName === 'loadend') {
- lstr += '...loadend!';
- } else if (eventName === 'onerror') {
- }
- };
- });
- // Special event
- xml.onreadystatechange = function () {
- // console.log('xml.readyState=',xml.readyState, 'xml.status=',xml.status, 'xml.responseText=',xml.responseText)
- if (xml.readyState === 4 && xml.status >= 200) {
- call_back(null, xml.responseText);
- } else if (xml.status === 404) {
- call_back('404 page not found!', null);
- }
- };
- }
- }
- }
|