├── .gitattributes ├── .vscode └── tasks.json ├── LICENSE ├── README.md ├── datacontext └── index.ts ├── dist ├── game.js └── game.json ├── index.d.ts ├── package.json ├── tsconfig.json ├── tslint.json └── wegame-api-tests.ts /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ts linguist-language=TypeScript 2 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "presentation": { 4 | "echo": true, 5 | "reveal": "always", 6 | "focus": false, 7 | "panel": "shared" 8 | }, 9 | "problemMatcher" : "$tsc", 10 | "tasks": [ 11 | { 12 | "label": "buildProject", 13 | "group": { 14 | "kind": "build", 15 | "isDefault": true 16 | }, 17 | "type": "shell", 18 | "command": "tsc", 19 | "args": [ 20 | "--outDir", 21 | "dist/" 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 J.C 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wegame-api - 微信小游戏TypeScript定义文件 2 | 3 | ### 更新状态: 4 | ~~官方基础库2.9.3~~ 5 | 6 | - [x] ❗ **该库已归档,请直接使用官方Type库** 7 | 8 | ### TODO列表: 9 | 10 | * iBeacon 11 | * 蓝牙 12 | * 低功耗蓝牙 13 | * GamePortal 14 | * GameIcon 15 | * GameBanner 16 | * GameRecorder 17 | * GameRecorderShareButton 18 | 19 | ### 安装: 20 | **npm install @types/wegame-api** 21 | 22 | 欢迎PR纠错 23 | 24 | License MIT 25 | -------------------------------------------------------------------------------- /datacontext/index.ts: -------------------------------------------------------------------------------- 1 | wx.onMessage(data => { 2 | console.log("cmd in worker -> " + data.item); 3 | 4 | switch (data.item) { 5 | case "friend": 6 | wx.getFriendCloudStorage({ 7 | keyList: ["selfOpenId"], 8 | success: res => { 9 | console.log("----------> in worker - getFriendCloudStorage: " + console.dir(res.data)); 10 | } 11 | }); 12 | break; 13 | case "user": 14 | wx.getUserInfo({ 15 | openIdList: ["selfOpenId"], 16 | success: res => { 17 | console.log("----------> in worker - getUserInfo: " + res.data[0].nickName); 18 | } 19 | }); 20 | break; 21 | case "group": 22 | wx.getGroupCloudStorage({ 23 | shareTicket: "", 24 | keyList: ["selfOpenId"], 25 | success: res => { 26 | console.log("----------> in worker - getGroupCloudStorage: " + res.data); 27 | } 28 | }); 29 | break; 30 | } 31 | }); 32 | -------------------------------------------------------------------------------- /dist/game.js: -------------------------------------------------------------------------------- 1 | import "wegame-api-test.js" -------------------------------------------------------------------------------- /dist/game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait", 3 | "openDataContext": "datacontext" 4 | } 5 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for non-npm package wegame 2.8 2 | // Project: https://developers.weixin.qq.com/minigame/dev/index.html 3 | // Definitions by: J.C 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | // TypeScript Version: 3.0 6 | 7 | /** 8 | * IOS及安卓不支持: 9 | * globalCompositeOperation不支持以下值:source-in source-out destination-atop lighter copy 10 | * isPointInPath 不支持 11 | */ 12 | declare class WxRenderingContext extends CanvasRenderingContext2D { 13 | } 14 | 15 | /** 16 | * IOS及安卓不支持: 17 | * pixelStorei 当第一个参数是 gl.UNPACK_COLORSPACE_CONVERSION_WEBGL 时不支持 18 | * compressedTexImage2D不支持 19 | * compressedTexSubImage2D不支持 20 | * 安卓不支持: 21 | * getExtension 22 | * getSupportedExtensions 23 | */ 24 | declare class WxWebGLRenderingContext extends WebGLRenderingContext { 25 | /** 26 | * 将一个Canvas对应的Texture绑定到WebGL上下文。(目前该方法仅支持 iOS 6.6.6 以上版本,Android/开发者工具暂不支持。) 27 | * 示例:gl.wxBindCanvasTexture(gl.TEXTURE_2D, canvas) 28 | * @param texture WebGL的纹理类型枚举值 29 | * @param canvas 需要绑定为Texture的Canvas 30 | */ 31 | wxBindCanvasTexture(texture: number, canvas: Canvas): void; 32 | } 33 | 34 | declare class WxPerformance { 35 | /** 36 | * 时间戳 37 | */ 38 | now(): number; 39 | } 40 | 41 | declare class Canvas { 42 | /** 43 | * 画布的宽度 44 | */ 45 | width: number; 46 | /** 47 | * 画布的高度 48 | */ 49 | height: number; 50 | /** 51 | * 将当前 Canvas 保存为一个临时文件,并生成相应的临时文件路径。 52 | */ 53 | toTempFilePath(p: wx.types.ToTempFileParams): void; 54 | /** 55 | * toTempFilePath 的同步版本 56 | */ 57 | toTempFilePathSync(p: wx.types.ToTempFileSyncParams): string; 58 | /** 59 | * 获取画布对象的绘图上下文 60 | * @param contextType 上下文类型 61 | * @param contextAttributes webgl 上下文属性,仅当 contextType 为 webgl 时有效 62 | */ 63 | getContext(contextType: "2d" | "webgl", contextAttributes?: wx.types.RenderingContextConfig): WxRenderingContext | WxWebGLRenderingContext; 64 | /** 65 | * 把画布上的绘制内容以一个 data URI 的格式返回 66 | */ 67 | toDataURL(): string; 68 | } 69 | 70 | declare class Stats { 71 | /** 72 | * 文件的类型和存取的权限,对应 POSIX stat.st_mode 73 | */ 74 | mode: string; 75 | /** 76 | * 文件大小,单位:B,对应 POSIX stat.st_size 77 | */ 78 | size: number; 79 | /** 80 | * 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime 81 | */ 82 | lastAccessedTime: number; 83 | /** 84 | * 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime 85 | */ 86 | lastModifiedTime: number; 87 | 88 | /** 89 | * 判断当前文件是否一个目录 90 | */ 91 | isDirectory(): boolean; 92 | /** 93 | * 判断当前文件是否一个普通文件 94 | */ 95 | isFile(): boolean; 96 | } 97 | 98 | /** 99 | * 日志管理类,最多保存5M的日志内容,超过5M后,旧的日志内容会被删除。 100 | * 对于小程序,用户可以通过使用 button 组件的 open-type="feedback" 来上传打印的日志。 101 | * 对于小游戏,用户可以通过使用 wx.createFeedbackButton 来创建上传打印的日志的按钮。 102 | * 开发者可以通过小程序管理后台左侧菜单“反馈管理”页面查看相关打印日志。 103 | * 基础库默认会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志。 104 | */ 105 | declare class LogManager { 106 | /** 107 | * 写debug日志 108 | * @param args 要记录的日志内容 109 | */ 110 | debug(... args: unknown[]): void; 111 | 112 | /** 113 | * 写info日志 114 | * @param args 要记录的日志内容 115 | */ 116 | info(... args: unknown[]): void; 117 | 118 | /** 119 | * 写log日志 120 | * @param args 要记录的日志内容 121 | */ 122 | log(... args: unknown[]): void; 123 | 124 | /** 125 | * 写warn日志 126 | * @param args 要记录的日志内容 127 | */ 128 | warn(... args: unknown[]): void; 129 | } 130 | 131 | declare class FileSystemManager { 132 | /** 133 | * 重命名文件,可以把文件从 oldPath 移动到 newPath 134 | */ 135 | rename(param: wx.types.RenameParams): void; 136 | /** 137 | * FileSystemManager.rename 的同步版本 138 | * @param oldPath 源文件路径,可以是普通文件或目录 139 | * @param newPath 新文件路径 140 | * @throws 指定源文件或目标文件没有写权限 141 | * @throws 源文件不存在,或目标文件路径的上层目录不存在 142 | */ 143 | renameSync(oldPath: string, newPath: string): void; 144 | 145 | /** 146 | * 删除目录 147 | */ 148 | rmdir(param: wx.types.RmdirParams): void; 149 | /** 150 | * rmdir 的同步版本 151 | * @param dirPath 要删除的目录路径 152 | * @param recursive 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。 153 | * @throws 目录不存在, 目录不为空, 指定的 dirPath 路径没有写权限 154 | */ 155 | rmdirSync(dirPath: string, recursive?: boolean): void; 156 | 157 | /** 158 | * 读取目录内文件列表 159 | */ 160 | readdir(param: wx.types.ReaddirParams): void; 161 | /** 162 | * readdir的同步版本 163 | * @param dirPath 要读取的目录路径 164 | * @throws 目录不存在 165 | * @throws dirPath 不是目录 166 | * @throws 指定的 filePath 路径没有读权限 167 | */ 168 | readdirSync(dirPath: string): ReadonlyArray; 169 | 170 | /** 171 | * 创建目录 172 | */ 173 | mkdir(param: wx.types.MkdirParams): void; 174 | /** 175 | * mkdir 的同步版本 176 | * @param dirPath 创建的目录路径 177 | * @param recursive 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。 178 | * @throws 上级目录不存在 179 | * @throws 指定的 filePath 路径没有写权限 180 | * @throws 有同名文件或目录 181 | */ 182 | mkdirSync(dirPath: string, recursive?: boolean): void; 183 | 184 | /** 185 | * 解链文件 186 | */ 187 | unlink(param: wx.types.UnlinkParams): void; 188 | /** 189 | * unlink 的同步版本 190 | * @param filePath 要解链的文件路径 191 | * @throws 指定的 path 路径没有读权限 192 | * @throws 文件不存在 193 | * @throws 传入的 filePath 是一个目录 194 | */ 195 | unlinkSync(filePath: string): void; 196 | 197 | /** 198 | * 解压文件 199 | */ 200 | unzip(param: wx.types.UnzipParams): void; 201 | 202 | /** 203 | * 读取本地文件内容 204 | */ 205 | readFile(param: wx.types.ReadfileParams): void; 206 | /** 207 | * readFile 的同步版本,读取并返回指定路径的文件的原始二进制内容 208 | * @param filePath 要读取的文件的路径 209 | * @throws 指定的 filePath 所在目录不存在 210 | * @throws 指定的 filePath 路径没有读权限 211 | */ 212 | readFileSync(filePath: string): ArrayBuffer; 213 | /** 214 | * readFile 的同步版本,读取并按指定字符编码返回字符串 215 | * @param filePath 要读取的文件的路径 216 | * @param encoding 指定读取文件的字符编码 217 | * @throws 指定的 filePath 所在目录不存在 218 | * @throws 指定的 filePath 路径没有读权限 219 | */ 220 | readFileSync(filePath: string, encoding: wx.types.FileContentEncoding): string; 221 | 222 | /** 223 | * 获取文件 Stats 对象 224 | */ 225 | stat(param: wx.types.StatParams): void; 226 | /** 227 | * stat 的同步版本 228 | * @param path 文件/目录路径 229 | * @throws 指定的 path 路径没有读权限 230 | * @throws 文件不存在 231 | */ 232 | statSync(path: string): Stats; 233 | 234 | /** 235 | * 写文件 236 | */ 237 | writeFile(param: wx.types.WritefileParams): void; 238 | /** 239 | * writeFile 的同步版本,写入二进制原始文件数据 240 | * @param filePath 要写入的文件路径 241 | * @param data 要写入的二进制数据 242 | * @throws 指定的 filePath 所在目录不存在 243 | * @throws 指定的 filePath 路径没有写权限 244 | */ 245 | writeFileSync(filePath: string, data: ArrayBuffer): void; 246 | /** 247 | * writeFile 的同步版本,写入文本字符串数据至文件 248 | * @param filePath 要写入的文件路径 249 | * @param data 要写入的文本内容 250 | * @param encoding 指定写入的文本的字符编码格式 251 | * @throws 指定的 filePath 所在目录不存在 252 | * @throws 指定的 filePath 路径没有写权限 253 | */ 254 | writeFileSync(filePath: string, data: string, encoding: wx.types.FileContentEncoding): void; 255 | 256 | /** 257 | * 判断文件/目录是否存在 258 | */ 259 | access(param: wx.types.AccessfileParams): void; 260 | /** 261 | * access的同步版本 262 | * @param path 要判断是否存在的文件/目录路径 263 | * @throws 文件/目录不存在 264 | */ 265 | accessSync(path: string): void; 266 | 267 | /** 268 | * 复制文件 269 | */ 270 | copyFile(param: wx.types.CopyfileParams): void; 271 | /** 272 | * copyFile 的同步版本 273 | * @param srcPath 源文件路径,只可以是普通文件 274 | * @param destPath 目标文件路径 275 | * @throws 指定目标文件路径没有写权限 276 | * @throws 源文件不存在,或目标文件路径的上层目录不存在 277 | */ 278 | copyFileSync(srcPath: string, destPath: string): void; 279 | 280 | /** 281 | * 获取该小程序下已保存的本地缓存文件列表 282 | * @param res.fileList.filePath 本地路径 283 | * @param res.fileList.size 本地文件大小,以字节为单位 284 | * @param res.fileList.createTime 文件创建时间 285 | */ 286 | getSavedFileList(param: wx.types.CallbacksWithType): void; 287 | 288 | /** 289 | * 获取该小程序下的 本地临时文件 或 本地缓存文件 信息 290 | */ 291 | getFileInfo(param: wx.types.FileinfoParams): void; 292 | 293 | /** 294 | * 删除该小程序下已保存的本地缓存文件(新版本应使用unlink) 295 | */ 296 | removeSavedFile(param: wx.types.RemovefileParams): void; 297 | 298 | /** 299 | * 保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。 300 | */ 301 | saveFile(param: wx.types.SavefileParams): void; 302 | /** 303 | * saveFile的同步版本 304 | * @param tempFilePath 临时存储文件路径 305 | * @param filePath 要存储的文件路径 306 | * @throws 指定的 tempFilePath 找不到文件 307 | * @throws 指定的 filePath 路径没有写权限 308 | * @throws 上级目录不存在 309 | */ 310 | saveFileSync(tempFilePath: string, filePath?: string): string; 311 | 312 | /** 313 | * 在文件结尾追加内容 314 | */ 315 | appendFile(param: wx.types.AppendfileParams): void; 316 | /** 317 | * appendFile的同步版本 318 | * @param filePath 要追加内容的文件路径 319 | * @param data 要追加的文本或二进制数据 320 | * @param encoding 指定写入文件的字符编码 321 | * @throws 指定的 filePath 文件不存在 322 | * @throws 指定的 filePath 是一个已经存在的目录 323 | * @throws 指定的 filePath 路径没有写权限 324 | * @throws 指定的 filePath 是一个已经存在的目录 325 | */ 326 | appendFileSync(filePath: string, data: string | ArrayBuffer, encoding: wx.types.FileContentEncoding): void; 327 | } 328 | 329 | declare class DownloadTask { 330 | /** 331 | * 中断下载任务 332 | */ 333 | abort(): void; 334 | /** 335 | * 监听下载进度变化事件 336 | * @param res.progress 下载进度百分比,值为0至100 337 | * @param res.totalBytesWritten 已经下载的数据长度,单位 Bytes 338 | * @param res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes 339 | */ 340 | onProgressUpdate(callback: (res: { progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number }) => void): void; 341 | } 342 | 343 | declare class RequestTask { 344 | /** 345 | * 中断请求任务 346 | */ 347 | abort(): void; 348 | } 349 | 350 | declare class SocketTask { 351 | /** 352 | * 通过WebSocket发送数据 353 | */ 354 | send(param: wx.types.SocketSendParams): void; 355 | /** 356 | * 关闭WebSocket连接 357 | */ 358 | close(param: wx.types.SocketCloseParams): void; 359 | /** 360 | * 监听WebSocket 连接打开事件 361 | */ 362 | onOpen(callback: wx.types.SocketOpenCallback): void; 363 | /** 364 | * 监听WebSocket 连接关闭事件 365 | */ 366 | onClose(callback: () => void): void; 367 | /** 368 | * 监听WebSocket 错误事件 369 | */ 370 | onError(callback: wx.types.SocketErrorCallback): void; 371 | /** 372 | * 监听WebSocket 接受到服务器的消息事件 373 | */ 374 | onMessage(callback: wx.types.SocketMessageCallback): void; 375 | } 376 | 377 | /** 378 | * 一个 UDP Socket 实例,默认使用 IPv4 协议。 379 | * 错误码: 380 | * -1 系统错误 381 | * -2 socket接口错误 382 | * -3 发送失败,无接口权限 383 | * 1 发送失败,参数错误,address不合法 384 | * 2 发送失败,参数错误,port不合法 385 | */ 386 | declare class UDPSocket { 387 | /** 388 | * 绑定一个系统随机分配的可用端口,或绑定一个指定的端口号 389 | * @param port 需要绑定的端口号,不指定时使用随机端口 390 | * @returns 绑定成功的端口号 391 | */ 392 | bind(port?: number): number; 393 | 394 | /** 395 | * 向指定的 IP 和 port 发送消息 396 | */ 397 | send(param: wx.types.UDPSendParams): void; 398 | 399 | /** 400 | * 关闭 UDP Socket 实例,相当于销毁。 在关闭之后,UDP Socket 实例不能再发送消息,每次调用 UDPSocket.send 将会触发错误事件, 401 | * 并且 message 事件回调函数也不会再执行。在 UDPSocket 实例被创建后将被 Native 强引用,保证其不被 GC。在 UDPSocket.close 后 402 | * 将解除对其的强引用,让 UDPSocket 实例遵从 GC。 403 | */ 404 | close(): void; 405 | 406 | /** 407 | * 设置监听关闭事件回调 408 | * @param callback 关闭事件的回调函数 409 | */ 410 | onClose(callback: () => void): void; 411 | 412 | /** 413 | * 清除监听关闭事件回调 414 | * @param callback 之前监听的函数 415 | */ 416 | offClose(callback: () => void): void; 417 | 418 | /** 419 | * 监听错误事件 420 | * @param callback 错误回调函数 421 | */ 422 | onError(callback: (res: { 423 | /** 424 | * 错误信息 425 | */ 426 | errMsg: string; 427 | }) => void): void; 428 | 429 | /** 430 | * 取消监听错误事件 431 | * @param callback 之前设置的错误回调函数 432 | */ 433 | offError(callback: (res: { 434 | /** 435 | * 错误信息 436 | */ 437 | errMsg: string; 438 | }) => void): void; 439 | 440 | /** 441 | * 监听开始监听数据包消息的事件 442 | * @param callback 回调函数 443 | */ 444 | onListening(callback: () => void): void; 445 | 446 | /** 447 | * 取消监听开始监听数据包消息的事件 448 | * @param callback 之前设置的回调函数 449 | */ 450 | offListening(callback: () => void): void; 451 | 452 | /** 453 | * 监听收到消息的事件 454 | * @param callback 回调函数 455 | */ 456 | onMessage(callback: (res: wx.types.UDPMessage) => void): void; 457 | 458 | /** 459 | * 取消监听收到消息的事件 460 | * @param callback 之前设置的回调函数 461 | */ 462 | offMessage(callback: (res: wx.types.UDPMessage) => void): void; 463 | } 464 | 465 | declare class UploadTask { 466 | /** 467 | * 中断上传任务 468 | */ 469 | abort(): void; 470 | /** 471 | * 监听上传进度变化事件 472 | * @param callback.res.progress 上传进度百分比 473 | * @param callback.res.totalBytesSent 已经上传的数据长度,单位 Bytes 474 | * @param callback.res.totalBytesExpectedToSend 预期需要上传的数据总长度,单位 Bytes 475 | */ 476 | onProgressUpdate(callback: (res: { progress: number, totalBytesSent: number, totalBytesExpectedToSend: number }) => void): void; 477 | } 478 | 479 | declare class KVData { 480 | key: string; 481 | value: string; 482 | } 483 | 484 | declare class UserGameData { 485 | /** 486 | * 用户的微信头像 url 487 | */ 488 | avatarUrl: string; 489 | /** 490 | * 用户的微信昵称 491 | */ 492 | nickname: string; 493 | /** 494 | * 用户的openid 495 | */ 496 | openid: string; 497 | /** 498 | * 用户的托管 KV 数据列表 499 | */ 500 | KVDataList: ReadonlyArray; 501 | } 502 | 503 | declare class CreatedButton { 504 | type: wx.types.ButtonType; 505 | text: string; 506 | image: string; 507 | style: wx.types.ButtonStyle; 508 | show(): void; 509 | hide(): void; 510 | onTap(callback: (res?: any) => void): void; // res参数会被具体按钮的API定义覆盖为具体信息 511 | offTap(callback: (res?: any) => void): void; 512 | destroy(): void; 513 | } 514 | declare class UserInfoButton extends CreatedButton { 515 | onTap(callback: (res: { 516 | /** 517 | * 用户信息对象,不包含 openid 等敏感信息 518 | */ 519 | userInfo: wx.types.UserInfo, 520 | /** 521 | * 不包括敏感信息的原始数据字符串,用于计算签名 522 | */ 523 | rawData: string, 524 | /** 525 | * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822) 526 | */ 527 | signature: string, 528 | /** 529 | * 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) 530 | */ 531 | encryptedData: string, 532 | /** 533 | * 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) 534 | */ 535 | iv: string, 536 | errMsg: string 537 | }) => void): void; 538 | } 539 | declare class OpenSettingButton extends CreatedButton { 540 | onTap(callback: () => void): void; 541 | offTap(callback: () => void): void; 542 | } 543 | declare class GameClubButton extends CreatedButton { 544 | icon: wx.types.GameClubButtonIcon; 545 | onTap(callback: (res: { 546 | errMsg: string; 547 | }) => void): void; 548 | } 549 | declare class FeedbackButton extends CreatedButton { 550 | onTap(callback: (res: { 551 | errMsg: string; 552 | }) => void): void; 553 | } 554 | 555 | declare class OpenDataContext { 556 | /** 557 | * 开放数据域和主域共享的 sharedCanvas,注意在开放数据域内时getContext只能使用2d模式 558 | */ 559 | canvas: Canvas; 560 | /** 561 | * 向开放数据域发送消息 562 | * @param message 要发送的消息,message 中及嵌套对象中 key 的 value 只能是 primitive value。即 number、string、boolean、null、undefined。 563 | */ 564 | postMessage(message: any): void; 565 | } 566 | 567 | declare class LoadSubpackageTask { 568 | /** 569 | * 监听分包加载进度变化事件 570 | * @param callback.res.progress 分包下载进度百分比 571 | * @param callback.res.totalBytesWritten 已经下载的数据长度,单位 Bytes 572 | * @param callback.res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes 573 | */ 574 | onProgressUpdate(callback: (res: { progress: number, totalBytesWritten: number, totalBytesExpectedToWrite: number }) => void): void; 575 | } 576 | 577 | declare class UpdateManager { 578 | /** 579 | * 应用更新包并重启 580 | */ 581 | applyUpdate(): void; 582 | /** 583 | * 监听检查更新结果回调 584 | */ 585 | onCheckForUpdate(callback: () => void): void; 586 | /** 587 | * 监听更新包下载成功回调 588 | */ 589 | onUpdateReady(callback: () => void): void; 590 | /** 591 | * 监听更新包下载失败回调 592 | */ 593 | onUpdateFailed(callback: () => void): void; 594 | } 595 | 596 | declare class WxWorker { 597 | /** 598 | * 向主线程或Worker线程发送的消息。 599 | * @param message 需要发送的消息,必须是一个可序列化的 JavaScript 对象。 600 | */ 601 | postMessage(message: any): void; 602 | /** 603 | * 结束当前 worker 线程,仅限在主线程 worker 对象上调用。 604 | */ 605 | terminate(): void; 606 | /** 607 | * 监听接收主线程/Worker 线程向当前线程发送的消息 608 | * @param callback.res.message 接收主线程/Worker 线程向当前线程发送的消息 609 | */ 610 | onMessage(callback: (res: { message: any }) => void): void; 611 | 612 | /** 613 | * 监听 worker线程被系统回收事件(当iOS系统资源紧张时,worker线程存在被系统回收的可能,开发者可监听此事件并重新创建一个worker)。仅限在主线程 worker 对象上调用。 614 | */ 615 | onProcessKilled(callback: () => void): void; 616 | } 617 | 618 | /** 619 | * InnerAudioContext 实例,可通过 wx.createInnerAudioContext 接口获取实例。 620 | */ 621 | declare class InnerAudioContext { 622 | /** 623 | * 音频资源的地址 624 | */ 625 | src: string; 626 | /** 627 | * 是否自动播放 628 | */ 629 | autoplay: boolean; 630 | /** 631 | * 是否循环播放 632 | */ 633 | loop: boolean; 634 | /** 635 | * 是否遵循系统静音开关,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音 636 | */ 637 | obeyMuteSwitch: boolean; 638 | /** 639 | * 当前音频的长度,单位 s。只有在当前有合法的 src 时返回 640 | */ 641 | readonly duration: number; 642 | /** 643 | * 当前音频的播放位置,单位 s。只有在当前有合法的 src 时返回,时间不取整,保留小数点后 6 位 644 | */ 645 | readonly currentTime: number; 646 | /** 647 | * 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播放 648 | */ 649 | paused: boolean; 650 | /** 651 | * 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲 652 | */ 653 | readonly buffered: number; 654 | /** 655 | * 音量。范围 0~1。 656 | */ 657 | volume: number; 658 | 659 | /** 660 | * 播放 661 | */ 662 | play(): void; 663 | /** 664 | * 暂停。暂停后的音频再播放会从暂停处开始播放 665 | */ 666 | pause(): void; 667 | /** 668 | * 停止。停止后的音频再播放会从头开始播放。 669 | */ 670 | stop(): void; 671 | /** 672 | * 跳转到指定位置,单位 s 673 | * @param position 跳转的时间 674 | */ 675 | seek(position: number): void; 676 | /** 677 | * 销毁当前实例 678 | */ 679 | destroy(): void; 680 | /** 681 | * 监听音频进入可以播放状态的事件 682 | */ 683 | onCanplay(callback: () => void): void; 684 | /** 685 | * 取消监听音频进入可以播放状态的事件 686 | */ 687 | offCanplay(callback: () => void): void; 688 | /** 689 | * 监听音频播放事件 690 | */ 691 | onPlay(callback: () => void): void; 692 | /** 693 | * 取消监听音频播放事件 694 | */ 695 | offPlay(callback: () => void): void; 696 | /** 697 | * 监听音频暂停事件 698 | */ 699 | onPause(callback: () => void): void; 700 | /** 701 | * 取消监听音频暂停事件 702 | */ 703 | offPause(callback: () => void): void; 704 | /** 705 | * 监听音频停止事件 706 | */ 707 | onStop(callback: () => void): void; 708 | /** 709 | * 取消监听音频停止事件 710 | */ 711 | offStop(callback: () => void): void; 712 | /** 713 | * 监听音频自然播放至结束的事件 714 | */ 715 | onEnded(callback: () => void): void; 716 | /** 717 | * 取消监听音频自然播放至结束的事件 718 | */ 719 | offEnded(callback: () => void): void; 720 | /** 721 | * 监听音频播放进度更新事件 722 | */ 723 | onTimeUpdate(callback: () => void): void; 724 | /** 725 | * 取消监听音频播放进度更新事件 726 | */ 727 | offTimeUpdate(callback: () => void): void; 728 | /** 729 | * 监听音频播放错误事件 730 | */ 731 | onError(callback: () => void): void; 732 | /** 733 | * 取消监听音频播放错误事件 734 | */ 735 | offError(callback: () => void): void; 736 | /** 737 | * 监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 738 | */ 739 | onWaiting(callback: () => void): void; 740 | /** 741 | * 取消监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发 742 | */ 743 | offWaiting(callback: () => void): void; 744 | /** 745 | * 监听音频进行跳转操作的事件 746 | */ 747 | onSeeking(callback: () => void): void; 748 | /** 749 | * 取消监听音频进行跳转操作的事件 750 | */ 751 | offSeeking(callback: () => void): void; 752 | /** 753 | * 监听音频完成跳转操作的事件 754 | */ 755 | onSeeked(callback: () => void): void; 756 | /** 757 | * 取消监听音频完成跳转操作的事件 758 | */ 759 | offSeeked(callback: () => void): void; 760 | } 761 | 762 | declare class RecorderManager { 763 | /** 764 | * 开始录音 765 | */ 766 | start(param: { 767 | /** 768 | * 录音的时长,单位 ms,最大值 600000(10 分钟),默认值60000(1 分钟) 769 | */ 770 | duration?: number | undefined, 771 | /** 772 | * 采样率 773 | */ 774 | sampleRate: 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000, 775 | /** 776 | * 录音通道数 777 | */ 778 | numberOfChannels: 1 | 2, 779 | /** 780 | * 编码码率 781 | */ 782 | encodeBitRate: number, 783 | /** 784 | * 音频格式 785 | */ 786 | format: "mp3" | "aac", 787 | /** 788 | * 指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调 789 | */ 790 | frameSize: number, 791 | /** 792 | * 指定录音的音频源,可通过 wx.getAvailableAudioSources() 获取当前可用的音频源,默认值auto 793 | */ 794 | audioSource?: wx.types.AudioSourceType | undefined 795 | }): void; 796 | /** 797 | * 暂停录音 798 | */ 799 | pause(): void; 800 | /** 801 | * 继续录音 802 | */ 803 | resume(): void; 804 | /** 805 | * 停止录音 806 | */ 807 | stop(): void; 808 | /** 809 | * 监听录音开始事件 810 | */ 811 | onStart(callback: () => void): void; 812 | /** 813 | * 监听录音继续事件 814 | */ 815 | onResume(callback: () => void): void; 816 | /** 817 | * 监听录音暂停事件 818 | */ 819 | onPause(callback: () => void): void; 820 | /** 821 | * 监听录音结束事件 822 | * @param callback.res.tempFilePath 录音文件的临时路径 823 | */ 824 | onStop(callback: (res: { tempFilePath: string }) => void): void; 825 | /** 826 | * 监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。 827 | * @param callback.res.frameBuffer 录音分片数据 828 | * @param callback.res.isLastFrame 当前帧是否正常录音结束前的最后一帧 829 | */ 830 | onFrameRecorded(callback: (res: { frameBuffer: ArrayBuffer, isLastFrame: boolean }) => void): void; 831 | /** 832 | * 监听录音错误事件 833 | */ 834 | onError(callback: (res: { errMsg: string }) => void): void; 835 | } 836 | 837 | declare class ImageFile { 838 | /** 839 | * 本地文件路径 840 | */ 841 | path: string; 842 | /** 843 | * 本地文件大小,单位 B 844 | */ 845 | size: number; 846 | } 847 | 848 | declare class Video { 849 | /** 850 | * 视频的左上角横坐标 851 | */ 852 | x: number; 853 | /** 854 | * 视频的左上角纵坐标 855 | */ 856 | y: number; 857 | /** 858 | * 视频的宽度,默认值300 859 | */ 860 | width: number; 861 | /** 862 | * 默认值150 863 | */ 864 | height: number; 865 | /** 866 | * 视频的资源地址 867 | */ 868 | src: string; 869 | /** 870 | * 视频的封面 871 | */ 872 | poster: string; 873 | /** 874 | * 视频的初始播放位置,单位为 s 秒,默认值0 875 | */ 876 | initialTime: number; 877 | /** 878 | * 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0 879 | */ 880 | playbackRate: number; 881 | /** 882 | * 视频是否为直播,默认值0 883 | */ 884 | live?: number | undefined; 885 | /** 886 | * 视频的缩放模式 887 | * fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例 888 | * contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白 889 | * cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见 890 | */ 891 | objectFit: "contain" | "cover" | "fill"; 892 | /** 893 | * 视频是否显示控件,默认true 894 | */ 895 | controls: boolean; 896 | /** 897 | * 视频是否自动播放,默认false 898 | */ 899 | autoplay: boolean; 900 | /** 901 | * 视频是否是否循环播放,默认值false 902 | */ 903 | loop: boolean; 904 | /** 905 | * 视频是否禁音播放,默认值false 906 | */ 907 | muted: boolean; 908 | 909 | /** 910 | * 视频开始缓冲时触发的回调函数 911 | */ 912 | onwaiting: () => void; 913 | /** 914 | * 视频开始播放时触发的回调函数 915 | */ 916 | onplay: () => void; 917 | /** 918 | * 视频暂停时触发的回调函数 919 | */ 920 | onpause: () => void; 921 | /** 922 | * 视频播放到末尾时触发的回调函数 923 | */ 924 | onended: () => void; 925 | /** 926 | * 每当视频播放进度更新时触发的回调函数 927 | */ 928 | ontimeupdate: () => void; 929 | /** 930 | * 视频发生错误时触发的回调函数 931 | */ 932 | onerror: () => void; 933 | 934 | /** 935 | * 销毁视频 936 | */ 937 | destroy(): void; 938 | /** 939 | * 监听视频缓冲事件 940 | */ 941 | onWaiting(callback: () => void): void; 942 | /** 943 | * 取消监听视频缓冲事件 944 | */ 945 | offWaiting(callback: () => void): void; 946 | 947 | /** 948 | * 监听视频播放事件 949 | */ 950 | onPlay(callback: () => void): void; 951 | /** 952 | * 取消监听视频播放事件 953 | */ 954 | offPlay(callback: () => void): void; 955 | /** 956 | * 监听视频暂停事件 957 | */ 958 | onPause(callback: () => void): void; 959 | /** 960 | * 取消监听视频暂停事件 961 | */ 962 | offPause(callback: () => void): void; 963 | /** 964 | * 监听视频播放到末尾事件 965 | */ 966 | onEnded(callback: () => void): void; 967 | /** 968 | * 取消监听视频播放到末尾事件 969 | */ 970 | offEnded(callback: () => void): void; 971 | /** 972 | * 监听视频播放进度更新事件 973 | * @param callback.res.position 当前的播放位置,单位为秒 974 | * @param callback.res.duration 视频的总时长,单位为秒 975 | */ 976 | onTimeUpdate(callback: (res: { position: number, duration: number }) => void): void; 977 | /** 978 | * 取消监听视频播放进度更新事件 979 | */ 980 | offTimeUpdate(callback: (res: { position: number, duration: number }) => void): void; 981 | /** 982 | * 监听视频错误事件 983 | * @param callback.res.errMsg 错误信息,有如下值 984 | * MEDIA_ERR_NETWORK - 当下载时发生错误 985 | * MEDIA_ERR_DECODE - 当解码时发生错误 986 | * MEDIA_ERR_SRC_NOT_SUPPORTED - video 的 src 属性是不支持的资源类型 987 | */ 988 | onError(callback: (res: { errMsg: string }) => void): void; 989 | /** 990 | * 取消监听视频错误事件 991 | */ 992 | offError(callback: (res: { errMsg: string }) => void): void; 993 | 994 | /** 995 | * 播放视频 996 | */ 997 | play(): Promise; 998 | /** 999 | * 暂停视频 1000 | */ 1001 | pause(): Promise; 1002 | /** 1003 | * 停止视频 1004 | */ 1005 | stop(): Promise; 1006 | /** 1007 | * 视频跳转 1008 | * @param time 视频跳转到指定位置,单位为 s 秒 1009 | */ 1010 | seek(time: number): Promise; 1011 | 1012 | /** 1013 | * 视频全屏 1014 | */ 1015 | requestFullScreen(): Promise; 1016 | 1017 | /** 1018 | * 视频退出全屏 1019 | */ 1020 | exitFullScreen(): Promise; 1021 | } 1022 | 1023 | /** 1024 | * 相机对象 1025 | */ 1026 | declare class Camera { 1027 | /** 1028 | * 相机的左上角横坐标 1029 | */ 1030 | x: number; 1031 | 1032 | /** 1033 | * 相机的左上角纵坐标 1034 | */ 1035 | y: number; 1036 | 1037 | /** 1038 | * 相机的宽度 1039 | */ 1040 | width: number; 1041 | 1042 | /** 1043 | * 相机的高度 1044 | */ 1045 | height: number; 1046 | 1047 | /** 1048 | * 摄像头朝向 1049 | */ 1050 | devicePosition: "front" | "back"; 1051 | 1052 | /** 1053 | * 闪光灯状态 1054 | */ 1055 | flash: "auto" | "on" | "off"; 1056 | 1057 | /** 1058 | * 帧数据图像尺寸 1059 | */ 1060 | size: "small" | "medium" | "large"; 1061 | 1062 | /** 1063 | * 拍照,可指定质量,成功则返回图片 1064 | * @param quality 图片质量 1065 | */ 1066 | takePhoto(quality?: "high" | "normal" | "low"): Promise<{ 1067 | /** 1068 | * 临时图片路径 1069 | */ 1070 | tempImagePath: string, 1071 | /** 1072 | * 图片宽度 1073 | */ 1074 | width: string, 1075 | /** 1076 | * 图片高度 1077 | */ 1078 | height: string 1079 | }>; 1080 | 1081 | /** 1082 | * 开始录像 1083 | */ 1084 | startRecord(): Promise; 1085 | 1086 | /** 1087 | * 结束录像,成功则返回封面与视频 1088 | * @param compressed 是否压缩录制视频 1089 | */ 1090 | stopRecord(compressed: boolean): Promise<{ 1091 | /** 1092 | * 临时视频路径 1093 | */ 1094 | tempThumbPath: string, 1095 | /** 1096 | * 临时封面路径 1097 | */ 1098 | tempVideoPath: string 1099 | }>; 1100 | 1101 | /** 1102 | * 监听用户不允许授权使用摄像头的情况 1103 | * @param callback 回调函数 1104 | */ 1105 | onAuthCancel(callback: () => void): void; 1106 | 1107 | /** 1108 | * 监听摄像头非正常终止事件,如退出后台等情况 1109 | * @param callback 回调函数 1110 | */ 1111 | onStop(callback: () => void): void; 1112 | 1113 | /** 1114 | * 监听摄像头实时帧数据 1115 | */ 1116 | onCameraFrame(callback: (res: { 1117 | /** 1118 | * 图像数据矩形的宽度 1119 | */ 1120 | width: number, 1121 | /** 1122 | * 图像数据矩形的高度 1123 | */ 1124 | height: number, 1125 | /** 1126 | * 图像像素点数据,一维数组,每四项表示一个像素点的 rgba 1127 | */ 1128 | data: ArrayBuffer 1129 | }) => void): void; 1130 | 1131 | /** 1132 | * 开启监听帧数据 1133 | */ 1134 | listenFrameChange(): void; 1135 | 1136 | /** 1137 | * 关闭监听帧数据 1138 | */ 1139 | closeFrameChange(): void; 1140 | 1141 | /** 1142 | * 销毁相机 1143 | */ 1144 | destroy(): void; 1145 | } 1146 | 1147 | declare class AdObject { 1148 | /** 1149 | * 广告单元 id 1150 | */ 1151 | adUnitId: string; 1152 | /** 1153 | * 显示广告。 1154 | */ 1155 | show(): Promise; 1156 | /** 1157 | * 销毁广告 1158 | */ 1159 | destroy(): void; 1160 | /** 1161 | * 监听广告加载事件 1162 | */ 1163 | onLoad(callback: () => void): void; 1164 | /** 1165 | * 取消监听广告加载事件 1166 | */ 1167 | offLoad(callback: () => void): void; 1168 | /** 1169 | * 监听广告错误事件 1170 | */ 1171 | onError(callback: (res: { errMsg: string }) => void): void; 1172 | /** 1173 | * 取消监听广告错误事件 1174 | */ 1175 | offError(callback: (res: { errMsg: string }) => void): void; 1176 | } 1177 | 1178 | declare class ResizableAdObject extends AdObject { 1179 | /** 1180 | * 隐藏广告 1181 | */ 1182 | hide(): void; 1183 | /** 1184 | * 监听广告缩放 1185 | */ 1186 | onResize(callback: (res: { width: number, height: number }) => void): void; 1187 | /** 1188 | * 取消监听广告缩放事件 1189 | */ 1190 | offResize(callback: (res: { width: number, height: number }) => void): void; 1191 | } 1192 | 1193 | /** 1194 | * banner 广告组件。banner 广告组件是一个原生组件,层级比普通组件高。banner 广告组件默认是隐藏的,需要调用 BannerAd.show() 将其显示。banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的尺寸将通过 BannerAd.onResize() 事件中提供。 1195 | */ 1196 | declare class BannerAd extends ResizableAdObject { 1197 | /** 1198 | * 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 Banner 广告不会自动刷新) 1199 | */ 1200 | adIntervals?: number | undefined; 1201 | /** 1202 | * banner 广告组件的样式。style 上的属性的值仅为开发者设置的值,banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的真实尺寸需要通过 BannerAd.onResize() 事件获得。 1203 | */ 1204 | style: wx.types.AdStyle & { 1205 | /** 1206 | * banner 广告组件经过缩放后真实的宽度 1207 | */ 1208 | realWidth: number; 1209 | /** 1210 | * banner 广告组件经过缩放后真实的高度 1211 | */ 1212 | realHeight: number; 1213 | }; 1214 | } 1215 | 1216 | /** 1217 | * 激励视频广告组件。激励视频广告组件是一个原生组件,层级比普通组件高。激励视频广告是一个单例(小游戏端是全局单例,小程序端是页面内单例,在小程序端的单例对象不允许跨页面使用),默认是隐藏的,需要调用 RewardedVideoAd.show() 将其显示。 1218 | */ 1219 | declare class RewardedVideoAd extends AdObject { 1220 | /** 1221 | * 是否启用多例模式,默认为false 1222 | */ 1223 | multiton: boolean; 1224 | /** 1225 | * 加载广告 1226 | */ 1227 | load(): Promise; 1228 | /** 1229 | * 监听用户点击 关闭广告 按钮的事件 1230 | */ 1231 | onClose(callback: (res: { isEnded: boolean }) => void): void; 1232 | /** 1233 | * 监听用户点击 关闭广告 按钮的事件 1234 | */ 1235 | offClose(callback: (res: { isEnded: boolean }) => void): void; 1236 | } 1237 | 1238 | /** 1239 | * 插屏广告组件。插屏广告组件是一个原生组件,层级比普通组件高。插屏广告组件每次创建都会返回一个全新的实例(小程序端的插屏广告实例不允许跨页面使用),默认是隐藏的,需要调用 InterstitialAd.show() 将其显示。 1240 | */ 1241 | declare class InterstitialAd extends AdObject { 1242 | /** 1243 | * 加载广告 1244 | */ 1245 | load(): Promise; 1246 | /** 1247 | * 监听用户点击 关闭广告 按钮的事件 1248 | */ 1249 | onClose(callback: (res: { isEnded: boolean }) => void): void; 1250 | /** 1251 | * 监听用户点击 关闭广告 按钮的事件 1252 | */ 1253 | offClose(callback: (res: { isEnded: boolean }) => void): void; 1254 | } 1255 | 1256 | /** 1257 | * grid(格子) 广告组件。grid(格子) 广告组件是一个原生组件,层级比普通组件高。grid(格子) 广告组件默认是隐藏的,需要调用 GridAd.show() 将其显示。grid(格子) 广告会根据开发者设置的宽度进行等比缩放,缩放后的尺寸将通过 GridAd.onResize() 事件中提供。 1258 | */ 1259 | declare class GridAd extends ResizableAdObject { 1260 | /** 1261 | * 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 Banner 广告不会自动刷新) 1262 | */ 1263 | adIntervals?: number | undefined; 1264 | /** 1265 | * grid(格子) 广告广告组件的主题,提供 white black 两种主题选择。 1266 | */ 1267 | adTheme: string; 1268 | /** 1269 | * grid(格子) 广告组件的格子个数,可设置爱5,8两种格子个数样式,默认值为5 1270 | */ 1271 | gridCount: number; 1272 | /** 1273 | * grid(格子) 广告广告组件的样式。style 上的属性的值仅为开发者设置的grid(格子) 广告) 广告会根据开发者设置的宽度进行等比缩放,缩放后的真实尺寸需要通过 GridAd.onResize() 事件获得。 1274 | */ 1275 | style: wx.types.AdStyle & { 1276 | /** 1277 | * grid(格子) 广告组件经过缩放后真实的宽度 1278 | */ 1279 | realWidth: number; 1280 | /** 1281 | * grid(格子) 广告组件经过缩放后真实的高度 1282 | */ 1283 | realHeight: number; 1284 | }; 1285 | } 1286 | 1287 | /** 1288 | * 原生模板广告组件。原生模板广告组件是一个原生组件,层级比普通组件高。原生模板广告组件默认是隐藏的,需要调用 CustomAd.show() 将其显示。如果宽度可配置,原生模板广告会根据开发者设置的宽度进行等比缩放。 1289 | */ 1290 | declare class CustomAd extends AdObject { 1291 | /** 1292 | * 原生模板广告组件的样式 1293 | */ 1294 | style: wx.types.CustomAdStyle; 1295 | /** 1296 | * 查询原生模板广告展示状态。 1297 | */ 1298 | isShow(): boolean; 1299 | /** 1300 | * 隐藏原生模板广告。(某些模板广告无法隐藏) 1301 | */ 1302 | hide(): void; 1303 | /** 1304 | * 监听原生模板广告隐藏事件, 某些模板如矩阵格子模板用户点击关闭时也会触发该事件。 1305 | */ 1306 | onHide(callback: () => void): void; 1307 | /** 1308 | * 取消监听原生模板广告隐藏事件 1309 | */ 1310 | offHide(callback: () => void): void; 1311 | /** 1312 | * 监听用户点击 关闭广告 按钮的事件 1313 | */ 1314 | onClose(callback: (res: { isEnded: boolean }) => void): void; 1315 | /** 1316 | * 监听用户点击 关闭广告 按钮的事件 1317 | */ 1318 | offClose(callback: (res: { isEnded: boolean }) => void): void; 1319 | } 1320 | 1321 | // --定时器 1322 | declare function clearTimeout(timeoutID: number): void; 1323 | declare function clearInterval(intervalID: number): void; 1324 | declare function setTimeout(fn: () => void, delay: number, ...rest: any[]): number; 1325 | declare function setInterval(fn: () => void, delay: number, ...rest: any[]): number; 1326 | 1327 | // --渲染 1328 | declare function cancelAnimationFrame(requestID: number): void; 1329 | declare function requestAnimationFrame(callback: () => void): number; 1330 | 1331 | declare namespace wx { 1332 | namespace types { 1333 | interface Callbacks { 1334 | success?: (() => void) | undefined; 1335 | fail?: (() => void) | undefined; 1336 | complete?: (() => void) | undefined; 1337 | } 1338 | 1339 | interface CallbacksWithType { 1340 | success?: ((res: T) => void) | undefined; 1341 | fail?: (() => void) | undefined; 1342 | complete?: (() => void) | undefined; 1343 | } 1344 | 1345 | interface CallbacksWithType2 { 1346 | success?: ((res: T) => void) | undefined; 1347 | fail?: ((res: F) => void) | undefined; 1348 | complete?: (() => void) | undefined; 1349 | } 1350 | 1351 | interface RenderingContextConfig { 1352 | /** 1353 | * 表示是否抗锯齿 1354 | */ 1355 | antialias?: boolean | undefined; 1356 | /** 1357 | * 表示是否绘图完成后是否保留绘图缓冲区 1358 | */ 1359 | preserveDrawingBuffer?: boolean | undefined; 1360 | /** 1361 | * 抗锯齿样本数。最小值为 2,最大不超过系统限制数量,仅 iOS 支持 1362 | */ 1363 | antialiasSamples?: number | undefined; 1364 | } 1365 | 1366 | interface ToTempFileSyncParams { 1367 | /** 1368 | * 截取 canvas 的左上角横坐标 1369 | */ 1370 | x?: number | undefined; 1371 | /** 1372 | * 截取 canvas 的左上角纵坐标 1373 | */ 1374 | y?: number | undefined; 1375 | /** 1376 | * 截取 canvas 的宽度 1377 | */ 1378 | width?: number | undefined; 1379 | /** 1380 | * 截取 canvas 的高度 1381 | */ 1382 | height?: number | undefined; 1383 | /** 1384 | * 目标文件的宽度,会将截取的部分拉伸或压缩至该数值 1385 | */ 1386 | destWidth?: number | undefined; 1387 | /** 1388 | * 目标文件的高度,会将截取的部分拉伸或压缩至该数值 1389 | */ 1390 | destHeight?: number | undefined; 1391 | /** 1392 | * 目标文件的类型 1393 | */ 1394 | fileType?: "jpg" | "png" | undefined; 1395 | /** 1396 | * jpg图片的质量,仅当 fileType 为 jpg 时有效。取值范围为 0.0(最低)- 1.0(最高),不含 0。不在范围内时当作 1.0 1397 | */ 1398 | quality?: number | undefined; 1399 | } 1400 | 1401 | interface ToTempFileParams extends ToTempFileSyncParams { 1402 | success?: ((res: { tempFilePath: string }) => void) | undefined; 1403 | fail?: (() => void) | undefined; 1404 | complete?: (() => void) | undefined; 1405 | } 1406 | 1407 | interface RenameParams { 1408 | oldPath: string; 1409 | newPath: string; 1410 | success?: (() => void) | undefined; 1411 | fail?: ((res: { errMsg: string }) => void) | undefined; 1412 | complete?: (() => void) | undefined; 1413 | } 1414 | 1415 | interface RmdirParams { 1416 | dirPath: string; 1417 | recursive?: boolean | undefined; 1418 | success?: (() => void) | undefined; 1419 | fail?: ((res: { errMsg: string }) => void) | undefined; 1420 | complete?: (() => void) | undefined; 1421 | } 1422 | 1423 | interface ReaddirParams { 1424 | dirPath: string; 1425 | success?: ((res: { files: ReadonlyArray }) => void) | undefined; 1426 | fail?: ((res: { errMsg: string }) => void) | undefined; 1427 | complete?: (() => void) | undefined; 1428 | } 1429 | 1430 | interface MkdirParams { 1431 | dirPath: string; 1432 | recursive?: boolean | undefined; 1433 | success?: (() => void) | undefined; 1434 | fail?: ((res: { errMsg: string }) => void) | undefined; 1435 | complete?: (() => void) | undefined; 1436 | } 1437 | 1438 | type FileContentEncoding = "ascii" | "base64" | "binary" | "hex" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" | "utf-8" | "utf8" | "latin1"; 1439 | 1440 | interface ReadfileParams { 1441 | filePath: string; 1442 | encoding?: FileContentEncoding | undefined; 1443 | success?: ((res: { data: string | ArrayBuffer }) => void) | undefined; 1444 | fail?: ((res: { errMsg: string }) => void) | undefined; 1445 | complete?: (() => void) | undefined; 1446 | } 1447 | 1448 | interface StatParams { 1449 | path: string; 1450 | success?: ((res: { stat: Stats }) => void) | undefined; 1451 | fail?: ((res: { errMsg: string }) => void) | undefined; 1452 | complete?: (() => void) | undefined; 1453 | } 1454 | 1455 | interface WritefileParams { 1456 | filePath: string; 1457 | data: string | ArrayBuffer; 1458 | encoding?: FileContentEncoding | undefined; 1459 | success?: (() => void) | undefined; 1460 | fail?: ((res: { errMsg: string }) => void) | undefined; 1461 | complete?: (() => void) | undefined; 1462 | } 1463 | 1464 | interface UnlinkParams { 1465 | filePath: string; 1466 | success?: (() => void) | undefined; 1467 | fail?: ((res: { errMsg: string }) => void) | undefined; 1468 | complete?: (() => void) | undefined; 1469 | } 1470 | 1471 | interface UnzipParams { 1472 | zipFilePath: string; 1473 | targetPath: string; 1474 | success?: (() => void) | undefined; 1475 | fail?: ((res: { errMsg: string }) => void) | undefined; 1476 | complete?: (() => void) | undefined; 1477 | } 1478 | 1479 | interface AccessfileParams { 1480 | path: string; 1481 | success?: (() => void) | undefined; 1482 | fail?: ((res: { errMsg: string }) => void) | undefined; 1483 | complete?: (() => void) | undefined; 1484 | } 1485 | 1486 | interface SavedfileList { 1487 | fileList: { 1488 | filePath: string; 1489 | size: number; 1490 | createTime: number; 1491 | }; 1492 | } 1493 | 1494 | interface CopyfileParams { 1495 | srcPath: string; 1496 | destPath: string; 1497 | success?: (() => void) | undefined; 1498 | fail?: ((res: { errMsg: string }) => void) | undefined; 1499 | complete?: (() => void) | undefined; 1500 | } 1501 | 1502 | interface FileinfoParams { 1503 | filePath: string; 1504 | success?: ((res: { size: number, digest: string }) => void) | undefined; 1505 | fail?: ((res: { errMsg: string }) => void) | undefined; 1506 | complete?: (() => void) | undefined; 1507 | } 1508 | 1509 | interface RemovefileParams { 1510 | filePath: string; 1511 | success?: (() => void) | undefined; 1512 | fail?: (() => void) | undefined; 1513 | complete?: (() => void) | undefined; 1514 | } 1515 | 1516 | interface SavefileParams { 1517 | tempFilePath: string; 1518 | filePath?: string | undefined; 1519 | success?: ((res: { savedFilePath: string }) => void) | undefined; 1520 | fail?: ((res: { errMsg: string }) => void) | undefined; 1521 | complete?: (() => void) | undefined; 1522 | } 1523 | 1524 | interface AppendfileParams { 1525 | filePath: string; 1526 | data: string | ArrayBuffer; 1527 | encoding?: FileContentEncoding | undefined; 1528 | success?: (() => void) | undefined; 1529 | fail?: ((res: { errMsg: string }) => void) | undefined; 1530 | complete?: (() => void) | undefined; 1531 | } 1532 | 1533 | interface LineHeightParams { 1534 | fontStyle?: "normal" | "italic" | undefined; 1535 | fontWeight?: "normal" | "bold" | undefined; 1536 | fontSize?: number | undefined; 1537 | fontFamily: string; 1538 | text: string; 1539 | success?: ((res: { lineHeight: number }) => void) | undefined; 1540 | fail?: (() => void) | undefined; 1541 | complete?: (() => void) | undefined; 1542 | } 1543 | 1544 | interface Image { 1545 | src: string; 1546 | width: number; 1547 | height: number; 1548 | onload: () => void; 1549 | onerror: (e?: any) => void; 1550 | } 1551 | 1552 | // --启动参数 1553 | interface LaunchOption { 1554 | /** 1555 | * 场景值 1556 | */ 1557 | scene: number; 1558 | /** 1559 | * 启动参数 1560 | */ 1561 | query: any; 1562 | /** 1563 | * 当前小游戏是否被显示在聊天顶部 1564 | */ 1565 | isSticky: boolean; 1566 | /** 1567 | * 票据 1568 | */ 1569 | shareTicket: string; 1570 | } 1571 | 1572 | // --系统信息 1573 | interface SystemInfo { 1574 | /** 1575 | * 手机品牌 1576 | */ 1577 | brand: string; 1578 | /** 1579 | * 手机型号 1580 | */ 1581 | model: string; 1582 | /** 1583 | * 设备像素比 1584 | */ 1585 | pixelRatio: number; 1586 | /** 1587 | * 屏幕宽度 1588 | */ 1589 | screenWidth: number; 1590 | /** 1591 | * 屏幕高度 1592 | */ 1593 | screenHeight: number; 1594 | /** 1595 | * 可使用窗口宽度 1596 | */ 1597 | windowWidth: number; 1598 | /** 1599 | * 可使用窗口高度 1600 | */ 1601 | windowHeight: number; 1602 | /** 1603 | * 微信设置的语言 1604 | */ 1605 | language: string; 1606 | /** 1607 | * 微信版本号 1608 | */ 1609 | version: string; 1610 | /** 1611 | * 操作系统版本 1612 | */ 1613 | system: string; 1614 | /** 1615 | * 客户端平台 1616 | */ 1617 | platform: string; 1618 | /** 1619 | * 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位 px。 1620 | */ 1621 | fontSizeSetting: string; 1622 | /** 1623 | * 客户端基础库版本 1624 | */ 1625 | SDKVersion: string; 1626 | /** 1627 | * 性能等级 1628 | */ 1629 | benchmarkLevel: number; 1630 | /** 1631 | * 电量,范围 1 - 100 1632 | */ 1633 | battery: number; 1634 | /** 1635 | * wifi 信号强度,范围 0 - 4 1636 | */ 1637 | wifiSignal: number; 1638 | } 1639 | 1640 | // --触摸对象 1641 | interface Touch { 1642 | /** 1643 | * Touch 对象的唯一标识符,只读属性。一次触摸动作(我们值的是手指的触摸)在平面上移动的整个过程中, 该标识符不变。可以根据它来判断跟踪的是否是同一次触摸过程。 1644 | */ 1645 | identifier: number; 1646 | /** 1647 | * 触点相对于整体页面的 X 轴距离。 1648 | */ 1649 | pageX: number; 1650 | /** 1651 | * 触点相对于整体页面的 Y 轴距离。 1652 | */ 1653 | pageY: number; 1654 | /** 1655 | * 触点相对于游戏窗口的 X 轴距离。 1656 | */ 1657 | clientX: number; 1658 | /** 1659 | * 触点相对于游戏窗口的 Y 轴距离。 1660 | */ 1661 | clientY: number; 1662 | } 1663 | 1664 | interface TouchData { 1665 | /** 1666 | * 当前事件的类型 1667 | */ 1668 | type: string; 1669 | /** 1670 | * 当前所有触摸点的列表 1671 | */ 1672 | touches: ReadonlyArray; 1673 | /** 1674 | * 触发此次事件的触摸点列表 1675 | */ 1676 | changedTouches: ReadonlyArray; 1677 | /** 1678 | * 事件触发时的时间戳 1679 | */ 1680 | timeStamp: number; 1681 | } 1682 | 1683 | // --iBeacon(TODO) 1684 | /** 1685 | * 停止搜索附近的 iBeacon 设备 1686 | */ 1687 | function stopBeaconDiscovery(param: unknown): void; 1688 | /** 1689 | * 开始搜索附近的 iBeacon 设备 1690 | */ 1691 | function startBeaconDiscovery(param: unknown): void; 1692 | /** 1693 | * 监听 iBeacon 设备更新事件,仅能注册一个监听 1694 | */ 1695 | function onBeaconUpdate(callback: unknown): void; 1696 | /** 1697 | * 监听 iBeacon 服务状态变化事件,仅能注册一个监听 1698 | */ 1699 | function onBeaconServiceChange(callback: unknown): void; 1700 | /** 1701 | * 取消监听 iBeacon 设备更新事件 1702 | */ 1703 | function offBeaconUpdate(callback: unknown): void; 1704 | /** 1705 | * 取消监听 iBeacon 服务状态变化事件 1706 | */ 1707 | function offBeaconServiceChange(callback: unknown): void; 1708 | /** 1709 | * 获取所有已搜索到的 iBeacon 设备 1710 | */ 1711 | function getBeacons(param: unknown): void; 1712 | /* 1713 | IBeaconInfo 1714 | 属性 1715 | string uuid 1716 | iBeacon 设备广播的 uuid 1717 | 1718 | string major 1719 | iBeacon 设备的主 id 1720 | 1721 | string minor 1722 | iBeacon 设备的次 id 1723 | 1724 | number proximity 1725 | 表示设备距离的枚举值 1726 | 1727 | number accuracy 1728 | iBeacon 设备的距离 1729 | 1730 | number rssi 1731 | 表示设备的信号强度 1732 | */ 1733 | 1734 | // --低功耗蓝牙(TODO) 1735 | function writeBLECharacteristicValue(): void; 1736 | function readBLECharacteristicValue(): void; 1737 | function onBLEConnectionStateChange(): void; 1738 | function onBLECharacteristicValueChange(): void; 1739 | function notifyBLECharacteristicValueChange(): void; 1740 | function getBLEDeviceServices(): void; 1741 | function getBLEDeviceCharacteristics(): void; 1742 | function createBLEConnection(): void; 1743 | function closeBLEConnection(): void; 1744 | 1745 | // --蓝牙(TODO) 1746 | function stopBluetoothDevicesDiscovery(): void; 1747 | function startBluetoothDevicesDiscovery(): void; 1748 | function openBluetoothAdapter(): void; 1749 | function onBluetoothDeviceFound(): void; 1750 | function onBluetoothAdapterStateChange(): void; 1751 | function getConnectedBluetoothDevices(): void; 1752 | function getBluetoothDevices(): void; 1753 | function getBluetoothAdapterState(): void; 1754 | function closeBluetoothAdapter(): void; 1755 | 1756 | // --电量 1757 | interface BatteryInfo { 1758 | /** 1759 | * 设备电量,范围 1 - 100 1760 | */ 1761 | level: string; 1762 | /** 1763 | * 是否正在充电 1764 | */ 1765 | isCharging: boolean; 1766 | } 1767 | 1768 | // --剪切板 1769 | interface ClipboardData { 1770 | data: string; 1771 | } 1772 | 1773 | interface SetClipboardDataParams { 1774 | success?: (() => void) | undefined; 1775 | fail?: (() => void) | undefined; 1776 | complete?: (() => void) | undefined; 1777 | data: string; 1778 | } 1779 | 1780 | interface SetKeepScreenOnParams { 1781 | success?: (() => void) | undefined; 1782 | fail?: (() => void) | undefined; 1783 | complete?: (() => void) | undefined; 1784 | keepScreenOn: boolean; 1785 | } 1786 | 1787 | interface SetScreenBrightnessParams { 1788 | success?: (() => void) | undefined; 1789 | fail?: (() => void) | undefined; 1790 | complete?: (() => void) | undefined; 1791 | /** 1792 | * 屏幕亮度值,范围 0 ~ 1,0 最暗,1 最亮 1793 | */ 1794 | value: number; 1795 | } 1796 | 1797 | interface DownfileParams { 1798 | url: string; 1799 | /** 1800 | * 在指定filePath之后success回调中将不会有res.tempFilePath路径值,下载的文件会直接写入filePath指定的路径(有写入权限的情况下,根目录请使用wx.env.USER_DATA_PATH,路径文件夹必须存在,否则写入失败) 1801 | */ 1802 | filePath?: string | undefined; 1803 | /** 1804 | * HTTP 请求的 Header,Header 中不能设置 Referer 1805 | */ 1806 | header?: { [key: string]: string } | undefined; 1807 | /** 1808 | * res.tempFilePath 临时文件路径。如果没传入 filePath 指定文件存储路径,则下载后的文件会存储到一个临时文件 1809 | * res.statusCode 开发者服务器返回的 HTTP 状态码 1810 | */ 1811 | success?: ((res: { tempFilePath?: string | undefined, statusCode: number }) => void) | undefined; 1812 | fail?: ((res: { errMsg: string }) => void) | undefined; 1813 | complete?: (() => void) | undefined; 1814 | } 1815 | 1816 | type NetworkType = "wifi" | "2g" | "3g" | "4g" | "unknown" | "none"; 1817 | 1818 | type RequestMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT"; 1819 | 1820 | interface RequestParams { 1821 | /** 1822 | * 开发者服务器接口地址 1823 | */ 1824 | url: string; 1825 | /** 1826 | * 请求的参数 1827 | */ 1828 | data?: string | { [key: string]: any } | undefined; 1829 | /** 1830 | * 设置请求的 header,header 中不能设置 Referer 1831 | */ 1832 | header?: { [name: string]: string } | undefined; 1833 | /** 1834 | * HTTP 请求方法 1835 | */ 1836 | method?: RequestMethod | undefined; 1837 | /** 1838 | * 返回的数据格式 1839 | */ 1840 | dataType?: "json" | "arraybuffer" | undefined; 1841 | /** 1842 | * res.data usually can be string or ArrayBuffer 1843 | */ 1844 | success?: ((res: { data: any, statusCode: number, header?: { [key: string]: string } | undefined }) => void) | undefined; 1845 | fail?: (() => void) | undefined; 1846 | complete?: (() => void) | undefined; 1847 | } 1848 | 1849 | interface SocketSendParams { 1850 | data: string | ArrayBuffer; 1851 | success?: (() => void) | undefined; 1852 | fail?: (() => void) | undefined; 1853 | complete?: (() => void) | undefined; 1854 | } 1855 | interface SocketConnectParams { 1856 | url: string; 1857 | protocols?: string[] | undefined; 1858 | header?: { [key: string]: string } | undefined; 1859 | method?: RequestMethod | undefined; 1860 | success?: (() => void) | undefined; 1861 | fail?: (() => void) | undefined; 1862 | complete?: (() => void) | undefined; 1863 | } 1864 | interface SocketCloseParams { 1865 | /** 1866 | * 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。如果这个参数没有被指定,默认的取值是1000 (表示正常连接关闭) 1867 | */ 1868 | code?: number | undefined; 1869 | /** 1870 | * 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于123字节的UTF-8 文本(不是字符) 1871 | */ 1872 | reason?: string | undefined; 1873 | success?: (() => void) | undefined; 1874 | fail?: (() => void) | undefined; 1875 | complete?: (() => void) | undefined; 1876 | } 1877 | 1878 | type SocketOpenCallback = (res: { header?: { [key: string]: string } | undefined }) => void; 1879 | type SocketMessageCallback = (res: { data: string | ArrayBuffer }) => void; 1880 | type SocketErrorCallback = (res: { errMsg: string }) => void; 1881 | 1882 | interface UDPSendParams { 1883 | /** 1884 | * 要发消息的地址。可以是一个和本机同网段的 IP 地址,也可以是在安全域名列表内的域名地址 1885 | */ 1886 | address: string; 1887 | /** 1888 | * 要发送消息的端口号 1889 | */ 1890 | port: number; 1891 | /** 1892 | * 要发送的数据 1893 | */ 1894 | message: string | ArrayBuffer; 1895 | /** 1896 | * 发送数据的偏移量,仅当 message 为 ArrayBuffer 类型时有效,默认值0 1897 | */ 1898 | offset?: number | undefined; 1899 | /** 1900 | * 发送数据的长度,仅当 message 为 ArrayBuffer 类型时有效,默认值message.byteLength 1901 | */ 1902 | length?: number | undefined; 1903 | } 1904 | interface UDPMessage { 1905 | /** 1906 | * 收到的消息 1907 | */ 1908 | message: ArrayBuffer; 1909 | /** 1910 | * 消息来源的结构化信息 1911 | */ 1912 | remoteInfo: { 1913 | /** 1914 | * 发送消息的 socket 的地址 1915 | */ 1916 | address: string; 1917 | /** 1918 | * 使用的协议族,为 IPv4 或者 IPv6 1919 | */ 1920 | family: string; 1921 | /** 1922 | * 端口号 1923 | */ 1924 | port: number; 1925 | /** 1926 | * message 的大小,单位:字节 1927 | */ 1928 | size: number; 1929 | }; 1930 | } 1931 | 1932 | /** 1933 | * wx.getUserInfo的旧版本API参数,随时会被删除,不推荐使用 1934 | */ 1935 | interface OldUserInfoParam { 1936 | /** 1937 | * 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。 1938 | */ 1939 | withCredentials?: boolean | undefined; 1940 | /** 1941 | * 显示用户信息的语言 1942 | */ 1943 | lang?: "en" | "zh_CN" | "zh_TW" | undefined; 1944 | success?: ((res: { 1945 | /** 1946 | * 用户信息对象,不包含 openid 等敏感信息 1947 | */ 1948 | userInfo: UserInfo, 1949 | /** 1950 | * 不包括敏感信息的原始数据字符串,用于计算签名 1951 | */ 1952 | rawData: string, 1953 | /** 1954 | * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822) 1955 | */ 1956 | signature: string, 1957 | /** 1958 | * 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) 1959 | */ 1960 | encryptedData: string, 1961 | /** 1962 | * 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822) 1963 | */ 1964 | iv: string, 1965 | errMsg: string 1966 | }) => void) | undefined; 1967 | fail?: (() => void) | undefined; 1968 | complete?: (() => void) | undefined; 1969 | } 1970 | 1971 | /** 1972 | * 新版本wx.getUserInfo的参数,需要在开放数据域内调用 1973 | */ 1974 | interface NewUserInfoParam { 1975 | /** 1976 | * 要获取信息的用户的 openId 数组,如果要获取当前用户信息,则将数组中的一个元素设为 'selfOpenId' 1977 | */ 1978 | openIdList?: string[] | undefined; 1979 | /** 1980 | * 显示用户信息的语言 1981 | */ 1982 | lang?: "en" | "zh_CN" | "zh_TW" | undefined; 1983 | success?: ((res: { data: ReadonlyArray }) => void) | undefined; 1984 | fail?: (() => void) | undefined; 1985 | complete?: (() => void) | undefined; 1986 | } 1987 | 1988 | interface UserInfo { 1989 | language: string; 1990 | nickName: string; 1991 | avatarUrl: string; 1992 | /** 1993 | * 0:未知、1:男、2:女 1994 | */ 1995 | gender: 0 | 1 | 2; 1996 | country: string; 1997 | province: string; 1998 | city: string; 1999 | } 2000 | 2001 | type ButtonType = "text" | "image"; 2002 | interface ButtonStyle { 2003 | left?: number | undefined; 2004 | top?: number | undefined; 2005 | width?: number | undefined; 2006 | height?: number | undefined; 2007 | /** 2008 | * 格式#ff0000 2009 | */ 2010 | backgroundColor?: string | undefined; 2011 | /** 2012 | * 格式#ff0000 2013 | */ 2014 | borderColor?: string | undefined; 2015 | borderWidth?: number | undefined; 2016 | borderRadius?: number | undefined; 2017 | textAlign?: "left" | "center" | "right" | undefined; 2018 | fontSize?: number | undefined; 2019 | lineHeight?: number | undefined; 2020 | } 2021 | 2022 | type GameClubButtonIcon = "green" | "white" | "dark" | "light"; 2023 | 2024 | // --设置 2025 | interface AuthSetting { 2026 | /** 2027 | * 用户信息,对应接口 wx.getUserInfo 2028 | */ 2029 | "scope.userInfo"?: boolean | undefined; 2030 | /** 2031 | * 地理位置,对应接口 wx.getLocation wx.chooseLocation 2032 | */ 2033 | "scope.userLocation"?: boolean | undefined; 2034 | /** 2035 | * 通讯地址,对应接口 wx.chooseAddress 2036 | */ 2037 | "scope.address"?: boolean | undefined; 2038 | /** 2039 | * 发票抬头,对应接口 wx.chooseInvoiceTitle 2040 | */ 2041 | "scope.invoiceTitle"?: boolean | undefined; 2042 | /** 2043 | * 微信运动步数,对应接口 wx.getWeRunData 2044 | */ 2045 | "scope.werun"?: boolean | undefined; 2046 | /** 2047 | * 录音功能,对应接口 wx.startRecord 2048 | */ 2049 | "scope.record"?: boolean | undefined; 2050 | /** 2051 | * 保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum 2052 | */ 2053 | "scope.writePhotosAlbum"?: boolean | undefined; 2054 | /** 2055 | * 摄像头 wx.camera 2056 | */ 2057 | "scope.camera"?: boolean | undefined; 2058 | } 2059 | 2060 | interface SetStorageParams { 2061 | key: string; 2062 | data: any; 2063 | success?: (() => void) | undefined; 2064 | fail?: (() => void) | undefined; 2065 | complete?: (() => void) | undefined; 2066 | } 2067 | interface RemoveStorageParams { 2068 | key: string; 2069 | success?: (() => void) | undefined; 2070 | fail?: (() => void) | undefined; 2071 | complete?: (() => void) | undefined; 2072 | } 2073 | interface GetStorageParams { 2074 | key: string; 2075 | success?: ((res: { data: any }) => void) | undefined; 2076 | fail?: (() => void) | undefined; 2077 | complete?: (() => void) | undefined; 2078 | } 2079 | 2080 | interface StorageInfo { 2081 | /** 2082 | * 当前 storage 中所有的 key 2083 | */ 2084 | keys: ReadonlyArray; 2085 | /** 2086 | * 当前占用的空间大小, 单位 KB 2087 | */ 2088 | currentSize: number; 2089 | /** 2090 | * 限制的空间大小,单位 KB 2091 | */ 2092 | limitSize: number; 2093 | } 2094 | 2095 | interface ShareOption { 2096 | /** 2097 | * 转发标题,不传则默认使用当前小游戏的昵称。 2098 | */ 2099 | title?: string | undefined; 2100 | /** 2101 | * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5:4 2102 | */ 2103 | imageUrl?: string | undefined; 2104 | /** 2105 | * 查询字符串,必须是 key1=val1&key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionsSync() 或 wx.onShow 获取启动参数中的 query。 2106 | */ 2107 | query?: string | undefined; 2108 | } 2109 | 2110 | interface AccelerometerParams { 2111 | interval: "game" | "ui" | "normal"; 2112 | success?: (() => void) | undefined; 2113 | fail?: (() => void) | undefined; 2114 | complete?: (() => void) | undefined; 2115 | } 2116 | 2117 | type AudioSourceType = "auto" | "buildInMic" | "headsetMic" | "mic" | "camcorder"; 2118 | 2119 | interface AdStyle { 2120 | /** 2121 | * 广告组件的左上角横坐标 2122 | */ 2123 | left: number; 2124 | /** 2125 | * 广告组件的左上角纵坐标 2126 | */ 2127 | top: number; 2128 | /** 2129 | * 广告组件的宽度。最小 300,最大至 屏幕宽度(屏幕宽度可以通过 wx.getSystemInfoSync() 获取)。 2130 | */ 2131 | width: number; 2132 | /** 2133 | * 广告组件的高度 2134 | */ 2135 | height: number; 2136 | } 2137 | 2138 | interface CustomAdStyle { 2139 | /** 2140 | * 原生模板广告组件的左上角横坐标 2141 | */ 2142 | left: number; 2143 | /** 2144 | * 原生模板广告组件的左上角纵坐标 2145 | */ 2146 | top: number; 2147 | /** 2148 | * (只对小程序适用) 原生模板广告组件是否固定屏幕位置(不跟随屏幕滚动) 2149 | */ 2150 | fixed?: boolean | undefined; 2151 | } 2152 | 2153 | interface BannerAdParams { 2154 | /** 2155 | * 广告单元 id 2156 | */ 2157 | adUnitId: string; 2158 | /** 2159 | * 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 Banner 广告不会自动刷新) 2160 | */ 2161 | adIntervals?: number | undefined; 2162 | /** 2163 | * banner 广告组件的样式 2164 | */ 2165 | style: AdStyle; 2166 | } 2167 | 2168 | interface VideoAdParams { 2169 | /** 2170 | * 广告单元 id 2171 | */ 2172 | adUnitId: string; 2173 | /** 2174 | * 是否启用多例模式,默认为false 2175 | */ 2176 | multiton?: boolean | undefined; 2177 | } 2178 | 2179 | interface InterstitialAdParam { 2180 | /** 2181 | * 广告单元 id 2182 | */ 2183 | adUnitId: string; 2184 | } 2185 | 2186 | interface GridAdParam { 2187 | /** 2188 | * 广告单元 id 2189 | */ 2190 | adUnitId: string; 2191 | /** 2192 | * 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 grid(格子) 广告不会自动刷新) 2193 | */ 2194 | adIntervals?: number | undefined; 2195 | /** 2196 | * grid(格子) 广告组件的样式 2197 | */ 2198 | style: AdStyle; 2199 | /** 2200 | * grid(格子) 广告广告组件的主题,提供 white black 两种主题选择。 2201 | */ 2202 | adTheme: 'white' | 'black'; 2203 | /** 2204 | * grid(格子) 广告组件的格子个数,可设置为5,8两种格子个数样式,默认值为5 2205 | */ 2206 | gridCount?: 5 | 8 | undefined; 2207 | } 2208 | 2209 | interface CustomAdParam { 2210 | /** 2211 | * 广告单元 id 2212 | */ 2213 | adUnitId: string; 2214 | /** 2215 | * 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 grid(格子) 广告不会自动刷新) 2216 | */ 2217 | adIntervals?: number | undefined; 2218 | /** 2219 | * 原生模板广告组件的样式 2220 | */ 2221 | style: CustomAdStyle; 2222 | } 2223 | } 2224 | 2225 | /** 2226 | * 创建一个画布对象。首次调用创建的是显示在屏幕上的画布,之后调用创建的都是离屏画布。 2227 | */ 2228 | function createCanvas(): Canvas; 2229 | 2230 | /** 2231 | * 只有开放数据域能调用,获取主域和开放数据域共享的 sharedCanvas 2232 | */ 2233 | function getSharedCanvas(): Canvas; 2234 | 2235 | /** 2236 | * 创建一个图片对象 2237 | */ 2238 | function createImage(): types.Image; 2239 | 2240 | /** 2241 | * 获取一行文本的行高 2242 | * @param p 字体参数 2243 | */ 2244 | function getTextLineHeight(p: types.LineHeightParams): number; 2245 | 2246 | /** 2247 | * 加载自定义字体文件 2248 | * @param path 字体文件路径。可以是代码包文件路径,也可以是 wxfile:// 协议的本地文件路径。 2249 | */ 2250 | function loadFont(path: string): string; 2251 | 2252 | /** 2253 | * 可以修改渲染帧率。默认渲染帧率为 60 帧每秒。修改后,requestAnimationFrame 的回调频率会发生改变。 2254 | * @param fps 帧率,有效范围 1 - 60。 2255 | */ 2256 | function setPreferredFramesPerSecond(fps: number): void; 2257 | 2258 | // --生命周期 2259 | function exitMiniProgram(cb?: types.Callbacks): void; 2260 | function getLaunchOptionsSync(): types.LaunchOption; 2261 | function onHide(cb: () => void): void; 2262 | function offHide(cb: () => void): void; 2263 | function onShow(cb: (res: { scene: string, query: any, shareTicket: string }) => void): void; 2264 | function offShow(cb: (res: { scene: string, query: any, shareTicket: string }) => void): void; 2265 | 2266 | // --系统信息 2267 | function getSystemInfo(cb: types.CallbacksWithType): void; 2268 | function getSystemInfoSync(): types.SystemInfo; 2269 | 2270 | /** 2271 | * 监听音频中断结束,在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功 2272 | */ 2273 | function onAudioInterruptionEnd(cb: () => void): void; 2274 | /** 2275 | * 取消监听音频中断结束,在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功 2276 | */ 2277 | function offAudioInterruptionEnd(cb: () => void): void; 2278 | /** 2279 | * 监听音频因为受到系统占用而被中断开始,以下场景会触发此事件:闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天。此事件触发后,小程序内所有音频会暂停。 2280 | */ 2281 | function onAudioInterruptionBegin(cb: () => void): void; 2282 | /** 2283 | * 取消监听音频因为受到系统占用而被中断开始,以下场景会触发此事件:闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天。此事件触发后,小程序内所有音频会暂停。 2284 | */ 2285 | function offAudioInterruptionBegin(cb: () => void): void; 2286 | /** 2287 | * 监听全局错误事件 2288 | */ 2289 | function onError(cb: (res: { message: string, stack: string }) => void): void; 2290 | function offError(cb: (res: { message: string, stack: string }) => void): void; 2291 | 2292 | // --触摸事件 2293 | /** 2294 | * 监听开始始触摸事件 2295 | */ 2296 | function onTouchStart(cb: (res: types.TouchData) => void): void; 2297 | function offTouchStart(cb: (res: types.TouchData) => void): void; 2298 | /** 2299 | * 监听触点移动事件 2300 | */ 2301 | function onTouchMove(cb: (res: types.TouchData) => void): void; 2302 | function offTouchMove(cb: (res: types.TouchData) => void): void; 2303 | /** 2304 | * 监听触摸结束事件 2305 | */ 2306 | function onTouchEnd(cb: (res: types.TouchData) => void): void; 2307 | function offTouchEnd(cb: (res: types.TouchData) => void): void; 2308 | /** 2309 | * 监听触点失效事件 2310 | */ 2311 | function onTouchCancel(cb: (res: types.TouchData) => void): void; 2312 | function offTouchCancel(cb: (res: types.TouchData) => void): void; 2313 | 2314 | // --加速计 2315 | /** 2316 | * 监听加速度数据,频率:5次/秒,接口调用后会自动开始监听,可使用 wx.stopAccelerometer 停止监听。 2317 | */ 2318 | function onAccelerometerChange(cb: (res: { x: number, y: number, z: number }) => void): void; 2319 | /** 2320 | * 开始监听加速度数据。 2321 | */ 2322 | function startAccelerometer(cb: types.AccelerometerParams): void; 2323 | /** 2324 | * 停止监听加速度数据。 2325 | */ 2326 | function stopAccelerometer(cb?: types.Callbacks): void; 2327 | 2328 | // --电量 2329 | /** 2330 | * 获取设备电量。同步 API wx.getBatteryInfoSync 在 iOS 上不可用。 2331 | */ 2332 | function getBatteryInfo(cb: types.CallbacksWithType): void; 2333 | /** 2334 | * IOS上这个同步API无法使用 2335 | */ 2336 | function getBatteryInfoSync(): types.BatteryInfo; 2337 | 2338 | // --剪贴板 2339 | /** 2340 | * 取得系统剪贴板的内容 2341 | */ 2342 | function getClipboardData(cb: types.CallbacksWithType): void; 2343 | /** 2344 | * 设置系统剪贴板的内容 2345 | */ 2346 | function setClipboardData(p: types.SetClipboardDataParams): void; 2347 | 2348 | // --罗盘 2349 | /** 2350 | * 监听罗盘数据,频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。 2351 | * @param cb.res.direction 面对的方向度数 2352 | */ 2353 | function onCompassChange(cb: (res: { direction: number }) => void): void; 2354 | /** 2355 | * 开始监听罗盘数据 2356 | */ 2357 | function startCompass(cb?: types.Callbacks): void; 2358 | /** 2359 | * 停止监听罗盘数据 2360 | */ 2361 | function stopCompass(cb?: types.Callbacks): void; 2362 | 2363 | // --网络 2364 | /** 2365 | * 获取网络类型 2366 | */ 2367 | function getNetworkType(cb: types.CallbacksWithType<{ isConnected: boolean, networkType: types.NetworkType }>): void; 2368 | /** 2369 | * 监听网络状态变化事件 2370 | */ 2371 | function onNetworkStatusChange(cb: (res: { 2372 | /** 2373 | * 当前是否有网络链接 2374 | */ 2375 | isConnected: boolean, 2376 | /** 2377 | * none - 无网络, unknown - Android 下不常见的网络类型 2378 | */ 2379 | networkType: types.NetworkType 2380 | }) => void): void; 2381 | 2382 | // --屏幕 2383 | /** 2384 | * 获取屏幕亮度 2385 | */ 2386 | function getScreenBrightness(cb: types.CallbacksWithType<{ value: number }>): void; 2387 | /** 2388 | * 设置是否保持常亮状态。仅在当前小程序生效,离开小程序后设置失效。 2389 | */ 2390 | function setKeepScreenOn(p: types.SetKeepScreenOnParams): void; 2391 | /** 2392 | * 设置屏幕亮度 2393 | */ 2394 | function setScreenBrightness(p: types.SetScreenBrightnessParams): void; 2395 | 2396 | // --转屏 2397 | /** 2398 | * 监听横竖屏切换事件 2399 | */ 2400 | function onDeviceOrientationChange(callback: (res: { value: string }) => void): void; 2401 | /** 2402 | * 取消监听横竖屏切换事件 2403 | */ 2404 | function offDeviceOrientationChange(callback: (res: { value: string }) => void): void; 2405 | 2406 | // --设备方向 2407 | /** 2408 | * 停止监听设备方向的变化。 2409 | */ 2410 | function stopDeviceMotionListening(cb?: types.Callbacks): void; 2411 | /** 2412 | * 开始监听设备方向的变化 2413 | */ 2414 | function startDeviceMotionListening(param: { 2415 | /** 2416 | * 开始监听设备方向的变化。默认值normal, 2417 | * game - 适用于更新游戏的回调频率,在 20ms/次 左右 2418 | * ui - 适用于更新 UI 的回调频率,在 60ms/次 左右 2419 | * normal - 普通的回调频率,在 200ms/次 左右 2420 | */ 2421 | interval: "game" | "ui" | "normal" 2422 | } & types.Callbacks): void; 2423 | /** 2424 | * 监听设备方向变化事件。频率根据 wx.startDeviceMotionListening() 的 interval 参数。可以使用 wx.stopDeviceMotionListening() 停止监听。 2425 | */ 2426 | function onDeviceMotionChange(callback: (res: { 2427 | /** 2428 | * 当 手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。 2429 | */ 2430 | alpha: number, 2431 | /** 2432 | * 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 2433 | */ 2434 | beta: number, 2435 | /** 2436 | * 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 2437 | */ 2438 | gamma: number 2439 | }) => void): void; 2440 | /** 2441 | * 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。 2442 | * @param callback 之前添加过的监听回调函数,如果不指定,则清空所有 2443 | */ 2444 | function offDeviceMotionChange(callback?: unknown): void; 2445 | 2446 | // --陀螺仪 2447 | /** 2448 | * 停止监听陀螺仪数据 2449 | */ 2450 | function stopGyroscope(cb?: types.Callbacks): void; 2451 | /** 2452 | * 开始监听陀螺仪数据。 2453 | */ 2454 | function startGyroscope(param: { 2455 | /** 2456 | * 开始监听设备方向的变化。默认值normal, 2457 | * game - 适用于更新游戏的回调频率,在 20ms/次 左右 2458 | * ui - 适用于更新 UI 的回调频率,在 60ms/次 左右 2459 | * normal - 普通的回调频率,在 200ms/次 左右 2460 | */ 2461 | interval: "game" | "ui" | "normal" 2462 | } & types.Callbacks): void; 2463 | /** 2464 | * 监听陀螺仪数据变化事件。频率根据 wx.startGyroscope() 的 interval 参数。可以使用 wx.stopGyroscope() 停止监听。 2465 | * @param callback 监听函数 2466 | */ 2467 | function onGyroscopeChange(callback: (res: { 2468 | /** 2469 | * x 轴的角速度 2470 | */ 2471 | x: number, 2472 | /** 2473 | * y 轴的角速度 2474 | */ 2475 | y: number, 2476 | /** 2477 | * z 轴的角速度 2478 | */ 2479 | z: number 2480 | }) => void): void; 2481 | /** 2482 | * 取消监听陀螺仪数据变化事件。 2483 | * @param callback 之前监听的回调函数 2484 | */ 2485 | function offGyroscopeChange(callback: unknown): void; 2486 | 2487 | // --振动 2488 | /** 2489 | * 使手机发生较短时间的振动(15 ms) 2490 | */ 2491 | function vibrateShort(cb?: types.Callbacks): void; 2492 | /** 2493 | * 使手机发生较长时间的振动(400 ms) 2494 | */ 2495 | function vibrateLong(cb?: types.Callbacks): void; 2496 | 2497 | // --文件系统 2498 | function getFileSystemManager(): FileSystemManager; 2499 | 2500 | // --推荐弹窗 2501 | /** 2502 | * 创建小游戏推荐弹窗组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.7.5 后再使用该 API。每次调用该方法都会返回一个全新的实例。 2503 | */ 2504 | function createGamePortal(param: { 2505 | /** 2506 | * 推荐单元 id 2507 | */ 2508 | adUnitId: string 2509 | }): unknown /* GamePortal */; // TODO: GamePortal 2510 | /** 2511 | * 创建小游戏推荐icon组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.8.2 后再使用该 API。每次调用该方法都会返回一个全新的实例。 2512 | */ 2513 | function createGameIcon(param: { 2514 | /** 2515 | * 推荐单元 id 2516 | */ 2517 | adUnitId: string, 2518 | /** 2519 | * 游戏icon的数量,请注意,正式版下面渲染出来的icon数量会小于等于count,请注册做好样式兼容 2520 | */ 2521 | count: number, 2522 | /** 2523 | * 数组的每一项可以针对对应的icon设置位置和样式等信息,style的每一项称为styleItem 2524 | */ 2525 | style: ReadonlyArray<{ 2526 | /** 2527 | * 游戏名称是否隐藏 2528 | */ 2529 | appNameHidden: boolean, 2530 | /** 2531 | * 游戏名称的颜色色值 2532 | */ 2533 | color: string, 2534 | /** 2535 | * 游戏icon的宽高值 2536 | */ 2537 | size: number, 2538 | /** 2539 | * 游戏icon的border尺寸 2540 | */ 2541 | borderWidth: number, 2542 | /** 2543 | * 游戏icon的border颜色色值 2544 | */ 2545 | borderColor: string, 2546 | /** 2547 | * 游戏icon的X轴坐标 2548 | */ 2549 | left: number, 2550 | /** 2551 | * 游戏icon的Y轴坐标 2552 | */ 2553 | top: number 2554 | }> 2555 | }): unknown /* GameIcon */; // TODO: GameIcon 2556 | /** 2557 | * 创建小游戏推荐banner组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.7.5 后再使用该 API。每次调用该方法都会返回一个全新的实例。 2558 | */ 2559 | function createGameBanner(param: { 2560 | /** 2561 | * 推荐单元 id 2562 | */ 2563 | adUnitId: string, 2564 | /** 2565 | * 小游戏推荐banner组件样式 2566 | */ 2567 | style: { 2568 | /** 2569 | * 小游戏推荐banner组件左上角横坐标 2570 | */ 2571 | left: number, 2572 | /** 2573 | * 小游戏推荐banner组件左上角纵坐标 2574 | */ 2575 | top: number 2576 | } 2577 | }): unknown /* GameBanner */; // TODO: GameBanner 2578 | 2579 | // --游戏对局回放 2580 | /** 2581 | * 获取全局唯一的游戏画面录制对象 2582 | */ 2583 | function getGameRecorder(): unknown /* GameRecorder */; // TODO: GameRecorder 2584 | /** 2585 | * 创建游戏对局回放分享按钮,返回一个单例对象。按钮在被用户点击后会发起对最近一次录制完成的游戏对局回放的分享。 2586 | */ 2587 | function createGameRecorderShareButton(): unknown /* GameRecorderShareButton */; // TODO: GameRecorderShareButton 2588 | 2589 | // --第三方平台 2590 | /** 2591 | * 获取第三方平台自定义的数据字段。 2592 | * Tips: 本接口暂时无法通过 wx.canIUse 判断是否兼容,开发者需要自行判断 wx.getExtConfig 是否存在来兼容,示例: 2593 | * if (wx.getExtConfig) { 2594 | * wx.getExtConfig({ 2595 | * success (res) { 2596 | * console.log(res.extConfig) 2597 | * } 2598 | * }) 2599 | * } 2600 | */ 2601 | function getExtConfig(callbacks: types.CallbacksWithType<{ 2602 | /** 2603 | * 第三方平台自定义的数据 2604 | */ 2605 | extConfig: unknown 2606 | }>): void; 2607 | /** 2608 | * wx.getExtConfig 的同步版本。 2609 | */ 2610 | function getExtConfigSync(): unknown; 2611 | 2612 | /** 2613 | * 系统环境变量 2614 | */ 2615 | const env: { 2616 | /** 2617 | * 用户下载数据根目录 2618 | */ 2619 | USER_DATA_PATH: string 2620 | }; 2621 | 2622 | // --位置 2623 | /** 2624 | * 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。 2625 | */ 2626 | function getLocation(param: { 2627 | /** 2628 | * wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 2629 | */ 2630 | type?: "wgs84" | "gcj02" | undefined, 2631 | /** 2632 | * 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度 >= 1.6.0 2633 | */ 2634 | altitude?: boolean | undefined, 2635 | success?: ((res: { 2636 | /** 2637 | * 纬度,范围为 -90~90,负数表示南纬 2638 | */ 2639 | latitude: number, 2640 | /** 2641 | * 经度,范围为 -180~180,负数表示西经 2642 | */ 2643 | longitude: number, 2644 | /** 2645 | * 速度,单位 m/s 2646 | */ 2647 | speed: number, 2648 | /** 2649 | * 位置的精确度 2650 | */ 2651 | accuracy: number, 2652 | /** 2653 | * 高度,单位 m 2654 | */ 2655 | altitude: number, 2656 | /** 2657 | * 垂直精度,单位 m(Android 无法获取,返回 0) 2658 | */ 2659 | verticalAccuracy: number, 2660 | /** 2661 | * 水平精度,单位 m 2662 | */ 2663 | horizontalAccuracy: number 2664 | }) => void) | undefined, 2665 | fail?: (() => void) | undefined, 2666 | complete?: (() => void) | undefined 2667 | }): void; 2668 | 2669 | // --网络 2670 | /** 2671 | * 下载文件 2672 | */ 2673 | function downloadFile(param: types.DownfileParams): DownloadTask; 2674 | 2675 | // --发起请求 2676 | function request(param: types.RequestParams): RequestTask; 2677 | 2678 | // --websocket 2679 | /** 2680 | * 创建一个 WebSocket 连接。最多同时存在 5 个 WebSocket 连接。 2681 | */ 2682 | function connectSocket(param: types.SocketConnectParams): SocketTask; 2683 | /** 2684 | * 关闭WebSocket 2685 | */ 2686 | function closeSocket(param: types.SocketCloseParams): void; 2687 | /** 2688 | * 监听WebSocket 连接打开事件 2689 | */ 2690 | function onSocketOpen(callback: types.SocketOpenCallback): void; 2691 | /** 2692 | * 监听WebSocket 连接关闭事件 2693 | */ 2694 | function onSocketClose(callback: () => void): void; 2695 | /** 2696 | * 监听WebSocket 接受到服务器的消息事件 2697 | */ 2698 | function onSocketMessage(callback: types.SocketMessageCallback): void; 2699 | /** 2700 | * 监听WebSocket 错误事件 2701 | */ 2702 | function onSocketError(callback: types.SocketErrorCallback): void; 2703 | /** 2704 | * 通过 WebSocket 连接发送数据,需要先 wx.connectSocket,并在 wx.onSocketOpen 回调之后才能发送。 2705 | */ 2706 | function sendSocketMessage(param: types.SocketSendParams): void; 2707 | 2708 | // --UDP通信 2709 | /** 2710 | * 创建一个 UDP Socket 实例 2711 | */ 2712 | function createUDPSocket(): UDPSocket; 2713 | 2714 | // --上传 2715 | function uploadFile(param: { 2716 | /** 2717 | * 开发者服务器地址 2718 | */ 2719 | url: string, 2720 | /** 2721 | * 要上传文件资源的路径 2722 | */ 2723 | filePath: string, 2724 | /** 2725 | * 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容 2726 | */ 2727 | name: string, 2728 | /** 2729 | * HTTP 请求 Header,Header 中不能设置 Referer 2730 | */ 2731 | header?: { [key: string]: string } | undefined, 2732 | /** 2733 | * HTTP 请求中其他额外的 form data 2734 | */ 2735 | formData?: { [key: string]: any } | undefined, 2736 | success?: ((res: { data: string, statusCode: number }) => void) | undefined, 2737 | fail?: (() => void) | undefined, 2738 | complete?: (() => void) | undefined 2739 | }): UploadTask; 2740 | 2741 | // --开放数据 2742 | /** 2743 | * 拉取当前用户所有同玩好友的托管数据。该接口只可在开放数据域下使用 2744 | */ 2745 | function getFriendCloudStorage(param: { 2746 | /** 2747 | * 要拉取的 key 列表 2748 | */ 2749 | keyList: string[], 2750 | success?: ((res: { data: ReadonlyArray }) => void) | undefined, 2751 | fail?: (() => void) | undefined, 2752 | complete?: (() => void) | undefined 2753 | }): void; 2754 | /** 2755 | * 获取当前用户托管数据当中对应 key 的数据。该接口只可在开放数据域下使用 2756 | */ 2757 | function getUserCloudStorage(param: { 2758 | /** 2759 | * 要拉取的 key 列表 2760 | */ 2761 | keyList: string[], 2762 | success?: ((res: { KVDataList: ReadonlyArray }) => void) | undefined, 2763 | fail?: (() => void) | undefined, 2764 | complete?: (() => void) | undefined 2765 | }): void; 2766 | 2767 | /** 2768 | * 在无须用户授权的情况下,批量获取用户信息。该接口只在开放数据域下可用 2769 | * 请注意!!旧版本的该接口已过期,微信不允许主动弹出授权框,旧版本API会被逐渐作废,请使用wx.createUserInfoButton或在隔离数据区取得用户信息 2770 | * 如使用旧接口取得用户信息,withCredentials 为 true 时需要先调用 wx.login 接口。需要用户授权 scope.userInfo 2771 | */ 2772 | function getUserInfo(param: types.NewUserInfoParam | types.OldUserInfoParam): void; 2773 | /** 2774 | * 在小游戏是通过群分享卡片打开的情况下,可以通过调用该接口获取群同玩成员的游戏数据。该接口只可在开放数据域下使用。 2775 | */ 2776 | function getGroupCloudStorage(param: { 2777 | /** 2778 | * 群分享对应的 shareTicket 2779 | */ 2780 | shareTicket: string, 2781 | /** 2782 | * 要拉取的 key 列表 2783 | */ 2784 | keyList: string[], 2785 | success?: ((res: { data: ReadonlyArray }) => void) | undefined, 2786 | fail?: (() => void) | undefined, 2787 | complete?: (() => void) | undefined 2788 | }): void; 2789 | /** 2790 | * 删除用户托管数据当中对应 key 的数据。 2791 | */ 2792 | function removeUserCloudStorage(param: { 2793 | /** 2794 | * 要删除掉 key 列表 2795 | */ 2796 | keyList: string[], 2797 | success?: (() => void) | undefined, 2798 | fail?: (() => void) | undefined, 2799 | complete?: (() => void) | undefined 2800 | }): void; 2801 | /** 2802 | * 对用户托管数据进行写数据操作,允许同时写多组 KV 数据。 2803 | * 托管数据的限制 2804 | * > 每个openid所标识的微信用户在每个游戏上托管的数据不能超过128个key-value对。 2805 | * > 上报的key-value列表当中每一项的key+value长度都不能超过1K(1024)字节。 2806 | * > 上报的key-value列表当中每一个key长度都不能超过128字节。 2807 | */ 2808 | function setUserCloudStorage(param: { 2809 | /** 2810 | * 要修改的 KV 数据列表 2811 | */ 2812 | KVDataList: ReadonlyArray, 2813 | success?: (() => void) | undefined, 2814 | fail?: (() => void) | undefined, 2815 | complete?: (() => void) | undefined 2816 | }): void; 2817 | /** 2818 | * 监听成功修改好友的互动型托管数据事件,该接口在游戏主域使用 2819 | * @param callback 事件发生的回调函数,只有一个参数为 wx.modifyFriendInteractiveStorage 传入的 key 2820 | */ 2821 | function onInteractiveStorageModified(callback: (key: string) => void): void; 2822 | /** 2823 | * 修改好友的互动型托管数据,该接口只可在开放数据域下使用,示例代码: 2824 | * wx.modifyFriendInteractiveStorage({ 2825 | * key: '1', 2826 | * opNum: 1, 2827 | * operation: 'add', 2828 | * toUser: '', // 好友的 openId 2829 | * title: '送你 10 个金币,赶快打开游戏看看吧', // 2.9.0 支持 2830 | * imageUrl: 'image/xxx' // 2.9.0 支持 2831 | * }); 2832 | * 2833 | * 赠送动作的校验: 2834 | * 调用该接口需要上传 JSServer 函数 "checkInteractiveData",该函数可用于执行赠送动作的校验逻辑,校验通过后返回结果表示本次赠送是否合法。只有 checkInteractiveData 返回了 {ret: true},此次修改才会成功。 2835 | * 2836 | * 使用模板规则进行交互: 2837 | * 每次调用该接口会弹窗询问用户是否确认执行该操作,2.9.0 之后版本,需要在 game.json 中设置 modifyFriendInteractiveStorageTemplates 来定制交互的文案。 2838 | * modifyFriendInteractiveStorageTemplates是一个模板数组,每一个模板需要有 key, action, object 参数,还有一个可选参数 ratio,详细说明见示例配置: 2839 | * { 2840 | * "modifyFriendInteractiveStorageTemplates": [ 2841 | * { 2842 | * "key": "1", // 这个 key 与接口中同名参数相对应,不同的 key 对应不同的模板 2843 | * "action": "赠送", // 互动行为 2844 | * "object": "金币", // 互动物品 2845 | * "ratio": 10 // 物品比率,opNum * ratio 代表物品个数 2846 | * } 2847 | * ] 2848 | * } 2849 | * 最后生成的文案为 "确认 ${action} ${nickname} ${object}?",或者 "确认 ${action} ${nickname} ${object} x ${opNum * ratio}?" 2850 | * 2851 | * 使用自定义文案进行交互: 2852 | * 2.7.7 之后,2.9.0 之前的版本,文案通过 game.json 的 modifyFriendInteractiveStorageConfirmWording 字段配置。 配置内容可包含 nickname 变量,用 ${nickname} 表示,实际调用时会被替换成好友的昵称。示例配置: 2853 | * { 2854 | * "modifyFriendInteractiveStorageConfirmWording": "确认送给${nickname}一个体力?" 2855 | * } 2856 | * 2.9.0 之后,在 modifyFriendInteractiveStorageTemplates 和 modifyFriendInteractiveStorageConfirmWording 都存在的情况下,会优先使用前者。 2857 | */ 2858 | function modifyFriendInteractiveStorage(param: { 2859 | /** 2860 | * 需要修改的数据的 key,目前可以为 '1' - '50' 2861 | */ 2862 | key: string, 2863 | /** 2864 | * 需要修改的数值,目前只能为 1 2865 | */ 2866 | opNum: number, 2867 | /** 2868 | * 修改类型 2869 | */ 2870 | operation: "add", 2871 | /** 2872 | * 目标好友的 openId 2873 | */ 2874 | toUser?: string | undefined 2875 | /** 2876 | * 分享标题,如果设置了这个值,则在交互成功后自动询问用户是否分享给好友(需要配置模板规则) 2877 | */ 2878 | title?: string | undefined 2879 | /** 2880 | * 分享图片地址,详见 wx.shareMessageToFriend 同名参数(需要配置模板规则) 2881 | */ 2882 | imageUrl?: string | undefined, 2883 | /** 2884 | * 分享图片 ID,详见 wx.shareMessageToFriend 同名参数(需要配置模板规则) 2885 | */ 2886 | imageUrlId?: string | undefined, 2887 | /** 2888 | * 是否静默修改(不弹框),静默修改需要用户通过快捷分享消息卡片进入才有效,代表分享反馈操作,无需填写 toUser,直接修改分享者与被分享者交互数据 2889 | * 默认值false 2890 | */ 2891 | quiet?: boolean | undefined, 2892 | success?: (() => void) | undefined; 2893 | fail?: ((res: { 2894 | /** 2895 | * 错误信息 2896 | */ 2897 | errMsg: string, 2898 | /** 2899 | * 错误码 2900 | * -17006 非好友关系 2901 | * -17007 非法的 toUser openId 2902 | * -17008 非法的 key 2903 | * -17009 非法的 operation 2904 | * -17010 非法的操作数 2905 | * -17011 JSServer 校验写操作失败 2906 | */ 2907 | errCode: number 2908 | }) => void) | undefined; 2909 | complete?: (() => void) | undefined; 2910 | }): void; 2911 | /** 2912 | * 获取当前用户互动型托管数据对应 key 的数据 2913 | */ 2914 | function getUserInteractiveStorage(param: { 2915 | /** 2916 | * 要获取的 key 列表 2917 | */ 2918 | keyList: string[] 2919 | } & types.CallbacksWithType2<{ 2920 | /** 2921 | * 加密数据,包含互动型托管数据的值。解密后的结果为一个 KVDataList,每一项为一个 KVData。 用户数据的签名验证和加解密 2922 | */ 2923 | encryptedData: string, 2924 | /** 2925 | * 敏感数据对应的云 ID,开通云开发的小程序才会返回,可通过云调用直接获取开放数据,详细见云调用直接获取开放数据 2926 | */ 2927 | cloudID: string 2928 | }, { 2929 | /** 2930 | * 错误信息 2931 | */ 2932 | errMsg: string, 2933 | /** 2934 | * 错误码 2935 | * -17008 非法的 key 2936 | */ 2937 | errCode: number 2938 | }>): void; 2939 | /** 2940 | * 获取可能对游戏感兴趣的未注册的好友名单。每次调用最多可获得 5 个好友,此接口只能在开放数据域中使用 2941 | */ 2942 | function getPotentialFriendList(callback: types.CallbacksWithType<{ 2943 | /** 2944 | * 可能对游戏感兴趣的未注册好友名单 2945 | */ 2946 | list: ReadonlyArray<{ 2947 | /** 2948 | * 用户的微信头像 url 2949 | */ 2950 | avatarUrl: string, 2951 | /** 2952 | * 用户的微信昵称 2953 | */ 2954 | nickname: string, 2955 | /** 2956 | * 用户 openid 2957 | */ 2958 | openid: string 2959 | }> 2960 | }>): void; 2961 | 2962 | // --登录 2963 | /** 2964 | * 通过 wx.login 接口获得的用户登录态拥有一定的时效性。用户越久未使用小程序,用户登录态越有可能失效。反之如果用户一直在使用小程序,则用户登录态一直保持有效。具体时效逻辑由微信维护,对开发者透明。开发者只需要调用 wx.checkSession 接口检测当前用户登录态是否有效。登录态过期后开发者可以再调用 wx.login 获取新的用户登录态。 2965 | */ 2966 | function checkSession(cb: types.Callbacks): void; 2967 | /** 2968 | * 调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。 2969 | */ 2970 | function login(cb: types.CallbacksWithType<{ 2971 | /** 2972 | * 用户登录凭证(有效期五分钟)。开发者需要在开发者服务器后台调用 code2accessToken,使用 code 换取 openid 和 session_key 等信息 2973 | */ 2974 | code: string 2975 | }>): void; 2976 | 2977 | // --防沉迷 2978 | /** 2979 | * 根据用户当天游戏时间判断用户是否需要休息 2980 | */ 2981 | function checkIsUserAdvisedToRest(param: { 2982 | /** 2983 | * 今天已经玩游戏的时间,单位:秒 2984 | */ 2985 | todayPlayedTime: number, 2986 | success?: ((res: { 2987 | /** 2988 | * 是否建议用户休息 2989 | */ 2990 | result: boolean 2991 | }) => void) | undefined, 2992 | fail?: (() => void) | undefined, 2993 | complete?: (() => void) | undefined 2994 | }): void; 2995 | 2996 | // --小程序跳转 2997 | /** 2998 | * 打开另一个小程序 2999 | * @param param 跳转参数 3000 | */ 3001 | function navigateToMiniProgram(param: { 3002 | /** 3003 | * 要打开的小程序 appId 3004 | */ 3005 | appId: string, 3006 | /** 3007 | * 打开的页面路径,如果为空则打开首页。path 中 ? 后面的部分会成为 query,在小程序的 App.onLaunch、App.onShow 3008 | * 和 Page.onLoad 的回调函数或小游戏的 wx.onShow 回调函数、wx.getLaunchOptionsSync 中可以获取到 query 数据。 3009 | * 对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。 3010 | */ 3011 | path?: string | undefined, 3012 | /** 3013 | * 需要传递给目标小程序的数据,目标小程序可在 App.onLaunch,App.onShow 中获取到这份数据。如果跳转的是小游戏,可以在 wx.onShow、wx.getLaunchOptionsSync 中可以获取到这份数据数据。 3014 | */ 3015 | extraData?: unknown | undefined, 3016 | /** 3017 | * 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。默认值release 3018 | * develop 开发版 3019 | * trial 体验版 3020 | * release 正式版 3021 | */ 3022 | envVersion?: "develop" | "trial" | "release" | undefined 3023 | } & types.Callbacks): void; 3024 | 3025 | // --用户信息 3026 | function createUserInfoButton(param: { 3027 | /** 3028 | * 按钮类型 3029 | */ 3030 | type: types.ButtonType, 3031 | /** 3032 | * 按钮上的文本,仅当 type 为 text 时有效 3033 | */ 3034 | text?: string | undefined, 3035 | /** 3036 | * 按钮的背景图片,仅当 type 为 image 时有效 3037 | */ 3038 | image?: string | undefined, 3039 | /** 3040 | * 按钮的样式 3041 | */ 3042 | style?: types.ButtonStyle | undefined, 3043 | /** 3044 | * 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。 3045 | */ 3046 | withCredentials?: boolean | undefined, 3047 | lang?: "en" | "zh_CN" | "zh_TW" | undefined 3048 | }): UserInfoButton; 3049 | 3050 | // --设置 3051 | /** 3052 | * 创建打开设置页面的按钮 3053 | */ 3054 | function createOpenSettingButton(param: { 3055 | /** 3056 | * 按钮类型 3057 | */ 3058 | type: types.ButtonType, 3059 | /** 3060 | * 按钮上的文本,仅当 type 为 text 时有效 3061 | */ 3062 | text?: string | undefined, 3063 | /** 3064 | * 按钮的背景图片,仅当 type 为 image 时有效 3065 | */ 3066 | image?: string | undefined, 3067 | /** 3068 | * 按钮的样式 3069 | */ 3070 | style?: types.ButtonStyle | undefined 3071 | }): OpenSettingButton; 3072 | /** 3073 | * 获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。 3074 | */ 3075 | function getSetting(p: types.CallbacksWithType<{ authSetting: types.AuthSetting }>): void; 3076 | /** 3077 | * 调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。 3078 | * @deprecated 3079 | */ 3080 | function openSetting(p: types.CallbacksWithType<{ authSetting: types.AuthSetting }>): void; 3081 | 3082 | // --微信运动 3083 | /** 3084 | * 获取用户过去三十天微信运动步数,需要先调用 wx.login 接口。需要用户授权 scope.werun。 3085 | */ 3086 | function getWeRunData(p: types.CallbacksWithType<{ 3087 | /** 3088 | * 包括敏感数据在内的完整用户信息的加密数据,详细见加密数据解密算法 3089 | */ 3090 | encryptedData: string, 3091 | /** 3092 | * 加密算法的初始向量 3093 | */ 3094 | iv: string 3095 | }>): void; 3096 | 3097 | // --卡券 3098 | /** 3099 | * 查看微信卡包中的卡券。只有通过 认证 的小程序或文化互动类目的小游戏才能使用。更多文档请参考:微信卡券接口文档(https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2) 3100 | */ 3101 | function openCard(param: { 3102 | /** 3103 | * 需要打开的卡券列表 3104 | */ 3105 | cardList: ReadonlyArray<{ 3106 | /** 3107 | * 卡券 ID 3108 | */ 3109 | cardId: string, 3110 | /** 3111 | * 由 wx.addCard 的返回对象中的加密 code 通过解密后得到,解密请参照:code 解码接口(https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Coupons-Mini_Program_Start_Up.html) 3112 | */ 3113 | code: string 3114 | }> 3115 | } & types.CallbacksWithType): void; // TODO: success回调里的res的结构官方文档没写 3116 | /** 3117 | * 批量添加卡券。只有通过 认证 的小程序或文化互动类目的小游戏才能使用。更多文档请参考 微信卡券接口文档(https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2)。 3118 | */ 3119 | function addCard(param: { 3120 | /** 3121 | * 需要添加的卡券列表 3122 | */ 3123 | cardList: ReadonlyArray<{ 3124 | /** 3125 | * 卡券 ID 3126 | */ 3127 | cardId: string, 3128 | /** 3129 | * 卡券的扩展参数。需将 CardExt 对象 JSON 序列化为字符串传入 3130 | */ 3131 | cardExt: string 3132 | }> 3133 | } & types.CallbacksWithType<{ 3134 | /** 3135 | * 卡券添加结果列表 3136 | */ 3137 | cardList: ReadonlyArray<{ 3138 | /** 3139 | * 加密 code,为用户领取到卡券的code加密后的字符串,解密请参照:code 解码接口 3140 | */ 3141 | code: string, 3142 | /** 3143 | * 用户领取到卡券的 ID 3144 | */ 3145 | cardId: string, 3146 | /** 3147 | * 卡券的扩展参数,值为一个 JSON 字符串 3148 | */ 3149 | cardExt: string, 3150 | /** 3151 | * 是否成功 3152 | */ 3153 | isSuccess: boolean 3154 | }> 3155 | }>): void; 3156 | 3157 | // --授权 3158 | /** 3159 | * 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。 3160 | */ 3161 | function authorize(param: { 3162 | /** 3163 | * 需要获取权限的 scope 3164 | */ 3165 | scope: string, 3166 | success?: (() => void) | undefined, 3167 | fail?: (() => void) | undefined, 3168 | complete?: (() => void) | undefined 3169 | }): void; 3170 | 3171 | // --游戏圈 3172 | /** 3173 | * 创建游戏圈按钮。游戏圈按钮被点击后会跳转到小游戏的游戏圈。更多关于游戏圈的信息见 游戏圈使用指南 3174 | */ 3175 | function createGameClubButton(param: { 3176 | type: types.ButtonType, 3177 | text?: string | undefined, 3178 | image?: string | undefined, 3179 | style?: types.ButtonStyle | undefined, 3180 | /** 3181 | * 游戏圈按钮的图标,仅当 object.type 参数为 image 时有效 3182 | */ 3183 | icon?: types.GameClubButtonIcon | undefined 3184 | }): GameClubButton; 3185 | 3186 | // --意见反馈 3187 | /** 3188 | * 用户点击后打开意见反馈页面的按钮 3189 | */ 3190 | function createFeedbackButton(param: { 3191 | type: types.ButtonType, 3192 | text?: string | undefined, 3193 | image?: string | undefined, 3194 | style?: types.ButtonStyle | undefined 3195 | }): FeedbackButton; 3196 | 3197 | // --客服消息 3198 | /** 3199 | * 进入客服会话,要求在用户发生过至少一次 touch 事件后才能调用。后台接入方式与小程序一致,详见 客服消息接入 3200 | */ 3201 | function openCustomerServiceConversation(param: { 3202 | /** 3203 | * 会话来源 3204 | */ 3205 | sessionFrom?: string | undefined, 3206 | /** 3207 | * 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话之后会收到一个消息卡片,通过以下三个参数设置卡片的内容 3208 | */ 3209 | showMessageCard?: boolean | undefined, 3210 | /** 3211 | * 会话内消息卡片标题 3212 | */ 3213 | sendMessageTitle?: string | undefined, 3214 | /** 3215 | * 会话内消息卡片路径 3216 | */ 3217 | sendMessagePath?: string | undefined, 3218 | /** 3219 | * 会话内消息卡片图片路径 3220 | */ 3221 | sendMessageImg?: string | undefined, 3222 | success?: (() => void) | undefined, 3223 | fail?: (() => void) | undefined, 3224 | complete?: (() => void) | undefined 3225 | }): void; 3226 | 3227 | // --开放数据域 3228 | /** 3229 | * 获取开放数据域 3230 | */ 3231 | function getOpenDataContext(): OpenDataContext; 3232 | /** 3233 | * 监听主域发送的消息 3234 | */ 3235 | function onMessage(callback: (data: any) => void): void; 3236 | 3237 | // --转发 3238 | /** 3239 | * 获取转发详细信息 3240 | */ 3241 | function getShareInfo(param: { 3242 | shareTicket: string, 3243 | success?: ((res: { 3244 | /** 3245 | * 错误信息 3246 | */ 3247 | errMsg: string, 3248 | /** 3249 | * 包括敏感数据在内的完整转发信息的加密数据 3250 | */ 3251 | encryptedData: string, 3252 | /** 3253 | * 加密算法的初始向量 3254 | */ 3255 | iv: string 3256 | }) => void) | undefined, 3257 | fail?: (() => void) | undefined, 3258 | complete?: (() => void) | undefined 3259 | }): void; 3260 | /** 3261 | * 隐藏转发按钮 3262 | */ 3263 | function hideShareMenu(cb?: types.Callbacks): void; 3264 | /** 3265 | * 监听用户点击右上角菜单的“转发”按钮时触发的事件 3266 | */ 3267 | function onShareAppMessage(cb: () => types.ShareOption): void; 3268 | /** 3269 | * 取消监听用户点击右上角菜单的“转发”按钮时触发的事件 3270 | */ 3271 | function offShareAppMessage(cb: () => types.ShareOption): void; 3272 | /** 3273 | * 显示当前页面的转发按钮 3274 | */ 3275 | function showShareMenu(param?: { 3276 | /** 3277 | * 是否使用带 shareTicket 的转发 3278 | */ 3279 | withShareTicket: boolean, 3280 | success?: (() => void) | undefined, 3281 | fail?: (() => void) | undefined, 3282 | complete?: (() => void) | undefined 3283 | }): void; 3284 | /** 3285 | * 主动拉起转发,进入选择通讯录界面。 3286 | */ 3287 | function shareAppMessage(param: types.ShareOption): void; 3288 | /** 3289 | * 设置 wx.shareMessageToFriend 接口 query 字段的值 3290 | * @param param 设置参数 3291 | * @returns 是否设置成功 3292 | */ 3293 | function setMessageToFriendQuery(param: { 3294 | /** 3295 | * 需要传递的代表场景的数字,需要在 0 - 50 之间 3296 | */ 3297 | shareMessageToFriendScene: number; 3298 | }): boolean; 3299 | /** 3300 | * 给指定的好友分享游戏信息,该接口只可在开放数据域下使用 3301 | * 定向分享不允许直接在开放数据域设置 query 参数 需要设置时请参见游戏域 wx.setMessageToFriendQuery 接口 3302 | * @param param 分享参数 3303 | */ 3304 | function shareMessageToFriend(param: { 3305 | /** 3306 | * 发送对象的 openId 3307 | */ 3308 | openId: string, 3309 | /** 3310 | * 转发标题,不传则默认使用当前小游戏的昵称。 3311 | */ 3312 | title?: string | undefined, 3313 | /** 3314 | * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5:4 3315 | */ 3316 | imageUrl?: string | undefined 3317 | /** 3318 | * 审核通过的图片 ID,详见 使用审核通过的转发图片(https://developers.weixin.qq.com/minigame/dev/guide/open-ability/sh 3319 | * are/share.html#%E4%BD%BF%E7%94%A8%E5%AE%A1%E6%A0%B8%E9%80%9A%E8%BF%87%E7%9A%84%E8%BD%AC%E5%8F%91%E5%9B%BE%E7%89%87) 3320 | */ 3321 | imageUrlId?: string | undefined 3322 | }): void; 3323 | /** 3324 | * 更新转发属性 3325 | */ 3326 | function updateShareMenu(param: { 3327 | /** 3328 | * 是否使用带 shareTicket 的转发详情 3329 | */ 3330 | withShareTicket: boolean, 3331 | success?: (() => void) | undefined, 3332 | fail?: (() => void) | undefined, 3333 | complete?: (() => void) | undefined 3334 | }): void; 3335 | 3336 | // --性能 3337 | /** 3338 | * 获取性能管理器 3339 | */ 3340 | function getPerformance(): WxPerformance; 3341 | /** 3342 | * 加快触发 JavaScriptCore Garbage Collection(垃圾回收),GC 时机是由 JavaScriptCore 来控制的,并不能保证调用后马上触发 GC。 3343 | */ 3344 | function triggerGC(): void; 3345 | /** 3346 | * 监听内存不足告警 3347 | * @param callback.res.level 内存告警等级,只有 Android 才有,对应系统宏定义: 3348 | * 10 TRIM_MEMORY_RUNNING_LOW 3349 | * 15 TRIM_MEMORY_RUNNING_CRITICAL 3350 | */ 3351 | function onMemoryWarning(callback: (res: { level: number }) => void): void; 3352 | 3353 | /** 3354 | * 标记自定义场景 3355 | * @param sceneId 在管理后台配置过的场景ID 3356 | */ 3357 | function markScene(sceneId: number): void; 3358 | 3359 | // --调试 3360 | function setEnableDebug(p: { 3361 | enableDebug: boolean, 3362 | success?: (() => void) | undefined, 3363 | fail?: (() => void) | undefined, 3364 | complete?: (() => void) | undefined 3365 | }): void; 3366 | 3367 | /** 3368 | * 获取日志管理器对象 3369 | * @param param 初始化时的参数 3370 | */ 3371 | function getLogManager(param?: { 3372 | /** 3373 | * 取值为0或1,取值为0时会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志,取值为1则不会。 3374 | * 默认值是 0 3375 | */ 3376 | level?: 0 | 1 | undefined 3377 | }): LogManager; 3378 | 3379 | // --数据上报 3380 | /** 3381 | * 自定义业务数据监控上报接口。 3382 | * 使用前,需要在「小程序管理后台-运维中心-性能监控-业务数据监控」中新建监控事件,配置监控描述与告警类型。每一个监控事件对应唯一的监控ID,开发者最多可以创建128个监控事件。 3383 | * @param name 监控ID,在「小程序管理后台」新建数据指标后获得 3384 | * @param value 上报数值,经处理后会在「小程序管理后台」上展示每分钟的上报总量 3385 | */ 3386 | function reportMonitor(name: string, value: number): void; 3387 | 3388 | // --订阅消息 3389 | /** 3390 | * 调起小游戏订阅消息界面,返回用户订阅消息的操作结果。(需要在 touchend 事件的回调中调用) 3391 | */ 3392 | function requestSubscribeMessage(param: { 3393 | /** 3394 | * 需要订阅的消息模板的id的集合(注意:iOS客户端7.0.6版本、Android客户端7.0.7版本之后的一次订阅才支持多个模板消息,iOS客户端7.0.5版本、Android客户端7.0.6版本之前的一次订阅 3395 | * 只支持一个模板消息)消息模板id在[微信公众平台(mp.weixin.qq.com)-功能-订阅消息]中配置 3396 | */ 3397 | tmplIds: ReadonlyArray; 3398 | } & types.CallbacksWithType2<{ 3399 | /** 3400 | * 接口调用成功时errMsg值为'requestSubscribeMessage:ok' 3401 | */ 3402 | errMsg: string; 3403 | /** 3404 | * [TEMPLATE_ID]是动态的键,即模板id,值包括'accept'、'reject'、'ban'。'accept'表示用户同意订阅该条id对应的模板消息,'reject'表示用户拒绝订阅该条id对应的模板消息,'ban'表示 3405 | * 已被后台封禁。例如 { errMsg: "requestSubscribeMessage:ok", zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept"} 表示用户同意订阅zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE这条消息 3406 | */ 3407 | [TEMPLATE_ID: string]: 'accept' | 'reject' | 'ban' | string; 3408 | }, { 3409 | /** 3410 | * 接口调用失败错误信息 3411 | */ 3412 | errMsg: string; 3413 | /** 3414 | * 接口调用失败错误码 3415 | */ 3416 | errCode: number; 3417 | }>): void; 3418 | 3419 | // --数据缓存 3420 | /** 3421 | * 清理本地数据缓存 3422 | */ 3423 | function clearStorage(param: types.Callbacks): void; 3424 | /** 3425 | * clearStorage的同步版本 3426 | */ 3427 | function clearStorageSync(): void; 3428 | /** 3429 | * 从本地缓存中异步获取指定 key 的内容 3430 | */ 3431 | function getStorage(param: types.GetStorageParams): void; 3432 | /** 3433 | * getStorage 的同步版本 3434 | */ 3435 | function getStorageSync(key: string): any; 3436 | /** 3437 | * 异步获取当前storage的相关信息 3438 | */ 3439 | function getStorageInfo(param: types.CallbacksWithType): void; 3440 | /** 3441 | * getStorageInfo 的同步版本 3442 | */ 3443 | function getStorageInfoSync(): types.StorageInfo; 3444 | /** 3445 | * 从本地缓存中移除指定 key 3446 | */ 3447 | function removeStorage(param: types.RemoveStorageParams): void; 3448 | /** 3449 | * removeStorage 的同步版本 3450 | * @param key 本地缓存中指定的 key 3451 | */ 3452 | function removeStorageSync(key: string): void; 3453 | /** 3454 | * 将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容。 3455 | */ 3456 | function setStorage(param: types.SetStorageParams): void; 3457 | /** 3458 | * setStorage 的同步版本 3459 | * @param key 本地缓存中指定的 key 3460 | * @param data 需要存储的内容 3461 | */ 3462 | function setStorageSync(key: string, data: any): void; 3463 | 3464 | // --分包加载 3465 | /** 3466 | * 触发分包加载,详见 分包加载 3467 | */ 3468 | function loadSubpackage(param: { 3469 | /** 3470 | * 分包的名字,可以填 name 或者 root 3471 | */ 3472 | name: string, 3473 | success?: (() => void) | undefined, 3474 | fail?: (() => void) | undefined, 3475 | complete?: (() => void) | undefined 3476 | }): LoadSubpackageTask; 3477 | 3478 | // --菜单 3479 | /** 3480 | * 获取菜单按钮的布局置信息 3481 | */ 3482 | function getMenuButtonBoundingClientRect(): { 3483 | /** 3484 | * 宽度 3485 | */ 3486 | width: number, 3487 | /** 3488 | * 高度 3489 | */ 3490 | height: number, 3491 | /** 3492 | * 上边界坐标 3493 | */ 3494 | top: number, 3495 | /** 3496 | * 右边界坐标 3497 | */ 3498 | right: number, 3499 | /** 3500 | * 下边界坐标 3501 | */ 3502 | bottom: number, 3503 | /** 3504 | * 左边界坐标 3505 | */ 3506 | left: number 3507 | }; 3508 | function setMenuStyle(param: { 3509 | /** 3510 | * 样式风格 3511 | */ 3512 | style: "light" | "dark", 3513 | success?: (() => void) | undefined, 3514 | fail?: (() => void) | undefined, 3515 | complete?: (() => void) | undefined 3516 | }): void; 3517 | 3518 | // --交互 3519 | /** 3520 | * 显示消息提示框 3521 | */ 3522 | function showToast(param: { 3523 | /** 3524 | * 提示的内容 3525 | */ 3526 | title?: string | undefined, 3527 | /** 3528 | * 图标 3529 | */ 3530 | icon?: "success" | "loading" | undefined, 3531 | /** 3532 | * 自定义图标的本地路径,image 的优先级高于 icon 3533 | */ 3534 | image?: string | undefined, 3535 | /** 3536 | * 提示的延迟时间 3537 | */ 3538 | duration?: number | undefined, 3539 | success?: (() => void) | undefined, 3540 | fail?: (() => void) | undefined, 3541 | complete?: (() => void) | undefined 3542 | }): void; 3543 | /** 3544 | * 隐藏消息提示框 3545 | */ 3546 | function hideToast(cb?: types.Callbacks): void; 3547 | /** 3548 | * 显示模态对话框 3549 | */ 3550 | function showModal(param: { 3551 | /** 3552 | * 提示的标题 3553 | */ 3554 | title?: string | undefined, 3555 | /** 3556 | * 提示的内容 3557 | */ 3558 | content?: string | undefined, 3559 | /** 3560 | * 是否显示取消按钮,默认true 3561 | */ 3562 | showCancel?: boolean | undefined, 3563 | /** 3564 | * 取消按钮的文字,最多 4 个字符串 3565 | */ 3566 | cancelText?: string | undefined, 3567 | /** 3568 | * 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值#000000 3569 | */ 3570 | cancelColor?: string | undefined, 3571 | /** 3572 | * 确认按钮的文字,最多 4 个字符串 3573 | */ 3574 | confirmText?: string | undefined, 3575 | /** 3576 | * 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值#3cc51f 3577 | */ 3578 | confirmColor?: string | undefined, 3579 | success?: ((res: { confirm?: boolean | undefined, cancel?: boolean | undefined }) => void) | undefined, 3580 | fail?: (() => void) | undefined, 3581 | complete?: (() => void) | undefined 3582 | }): void; 3583 | /** 3584 | * 显示 loading 提示框, 需主动调用 wx.hideLoading 才能关闭提示框 3585 | */ 3586 | function showLoading(prms?: { 3587 | /** 3588 | * 提示的内容 3589 | */ 3590 | title?: string | undefined, 3591 | /** 3592 | * 是否显示透明蒙层 3593 | */ 3594 | mask?: boolean | undefined, 3595 | success?: (() => void) | undefined, 3596 | fail?: (() => void) | undefined, 3597 | complete?: (() => void) | undefined 3598 | }): void; 3599 | /** 3600 | * 隐藏 loading 提示框 3601 | */ 3602 | function hideLoading(cb?: types.Callbacks): void; 3603 | /** 3604 | * 显示选择器 3605 | */ 3606 | function showActionSheet(params: { 3607 | /** 3608 | * 按钮的文字数组,数组长度最大为 6 3609 | */ 3610 | itemList: string[], 3611 | /** 3612 | * 按钮的文字颜色,默认值#000000 3613 | */ 3614 | itemColor?: string | undefined, 3615 | success?: (() => void) | undefined, 3616 | fail?: (() => void) | undefined, 3617 | complete?: (() => void) | undefined 3618 | }): void; 3619 | 3620 | // --键盘 3621 | function hideKeyboard(): void; 3622 | /** 3623 | * 监听键盘输入事件 3624 | * @param callback.res.value 键盘输入的当前值 3625 | */ 3626 | function onKeyboardInput(callback: (res: { value: string }) => void): void; 3627 | /** 3628 | * 取消监听键盘输入事件 3629 | */ 3630 | function offKeyboardInput(callback: (res: { value: string }) => void): void; 3631 | /** 3632 | * 监听用户点击键盘 Confirm 按钮时的事件 3633 | * @param callback.res.value 键盘输入的当前值 3634 | */ 3635 | function onKeyboardConfirm(callback: (res: { value: string }) => void): void; 3636 | /** 3637 | * 取消监听用户点击键盘 Confirm 按钮时的事件 3638 | */ 3639 | function offKeyboardConfirm(callback: (res: { value: string }) => void): void; 3640 | /** 3641 | * 监听监听键盘收起的事件 3642 | * @param callback.res.value 键盘输入的当前值 3643 | */ 3644 | function onKeyboardComplete(callback: (res: { value: string }) => void): void; 3645 | /** 3646 | * 取消监听监听键盘收起的事件 3647 | */ 3648 | function offKeyboardComplete(callback: (res: { value: string }) => void): void; 3649 | /** 3650 | * 显示键盘 3651 | */ 3652 | function showKeyboard(param: { 3653 | /** 3654 | * 键盘输入框显示的默认值 3655 | */ 3656 | defaultValue: string, 3657 | /** 3658 | * 键盘中文本的最大长度 3659 | */ 3660 | maxLength?: number | undefined, 3661 | /** 3662 | * 是否为多行输入 3663 | */ 3664 | multiple?: boolean | undefined, 3665 | /** 3666 | * 当点击完成时键盘是否收起 3667 | */ 3668 | confirmHold?: boolean | undefined, 3669 | /** 3670 | * 键盘右下角 confirm 按钮的类型,只影响按钮的文本内容 3671 | */ 3672 | confirmType?: "done" | "next" | "search" | "go" | "send" | undefined 3673 | }): void; 3674 | /** 3675 | * 更新键盘,只有当键盘处于拉起状态时才会产生效果 3676 | */ 3677 | function updateKeyboard(param: { 3678 | /** 3679 | * 键盘输入框的当前值 3680 | */ 3681 | value: string, 3682 | success?: (() => void) | undefined, 3683 | fail?: (() => void) | undefined, 3684 | complete?: (() => void) | undefined 3685 | }): void; 3686 | 3687 | // --状态栏 3688 | /** 3689 | * 当在配置中设置 showStatusBarStyle 时,屏幕顶部会显示状态栏。此接口可以修改状态栏的样式。 3690 | */ 3691 | function setStatusBarStyle(param: { 3692 | style: "white" | "black", 3693 | success?: (() => void) | undefined, 3694 | fail?: (() => void) | undefined, 3695 | complete?: (() => void) | undefined 3696 | }): void; 3697 | 3698 | // --窗口 3699 | /** 3700 | * 监听窗口尺寸变化事件 3701 | */ 3702 | function onWindowResize(cb: (res: { windowWidth: number, windowHeight: number }) => void): void; 3703 | /** 3704 | * 取消监听窗口尺寸变化事件 3705 | */ 3706 | function offWindowResize(cb: (res: { windowWidth: number, windowHeight: number }) => void): void; 3707 | 3708 | // --更新 3709 | function getUpdateManager(): UpdateManager; 3710 | 3711 | // --Worker 3712 | /** 3713 | * 创建一个 Worker 线程,目前限制最多只能创建一个 Worker,创建下一个 Worker 前请调用 Worker.terminate 3714 | */ 3715 | function createWorker(scriptPath: string, options?: { 3716 | /** 3717 | * 是否使用实验worker。在iOS下,实验worker的JS运行效率比非实验worker提升近十倍,如需在worker内进行重度计算的建议开启 3718 | * 此选项。同时,实验worker存在极小概率会在系统资源紧张时被系统回收,因此建议配合 worker.onProcessKilled 事件使用, 3719 | * 在worker被回收后可重新创建一个。 3720 | */ 3721 | useExperimentalWorker?: boolean | undefined 3722 | }): WxWorker; 3723 | 3724 | // --音频 3725 | /** 3726 | * 创建一个 InnerAudioContext 实例 3727 | */ 3728 | function createInnerAudioContext(): InnerAudioContext; 3729 | /** 3730 | * 获取当前支持的音频输入源 3731 | */ 3732 | function getAvailableAudioSources(param: types.CallbacksWithType<{ 3733 | /** 3734 | * 音频输入源,每一项对应一种音频输入源 3735 | */ 3736 | audioSources: ReadonlyArray 3737 | }>): void; 3738 | 3739 | // --录音 3740 | function getRecorderManager(): RecorderManager; 3741 | 3742 | // --图片 3743 | /** 3744 | * 从本地相册选择图片或使用相机拍照。 3745 | */ 3746 | function chooseImage(param: { 3747 | count: number, 3748 | /** 3749 | * 所选的图片的尺寸 3750 | */ 3751 | sizeType: ['original'] | ['compressed'] | ['original', 'compressed'], 3752 | /** 3753 | * 选择图片的来源 3754 | */ 3755 | sourceType: ['album'] | ['camera'] | ['album', 'camera'], 3756 | success?: ((res: { tempFilePaths: ReadonlyArray, tempFiles: ReadonlyArray }) => void) | undefined, 3757 | fail?: (() => void) | undefined, 3758 | complete?: (() => void) | undefined 3759 | }): void; 3760 | /** 3761 | * 预览图片,调用之后会在新打开的页面中全屏预览传入的图片,预览的过程中用户可以进行保存图片、发送给朋友等操作 3762 | */ 3763 | function previewImage(param: { 3764 | /** 3765 | * 需要预览的图片链接列表 3766 | */ 3767 | urls: string[], 3768 | /** 3769 | * 当前显示图片的链接,默认为urls的第一张 3770 | */ 3771 | current?: string | undefined, 3772 | success?: (() => void) | undefined, 3773 | fail?: (() => void) | undefined, 3774 | complete?: (() => void) | undefined 3775 | }): void; 3776 | /** 3777 | * 保存图片到系统相册。需要用户授权 scope.writePhotosAlbum 3778 | */ 3779 | function saveImageToPhotosAlbum(param: { 3780 | /** 3781 | * 图片文件路径,可以是临时文件路径也可以是永久文件路径,不支持网络图片路径 3782 | */ 3783 | filePath: string, 3784 | success?: (() => void) | undefined, 3785 | fail?: (() => void) | undefined, 3786 | complete?: (() => void) | undefined 3787 | }): void; 3788 | 3789 | // --视频 3790 | function createVideo(param: { 3791 | /** 3792 | * 视频的左上角横坐标 3793 | */ 3794 | x?: number | undefined, 3795 | /** 3796 | * 视频的左上角纵坐标 3797 | */ 3798 | y?: number | undefined, 3799 | /** 3800 | * 视频的宽度,默认值300 3801 | */ 3802 | width?: number | undefined, 3803 | /** 3804 | * 默认值150 3805 | */ 3806 | height?: number | undefined, 3807 | /** 3808 | * 视频的资源地址 3809 | */ 3810 | src: string, 3811 | /** 3812 | * 视频的封面 3813 | */ 3814 | poster?: string | undefined, 3815 | /** 3816 | * 视频的初始播放位置,单位为 s 秒,默认值0 3817 | */ 3818 | initialTime?: number | undefined, 3819 | /** 3820 | * 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0 3821 | */ 3822 | playbackRate?: number | undefined, 3823 | /** 3824 | * 视频是否为直播,默认值0 3825 | */ 3826 | live?: number | undefined, 3827 | /** 3828 | * 视频的缩放模式 3829 | * fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例 3830 | * contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白 3831 | * cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见 3832 | */ 3833 | objectFit?: "contain" | "cover" | "fill" | undefined, 3834 | /** 3835 | * 视频是否显示控件,默认true 3836 | */ 3837 | controls?: boolean | undefined, 3838 | /** 3839 | * 视频是否自动播放,默认false 3840 | */ 3841 | autoplay?: boolean | undefined, 3842 | /** 3843 | * 视频是否是否循环播放,默认值false 3844 | */ 3845 | loop?: boolean | undefined, 3846 | /** 3847 | * 视频是否禁音播放,默认值false 3848 | */ 3849 | muted?: boolean | undefined 3850 | }): Video; 3851 | 3852 | // --相机 3853 | /** 3854 | * 创建相机 3855 | * @param param 创建相机所需的初始化信息 3856 | */ 3857 | function createCamera(param?: types.Callbacks & { 3858 | /** 3859 | * 相机的左上角横坐标,默认值0 3860 | */ 3861 | x?: number | undefined; 3862 | /** 3863 | * 相机的左上角纵坐标,默认值0 3864 | */ 3865 | y?: number | undefined; 3866 | /** 3867 | * 相机的宽度,默认值300 3868 | */ 3869 | width?: number | undefined; 3870 | /** 3871 | * 相机的高度,默认值150 3872 | */ 3873 | height?: number | undefined; 3874 | /** 3875 | * 摄像头朝向,值为 front, back,默认值back 3876 | */ 3877 | devicePosition?: "front" | "back" | undefined; 3878 | /** 3879 | * 闪光灯,值为 auto, on, off,默认值auto 3880 | */ 3881 | flash?: "auto" | "on" | "off" | undefined; 3882 | /** 3883 | * 帧数据图像尺寸,值为 small, medium, large,默认值small 3884 | */ 3885 | size?: "small" | "medium" | "large" | undefined; 3886 | }): Camera; 3887 | 3888 | // -- VoIP 3889 | /** 3890 | * 更新实时语音静音设置 3891 | * @param param 静音设置 3892 | */ 3893 | function updateVoIPChatMuteConfig(param: types.Callbacks & { 3894 | /** 3895 | * 静音设置 3896 | */ 3897 | muteConfig: { 3898 | /** 3899 | * 是否静音麦克风,默认值false 3900 | */ 3901 | muteMicrophone?: boolean | undefined, 3902 | /** 3903 | * 是否静音耳机,默认值false 3904 | */ 3905 | muteEarphone?: boolean | undefined 3906 | } 3907 | }): void; 3908 | /** 3909 | * 监听实时语音通话成员通话状态变化事件。有成员开始/停止说话时触发回调 3910 | * @param callback 实时语音通话成员通话状态变化事件的回调函数 3911 | */ 3912 | function onVoIPChatSpeakersChanged(callback: (res: { 3913 | /** 3914 | * 还在实时语音通话中的成员 openId 名单 3915 | */ 3916 | openIdList: ReadonlyArray, 3917 | /** 3918 | * 错误码 3919 | */ 3920 | errCode: number, 3921 | /** 3922 | * 调用结果(错误原因) 3923 | */ 3924 | errMsg: string 3925 | }) => void): void; 3926 | /** 3927 | * 取消监听实时语音通话成员通话状态变化事件。 3928 | * @param callback 之前监听的回调函数 3929 | */ 3930 | function offVoIPChatSpeakersChanged(callback: unknown): void; 3931 | /** 3932 | * 监听实时语音通话成员在线状态变化事件。有成员加入/退出通话时触发回调 3933 | * @param callback 实时语音通话成员在线状态变化事件的回调函数 3934 | */ 3935 | function onVoIPChatMembersChanged(callback: (res: { 3936 | /** 3937 | * 还在实时语音通话中的成员 openId 名单 3938 | */ 3939 | openIdList: ReadonlyArray, 3940 | /** 3941 | * 错误码 3942 | */ 3943 | errCode: number, 3944 | /** 3945 | * 调用结果(错误原因) 3946 | */ 3947 | errMsg: string 3948 | }) => void): void; 3949 | /** 3950 | * 取消监听实时语音通话成员在线状态变化事件。 3951 | * @param callback 之前监听的回调函数 3952 | */ 3953 | function offVoIPChatMembersChanged(callback: unknown): void; 3954 | /** 3955 | * 监听被动断开实时语音通话事件。包括小游戏切入后端时断开 3956 | * @param callback 被动断开实时语音通话事件的回调函数 3957 | */ 3958 | function onVoIPChatInterrupted(callback: (res: { 3959 | /** 3960 | * 错误码 3961 | */ 3962 | errCode: number, 3963 | /** 3964 | * 调用结果(错误原因) 3965 | */ 3966 | errMsg: string 3967 | }) => void): void; 3968 | /** 3969 | * 取消监听被动断开实时语音通话事件。 3970 | * @param callback 之前监听的回调函数 3971 | */ 3972 | function offVoIPChatInterrupted(callback: unknown): void; 3973 | /** 3974 | * 加入 (创建) 实时语音通话,更多信息可见:实时语音指南(https://developers.weixin.qq.com/minigame/dev/guide/open-ability/voip-chat.html) 3975 | * 错误码 3976 | * -1 当前已在房间内 3977 | * -2 录音设备被占用,可能是当前正在使用微信内语音通话或系统通话 3978 | * -3 加入会话期间退出(可能是用户主动退出,或者退后台、来电等原因),因此加入失败 3979 | * -1000 系统错误 3980 | * @param param 加入语音聊天时的初始化参数 3981 | */ 3982 | function joinVoIPChat(param: types.CallbacksWithType<{ 3983 | /** 3984 | * 在此通话中的成员 openId 名单 3985 | */ 3986 | openIdList: ReadonlyArray, 3987 | /** 3988 | * 错误码 3989 | */ 3990 | errCode: number, 3991 | /** 3992 | * 调用结果 3993 | */ 3994 | errMsg: string 3995 | }> & { 3996 | /** 3997 | * 签名,用于验证小游戏的身份 3998 | */ 3999 | signature: string, 4000 | /** 4001 | * 验证所需的随机字符串 4002 | */ 4003 | nonceStr: string, 4004 | /** 4005 | * 验证所需的时间戳 4006 | */ 4007 | timeStamp: number, 4008 | /** 4009 | * 小游戏内此房间/群聊的 ID。同一时刻传入相同 groupId 的用户会进入到同个实时语音房间。 4010 | */ 4011 | groupId: string, 4012 | /** 4013 | * 静音设置 4014 | */ 4015 | muteConfig?: { 4016 | /** 4017 | * 是否静音麦克风,默认值false 4018 | */ 4019 | muteMicrophone?: boolean | undefined, 4020 | /** 4021 | * 是否静音耳机,默认值false 4022 | */ 4023 | muteEarphone?: boolean | undefined 4024 | } | undefined 4025 | }): void; 4026 | /** 4027 | * 退出(销毁)实时语音通话 4028 | */ 4029 | function exitVoIPChat(callbacks?: types.Callbacks): void; 4030 | 4031 | // --广告 4032 | /** 4033 | * 创建 banner 广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.0.4 后再使用该 API。每次调用该方法创建 banner 广告都会返回一个全新的实例。 4034 | * 基础库 2.0.4 开始支持,低版本需做兼容处理。 4035 | */ 4036 | function createBannerAd(param: types.BannerAdParams): BannerAd; 4037 | /** 4038 | * 创建激励视频广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号后再使用该 API(小游戏端要求 >= 2.0.4, 小程序端要求 >= 2.6.0)。调用该方法创建的激励视频广告是一个单例(小游戏端是全局单例,小程序端是页面内单例,在小程序端的单例对象不允许跨页面使用)。 4039 | * 基础库 2.0.4 开始支持,低版本需做兼容处理。 4040 | */ 4041 | function createRewardedVideoAd(param: types.VideoAdParams): RewardedVideoAd; 4042 | /** 4043 | * 插屏广告组件。插屏广告组件是一个原生组件,层级比普通组件高。插屏广告组件每次创建都会返回一个全新的实例(小程序端的插屏广告实例不允许跨页面使用),默认是隐藏的,需要调用 InterstitialAd.show() 将其显示。 4044 | */ 4045 | function createInterstitialAd(param: types.InterstitialAdParam): InterstitialAd; 4046 | /** 4047 | * 创建 grid(格子) 广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.9.2 后再使用该 API。每次调用该方法创建 grid(格子) 广告都会返回一个全新的实例。 4048 | * 基础库 2.9.2 开始支持,低版本需做兼容处理 4049 | */ 4050 | function createGridAd(param: types.GridAdParam): GridAd; 4051 | /** 4052 | * 创建原生模板广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.11.1 后再使用该 API。每次调用该方法创建原生模板广告都会返回一个全新的实例。 4053 | */ 4054 | function createCustomAd(param: types.CustomAdParam): CustomAd; 4055 | 4056 | // --虚拟支付 4057 | /** 4058 | * 发起米大师支付 4059 | */ 4060 | function requestMidasPayment(param: { 4061 | /** 4062 | * 支付的类型,不同的支付类型有各自额外要传的附加参数。 4063 | * game - 购买游戏币 4064 | */ 4065 | mode: "game", 4066 | /** 4067 | * 环境配置,默认值0 4068 | * 0 - 米大师正式环境 4069 | * 1 - 米大师沙箱环境 4070 | */ 4071 | env?: 0 | 1 | undefined, 4072 | /** 4073 | * 在米大师侧申请的应用 id 4074 | */ 4075 | offerId: string, 4076 | /** 4077 | * 币种 4078 | */ 4079 | currencyType: "CNY", 4080 | /** 4081 | * 申请接入时的平台,platform 与应用id有关。 4082 | */ 4083 | platform?: "android" | undefined, 4084 | /** 4085 | * 购买数量。mode=game 时必填。购买数量。详见 buyQuantity 限制说明。 4086 | * mode为game(购买游戏币)时,buyQuantity不可任意填写。需满足 buyQuantity * 游戏币单价 = 限定的价格等级。如:游戏币单价为 0.1 元,一次购买最少数量是 10。 4087 | * 有效价格等级如下: 4088 | * 价格等级(单位:人民币) 4089 | * 1 4090 | * 3 4091 | * 6 4092 | * 8 4093 | * 12 4094 | * 18 4095 | * 25 4096 | * 30 4097 | * 40 4098 | * 45 4099 | * 50 4100 | * 60 4101 | * 68 4102 | * 73 4103 | * 78 4104 | * 88 4105 | * 98 4106 | * 108 4107 | * 118 4108 | * 128 4109 | * 148 4110 | * 168 4111 | * 188 4112 | * 198 4113 | * 328 4114 | * 648 4115 | */ 4116 | buyQuantity?: number | undefined, 4117 | /** 4118 | * 分区 ID 4119 | */ 4120 | zoneId?: string | undefined, 4121 | success?: (() => void) | undefined, 4122 | /** 4123 | * @param res.errCode 有如下值: 4124 | * -1 系统失败 4125 | * -2 支付取消 4126 | * -15001 虚拟支付接口错误码,缺少参数 4127 | * -15002 虚拟支付接口错误码,参数不合法 4128 | * -15003 虚拟支付接口错误码,订单重复 4129 | * -15004 虚拟支付接口错误码,后台错误 4130 | * -15006 虚拟支付接口错误码,appId 权限被封禁 4131 | * -15006 虚拟支付接口错误码,货币类型不支持 4132 | * -15007 虚拟支付接口错误码,订单已支付 4133 | * 1 虚拟支付接口错误码,用户取消支付 4134 | * 2 虚拟支付接口错误码,客户端错误, 判断到小程序在用户处于支付中时,又发起了一笔支付请求 4135 | * 3 虚拟支付接口错误码,Android 独有错误:用户使用 Google Play 支付,而手机未安装 Google Play 4136 | * 4 虚拟支付接口错误码,用户操作系统支付状态异常 4137 | * 5 虚拟支付接口错误码,操作系统错误 4138 | * 6 虚拟支付接口错误码,其他错误 4139 | * 1000 参数错误 4140 | * 1003 米大师 Portal 错误 4141 | */ 4142 | fail?: ((res: { errMsg: string, errCode: number }) => void) | undefined, 4143 | complete?: (() => void) | undefined 4144 | }): void; 4145 | } 4146 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wegame-api", 3 | "version": "1.1", 4 | "homepage": "https://github.com/jcyuan/wegame-api", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/jcyuan/wegame-api.git" 8 | }, 9 | "license": "MIT", 10 | "bugs": { 11 | "url": "https://github.com/jcyuan/wegame-api/issues" 12 | }, 13 | "engines": { 14 | "node": ">=7.8.0" 15 | }, 16 | "devDependencies": { 17 | "tslint": "^5.9.1", 18 | "dtslint": "github:Microsoft/dtslint#production", 19 | "typescript": "^2.9.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": [ 5 | "es6", 6 | "dom" 7 | ], 8 | "noImplicitAny": true, 9 | "noImplicitThis": true, 10 | "strictNullChecks": true, 11 | "strictFunctionTypes": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noEmit": true 14 | }, 15 | "files": [ 16 | "index.d.ts", 17 | "wegame-api-tests.ts", 18 | "datacontext/index.ts" 19 | ] 20 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dt.json" 3 | } 4 | -------------------------------------------------------------------------------- /wegame-api-tests.ts: -------------------------------------------------------------------------------- 1 | // 画布 2 | let canvas = wx.createCanvas(); 3 | console.assert(canvas != null); 4 | // 图片 5 | let images = wx.createImage(); 6 | console.assert(images != null); 7 | // 字体 8 | let texts = wx.getTextLineHeight({ 9 | text: "", 10 | fontFamily: 'Arial', 11 | fontSize: 28, 12 | fontWeight: 'bold', 13 | fontStyle: 'normal', 14 | success: res => { 15 | console.assert(res.lineHeight === 0); 16 | } 17 | }); 18 | let textload = wx.loadFont('Arial'); 19 | console.assert(textload != null); // 当前版本不支持此加载自定义字体 20 | // 帧率 21 | wx.setPreferredFramesPerSecond(30); 22 | // 系统信息 23 | wx.getBatteryInfo({ 24 | success: info => { 25 | console.info(info.isCharging); 26 | console.info(info.level); 27 | } 28 | }); 29 | 30 | let sysinfo = wx.getSystemInfoSync(); 31 | console.dir(sysinfo); 32 | console.assert(sysinfo.brand != null); 33 | console.assert(sysinfo.model != null); 34 | console.assert(sysinfo.pixelRatio != null); 35 | console.assert(sysinfo.screenWidth != null); 36 | console.assert(sysinfo.screenHeight != null); 37 | console.assert(sysinfo.windowWidth != null); 38 | console.assert(sysinfo.windowHeight != null); 39 | console.assert(sysinfo.language != null); 40 | console.assert(sysinfo.system != null); 41 | console.assert(sysinfo.platform != null); 42 | console.assert(sysinfo.fontSizeSetting != null); 43 | console.assert(sysinfo.SDKVersion != null); 44 | console.assert(sysinfo.benchmarkLevel != null); 45 | console.assert(sysinfo.battery != null); // 手机电量 报错 46 | console.assert(sysinfo.wifiSignal != null); // 手机WIFI信号强度 报错 47 | 48 | // 系统事件 49 | const audioEnd = () => { 50 | console.log("audio interrupted end"); 51 | }; 52 | wx.onAudioInterruptionEnd(audioEnd); 53 | wx.offAudioInterruptionEnd(audioEnd); 54 | const audioBegin = () => { 55 | console.log("audio interrupted begin"); 56 | }; 57 | wx.onAudioInterruptionBegin(audioBegin); 58 | wx.offAudioInterruptionBegin(audioBegin); 59 | 60 | const onWXError = (res: { message: string, stack: string }) => { console.error(`sys error: ${res.message}....${res.stack}`); }; 61 | wx.onError(onWXError); 62 | wx.offError(onWXError); 63 | 64 | // 触摸事件 65 | wx.onTouchStart(d => { console.assert(d != null); }); 66 | wx.onTouchMove(d => { console.assert(d != null); }); 67 | wx.onTouchEnd(d => { console.assert(d != null); }); 68 | wx.onTouchCancel(d => { console.assert(d != null); }); 69 | // 加速计 70 | wx.onAccelerometerChange(res => { 71 | console.assert(res.x != null); 72 | console.assert(res.y != null); 73 | console.assert(res.z != null); 74 | }); 75 | wx.startAccelerometer({ 76 | interval: "game", 77 | success: () => { 78 | console.log("wx.startAccelerometer success"); 79 | } 80 | }); 81 | wx.stopAccelerometer({ 82 | success: () => { 83 | console.log("wx.stopAccelerometer success"); 84 | } 85 | }); 86 | // 电量 87 | let getBat = wx.getBatteryInfoSync(); 88 | console.dir(getBat); 89 | console.info(getBat.isCharging); 90 | console.info(getBat.level); 91 | // 剪切板 92 | wx.getClipboardData({ 93 | success: () => { 94 | console.log("wx.getClipboardData success"); 95 | } 96 | }); 97 | wx.setClipboardData({ 98 | data: "test", 99 | success: () => { 100 | console.log("wx.setClipboardData success"); 101 | } 102 | }); 103 | // 罗盘 104 | wx.onCompassChange(res => { 105 | console.assert(res.direction != null); 106 | }); 107 | wx.startCompass({ 108 | success: () => { 109 | console.log("wx.startCompass success"); 110 | } 111 | }); 112 | wx.stopCompass({ 113 | success: () => { 114 | console.log("wx.stopCompass success"); 115 | } 116 | }); 117 | // 网络 118 | wx.getNetworkType({ 119 | success: () => { 120 | console.log("wx.getNetworkType success"); 121 | } 122 | }); 123 | wx.onNetworkStatusChange(res => { 124 | console.assert(res.isConnected != null); 125 | }); 126 | // 屏幕 127 | wx.getScreenBrightness({ 128 | success: () => { 129 | console.log("wx.getScreenBrightness success"); 130 | } 131 | }); 132 | wx.setKeepScreenOn({ 133 | keepScreenOn: true, 134 | success: () => { 135 | console.log("wx.setKeepScreenOn success"); 136 | } 137 | }); 138 | wx.setScreenBrightness({ 139 | value: 1, 140 | success: () => { 141 | console.log("wx.setScreenBrightness success"); 142 | } 143 | }); 144 | // 震动 145 | wx.vibrateShort({ 146 | success: () => { 147 | console.log("wx.vibrateShort success"); 148 | } 149 | }); 150 | wx.vibrateLong({ 151 | success: () => { 152 | console.log("wx.vibrateLong success"); 153 | } 154 | }); 155 | // 转屏 156 | wx.onDeviceOrientationChange(res => { 157 | console.assert(res.value != null); 158 | }); 159 | // 文件 160 | let getFile = wx.getFileSystemManager(); 161 | console.assert(getFile != null); 162 | // 位置 163 | wx.getLocation({ 164 | success: res => { 165 | res.altitude != null; 166 | console.log("wx.getLocation success"); 167 | } 168 | }); 169 | // 下载 170 | let downLoad = wx.downloadFile({ 171 | url: "", 172 | header: {}, 173 | filePath: "", 174 | success: () => { 175 | console.log("wx.downloadFile success"); 176 | }, 177 | fail: () => { 178 | console.log("wx.downloadFile fail"); 179 | }, 180 | complete: () => { 181 | console.log("wx.downloadFile comp"); 182 | } 183 | }); 184 | console.assert(downLoad != null); 185 | downLoad.abort(); 186 | // 发起请求 187 | let requ = wx.request({ 188 | url: 'https://www.baidu.com/', 189 | success: () => { 190 | console.log("wx.request success"); 191 | } 192 | }); 193 | console.assert(requ != null); 194 | requ.abort(); 195 | // WebSocket 196 | let conne = wx.connectSocket({ 197 | url: 'wss://www.baidu.com/', 198 | header: {}, 199 | protocols: [], 200 | success: () => { 201 | console.log("wx.connectSocket success"); 202 | } 203 | }); 204 | console.assert(conne != null); 205 | wx.closeSocket({ 206 | reason: 'normal close', 207 | success: () => { 208 | console.log("wx.closeSocket success"); 209 | } 210 | }); 211 | wx.onSocketOpen(res => { 212 | console.assert(res.header != null); 213 | }); 214 | wx.onSocketClose; 215 | wx.sendSocketMessage({ 216 | data: "testdata", 217 | success: () => { 218 | console.log("wx.sendSocketMessage success"); 219 | } 220 | }); 221 | // 上传 222 | let upLoad = wx.uploadFile({ 223 | url: "https://www.baidu.com/", 224 | filePath: "./", 225 | name: "111", 226 | success: () => { 227 | console.log("wx.uploadFile success"); 228 | }, 229 | fail: () => { 230 | console.log("wx.uploadFile fail"); 231 | } 232 | }); 233 | console.assert(upLoad != null); 234 | upLoad.onProgressUpdate(res => { 235 | console.log(`upload progress: ${res.progress}, ${res.totalBytesSent / res.totalBytesExpectedToSend}`); 236 | }); 237 | upLoad.abort(); 238 | 239 | // 开放数据 240 | let context = wx.getOpenDataContext(); 241 | context.postMessage({ 242 | item: "friend" 243 | }); 244 | context.postMessage({ 245 | item: "group" 246 | }); 247 | context.postMessage({ 248 | item: "user" 249 | }); 250 | 251 | wx.removeUserCloudStorage({ 252 | keyList: [] 253 | }); 254 | wx.setUserCloudStorage({ 255 | KVDataList: [] 256 | }); 257 | 258 | // 登录 259 | wx.checkSession({ 260 | success: () => { 261 | console.log("session valid"); 262 | } 263 | }); 264 | wx.login({ 265 | success: (res) => { 266 | console.log(`login code: ${res.code}`); 267 | } 268 | }); 269 | // 防沉迷 270 | wx.checkIsUserAdvisedToRest({ 271 | todayPlayedTime: 10, 272 | success: res => { 273 | console.assert(res.result != null); 274 | } 275 | }); 276 | // 用户信息 277 | let ubtn = wx.createUserInfoButton({ 278 | type: 'text', 279 | text: 'test btn', 280 | style: { 281 | left: 1, 282 | top: 1, 283 | width: 100, 284 | height: 40, 285 | /** 286 | * 格式#ff0000 287 | */ 288 | backgroundColor: '#fefefe', 289 | /** 290 | * 格式#ff0000 291 | */ 292 | borderColor: '#cccccc', 293 | borderWidth: 1, 294 | borderRadius: 3, 295 | textAlign: "center", 296 | fontSize: 24, 297 | lineHeight: 24 298 | } 299 | }); 300 | console.assert(ubtn != null); 301 | ubtn.onTap(res => { 302 | console.assert(res.errMsg != null && res.userInfo != null); 303 | }); 304 | const newUserInfoParam: wx.types.NewUserInfoParam = { 305 | success: res => { 306 | console.assert(res.data != null); 307 | } 308 | }; 309 | wx.getUserInfo(newUserInfoParam); 310 | // 设置 311 | let createOpenSet = wx.createOpenSettingButton({ 312 | type: "text", 313 | text: "testbtn", 314 | style: { 315 | left: 10, 316 | top: 76, 317 | width: 200, 318 | height: 40, 319 | lineHeight: 40, 320 | backgroundColor: '#ff12ff', 321 | borderColor: '#000', 322 | borderWidth: 1, 323 | borderRadius: 3, 324 | textAlign: 'center', 325 | fontSize: 16 326 | } 327 | }); 328 | console.assert(createOpenSet != null); 329 | wx.getSetting({ 330 | success: res => { 331 | res.authSetting != null; 332 | } 333 | }); 334 | wx.openSetting({ 335 | success: res => { 336 | res.authSetting != null; 337 | } 338 | }); 339 | // 微信运动 340 | wx.getWeRunData({ 341 | success: res => { 342 | res.encryptedData != null; 343 | res.iv != null; 344 | } 345 | }); 346 | // 授权 347 | wx.authorize({ 348 | scope: "userInfo" 349 | }); 350 | // 游戏圈 351 | let yxq = wx.createGameClubButton({ 352 | type: "text", 353 | text: "dssss", 354 | style: { 355 | left: 10, 356 | top: 76, 357 | width: 200, 358 | height: 40, 359 | lineHeight: 40, 360 | backgroundColor: '#f00ff0', 361 | borderColor: '#fff222', 362 | borderWidth: 1, 363 | borderRadius: 3, 364 | textAlign: 'center', 365 | fontSize: 16 366 | }, 367 | icon: "green" 368 | }); 369 | console.assert(yxq != null); 370 | // 意见反馈 371 | wx.createFeedbackButton({ 372 | type: "text", 373 | text: "dssss", 374 | style: { 375 | left: 10, 376 | top: 76, 377 | width: 200, 378 | height: 40, 379 | lineHeight: 40, 380 | backgroundColor: '#00f0f0', 381 | borderColor: '#000', 382 | borderWidth: 1, 383 | borderRadius: 3, 384 | textAlign: 'center', 385 | fontSize: 16 386 | } 387 | }); 388 | // 客服消息 389 | wx.openCustomerServiceConversation({ 390 | success: () => { 391 | console.log("opened conversation window"); 392 | } 393 | }); 394 | // 开放数据域 395 | let getOpenD = wx.getOpenDataContext(); 396 | console.assert(getOpenD != null); 397 | // 转发 398 | wx.getShareInfo({ 399 | shareTicket: "", 400 | success: res => { 401 | res.encryptedData != null; 402 | res.errMsg != null; 403 | res.iv != null; 404 | } 405 | }); 406 | wx.hideShareMenu(); 407 | wx.onShareAppMessage((): wx.types.ShareOption => { 408 | return { 409 | imageUrl: "test.png", 410 | title: "test title", 411 | query: "__shareQueryStr" 412 | }; 413 | }); 414 | wx.showShareMenu({ 415 | withShareTicket: true 416 | }); 417 | wx.shareAppMessage({ 418 | title: '' 419 | }); 420 | wx.updateShareMenu({ 421 | withShareTicket: true 422 | }); 423 | // 性能 424 | let getPer = wx.getPerformance(); 425 | console.assert(getPer != null); 426 | // 调试 427 | wx.setEnableDebug({ 428 | enableDebug: true 429 | }); 430 | // 数据缓存 431 | wx.clearStorage({ 432 | success: () => { 433 | console.log("wx.clearStorage success"); 434 | } 435 | }); 436 | wx.getStorage({ 437 | key: 'test key', 438 | success: res => { 439 | console.assert(res.data != null); 440 | } 441 | }); 442 | wx.getStorageInfo({ 443 | success: res => { 444 | console.assert(res.keys != null); 445 | console.assert(res.currentSize != null); 446 | console.assert(res.limitSize != null); 447 | console.log('wx.getStorageInfo success'); 448 | } 449 | }); 450 | wx.removeStorage({ 451 | key: "test key", 452 | success: () => { 453 | console.log('wx.removeStorage success'); 454 | } 455 | }); 456 | wx.setStorage({ 457 | key: "", 458 | data: "", 459 | success: () => { 460 | console.log('wx.removeStorage success'); 461 | } 462 | }); 463 | // 分包加载 464 | let loadSu = wx.loadSubpackage({ 465 | name: 'package name', 466 | success: () => { 467 | console.log('wx.loadSubpackage success'); 468 | } 469 | }); 470 | // 菜单 471 | let getMenu = wx.getMenuButtonBoundingClientRect(); 472 | console.dir(getMenu); 473 | console.assert(getMenu.width != null); 474 | console.assert(getMenu.height != null); 475 | console.assert(getMenu.top != null); 476 | console.assert(getMenu.right != null); 477 | console.assert(getMenu.bottom != null); 478 | console.assert(getMenu.left != null); 479 | wx.setMenuStyle({ 480 | style: 'dark' 481 | }); 482 | // 交互 483 | wx.showModal({ 484 | title: "modal window" 485 | }); 486 | wx.showToast({ 487 | duration: 1, 488 | title: "show toast" 489 | }); 490 | wx.showLoading({ 491 | title: "loaidng..." 492 | }); 493 | wx.showActionSheet({ 494 | itemList: [] 495 | }); 496 | wx.hideToast(); 497 | wx.hideLoading(); 498 | // 键盘 499 | wx.hideKeyboard(); 500 | wx.onKeyboardInput(res => { 501 | console.assert(res.value != null); 502 | }); 503 | wx.showKeyboard({ 504 | defaultValue: "ABCDE", 505 | maxLength: 22, 506 | multiple: true, 507 | confirmHold: false, 508 | confirmType: "done" 509 | }); 510 | wx.updateKeyboard({ 511 | value: 'DEFGHI' 512 | }); 513 | // 状态栏 514 | wx.setStatusBarStyle({ 515 | style: "black" 516 | }); 517 | // 窗口 518 | wx.onWindowResize(res => { 519 | console.assert(res.windowHeight !== 0); 520 | console.assert(res.windowWidth !== 0); 521 | }); 522 | // 更新 523 | let getUpda = wx.getUpdateManager(); 524 | console.assert(getUpda != null); 525 | // worker 526 | let createWor = wx.createWorker('js/test.js'); 527 | console.assert(createWor != null); 528 | // 音频 529 | let creatInn = wx.createInnerAudioContext(); 530 | console.assert(creatInn != null); 531 | 532 | wx.getAvailableAudioSources({ 533 | success: res => { 534 | console.assert(res.audioSources.length > 0); 535 | } 536 | }); 537 | // 录音 538 | let getRecord = wx.getRecorderManager(); 539 | console.assert(getRecord != null); 540 | // 图片 541 | wx.chooseImage({ 542 | count: 1, 543 | sizeType: ['original'], 544 | sourceType: ['album'], 545 | success: res => { 546 | console.assert(res.tempFilePaths.length > 0); 547 | } 548 | }); 549 | wx.previewImage({ 550 | urls: [] 551 | }); 552 | wx.saveImageToPhotosAlbum({ 553 | filePath: "./temp" 554 | }); 555 | // 视频 556 | wx.createVideo({ 557 | src: "../res/testv.mp4", 558 | objectFit: 'fill' 559 | }); 560 | // 虚拟支付 561 | wx.requestMidasPayment({ 562 | mode: "game", 563 | offerId: "", 564 | currencyType: "CNY" 565 | }); 566 | // 广告 567 | const bannerAd = wx.createBannerAd({ adUnitId: "test", style: { width: 100, height: 64, left: 800, top: 300 } }); 568 | console.log("bannerAd: " + bannerAd.adUnitId); 569 | const videoAd = wx.createRewardedVideoAd({ adUnitId: "test" }); 570 | console.log("videoAd: " + videoAd.adUnitId); 571 | const intrAd = wx.createInterstitialAd({ adUnitId: "test" }); 572 | console.log("interstitialAd: " + intrAd.adUnitId); 573 | const gridAd = wx.createGridAd({ adUnitId: "test", style: { left: 100, top: 100, width: 100, height: 100 }, adTheme: 'black' }); 574 | console.log("gridAd: " + gridAd.adUnitId); 575 | const csmAd = wx.createCustomAd({ adUnitId: "test", style: { left: 100, top: 100 } }); 576 | console.log("customAd: " + csmAd.style.fixed); 577 | --------------------------------------------------------------------------------