"use strict"; cc._RF.push(module, '8bbd3GCsnVEz4NFoHK4N0BO', 'APIUtil'); // Scripts/erolabs/APIUtil.ts "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.APIUtil = void 0; var Result_1 = require("./Result"); var APIUtil = /** @class */ (function () { function APIUtil() { } APIUtil.test = function () { var api = new APIUtil(); var queryMap = new Result_1.Dictionary(); var url = "https://liap.condowlogp.com/api/getUserInfo?merchantId=&serviceId="; var authorization = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNWY5MTFmNWMtMGZmYS00NjhlLTgxYjgtOWQ4ODUxMjdmYmYzIiwidG9rZW5faWQiOiJlZTFlMTgwNC03YWIxLTQyN2MtYWM2Zi1iYjEwMzFiZTczYjIiLCJpYXQiOjE2MDYyNjkyNzN9.I6U2c3tBwMWM5ZcFg3-N_uIFontQzX85blEw2h2L4esfFRa6R4oCXBibEGF9xITcMIJTxICI3renSbFVnOACM_9TAMIdbE-W6pdtfKqRTlpL2fXRITZMAN69_anAr5Y1PJGtgzslDEE1rFlAmL-aOjoaserBHA8XuD8TRYz9VlL4gGPu7sNdiFmhtHF2iATcmgeif8kLpodAXK3zPvWEqXIhXALZTK31U6GQo0WUwm7DELReuYUcDlLWROsLdHpI913EvJY7bY9T1NzSEDDpHXgCnFVvtOpix0-Ip7RGYTzQd4bYxx3pFJmU8qLPi1Rugw4CsbWVi7CdQIcZnEr-qg"; api.requestAPI(url, queryMap, authorization, "", function (_) { console.log(_); }); }; APIUtil.prototype.requestAPI = function (url, queryStringMap, authorization, body, callback) { var _url = url; var buf = ""; // 將query 拼接成字串 if (Object.keys(queryStringMap).length > 0) { for (var key in queryStringMap) { var value = queryStringMap[key]; if (buf.length > 0) { buf = buf + "&"; } buf = "" + buf + key + "=" + value; } _url = _url + "?" + buf; } var method = body.length == 0 ? "GET" : "POST"; var xhr = cc.loader.getXMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) return; //cc.log('xhr.readyState=' + xhr.readyState + ' xhr.status=' + xhr.status); var rawResponse = new Result_1.RawResponse(); rawResponse.StatusCode = xhr.status; if (xhr.status >= 200 && xhr.status < 300) { rawResponse.Exception = ""; rawResponse.Data = xhr.responseText; } else { rawResponse.Exception = xhr.statusText; rawResponse.Data = ""; } callback(rawResponse); }; xhr.onerror = function () { var rawResponse = new Result_1.RawResponse(); rawResponse.StatusCode = xhr.status; rawResponse.Exception = xhr.statusText; rawResponse.Data = ""; callback(rawResponse); }; xhr.open(method, _url, true); if (authorization.length > 0) { xhr.setRequestHeader("Authorization", authorization); } if (body.length > 0) { xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); } xhr.send(body); }; return APIUtil; }()); exports.APIUtil = APIUtil; cc._RF.pop();