chsdk_inside.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 function getOption(): string;
  24. /**获取token*/
  25. export function getToken(): string;
  26. export function init_inside(gid: string, loglevel: number, serverIP: number | string, isLocal?: boolean, report?: reportType): Promise<{
  27. code: number;
  28. err?: string;
  29. data?: any;
  30. }>;
  31. /**
  32. * 获取基本功能完成接口地址
  33. * @param action 接口字符串如 '/user/shareList'
  34. * @returns
  35. */
  36. export function getUrl(action: string): string;
  37. /**
  38. * 获取上报功能完成接口地址
  39. * @param action 接口字符串如 '/user/shareList'
  40. * @returns
  41. */
  42. export function getReportUrl(action: string): string;
  43. export function check_req_time(req_type: string): {
  44. code: number;
  45. err: string;
  46. } | null;
  47. export function makePostTokenRequest(url: string, body?: any): Promise<{
  48. code: number;
  49. err?: string;
  50. data?: any;
  51. }>;
  52. export function base64_encode(input: string): string;
  53. export function base64_decode(input: string): string;
  54. export function base64_xo_encode(input: string, key: string): string;
  55. export function base64_xo_decode(input: string, key: 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. export function getQuery(): any;
  115. /**
  116. * @description 上传从分享进入(无需主动调用,除非需要在message里加入游戏特别数据)
  117. * @param openid 服务器拿到的玩家oid 如果为空从平台拿
  118. * @param message 分享的自定义数据
  119. */
  120. export function sendShare(openid?: string | null, message?: string | null): Promise<{
  121. code: number;
  122. err?: string;
  123. data?: any;
  124. }>;
  125. /**
  126. * @description 获取从自己分享进入游戏的玩家列表
  127. */
  128. export function getShareList(): Promise<{
  129. code: number;
  130. err?: string;
  131. data?: {
  132. gid: string;
  133. head: string;
  134. hid: number;
  135. ip: string;
  136. loginTime: number;
  137. nickName: string;
  138. openId: string;
  139. option: string;
  140. pf: string;
  141. registerTime: number;
  142. userId: number;
  143. msg?: string;
  144. }[];
  145. }>;
  146. /**开始录屏*/
  147. export function recorderStart(duration?: number): void;
  148. /**结束录屏*/
  149. export function recorderStop(): void;
  150. /**分享录屏 成功返回videoId,失败返回null*/
  151. export function shareRecord(options: {
  152. templateId?: string;
  153. imageUrl?: string;
  154. title?: string;
  155. desc?: string;
  156. query?: string;
  157. path?: string;
  158. topics?: string[];
  159. }): Promise<string | null>;
  160. /**上传配置
  161. * @param name 配置包名称
  162. * @param key 配置项名称
  163. * @param config 配置
  164. * @param secret 密钥
  165. * @returns errCode 错误码 errMsg 错误信息 data 关卡配置列表
  166. */
  167. export function uploadConfig(name: string, key: string, config: {
  168. [key: string]: any;
  169. }, secret?: string): Promise<{
  170. code: number;
  171. err?: string;
  172. }>;
  173. /**预加载配置
  174. * @param name 配置包名称
  175. * @param keys 配置项名称列表
  176. * @param secret 密钥
  177. * @param refesh 强制刷新否则从缓存中拿
  178. * @returns errCode 错误码 errMsg 错误信息 data 关卡配置列表
  179. */
  180. export function preloadConfig(name: string, keys: string[], secret?: string, refesh?: boolean): Promise<{
  181. code: number;
  182. err?: string;
  183. data?: {
  184. [key: string]: any;
  185. };
  186. }>;
  187. /**获取配置
  188. * @param name 配置包名称
  189. * @param key 配置项名称列表
  190. * @param secret 密钥
  191. * @param refesh 强制刷新否则从缓存中拿
  192. * @returns errCode 错误码 errMsg 错误信息 data 关卡配置列表
  193. */
  194. export function getConfig(name: string, key: string, secret?: string, refesh?: boolean): Promise<{
  195. code: number;
  196. err?: string;
  197. data?: {
  198. [key: string]: any;
  199. };
  200. }>;
  201. /**创建反馈按钮
  202. * @param op 按纽坐标大小
  203. * 例:feed_node.active = ch.sdk.createFeedbackButton(ch.util.getBtnOp(feed_node));
  204. * 如果对应平台有此功能(目前只有wx)返回true,没有返回false
  205. * 成功记得 destoryFeedbackButton();*/
  206. export function createFeedbackButton(op: {
  207. left: number;
  208. top: number;
  209. width: number;
  210. height: number;
  211. }): boolean;
  212. /**销毁反馈按钮*/
  213. export function destoryFeedbackButton(): void;
  214. /**复制到剪切板*/
  215. export function setClipboardData(content: string): void;
  216. /**短震动(15ms)*/
  217. export function vibrateShort(): void;
  218. /**长震动(400ms)*/
  219. export function vibrateLong(): void;
  220. /**界面提示信息*/
  221. export function showToast(title: string, duration?: number, icon?: 'success' | 'error' | 'fail' | 'loading' | 'none'): boolean;
  222. /**获取菜单坐标范围*/
  223. export function getMenuButtonBoundingClientRect(): any;
  224. export function showLoading(title?: string): boolean;
  225. export function hideLoading(): void;
  226. export function showModal(title?: string, content?: string, confirmText?: string, showCancel?: boolean, cancelText?: string): Promise<{
  227. confirm: boolean;
  228. cancel: boolean;
  229. }>;
  230. export function openSetting(scope: string | 'scope.userInfo' | 'scope.userLocation'): Promise<boolean>;
  231. /**加载图片
  232. * cocos里不要直接调用,使用 ch.util.loadImage(url);
  233. */
  234. export function loadImage(imgURL: string): Promise<any>;
  235. /**当前平台是否有关注功能*/
  236. export function canAwemeUserProfile(): boolean;
  237. /**检查是否已经关注*/
  238. export function checkFollowAwemeState(): Promise<boolean>;
  239. /**打开关注返回关注结果*/
  240. export function openAwemeUserProfile(): Promise<boolean>;
  241. /**当前平台是否有订阅功能*/
  242. export function canSubscribeMessage(): boolean;
  243. /**订阅消息 参数为空的话使用配置里的模板id*/
  244. export function requestSubscribeMessage(tmplIds?: string[]): Promise<boolean>;
  245. class ch_log {
  246. private static _instance;
  247. static getInstance(): ch_log;
  248. private _log_level;
  249. set_log_level(loglevel: loglevel): void;
  250. private _no;
  251. private _log;
  252. private _info;
  253. private _debug;
  254. private _trace;
  255. private _warn;
  256. private _error;
  257. private _log_start;
  258. private _log_end;
  259. get log(): (message?: any, ...optionalParams: any[]) => void;
  260. get info(): (message?: any, ...optionalParams: any[]) => void;
  261. get debug(): (message?: any, ...optionalParams: any[]) => void;
  262. get trace(): (message?: any, ...optionalParams: any[]) => void;
  263. get warn(): (message?: any, ...optionalParams: any[]) => void;
  264. get error(): (message?: any, ...optionalParams: any[]) => void;
  265. /**记录开始计时*/
  266. get log_start(): (label?: string) => void;
  267. /** 打印范围内时间消耗*/
  268. get log_end(): (label?: string) => void;
  269. }
  270. /**日志打印*/
  271. export const log: ch_log;
  272. /**事件*/
  273. export interface EventsMap {
  274. [event: string]: (...args: any[]) => void;
  275. }
  276. export type EventNames<Map extends EventsMap> = keyof Map & string;
  277. export type OmitIndex<T> = {
  278. [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
  279. };
  280. export type EventParams<Map extends EventsMap, Ev extends EventNames<Map>> = Parameters<Map[Ev]>;
  281. class EventModel<CT extends OmitIndex<EventsMap>> {
  282. private _handlersMap;
  283. /** 事件键 */
  284. key: {
  285. [k in EventNames<CT>]: k;
  286. };
  287. private _isEmitting;
  288. private _pendingOperations;
  289. /**
  290. * 监听事件
  291. * @param type_ 事件类型
  292. * @param callback_ 触发回调
  293. * @param target_ 事件目标对象
  294. * @param once_b_ 是否触发单次
  295. * @returns 触发回调
  296. */
  297. on<T extends EventNames<CT>, T2 extends (...event_: EventParams<CT, T>) => void>(type_: T, callback_: T2, target_?: any, once_?: boolean): typeof callback_ | null;
  298. once<T extends EventNames<CT>, T2 extends (...event_: EventParams<CT, T>) => void>(type_: T, callback_: T2, target_?: any): void;
  299. /**
  300. * 取消监听事件
  301. * @param type_ 事件类型
  302. * @param callback_ 触发回调
  303. * @param target_ 事件目标对象
  304. * @returns 触发回调
  305. */
  306. off<T extends EventNames<CT>, T2 extends (...event_: EventParams<CT, T>) => void>(type_: T, callback_?: T2, target_?: any): void;
  307. /**
  308. * 清除某个事件队列
  309. * @param type_ 事件名,为空的话清除所有
  310. */
  311. clearAll<T extends EventNames<CT>>(type_?: T): void;
  312. /**
  313. * 派发事件
  314. * @param type_ 事件类型
  315. * @param args_ 事件参数
  316. */
  317. emit<T extends EventNames<CT>, T2 extends EventParams<CT, T>>(type_: T, ...args_: T2): void;
  318. private _emit;
  319. }
  320. /**sdk事件*/
  321. export interface event_sdk {
  322. show(): void;
  323. hide(): void;
  324. onShare(success: boolean): void;
  325. onShowAd(type: 'Rewarded' | 'Interstitial' | 'Banner', success: boolean): void;
  326. }
  327. export const sdk_event: EventModel<event_sdk>;
  328. export function get_new_event<CT>(): EventModel<CT>;
  329. /**日期时间*/
  330. class ch_date {
  331. private static _instance;
  332. static getInstance(): ch_date;
  333. private _day_s;
  334. private _diff;
  335. updateServerTime(s: number): void;
  336. now(): number;
  337. getTime(): number;
  338. getDayStartTime(s: number): number;
  339. getDayEndTime(e: number): number;
  340. getWeekEndTime(e: number): number;
  341. getMonthEndTime(e: number): number;
  342. /**两个时间相隔天数*/
  343. getDiffDayNum(e: number, t: number): number;
  344. /**判定两个时间是否是同一天*/
  345. isSameDate(timestamp1: number, timestamp2: number): boolean;
  346. /**
  347. * 单位毫秒格式化
  348. * - $H: 替换为小时,补全空位(02:00:00)
  349. * - $h: 替换为小时,不补全(2:00:00)
  350. * - $M: 替换为分钟,补全空位(00:02:00)
  351. * - $m: 替换为分钟,不补全(00:2:00)
  352. * - $S: 替换为秒,补全空位(00:00:02)
  353. * - $s: 替换为秒,不补全(0:00:2)
  354. */
  355. ms_format(ms_n_: number, format_s_?: string): string;
  356. }
  357. export const date: ch_date;
  358. /**本地存储*/
  359. class ch_storage {
  360. private static _instance;
  361. static getInstance(): ch_storage;
  362. /**
  363. * 缓存变量存储
  364. * @param key
  365. * @param value
  366. * @param user_id 区别用户
  367. */
  368. set(key: string, value: any, user_id?: string | null): any;
  369. /**
  370. * 获取缓存变量区别用户
  371. * @param {*} key
  372. * @returns
  373. */
  374. private get;
  375. /** 获取指定关键字的string*/
  376. getString(key: string, user_id?: string | null): string | null;
  377. /** 获取指定关键字的数值 */
  378. getNumber(key: string, user_id?: string | null, defaultValue?: number): number;
  379. /** 获取指定关键字的布尔值*/
  380. getBoolean(key: string, user_id?: string | null): boolean;
  381. /** 获取指定关键字的JSON对象*/
  382. getJson(key: string, user_id?: string | null): any;
  383. /** 获取指定关键字的JSON对象*/
  384. getObject(key: string, user_id?: string | null): any;
  385. /**
  386. * 删除缓存变量
  387. * @param {*} key
  388. */
  389. remove(key: string, user_id?: string | null): any;
  390. /** 清空整个本地存储 */
  391. clear(): void;
  392. }
  393. /**本地存储*/
  394. export const storage: ch_storage;
  395. export { };
  396. }