消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

542 lines
19 KiB

1 week ago
import { _decorator, Component, EditBox, find, log, macro, Node } from 'cc';
import { OtherDataType } from '../game/GameData';
import { sdkConfig } from '../sdk/sdkConfig';
const { ccclass, property } = _decorator;
export class requestData {
public meth_custom: string = "post";
public readonly data_custom: any;
public url_custom: string = "";
public onSuccess_custom: Function = null;
public onFail_custom: Function = null;
constructor() {
this.data_custom = {};
}
}
export class UserGameData {
public uuid: string = '';
}
@ccclass('CheckLayer')
export class CheckLayer extends Component {
@property(EditBox)
UUIDEdit: EditBox = null;
private static readonly _gameData_custom: UserGameData = new UserGameData();
public static token_custom: string = null;
public static code_custom: string = "";
start() {
this.schedule(this.checkWhiteList,5,macro.REPEAT_FOREVER,0.1)
}
public getCurSecond(){
return Date.parse(new Date().toString())/1000;
}
public static get isLogin_custom() {
return (CheckLayer.code_custom != "") || (CheckLayer.token_custom != "");
}
public static setUUID(num: string) {
// CheckLayer._gameData_custom.uuid = num;
console.log('setUUID:'+num);
gg.data.setStringData(OtherDataType.BaiMingTianUUIid,num);
gg.data.saveLocal();
}
public static getUUID(): string {
return gg.data.getStringData(OtherDataType.BaiMingTianUUIid);
// return CheckLayer._gameData_custom.uuid;
}
checkWhiteList(){
if (!sdkConfig.isInitGameData){
this.UUIDEdit.string = "正在查找本地白名单...";
return;
}
let tmpUUID = "";
if (CheckLayer.getUUID() == ""){
tmpUUID = CheckLayer.getRandomNum(1000,9999) + "-" + Math.round(this.getCurSecond());
this.UUIDEdit.string = tmpUUID;
CheckLayer.setUUID(tmpUUID);
}
else {
tmpUUID = this.UUIDEdit.string = CheckLayer.getUUID();
console.log('getUUID:'+tmpUUID);
}
let rd = new requestData();
rd.data_custom.uuid = tmpUUID;
rd.meth_custom = "GET";
rd.url_custom = "https://dy.ioe-times.com/gamewhitelist/checkwhitelist?devid="+tmpUUID
rd.onSuccess_custom = (res)=>{
console.log(res);
}
let headers = {};
let time = "time=" + String(Date.now());
if (CheckLayer.token_custom) {
headers["token"] = CheckLayer.token_custom;
}
CheckLayer.sendHttpUrl_custom(rd,"{}",(res)=>{
if (res){
console.log("true");
this.node.active = false;
this.unschedule(this.checkWhiteList);
}
else{
this.node.active = true;
console.log("false");
}
},(err)=>{
console.log(err);
},headers);
}
/**
* min到max取随机数min>=max的情况
* @param min
* @param max
*/
public static getRandomNum(min:number,max:number){
let minNumber = Math.min(min,max);
let maxNumber = Math.max(min,max);
return Math.floor(Math.random()*(maxNumber - minNumber)) + minNumber;
}
// //
/**
* Http
* @param req
* @param sendMsg
* @param completeFunc
* @param errorFunc
* @param headers
*/
public static sendHttpUrl_custom(req: requestData, sendMsg: string, completeFunc: Function, errorFunc: Function, headers?: any) {
let headersTab = headers || {}; //头数据
let xhr: XMLHttpRequest = new XMLHttpRequest();
//请求过程发生意外的回调
xhr.onerror = function (error) {
CheckLayer.networkError_custom("网络请求异常" + error)
errorFunc("网络请求异常");
}
//超时
xhr.ontimeout = function (error) {
CheckLayer.networkError_custom("网络超时" + error)
errorFunc("网络超时");
}
xhr.onreadystatechange = function () {
/*
0 UNSENT open()
1 OPENED open()
2 HEADERS_RECEIVED send()
3 LOADING responseText
4 DONE
*/
let readyState = xhr.readyState;
let status = xhr.status;
if (readyState === 4) {
if (status >= 200 && status < 300) {
let responseText = xhr.responseText;
CheckLayer.networkLog_custom("接收数据:----------------------")
CheckLayer.networkLog_custom("接收内容:" + responseText)
const response = JSON.parse(responseText);
completeFunc(response);
} else {
let statusText = xhr.statusText;
CheckLayer.networkError_custom("接收数据异常:----------------------status " + status)
CheckLayer.networkLog_custom("接收内容:" + statusText)
errorFunc(statusText);
}
}
}
xhr.open(req.meth_custom, req.url_custom, true);
if (headersTab) {
for (let key in headersTab) {
xhr.setRequestHeader(key, headersTab[key]);
}
}
CheckLayer.networkLog_custom("发送数据:----------------------")
CheckLayer.networkLog_custom(req.url_custom + " " + req.meth_custom)
CheckLayer.networkLog_custom(sendMsg);
CheckLayer.networkLog_custom(JSON.stringify(headers));
CheckLayer.networkLog_custom("----------------------")
xhr.send(sendMsg);
}
public static request_custom(req: requestData) {
if (req.url_custom.indexOf("https://") > -1 ||
req.url_custom.indexOf("http://") > -1) {
req.url_custom = req.url_custom;
} else {
req.url_custom = CheckLayer.serverUrl_custom + req.url_custom;
// }
}
let completeFunc = (res) => {
CheckLayer.networkLog_custom(res, "http Success")
if (req.onSuccess_custom) {
req.onSuccess_custom(res);
}
req.onSuccess_custom = null;
req = null;
};
let fail = req.onFail_custom;
let errorFunc = (res) => {
CheckLayer.networkLog_custom(res, "http fail")
if (fail) {
fail(res);
}
req && (req.onFail_custom = null);
fail = null;
req = null;
};
// req.data_custom.code = User.code_custom;
//头文件
let time = "time=" + String(Date.now());
let headers = {};
//headers["Access-Control-Allow-Origin"] = "*";
//发送数据
let sendMsg = null;
if (req.data_custom) {
sendMsg = JSON.stringify(req.data_custom)
}
this.sendHttpUrl_custom(req, sendMsg, completeFunc, errorFunc, headers);
}
//todo:这里添加你们和服务器相互的接口
public static getServerTime_custom(onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.Get_ServerTime_custom;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
//todo:这里添加你们和服务器相互的接口
public static login_custom(onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.Login_custom;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
public static saveGameData_custom(gameData: any, onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.SaveGameData_custom;
// if (AppPlatform.is_VIVO_GAME_custom() || AppPlatform.is_Android_custom()) {//vivo andorid 用php
// req.url_custom = NetConfig.php_SaveGameData_custom;
// }
req.data_custom.gameData = gameData;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
public static getGameData_custom(onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.GetUser_custom;
req.onSuccess_custom = onSuccess;
// if (AppPlatform.is_VIVO_GAME_custom() || AppPlatform.is_Android_custom()) {//vivo andorid 用php
// req.url_custom = NetConfig.php_GetUser_custom;
// let fucSuccess = (res) => {
// if (res.data && res.data.gamedata) {//对php的数据做加工
// let _cdata = res.data.gamedata;
// res.data = _cdata;
// }
// if (onSuccess) {
// onSuccess(res);
// }
// }
// req.onSuccess_custom = fucSuccess;
// }
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
/**
* IP屏蔽方法NetConfig类中设置IpBlock的接口地址
* onSuccess方法返回参数的范例为 Object {code: 0, msg: "准一线", time: "1571034447", data: null}
* @static
* @memberof HttpUnit
*/
public static GetIpBlock_custom(onSuccess: Function, onFail: Function) {
console.error("启动新版本的屏蔽系统")
let url = "https://wxxyx.renyouwangluo.cn/renyou_other_template/ipLogin"
let headersTab = {}; //头数据
let xhr: XMLHttpRequest = new XMLHttpRequest();
xhr.timeout = 15000;
//请求过程发生意外的回调
xhr.onerror = function (error) {
CheckLayer.networkError_custom("网络请求异常" + error)
onFail("网络请求异常");
}
//超时
xhr.ontimeout = function (error) {
CheckLayer.networkError_custom("网络超时" + error)
onFail("网络超时");
}
xhr.onreadystatechange = function () {
/*
0 UNSENT open()
1 OPENED open()
2 HEADERS_RECEIVED send()
3 LOADING responseText
4 DONE
*/
let readyState = xhr.readyState;
let status = xhr.status;
if (readyState === 4) {
let tab = { code: 1 }
if (status >= 200 && status < 300) {
let responseText = xhr.responseText;
CheckLayer.networkLog_custom("接收数据:----------------------")
CheckLayer.networkLog_custom("接收内容:" + responseText)
const response = JSON.parse(responseText);
if (response && response.isBlackIp == 0) {//没有屏蔽
tab.code = 0;
console.error("新版本的屏蔽系统 不屏蔽")
} else {
console.error("新版本的屏蔽系统 ", responseText)
}
onSuccess(tab);
} else {
let statusText = xhr.statusText;
CheckLayer.networkError_custom("接收数据异常:----------------------status " + status)
CheckLayer.networkLog_custom("接收内容:" + statusText)
onSuccess(tab);
}
}
}
xhr.open("POST", url, true);
if (!headersTab["Content-Type"]) {
headersTab["Content-Type"] = "application/json";
}
if (headersTab) {
for (let key in headersTab) {
xhr.setRequestHeader(key, headersTab[key]);
}
}
}
public static reportExport_custom(appid: string, game_name: string, onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.reportExport_custom1;
req.data_custom.wbappid = appid;
req.data_custom.game_name = game_name;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
public static reportImport_custom(appid: string, channel: string, onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.reportImport_custom1;
req.data_custom.wbappid = appid;
req.data_custom.channel = channel;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
public static Getuserip_custom(onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.getuserip_custom;
// if (AppPlatform.is_VIVO_GAME_custom() || AppPlatform.is_Android_custom()) {//vivo andorid 用php
// req.url_custom = NetConfig.php_getuserip_custom;
// }
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
CheckLayer.request_custom(req);
}
//签到
public static SignIn_custom(onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.signin_custom;
// if (AppPlatform.is_VIVO_GAME_custom() || AppPlatform.is_Android_custom()) {//vivo andorid 用php
// req.url_custom = NetConfig.php_signin_custom;
// }
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
req.data_custom.type = 1;
CheckLayer.request_custom(req);
}
//获取签到状态
public static GetSignIn_custom(onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.signin_custom;
// if (AppPlatform.is_VIVO_GAME_custom() || AppPlatform.is_Android_custom()) {//vivo andorid 用php
// req.url_custom = NetConfig.php_signin_custom;
// }
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
req.data_custom.type = 0;
CheckLayer.request_custom(req);
}
//抖音上报渠道参数
public static reportTTLaunchChannel_custom(ak: string, cd: string, bid: string, onSuccess: Function, onFail: Function) {
var req = new requestData();
req.url_custom = CheckLayer.ttReportLaunchChannel_custom;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
req.data_custom.ak = ak;
req.data_custom.bid = bid;
req.data_custom.cd = cd;
CheckLayer.request_custom(req);
}
/**
*
* @param data
* @param onSuccess
* @param onFail
*/
public static userScanCode_custom(data: any, onSuccess?: Function, onFail?: Function) {
var req = new requestData();
req.url_custom = CheckLayer.userScanCode_custom1;
req.onSuccess_custom = onSuccess;
req.onFail_custom = onFail;
req.data_custom.code = data.code;
req.data_custom.state = data.state;
// req.data_custom.gameId = data.gameId;
req.data_custom.type = data.type;
req.data_custom.scan = data.scan;
CheckLayer.request_custom(req);
}
/** log状态 */
private static _logStatus_custom: boolean = true;
/** 设置日志状态 */
public static setLogStatus(flag: boolean): void {
CheckLayer._logStatus_custom = flag;
}
/**调试日志*/
public static log_custom(message?: any, ...optionalParams: any[]): void {
if (!CheckLayer._logStatus_custom) { return; }
console.log("[log][", CheckLayer.getFullTime_custom(), "]", ":", message, ...optionalParams);
}
/**输出日志*/
public static info_custom(message?: any, ...optionalParams: any[]): void {
if (!CheckLayer._logStatus_custom) { return; }
console.debug("[debug][", CheckLayer.getFullTime_custom(), "]", ":", message, ...optionalParams);
}
/**警告日志*/
public static warn_custom(message?: any, ...optionalParams: any[]): void {
if (!CheckLayer._logStatus_custom) { return; }
console.warn("[warn][", CheckLayer.getFullTime_custom(), "]", ":", message, ...optionalParams);
}
/**错误日志*/
public static error_custom(message?: any, ...optionalParams: any[]): void {
if (!CheckLayer._logStatus_custom) { return; }
console.error("[error][", CheckLayer.getFullTime_custom(), "]", ":", message, ...optionalParams);
}
/**网络日志*/
public static networkLog_custom(message?: any, ...optionalParams: any[]): void {
if (!CheckLayer._logStatus_custom) { return; }
console.log("[network][", CheckLayer.getFullTime_custom(), "]", ":", message, ...optionalParams);
}
/**网络错误日志*/
public static networkError_custom(message?: any, ...optionalParams: any[]): void {
if (!CheckLayer._logStatus_custom) { return; }
console.error("[network][", CheckLayer.getFullTime_custom(), "]", ":", message, ...optionalParams);
}
/** 获取完全时间 */
public static getFullTime_custom(): string {
let date = new Date();
return date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "-" + date.getMilliseconds();
}
public static readonly serverUrl_custom: string = "https://javaapi.renyouwangluo.cn";
//public static readonly serverUrl_test_custom: string = "https://javaapi.test.renyouwangluo.cn";
public static readonly Login_custom: string = "/api/user/login";
public static readonly SaveGameData_custom: string = "/api/user/game/data/write";
public static readonly GetUser_custom = "/api/user/game/data/read";
/* 用来对IP地址进行屏蔽的接口地址,可以使用接口的返回值让某些广告逻辑在微信的审核地区(广州)发生变化 */
public static readonly IpBlock_custom = "/api/user/ip/select";
public static readonly reportExport_custom1 = "/api/share/getwaibuad";
public static readonly reportImport_custom1 = "/api/share/getzjadml";
public static readonly getuserip_custom = "/api/user/ip";
public static readonly signin_custom = "/api/user/sign";//签到
public static readonly Get_ServerTime_custom = "/api/share/gettime"// 服务器当前的时间戳
public static readonly userScanCode_custom1 = "/api/user/scan/code" //上报2
//抖音上传统计报告
public static readonly ttReportLaunchChannel_custom = "https://javareport.renyouwangluo.cn/api/data/tt/report"
}