chsdk_inside.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. declare namespace chsdk {
  2. /**日志等级*/
  3. enum loglevel {
  4. OFF = 0,
  5. ERROR = 1,
  6. WARN = 2,
  7. DEBUG = 3,
  8. INFO = 4,
  9. ALL = 5
  10. }
  11. /**上报类型*/
  12. export enum reportType {
  13. /**默认不上报*/
  14. off = 0,
  15. /**使用ch服务器*/
  16. ch = 1,
  17. /**上报到应用平台(需在各平台后台设置上报事件,微信,抖音)*/
  18. platform = 2,
  19. /**上面两个都选*/
  20. ch__platform = 3
  21. }
  22. /**平台*/
  23. export enum pf {
  24. /**测试*/
  25. web = "web",
  26. /**微信*/
  27. wx = "wx",
  28. /**抖音*/
  29. tt = "tt"
  30. }
  31. export function init_inside(gid: string, loglevel: number, serverIP: number | string, isLocal?: boolean, report?: reportType): Promise<{
  32. code: number;
  33. err?: string;
  34. data?: any;
  35. }>;
  36. /**
  37. * 获取基本功能完成接口地址
  38. * @param action 接口字符串如 '/user/shareList'
  39. * @returns
  40. */
  41. export function getUrl(action: string): string;
  42. /**
  43. * 获取上报功能完成接口地址
  44. * @param action 接口字符串如 '/user/shareList'
  45. * @returns
  46. */
  47. export function getReportUrl(action: string): string;
  48. export function check_req_time(req_type: string): { code: number, err: string } | null;
  49. export function makePostTokenRequest(url: string, body?: any): Promise<{
  50. code: number;
  51. err?: string;
  52. data?: any;
  53. }>;
  54. export function base64_encode(input: string): string;
  55. export function base64_decode(input: string): string;
  56. /**
  57. * md5加密
  58. */
  59. export function md5HashStr(str: string): string;
  60. /**
  61. * 一次http请求
  62. * @param url 请求地址
  63. * @param method 请求方式
  64. * @param data
  65. * @param timeout
  66. * @param responseType
  67. * @param headers
  68. * @returns
  69. */
  70. export function do_request(url: string, method: 'POST' | 'GET' | 'PUT', data?: any, timeout?: number, responseType?: XMLHttpRequestResponseType, headers?: {
  71. [key in string]: string;
  72. }): Promise<any>;
  73. /**验证权限功能
  74. * key 某个功能权限
  75. * 返回 是否验证成功
  76. */
  77. export function verify_option(key: string): boolean;
  78. /**获取一个唯一标识的字符串 */
  79. export function guid(): string;
  80. /**判断是否有名字,没有返回玩家*/
  81. export function getDefNickName(info: any): string;
  82. /**
  83. * 主动记录分数到缓存
  84. * @param rankType 排行榜类型
  85. * @param update 更新类型
  86. * @param type 0 个人排行 1地区排行
  87. * @param score 分数
  88. */
  89. export function recordCacheScore(rankField: string, update: number, type: 0 | 1, score: number): void;
  90. /**
  91. * 获取缓存中的分数
  92. * @param rankField
  93. * @param update
  94. * @param type
  95. * @returns
  96. */
  97. export function getCacheScore(rankField: string, update: number, type: 0 | 1): number;
  98. /**清空所有缓存分数*/
  99. export function cleanCacheScore(): void;
  100. /**清空所有缓存排行榜数据*/
  101. export function cleanCacheRank(): void;
  102. /**当前平台是否有分享功能*/
  103. export function canShareAppMessage(): boolean;
  104. /**
  105. * 主动拉起分享转发
  106. */
  107. export function shareAppMessage(title?: string, imageUrlId?: string, imageUrl?: string, message?: string): void;
  108. /**
  109. * 主动拉起分享转发并等待是错分享成功
  110. */
  111. export function shareAppMessageAsync(title?: string, imageUrlId?: string, imageUrl?: string, message?: string): Promise<boolean>;
  112. /**设置被动分享参数,具体参看平台的参数设置*/
  113. export function setOnShareAppMessage(res: {}): void;
  114. /**
  115. * @description 上传从分享进入(无需主动调用,除非需要在message里加入游戏特别数据)
  116. * @param openid 服务器拿到的玩家oid 如果为空从平台拿
  117. * @param message 分享的自定义数据
  118. */
  119. export function sendShare(openid?: string | null, message?: string | null): Promise<{
  120. code: number;
  121. err?: string;
  122. data?: any;
  123. }>;
  124. /**
  125. * @description 获取从自己分享进入游戏的玩家列表
  126. */
  127. export function getShareList(): Promise<{
  128. code: number;
  129. err?: string;
  130. data?: {
  131. gid: string;
  132. head: string;
  133. hid: number;
  134. ip: string;
  135. loginTime: number;
  136. nickName: string;
  137. openId: string;
  138. option: string;
  139. pf: string;
  140. registerTime: number;
  141. userId: number;
  142. msg?: string;
  143. }[];
  144. }>;
  145. /**播放奖励广告
  146. * @param scene 奖励目的场景
  147. playRewardAd("复活")
  148. .then(success => {
  149. if (success) {
  150. console.log("广告播放成功,用户获得奖励");
  151. // 在这里执行成功后的操作
  152. } else {
  153. console.log("广告播放失败,用户未获得奖励");
  154. // 处理广告播放失败的逻辑
  155. }
  156. })
  157. .catch(error => {
  158. console.error("发生未处理的错误: ", error);
  159. });
  160. */
  161. export function playRewardAd(scene: string): Promise<boolean>;
  162. /**播放插屏广告*/
  163. export function playInsterAd(scene: string): Promise<boolean>;
  164. /**设置广告配置*/
  165. export function setConf(pf: pf, conf: {
  166. adUnitId: string;
  167. multiton: boolean;
  168. inster_unitId?: string;
  169. tmplIds?: string[];
  170. }): void;
  171. /**当前平台是否有侧边栏功能*/
  172. export function checkHasSidebar(): boolean;
  173. /**是否从侧边栏进入游戏 */
  174. export function checkFromSidebar(): boolean;
  175. /**进入侧边栏*/
  176. export function goToSidebar(): boolean;
  177. /**开始录屏*/
  178. export function recorderStart(duration?: number): void;
  179. /**结束录屏*/
  180. export function recorderStop(): void;
  181. /**分享录屏*/
  182. export function shareRecord(title?: string, desc?: string, path?: string, topics?: string[]): void;
  183. /**创建反馈按钮
  184. * @param op 按纽坐标大小
  185. * 例:feed_node.active = ch.sdk.createFeedbackButton(ch.util.getBtnOp(feed_node));
  186. * 如果对应平台有此功能(目前只有wx)返回true,没有返回false
  187. * 成功记得 destoryFeedbackButton();*/
  188. export function createFeedbackButton(op: {
  189. left: number;
  190. top: number;
  191. width: number;
  192. height: number;
  193. }): boolean;
  194. /**销毁反馈按钮*/
  195. export function destoryFeedbackButton(): void;
  196. /**复制到剪切板*/
  197. export function setClipboardData(content: string): void;
  198. /**短震动(15ms)*/
  199. export function vibrateShort(): void;
  200. /**长震动(400ms)*/
  201. export function vibrateLong(): void;
  202. /**界面提示信息*/
  203. export function showToast(title: string, duration?: number, icon?: 'success' | 'error' | 'fail' | 'loading' | 'none'): boolean;
  204. /**获取菜单坐标范围*/
  205. export function getMenuButtonBoundingClientRect(): any;
  206. export function showLoading(title?: string): boolean;
  207. export function hideLoading(): void;
  208. export function showModal(title?: string, content?: string, confirmText?: string, showCancel?: boolean, cancelText?: string): Promise<{
  209. confirm: boolean;
  210. cancel: boolean;
  211. }>;
  212. /**加载图片
  213. * cocos里不要直接调用,使用 ch.util.loadImage(url);
  214. */
  215. export function loadImage(imgURL: string): Promise<any>;
  216. /**当前平台是否有关注功能*/
  217. export function canAwemeUserProfile(): boolean;
  218. /**检查是否已经关注*/
  219. export function checkFollowAwemeState(): Promise<boolean>;
  220. /**打开关注返回关注结果*/
  221. export function openAwemeUserProfile(): Promise<boolean>;
  222. /**当前平台是否有订阅功能*/
  223. export function canSubscribeMessage(): boolean;
  224. /**订阅消息 参数为空的话使用配置里的模板id*/
  225. export function requestSubscribeMessage(tmplIds?: string[]): Promise<boolean>;
  226. class ch_log {
  227. private static _instance;
  228. static getInstance(): ch_log;
  229. private _log_level;
  230. set_log_level(loglevel: loglevel): void;
  231. private _no;
  232. private _log;
  233. private _info;
  234. private _debug;
  235. private _trace;
  236. private _warn;
  237. private _error;
  238. private _log_start;
  239. private _log_end;
  240. get log(): (message?: any, ...optionalParams: any[]) => void;
  241. get info(): (message?: any, ...optionalParams: any[]) => void;
  242. get debug(): (message?: any, ...optionalParams: any[]) => void;
  243. get trace(): (message?: any, ...optionalParams: any[]) => void;
  244. get warn(): (message?: any, ...optionalParams: any[]) => void;
  245. get error(): (message?: any, ...optionalParams: any[]) => void;
  246. /**记录开始计时*/
  247. get log_start(): (label?: string) => void;
  248. /** 打印范围内时间消耗*/
  249. get log_end(): (label?: string) => void;
  250. }
  251. /**日志打印*/
  252. export const log: ch_log;
  253. /**事件*/
  254. export interface EventsMap {
  255. [event: string]: (...args: any[]) => void;
  256. }
  257. export type EventNames<Map extends EventsMap> = keyof Map & string;
  258. export type OmitIndex<T> = {
  259. [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
  260. };
  261. export type EventParams<Map extends EventsMap, Ev extends EventNames<Map>> = Parameters<Map[Ev]>;
  262. class EventModel<CT extends OmitIndex<EventsMap>> {
  263. private _handlersMap;
  264. /** 事件键 */
  265. key: {
  266. [k in EventNames<CT>]: k;
  267. };
  268. /**
  269. * 监听事件
  270. * @param type_ 事件类型
  271. * @param callback_ 触发回调
  272. * @param target_ 事件目标对象
  273. * @param once_b_ 是否触发单次
  274. * @returns 触发回调
  275. */
  276. on<T extends EventNames<CT>, T2 extends (...event_: EventParams<CT, T>) => void>(type_: T, callback_: T2, target_?: any, once_?: boolean): typeof callback_ | null;
  277. once<T extends EventNames<CT>, T2 extends (...event_: EventParams<CT, T>) => void>(type_: T, callback_: T2, target_?: any): void;
  278. /**
  279. * 取消监听事件
  280. * @param type_ 事件类型
  281. * @param callback_ 触发回调
  282. * @param target_ 事件目标对象
  283. * @returns 触发回调
  284. */
  285. off<T extends EventNames<CT>, T2 extends (...event_: EventParams<CT, T>) => void>(type_: T, callback_?: T2, target_?: any): void;
  286. /**
  287. * 清除某个事件队列
  288. * @param type_ 事件名,为空的话清除所有
  289. */
  290. clearAll<T extends EventNames<CT>>(type_?: T): void;
  291. /**
  292. * 派发事件
  293. * @param type_ 事件类型
  294. * @param args_ 事件参数
  295. */
  296. emit<T extends EventNames<CT>, T2 extends EventParams<CT, T>>(type_: T, ...args_: T2): void;
  297. private _emit;
  298. }
  299. /**sdk事件*/
  300. export interface event_sdk {
  301. show(): void;
  302. hide(): void;
  303. onShare(success: boolean): void;
  304. }
  305. export const sdk_event: EventModel<event_sdk>;
  306. export function get_new_event<CT>(): EventModel<CT>;
  307. /**日期时间*/
  308. class ch_date {
  309. private static _instance;
  310. static getInstance(): ch_date;
  311. private _day_s;
  312. private _diff;
  313. updateServerTime(s: number): void;
  314. now(): number;
  315. getTime(): number;
  316. getDayStartTime(s: number): number;
  317. getDayEndTime(e: number): number;
  318. getWeekEndTime(e: number): number;
  319. getMonthEndTime(e: number): number;
  320. /**两个时间相隔天数*/
  321. getDiffDayNum(e: number, t: number): number;
  322. /**判定两个时间是否是同一天*/
  323. isSameDate(timestamp1: number, timestamp2: number): boolean;
  324. /**
  325. * 单位毫秒格式化
  326. * - $H: 替换为小时,补全空位(02:00:00)
  327. * - $h: 替换为小时,不补全(2:00:00)
  328. * - $M: 替换为分钟,补全空位(00:02:00)
  329. * - $m: 替换为分钟,不补全(00:2:00)
  330. * - $S: 替换为秒,补全空位(00:00:02)
  331. * - $s: 替换为秒,不补全(0:00:2)
  332. */
  333. ms_format(ms_n_: number, format_s_?: string): string;
  334. }
  335. export const date: ch_date;
  336. /**本地存储*/
  337. class ch_storage {
  338. private static _instance;
  339. static getInstance(): ch_storage;
  340. /**
  341. * 缓存变量存储
  342. * @param key
  343. * @param value
  344. * @param user_id 区别用户
  345. */
  346. set(key: string, value: any, user_id?: string | null): any;
  347. /**
  348. * 获取缓存变量区别用户
  349. * @param {*} key
  350. * @returns
  351. */
  352. private get;
  353. /** 获取指定关键字的string*/
  354. getString(key: string, user_id?: string | null): string | null;
  355. /** 获取指定关键字的数值 */
  356. getNumber(key: string, user_id?: string | null, defaultValue?: number): number;
  357. /** 获取指定关键字的布尔值*/
  358. getBoolean(key: string, user_id?: string | null): boolean;
  359. /** 获取指定关键字的JSON对象*/
  360. getJson(key: string, user_id?: string | null): any;
  361. /** 获取指定关键字的JSON对象*/
  362. getObject(key: string, user_id?: string | null): any;
  363. /**
  364. * 删除缓存变量
  365. * @param {*} key
  366. */
  367. remove(key: string, user_id?: string | null): any;
  368. /** 清空整个本地存储 */
  369. clear(): void;
  370. }
  371. /**本地存储*/
  372. export const storage: ch_storage;
  373. export { };
  374. }