declare namespace chsdk { /**日志等级*/ enum loglevel { OFF = 0, ERROR = 1, WARN = 2, DEBUG = 3, INFO = 4, ALL = 5 } /**上报类型*/ export enum reportType { /**默认不上报*/ off = 0, /**使用ch服务器*/ ch = 1, /**上报到应用平台(需在各平台后台设置上报事件,微信,抖音)*/ platform = 2, /**上面两个都选*/ ch__platform = 3 } /**平台*/ export enum pf { /**测试*/ web = "web", /**微信*/ wx = "wx", /**抖音*/ tt = "tt" } /**获取token*/ export function getToken(): string; export function init_inside(gid: string, loglevel: number, serverIP: number | string, isLocal?: boolean, report?: reportType): Promise<{ code: number; err?: string; data?: any; }>; /** * 获取基本功能完成接口地址 * @param action 接口字符串如 '/user/shareList' * @returns */ export function getUrl(action: string): string; /** * 获取上报功能完成接口地址 * @param action 接口字符串如 '/user/shareList' * @returns */ export function getReportUrl(action: string): string; export function check_req_time(req_type: string): { code: number; err: string; } | null; export function makePostTokenRequest(url: string, body?: any): Promise<{ code: number; err?: string; data?: any; }>; export function base64_encode(input: string): string; export function base64_decode(input: string): string; /** * md5加密 */ export function md5HashStr(str: string): string; /** * 一次http请求 * @param url 请求地址 * @param method 请求方式 * @param data * @param timeout * @param responseType * @param headers * @returns */ export function do_request(url: string, method: 'POST' | 'GET' | 'PUT', data?: any, timeout?: number, responseType?: XMLHttpRequestResponseType, headers?: { [key in string]: string; }): Promise; /**验证权限功能 * key 某个功能权限 * 返回 是否验证成功 */ export function verify_option(key: string): boolean; /**获取一个唯一标识的字符串 */ export function guid(): string; /**判断是否有名字,没有返回玩家*/ export function getDefNickName(info: any): string; /** * 主动记录分数到缓存 * @param rankType 排行榜类型 * @param update 更新类型 * @param type 0 个人排行 1地区排行 * @param score 分数 */ export function recordCacheScore(rankField: string, update: number, type: 0 | 1, score: number): void; /** * 获取缓存中的分数 * @param rankField * @param update * @param type * @returns */ export function getCacheScore(rankField: string, update: number, type: 0 | 1): number; /**清空所有缓存分数*/ export function cleanCacheScore(): void; /**清空所有缓存排行榜数据*/ export function cleanCacheRank(): void; /**当前平台是否有分享功能*/ export function canShareAppMessage(): boolean; /** * 主动拉起分享转发 */ export function shareAppMessage(title?: string, imageUrlId?: string, imageUrl?: string, message?: string): void; /** * 主动拉起分享转发并等待是错分享成功 */ export function shareAppMessageAsync(title?: string, imageUrlId?: string, imageUrl?: string, message?: string): Promise; /**设置被动分享参数,具体参看平台的参数设置*/ export function setOnShareAppMessage(res: {}): void; export function getQuery(): any; /** * @description 上传从分享进入(无需主动调用,除非需要在message里加入游戏特别数据) * @param openid 服务器拿到的玩家oid 如果为空从平台拿 * @param message 分享的自定义数据 */ export function sendShare(openid?: string | null, message?: string | null): Promise<{ code: number; err?: string; data?: any; }>; /** * @description 获取从自己分享进入游戏的玩家列表 */ export function getShareList(): Promise<{ code: number; err?: string; data?: { gid: string; head: string; hid: number; ip: string; loginTime: number; nickName: string; openId: string; option: string; pf: string; registerTime: number; userId: number; msg?: string; }[]; }>; /**播放奖励广告 * @param scene 奖励目的场景 playRewardAd("复活") .then(success => { if (success) { console.log("广告播放成功,用户获得奖励"); // 在这里执行成功后的操作 } else { console.log("广告播放失败,用户未获得奖励"); // 处理广告播放失败的逻辑 } }) .catch(error => { console.error("发生未处理的错误: ", error); }); */ export function playRewardAd(scene: string): Promise; /**播放插屏广告*/ export function playInsterAd(scene: string): Promise; /**设置广告配置*/ export function setConf(pf: pf, conf: { adUnitId: string; multiton: boolean; inster_unitId?: string; tmplIds?: string[]; }): void; /**当前平台是否有侧边栏功能*/ export function checkHasSidebar(): boolean; /**抖音是否从侧边栏进入游戏,微信是否从我的小程序进入游戏*/ export function checkFromSidebar(): boolean; /**抖音进入侧边栏*/ export function goToSidebar(): boolean; /**开始录屏*/ export function recorderStart(duration?: number): void; /**结束录屏*/ export function recorderStop(): void; /**分享录屏*/ export function shareRecord(title?: string, desc?: string, path?: string, topics?: string[]): void; /**创建反馈按钮 * @param op 按纽坐标大小 * 例:feed_node.active = ch.sdk.createFeedbackButton(ch.util.getBtnOp(feed_node)); * 如果对应平台有此功能(目前只有wx)返回true,没有返回false * 成功记得 destoryFeedbackButton();*/ export function createFeedbackButton(op: { left: number; top: number; width: number; height: number; }): boolean; /**销毁反馈按钮*/ export function destoryFeedbackButton(): void; /**复制到剪切板*/ export function setClipboardData(content: string): void; /**短震动(15ms)*/ export function vibrateShort(): void; /**长震动(400ms)*/ export function vibrateLong(): void; /**界面提示信息*/ export function showToast(title: string, duration?: number, icon?: 'success' | 'error' | 'fail' | 'loading' | 'none'): boolean; /**获取菜单坐标范围*/ export function getMenuButtonBoundingClientRect(): any; export function showLoading(title?: string): boolean; export function hideLoading(): void; export function showModal(title?: string, content?: string, confirmText?: string, showCancel?: boolean, cancelText?: string): Promise<{ confirm: boolean; cancel: boolean; }>; export function openSetting(scope: string | 'scope.userInfo' | 'scope.userLocation'): Promise; /**加载图片 * cocos里不要直接调用,使用 ch.util.loadImage(url); */ export function loadImage(imgURL: string): Promise; /**当前平台是否有关注功能*/ export function canAwemeUserProfile(): boolean; /**检查是否已经关注*/ export function checkFollowAwemeState(): Promise; /**打开关注返回关注结果*/ export function openAwemeUserProfile(): Promise; /**当前平台是否有订阅功能*/ export function canSubscribeMessage(): boolean; /**订阅消息 参数为空的话使用配置里的模板id*/ export function requestSubscribeMessage(tmplIds?: string[]): Promise; class ch_log { private static _instance; static getInstance(): ch_log; private _log_level; set_log_level(loglevel: loglevel): void; private _no; private _log; private _info; private _debug; private _trace; private _warn; private _error; private _log_start; private _log_end; get log(): (message?: any, ...optionalParams: any[]) => void; get info(): (message?: any, ...optionalParams: any[]) => void; get debug(): (message?: any, ...optionalParams: any[]) => void; get trace(): (message?: any, ...optionalParams: any[]) => void; get warn(): (message?: any, ...optionalParams: any[]) => void; get error(): (message?: any, ...optionalParams: any[]) => void; /**记录开始计时*/ get log_start(): (label?: string) => void; /** 打印范围内时间消耗*/ get log_end(): (label?: string) => void; } /**日志打印*/ export const log: ch_log; /**事件*/ export interface EventsMap { [event: string]: (...args: any[]) => void; } export type EventNames = keyof Map & string; export type OmitIndex = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]; }; export type EventParams> = Parameters; class EventModel> { private _handlersMap; /** 事件键 */ key: { [k in EventNames]: k; }; /** * 监听事件 * @param type_ 事件类型 * @param callback_ 触发回调 * @param target_ 事件目标对象 * @param once_b_ 是否触发单次 * @returns 触发回调 */ on, T2 extends (...event_: EventParams) => void>(type_: T, callback_: T2, target_?: any, once_?: boolean): typeof callback_ | null; once, T2 extends (...event_: EventParams) => void>(type_: T, callback_: T2, target_?: any): void; /** * 取消监听事件 * @param type_ 事件类型 * @param callback_ 触发回调 * @param target_ 事件目标对象 * @returns 触发回调 */ off, T2 extends (...event_: EventParams) => void>(type_: T, callback_?: T2, target_?: any): void; /** * 清除某个事件队列 * @param type_ 事件名,为空的话清除所有 */ clearAll>(type_?: T): void; /** * 派发事件 * @param type_ 事件类型 * @param args_ 事件参数 */ emit, T2 extends EventParams>(type_: T, ...args_: T2): void; private _emit; } /**sdk事件*/ export interface event_sdk { show(): void; hide(): void; onShare(success: boolean): void; } export const sdk_event: EventModel; export function get_new_event(): EventModel; /**日期时间*/ class ch_date { private static _instance; static getInstance(): ch_date; private _day_s; private _diff; updateServerTime(s: number): void; now(): number; getTime(): number; getDayStartTime(s: number): number; getDayEndTime(e: number): number; getWeekEndTime(e: number): number; getMonthEndTime(e: number): number; /**两个时间相隔天数*/ getDiffDayNum(e: number, t: number): number; /**判定两个时间是否是同一天*/ isSameDate(timestamp1: number, timestamp2: number): boolean; /** * 单位毫秒格式化 * - $H: 替换为小时,补全空位(02:00:00) * - $h: 替换为小时,不补全(2:00:00) * - $M: 替换为分钟,补全空位(00:02:00) * - $m: 替换为分钟,不补全(00:2:00) * - $S: 替换为秒,补全空位(00:00:02) * - $s: 替换为秒,不补全(0:00:2) */ ms_format(ms_n_: number, format_s_?: string): string; } export const date: ch_date; /**本地存储*/ class ch_storage { private static _instance; static getInstance(): ch_storage; /** * 缓存变量存储 * @param key * @param value * @param user_id 区别用户 */ set(key: string, value: any, user_id?: string | null): any; /** * 获取缓存变量区别用户 * @param {*} key * @returns */ private get; /** 获取指定关键字的string*/ getString(key: string, user_id?: string | null): string | null; /** 获取指定关键字的数值 */ getNumber(key: string, user_id?: string | null, defaultValue?: number): number; /** 获取指定关键字的布尔值*/ getBoolean(key: string, user_id?: string | null): boolean; /** 获取指定关键字的JSON对象*/ getJson(key: string, user_id?: string | null): any; /** 获取指定关键字的JSON对象*/ getObject(key: string, user_id?: string | null): any; /** * 删除缓存变量 * @param {*} key */ remove(key: string, user_id?: string | null): any; /** 清空整个本地存储 */ clear(): void; } /**本地存储*/ export const storage: ch_storage; export { }; }