wx.d.ts 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330
  1. // Type definitions for non-npm package wegame 2.6
  2. // Project: https://developers.weixin.qq.com/minigame/dev/index.html
  3. // Definitions by: J.C <https://github.com/jcyuan>
  4. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  5. /**
  6. * IOS及安卓不支持:
  7. * globalCompositeOperation不支持以下值:source-in source-out destination-atop lighter copy
  8. * isPointInPath 不支持
  9. */
  10. declare class WxRenderingContext extends CanvasRenderingContext2D {
  11. }
  12. /**
  13. * IOS及安卓不支持:
  14. * pixelStorei 当第一个参数是 gl.UNPACK_COLORSPACE_CONVERSION_WEBGL 时不支持
  15. * compressedTexImage2D不支持
  16. * compressedTexSubImage2D不支持
  17. * 安卓不支持:
  18. * getExtension
  19. * getSupportedExtensions
  20. */
  21. declare class WxWebGLRenderingContext extends WebGLRenderingContext {
  22. /**
  23. * 将一个Canvas对应的Texture绑定到WebGL上下文。(目前该方法仅支持 iOS 6.6.6 以上版本,Android/开发者工具暂不支持。)
  24. * 示例:gl.wxBindCanvasTexture(gl.TEXTURE_2D, canvas)
  25. * @param texture WebGL的纹理类型枚举值
  26. * @param canvas 需要绑定为Texture的Canvas
  27. */
  28. public wxBindCanvasTexture(texture: number, canvas: Canvas): void;
  29. }
  30. declare class WxPerformance {
  31. /**
  32. * 时间戳
  33. */
  34. public now(): number;
  35. }
  36. declare class Canvas {
  37. /**
  38. * 画布的宽度
  39. */
  40. public width: number;
  41. /**
  42. * 画布的高度
  43. */
  44. public height: number;
  45. /**
  46. * 将当前 Canvas 保存为一个临时文件,并生成相应的临时文件路径。
  47. */
  48. public toTempFilePath(p: wx.types.ToTempFileParams): void;
  49. /**
  50. * toTempFilePath 的同步版本
  51. */
  52. public toTempFilePathSync(p: wx.types.ToTempFileSyncParams): string;
  53. /**
  54. * 获取画布对象的绘图上下文
  55. * @param contextType 上下文类型
  56. * @param contextAttributes webgl 上下文属性,仅当 contextType 为 webgl 时有效
  57. */
  58. public getContext(contextType: '2d' | 'webgl', contextAttributes?: wx.types.RenderingContextConfig): WxRenderingContext | WxWebGLRenderingContext;
  59. /**
  60. * 把画布上的绘制内容以一个 data URI 的格式返回
  61. */
  62. public toDataURL(): string;
  63. }
  64. declare class Stats {
  65. /**
  66. * 文件的类型和存取的权限,对应 POSIX stat.st_mode
  67. */
  68. public mode: string;
  69. /**
  70. * 文件大小,单位:B,对应 POSIX stat.st_size
  71. */
  72. public size: number;
  73. /**
  74. * 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime
  75. */
  76. public lastAccessedTime: number;
  77. /**
  78. * 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime
  79. */
  80. public lastModifiedTime: number;
  81. /**
  82. * 判断当前文件是否一个目录
  83. */
  84. public isDirectory(): boolean;
  85. /**
  86. * 判断当前文件是否一个普通文件
  87. */
  88. public isFile(): boolean;
  89. }
  90. declare class FileSystemManager {
  91. /**
  92. * 重命名文件,可以把文件从 oldPath 移动到 newPath
  93. */
  94. public rename(param: wx.types.RenameParams): void;
  95. /**
  96. * FileSystemManager.rename 的同步版本
  97. * @param oldPath 源文件路径,可以是普通文件或目录
  98. * @param newPath 新文件路径
  99. * @throws 指定源文件或目标文件没有写权限
  100. * @throws 源文件不存在,或目标文件路径的上层目录不存在
  101. */
  102. public renameSync(oldPath: string, newPath: string): void;
  103. /**
  104. * 删除目录
  105. */
  106. public rmdir(param: wx.types.RmdirParams): void;
  107. /**
  108. * rmdir 的同步版本
  109. * @param dirPath 要删除的目录路径
  110. * @param recursive 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
  111. * @throws 目录不存在, 目录不为空, 指定的 dirPath 路径没有写权限
  112. */
  113. public rmdirSync(dirPath: string, recursive?: boolean): void;
  114. /**
  115. * 读取目录内文件列表
  116. */
  117. public readdir(param: wx.types.ReaddirParams): void;
  118. /**
  119. * readdir的同步版本
  120. * @param dirPath 要读取的目录路径
  121. * @throws 目录不存在
  122. * @throws dirPath 不是目录
  123. * @throws 指定的 filePath 路径没有读权限
  124. */
  125. public readdirSync(dirPath: string): ReadonlyArray<string>;
  126. /**
  127. * 创建目录
  128. */
  129. public mkdir(param: wx.types.MkdirParams): void;
  130. /**
  131. * mkdir 的同步版本
  132. * @param dirPath 创建的目录路径
  133. * @param recursive 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。
  134. * @throws 上级目录不存在
  135. * @throws 指定的 filePath 路径没有写权限
  136. * @throws 有同名文件或目录
  137. */
  138. public mkdirSync(dirPath: string, recursive?: boolean): void;
  139. /**
  140. * 解链文件
  141. */
  142. public unlink(param: wx.types.UnlinkParams): void;
  143. /**
  144. * unlink 的同步版本
  145. * @param filePath 要解链的文件路径
  146. * @throws 指定的 path 路径没有读权限
  147. * @throws 文件不存在
  148. * @throws 传入的 filePath 是一个目录
  149. */
  150. public unlinkSync(filePath: string): void;
  151. /**
  152. * 解压文件
  153. */
  154. public unzip(param: wx.types.UnzipParams): void;
  155. /**
  156. * 读取本地文件内容
  157. */
  158. public readFile(param: wx.types.ReadfileParams): void;
  159. /**
  160. * readFile 的同步版本
  161. * @param filePath 要读取的文件的路径
  162. * @param encoding 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容
  163. * @throws 指定的 filePath 所在目录不存在
  164. * @throws 指定的 filePath 路径没有读权限
  165. */
  166. public readFileSync(filePath: string, encoding?: wx.types.FileContentEncoding): string | ArrayBuffer;
  167. /**
  168. * 获取文件 Stats 对象
  169. */
  170. public stat(param: wx.types.StatParams): void;
  171. /**
  172. * stat 的同步版本
  173. * @param path 文件/目录路径
  174. * @throws 指定的 path 路径没有读权限
  175. * @throws 文件不存在
  176. */
  177. public statSync(path: string): Stats;
  178. /**
  179. * 写文件
  180. */
  181. public writeFile(param: wx.types.WritefileParams): void;
  182. /**
  183. * writeFile 的同步版本
  184. * @param filePath 要写入的文件路径
  185. * @param data 要写入的文本或二进制数据
  186. * @param encoding 指定写入文件的字符编码
  187. * @throws 指定的 filePath 所在目录不存在
  188. * @throws 指定的 filePath 路径没有写权限
  189. */
  190. public writeFileSync(filePath: string, data: string | ArrayBuffer, encoding?: wx.types.FileContentEncoding): void;
  191. /**
  192. * 判断文件/目录是否存在
  193. */
  194. public access(param: wx.types.AccessfileParams): void;
  195. /**
  196. * access的同步版本
  197. * @param path 要判断是否存在的文件/目录路径
  198. * @throws 文件/目录不存在
  199. */
  200. public accessSync(path: string): void;
  201. /**
  202. * 复制文件
  203. */
  204. public copyFile(param: wx.types.CopyfileParams): void;
  205. /**
  206. * copyFile 的同步版本
  207. * @param srcPath 源文件路径,只可以是普通文件
  208. * @param destPath 目标文件路径
  209. * @throws 指定目标文件路径没有写权限
  210. * @throws 源文件不存在,或目标文件路径的上层目录不存在
  211. */
  212. public copyFileSync(srcPath: string, destPath: string): void;
  213. /**
  214. * 获取该小程序下已保存的本地缓存文件列表
  215. * @param res.fileList.filePath 本地路径
  216. * @param res.fileList.size 本地文件大小,以字节为单位
  217. * @param res.fileList.createTime 文件创建时间
  218. */
  219. public getSavedFileList(param: wx.types.CallbacksWithType<wx.types.SavedfileList>): void;
  220. /**
  221. * 获取该小程序下的 本地临时文件 或 本地缓存文件 信息
  222. */
  223. public getFileInfo(param: wx.types.FileinfoParams): void;
  224. /**
  225. * 删除该小程序下已保存的本地缓存文件(新版本应使用unlink)
  226. */
  227. public removeSavedFile(param: wx.types.RemovefileParams): void;
  228. /**
  229. * 保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。
  230. */
  231. public saveFile(param: wx.types.SavefileParams): void;
  232. /**
  233. * saveFile的同步版本
  234. * @param tempFilePath 临时存储文件路径
  235. * @param filePath 要存储的文件路径
  236. * @throws 指定的 tempFilePath 找不到文件
  237. * @throws 指定的 filePath 路径没有写权限
  238. * @throws 上级目录不存在
  239. */
  240. public saveFileSync(tempFilePath: string, filePath?: string): string;
  241. /**
  242. * 在文件结尾追加内容
  243. */
  244. public appendFile(param: wx.types.AppendfileParams): void;
  245. /**
  246. * appendFile的同步版本
  247. * @param filePath 要追加内容的文件路径
  248. * @param data 要追加的文本或二进制数据
  249. * @param encoding 指定写入文件的字符编码
  250. * @throws 指定的 filePath 文件不存在
  251. * @throws 指定的 filePath 是一个已经存在的目录
  252. * @throws 指定的 filePath 路径没有写权限
  253. * @throws 指定的 filePath 是一个已经存在的目录
  254. */
  255. public appendFileSync(filePath: string, data: string | ArrayBuffer, encoding: wx.types.FileContentEncoding): void;
  256. }
  257. declare class DownloadTask {
  258. /**
  259. * 中断下载任务
  260. */
  261. public abort(): void;
  262. /**
  263. * 监听下载进度变化事件
  264. * @param res.progress 下载进度百分比
  265. * @param res.totalBytesWritten 已经下载的数据长度,单位 Bytes
  266. * @param res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes
  267. */
  268. public onProgressUpdate(callback: { res: { progress: number; totalBytesWritten: number; totalBytesExpectedToWrite: number } }): void;
  269. }
  270. declare class RequestTask {
  271. /**
  272. * 中断请求任务
  273. */
  274. public abort(): void;
  275. }
  276. declare class SocketTask {
  277. /**
  278. * 通过WebSocket发送数据
  279. */
  280. public send(param: wx.types.SocketSendParams): void;
  281. /**
  282. * 关闭WebSocket连接
  283. */
  284. public close(param: wx.types.SocketCloseParams): void;
  285. /**
  286. * 监听WebSocket 连接打开事件
  287. */
  288. public onOpen(callback: wx.types.SocketOpenCallback): void;
  289. /**
  290. * 监听WebSocket 连接关闭事件
  291. */
  292. public onClose(callback: () => void): void;
  293. /**
  294. * 监听WebSocket 错误事件
  295. */
  296. public onError(callback: wx.types.SocketErrorCallback): void;
  297. /**
  298. * 监听WebSocket 接受到服务器的消息事件
  299. */
  300. public onMessage(callback: wx.types.SocketMessageCallback): void;
  301. }
  302. declare class UploadTask {
  303. /**
  304. * 中断上传任务
  305. */
  306. public abort(): void;
  307. /**
  308. * 监听上传进度变化事件
  309. * @param callback.res.progress 上传进度百分比
  310. * @param callback.res.totalBytesSent 已经上传的数据长度,单位 Bytes
  311. * @param callback.res.totalBytesExpectedToSend 预期需要上传的数据总长度,单位 Bytes
  312. */
  313. public onProgressUpdate(callback: (res: { progress: number; totalBytesSent: number; totalBytesExpectedToSend: number }) => void): void;
  314. }
  315. declare class KVData {
  316. public key: string;
  317. public value: string;
  318. }
  319. declare class UserGameData {
  320. /**
  321. * 用户的微信头像 url
  322. */
  323. public avatarUrl: string;
  324. /**
  325. * 用户的微信昵称
  326. */
  327. public nickname: string;
  328. /**
  329. * 用户的openid
  330. */
  331. public openid: string;
  332. /**
  333. * 用户的托管 KV 数据列表
  334. */
  335. public KVDataList: ReadonlyArray<KVData>;
  336. }
  337. declare class CreatedButton {
  338. public type: wx.types.ButtonType;
  339. public text: string;
  340. public image: string;
  341. public style: wx.types.ButtonStyle;
  342. public show(): void;
  343. public hide(): void;
  344. public onTap(callback: (res?: any) => void): void; // res参数会被具体按钮的API定义覆盖为具体信息
  345. public offTap(callback: (res?: any) => void): void;
  346. public destroy(): void;
  347. }
  348. /**
  349. * 游戏对局回放分享按钮
  350. */
  351. declare class GameRecorderShareButton extends CreatedButton {
  352. /** 图标的 url。支持 http/https 开头的网络资源和 wxfile:// 开头的本地资源。如果不设置则使用默认图标 */
  353. public icon: string;
  354. /** 按钮的背景图片的 url。支持 http/https 开头的网络资源和 wxfile:// 开头的本地资源。如果不设置则使用默认图标 */
  355. public image: string;
  356. /** 按钮的文本 */
  357. public text: string;
  358. public share: wx.types.GameRecorderShareOption;
  359. }
  360. declare class UserInfoButton extends CreatedButton {
  361. public onTap(callback: (res: {
  362. /**
  363. * 用户信息对象,不包含 openid 等敏感信息
  364. */
  365. userInfo: wx.types.UserInfo;
  366. /**
  367. * 不包括敏感信息的原始数据字符串,用于计算签名
  368. */
  369. rawData: string;
  370. /**
  371. * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822)
  372. */
  373. signature: string;
  374. /**
  375. * 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822)
  376. */
  377. encryptedData: string;
  378. /**
  379. * 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822)
  380. */
  381. iv: string;
  382. errMsg: string;
  383. }) => void): void;
  384. }
  385. declare class OpenSettingButton extends CreatedButton {
  386. public onTap(callback: () => void): void;
  387. public offTap(callback: () => void): void;
  388. }
  389. declare class GameClubButton extends CreatedButton {
  390. public icon: wx.types.GameClubButtonIcon;
  391. public onTap(callback: (res: {
  392. errMsg: string;
  393. }) => void): void;
  394. }
  395. declare class FeedbackButton extends CreatedButton {
  396. public onTap(callback: (res: {
  397. errMsg: string;
  398. }) => void): void;
  399. }
  400. declare class OpenDataContext {
  401. /**
  402. * 开放数据域和主域共享的 sharedCanvas,注意在开放数据域内时getContext只能使用2d模式
  403. */
  404. public canvas: Canvas;
  405. /**
  406. * 向开放数据域发送消息
  407. * @param message 要发送的消息,message 中及嵌套对象中 key 的 value 只能是 primitive value。即 number、string、boolean、null、undefined。
  408. */
  409. public postMessage(message: any): void;
  410. }
  411. declare class LoadSubpackageTask {
  412. /**
  413. * 监听分包加载进度变化事件
  414. * @param callback.res.progress 分包下载进度百分比
  415. * @param callback.res.totalBytesWritten 已经下载的数据长度,单位 Bytes
  416. * @param callback.res.totalBytesExpectedToWrite 预期需要下载的数据总长度,单位 Bytes
  417. */
  418. public onProgressUpdate(callback: (res: { progress: number; totalBytesWritten: number; totalBytesExpectedToWrite: number }) => void): void;
  419. }
  420. declare class UpdateManager {
  421. /**
  422. * 应用更新包并重启
  423. */
  424. public applyUpdate(): void;
  425. /**
  426. * 监听检查更新结果回调
  427. */
  428. public onCheckForUpdate(callback: () => void): void;
  429. /**
  430. * 监听更新包下载成功回调
  431. */
  432. public onUpdateReady(callback: () => void): void;
  433. /**
  434. * 监听更新包下载失败回调
  435. */
  436. public onUpdateFailed(callback: () => void): void;
  437. }
  438. declare class WxWorker {
  439. /**
  440. * 向主线程或Worker线程发送的消息。
  441. * @param message 需要发送的消息,必须是一个可序列化的 JavaScript 对象。
  442. */
  443. public postMessage(message: any): void;
  444. /**
  445. * 结束当前 worker 线程,仅限在主线程 worker 对象上调用。
  446. */
  447. public terminate(): void;
  448. /**
  449. * 监听接收主线程/Worker 线程向当前线程发送的消息
  450. * @param callback.res.message 接收主线程/Worker 线程向当前线程发送的消息
  451. */
  452. public onMessage(callback: (res: { message: any }) => void): void;
  453. }
  454. /**
  455. * InnerAudioContext 实例,可通过 wx.createInnerAudioContext 接口获取实例。
  456. */
  457. declare class InnerAudioContext {
  458. /**
  459. * 音频资源的地址
  460. */
  461. public src: string;
  462. /**
  463. * 是否自动播放
  464. */
  465. public autoplay: boolean;
  466. /**
  467. * 是否循环播放
  468. */
  469. public loop: boolean;
  470. /**
  471. * 是否遵循系统静音开关,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音
  472. */
  473. public obeyMuteSwitch: boolean;
  474. /**
  475. * 当前音频的长度,单位 s。只有在当前有合法的 src 时返回
  476. */
  477. public readonly duration: number;
  478. /**
  479. * 当前音频的播放位置,单位 s。只有在当前有合法的 src 时返回,时间不取整,保留小数点后 6 位
  480. */
  481. public readonly currentTime: number;
  482. /**
  483. * 当前是是否暂停或停止状态,true 表示暂停或停止,false 表示正在播放
  484. */
  485. public paused: boolean;
  486. /**
  487. * 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲
  488. */
  489. public readonly buffered: number;
  490. /**
  491. * 音量。范围 0~1。
  492. */
  493. public volume: number;
  494. /**
  495. * 播放
  496. */
  497. public play(): void;
  498. /**
  499. * 暂停。暂停后的音频再播放会从暂停处开始播放
  500. */
  501. public pause(): void;
  502. /**
  503. * 停止。停止后的音频再播放会从头开始播放。
  504. */
  505. public stop(): void;
  506. /**
  507. * 跳转到指定位置,单位 s
  508. * @param position 跳转的时间
  509. */
  510. public seek(position: number): void;
  511. /**
  512. * 销毁当前实例
  513. */
  514. public destroy(): void;
  515. /**
  516. * 监听音频进入可以播放状态的事件
  517. */
  518. public onCanplay(callback: () => void): void;
  519. /**
  520. * 取消监听音频进入可以播放状态的事件
  521. */
  522. public offCanplay(callback: () => void): void;
  523. /**
  524. * 监听音频播放事件
  525. */
  526. public onPlay(callback: () => void): void;
  527. /**
  528. * 取消监听音频播放事件
  529. */
  530. public offPlay(callback: () => void): void;
  531. /**
  532. * 监听音频暂停事件
  533. */
  534. public onPause(callback: () => void): void;
  535. /**
  536. * 取消监听音频暂停事件
  537. */
  538. public offPause(callback: () => void): void;
  539. /**
  540. * 监听音频停止事件
  541. */
  542. public onStop(callback: () => void): void;
  543. /**
  544. * 取消监听音频停止事件
  545. */
  546. public offStop(callback: () => void): void;
  547. /**
  548. * 监听音频自然播放至结束的事件
  549. */
  550. public onEnded(callback: () => void): void;
  551. /**
  552. * 取消监听音频自然播放至结束的事件
  553. */
  554. public offEnded(callback: () => void): void;
  555. /**
  556. * 监听音频播放进度更新事件
  557. */
  558. public onTimeUpdate(callback: () => void): void;
  559. /**
  560. * 取消监听音频播放进度更新事件
  561. */
  562. public offTimeUpdate(callback: () => void): void;
  563. /**
  564. * 监听音频播放错误事件
  565. */
  566. public onError(callback: () => void): void;
  567. /**
  568. * 取消监听音频播放错误事件
  569. */
  570. public offError(callback: () => void): void;
  571. /**
  572. * 监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发
  573. */
  574. public onWaiting(callback: () => void): void;
  575. /**
  576. * 取消监听音频加载中事件,当音频因为数据不足,需要停下来加载时会触发
  577. */
  578. public offWaiting(callback: () => void): void;
  579. /**
  580. * 监听音频进行跳转操作的事件
  581. */
  582. public onSeeking(callback: () => void): void;
  583. /**
  584. * 取消监听音频进行跳转操作的事件
  585. */
  586. public offSeeking(callback: () => void): void;
  587. /**
  588. * 监听音频完成跳转操作的事件
  589. */
  590. public onSeeked(callback: () => void): void;
  591. /**
  592. * 取消监听音频完成跳转操作的事件
  593. */
  594. public offSeeked(callback: () => void): void;
  595. }
  596. declare class RecorderManager {
  597. /**
  598. * 开始录音
  599. */
  600. public start(param: {
  601. /**
  602. * 录音的时长,单位 ms,最大值 600000(10 分钟),默认值60000(1 分钟)
  603. */
  604. duration?: number;
  605. /**
  606. * 采样率
  607. */
  608. sampleRate: 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000;
  609. /**
  610. * 录音通道数
  611. */
  612. numberOfChannels: 1 | 2;
  613. /**
  614. * 编码码率
  615. */
  616. encodeBitRate: number;
  617. /**
  618. * 音频格式
  619. */
  620. format: 'mp3' | 'aac';
  621. /**
  622. * 指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调
  623. */
  624. frameSize: number;
  625. /**
  626. * 指定录音的音频源,可通过 wx.getAvailableAudioSources() 获取当前可用的音频源,默认值auto
  627. */
  628. audioSource?: wx.types.AudioSourceType;
  629. }): void;
  630. /**
  631. * 暂停录音
  632. */
  633. public pause(): void;
  634. /**
  635. * 继续录音
  636. */
  637. public resume(): void;
  638. /**
  639. * 停止录音
  640. */
  641. public stop(): void;
  642. /**
  643. * 监听录音开始事件
  644. */
  645. public onStart(callback: () => void): void;
  646. /**
  647. * 监听录音继续事件
  648. */
  649. public onResume(callback: () => void): void;
  650. /**
  651. * 监听录音暂停事件
  652. */
  653. public onPause(callback: () => void): void;
  654. /**
  655. * 监听录音结束事件
  656. * @param callback.res.tempFilePath 录音文件的临时路径
  657. */
  658. public onStop(callback: (res: { tempFilePath: string }) => void): void;
  659. /**
  660. * 监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。
  661. * @param callback.res.frameBuffer 录音分片数据
  662. * @param callback.res.isLastFrame 当前帧是否正常录音结束前的最后一帧
  663. */
  664. public onFrameRecorded(callback: (res: { frameBuffer: ArrayBuffer; isLastFrame: boolean }) => void): void;
  665. /**
  666. * 监听录音错误事件
  667. */
  668. public onError(callback: (res: { errMsg: string }) => void): void;
  669. }
  670. declare class ImageFile {
  671. /**
  672. * 本地文件路径
  673. */
  674. public path: string;
  675. /**
  676. * 本地文件大小,单位 B
  677. */
  678. public size: number;
  679. }
  680. declare class Video {
  681. /**
  682. * 视频的左上角横坐标
  683. */
  684. public x: number;
  685. /**
  686. * 视频的左上角纵坐标
  687. */
  688. public y: number;
  689. /**
  690. * 视频的宽度,默认值300
  691. */
  692. public width: number;
  693. /**
  694. * 默认值150
  695. */
  696. public height: number;
  697. /**
  698. * 视频的资源地址
  699. */
  700. public src: string;
  701. /**
  702. * 视频的封面
  703. */
  704. public poster: string;
  705. /**
  706. * 视频的初始播放位置,单位为 s 秒,默认值0
  707. */
  708. public initialTime: number;
  709. /**
  710. * 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0
  711. */
  712. public playbackRate: number;
  713. /**
  714. * 视频是否为直播,默认值0
  715. */
  716. public live?: number;
  717. /**
  718. * 视频的缩放模式
  719. * fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例
  720. * contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白
  721. * cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见
  722. */
  723. public objectFit: 'contain' | 'cover' | 'fill';
  724. /**
  725. * 视频是否显示控件,默认true
  726. */
  727. public controls: boolean;
  728. /**
  729. * 视频是否自动播放,默认false
  730. */
  731. public autoplay: boolean;
  732. /**
  733. * 视频是否是否循环播放,默认值false
  734. */
  735. public loop: boolean;
  736. /**
  737. * 视频是否禁音播放,默认值false
  738. */
  739. public muted: boolean;
  740. /**
  741. * 视频开始缓冲时触发的回调函数
  742. */
  743. public onwaiting: () => void;
  744. /**
  745. * 视频开始播放时触发的回调函数
  746. */
  747. public onplay: () => void;
  748. /**
  749. * 视频暂停时触发的回调函数
  750. */
  751. public onpause: () => void;
  752. /**
  753. * 视频播放到末尾时触发的回调函数
  754. */
  755. public onended: () => void;
  756. /**
  757. * 每当视频播放进度更新时触发的回调函数
  758. */
  759. public ontimeupdate: () => void;
  760. /**
  761. * 视频发生错误时触发的回调函数
  762. */
  763. public onerror: () => void;
  764. /**
  765. * 销毁视频
  766. */
  767. public destroy(): void;
  768. /**
  769. * 监听视频缓冲事件
  770. */
  771. public onWaiting(callback: () => void): void;
  772. /**
  773. * 取消监听视频缓冲事件
  774. */
  775. public offWaiting(callback: () => void): void;
  776. /**
  777. * 监听视频播放事件
  778. */
  779. public onPlay(callback: () => void): void;
  780. /**
  781. * 取消监听视频播放事件
  782. */
  783. public offPlay(callback: () => void): void;
  784. /**
  785. * 监听视频暂停事件
  786. */
  787. public onPause(callback: () => void): void;
  788. /**
  789. * 取消监听视频暂停事件
  790. */
  791. public offPause(callback: () => void): void;
  792. /**
  793. * 监听视频播放到末尾事件
  794. */
  795. public onEnded(callback: () => void): void;
  796. /**
  797. * 取消监听视频播放到末尾事件
  798. */
  799. public offEnded(callback: () => void): void;
  800. /**
  801. * 监听视频播放进度更新事件
  802. * @param callback.res.position 当前的播放位置,单位为秒
  803. * @param callback.res.duration 视频的总时长,单位为秒
  804. */
  805. public onTimeUpdate(callback: (res: { position: number; duration: number }) => void): void;
  806. /**
  807. * 取消监听视频播放进度更新事件
  808. */
  809. public offTimeUpdate(callback: (res: { position: number; duration: number }) => void): void;
  810. /**
  811. * 监听视频错误事件
  812. * @param callback.res.errMsg 错误信息,有如下值
  813. * MEDIA_ERR_NETWORK - 当下载时发生错误
  814. * MEDIA_ERR_DECODE - 当解码时发生错误
  815. * MEDIA_ERR_SRC_NOT_SUPPORTED - video 的 src 属性是不支持的资源类型
  816. */
  817. public onError(callback: (res: { errMsg: string }) => void): void;
  818. /**
  819. * 取消监听视频错误事件
  820. */
  821. public offError(callback: (res: { errMsg: string }) => void): void;
  822. /**
  823. * 播放视频
  824. */
  825. public play(): Promise<void>;
  826. /**
  827. * 暂停视频
  828. */
  829. public pause(): Promise<void>;
  830. /**
  831. * 停止视频
  832. */
  833. public stop(): Promise<void>;
  834. /**
  835. * 视频跳转
  836. * @param time 视频跳转到指定位置,单位为 s 秒
  837. */
  838. public seek(time: number): Promise<void>;
  839. /**
  840. * 视频全屏
  841. */
  842. public requestFullScreen(): Promise<void>;
  843. /**
  844. * 视频退出全屏
  845. */
  846. public exitFullScreen(): Promise<void>;
  847. }
  848. /**
  849. * banner 广告组件。banner 广告组件是一个原生组件,层级比上屏 Canvas 高,会覆盖在上屏 Canvas 上。banner 广告组件默认是隐藏的,需要调用 BannerAd.show() 将其显示。banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的尺寸将通过 BannerAd.onResize() 事件中提供。
  850. */
  851. declare class BannerAd {
  852. /**
  853. * 广告单元 id
  854. */
  855. public adUnitId: string;
  856. /**
  857. * banner 广告组件的样式。style 上的属性的值仅为开发者设置的值,banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的真实尺寸需要通过 BannerAd.onResize() 事件获得。
  858. */
  859. public style: wx.types.AdStyle;
  860. /**
  861. * 显示 banner 广告。
  862. */
  863. public show(): Promise<void>;
  864. /**
  865. * 隐藏 banner 广告
  866. */
  867. public hide(): void;
  868. /**
  869. * 销毁 banner 广告
  870. */
  871. public destroy(): void;
  872. /**
  873. * 监听 banner 广告缩放
  874. */
  875. public onResize(callback: (res: { width: number; height: number }) => void): void;
  876. /**
  877. * 取消监听隐藏 banner 广告缩放
  878. */
  879. public offResize(callback: (res: { width: number; height: number }) => void): void;
  880. /**
  881. * 监听banner 广告加载事件
  882. */
  883. public onLoad(callback: () => void): void;
  884. /**
  885. * 取消监听banner 广告加载事件
  886. */
  887. public offLoad(callback: () => void): void;
  888. /**
  889. * 监听banner 广告错误事件
  890. */
  891. public onError(callback: (res: { errMsg: string }) => void): void;
  892. /**
  893. * 取消监听banner 广告错误事件
  894. */
  895. public offError(callback: (res: { errMsg: string }) => void): void;
  896. }
  897. /**
  898. * 创建小游戏推荐icon组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.8.2 后再使用该 API。每次调用该方法都会返回一个全新的实例
  899. */
  900. declare class iconAd {
  901. /**监听小游戏推荐icon组件位置或者尺寸改变事件。回调函数回抛出一个数组,包含被渲染出来的游戏的信息,该数组为组件实例属性icons的子集。 */
  902. public onResize(callback: (res: any) => void): void;
  903. /**显示小游戏推荐icon组件。 */
  904. public show(): void;
  905. /**小游戏推荐icon组件加载数据接口。 */
  906. public load(): Promise<void>;
  907. /**隐藏小游戏推荐icon组件。 */
  908. public hide(): void;
  909. /**销毁小游戏推荐icon组件,组件销毁后所有方法和事件都将失效。 */
  910. public destroy(): void;
  911. /**监听小游戏推荐icon组件加载错误事件。 */
  912. public onError(callback: (res: { errMsg: string }) => void): void;
  913. /**监听小游戏推荐icon组件加载成功事件。 */
  914. public onLoad(callback: () => void): void
  915. }
  916. /**创建小游戏格子广告 */
  917. declare class gridAd {
  918. /**在适合的场景显示格子广告 */
  919. public show(): void;
  920. /**隐藏广告 */
  921. public hide(): void;
  922. /**销毁格子广告 */
  923. public destroy(): void;
  924. /**
  925. * 监听格子 广告加载事件
  926. */
  927. public onLoad(callback: () => void): void;
  928. /**
  929. * 监听格子 广告错误事件
  930. */
  931. public onError(callback: (res: { errMsg: string }) => void): void;
  932. }
  933. /**阿拉丁统计 */
  934. declare class aldStage {
  935. /**关卡开始 传对象{stageId,stageName,userId(可以不传)} */
  936. public onStart(obj: object);
  937. /**关卡完成 传对象{stageId,stageName,userId(可选),event,params} */
  938. public onEnd(obj: object);
  939. }
  940. declare class RewardedVideoAd extends BannerAd {
  941. /**
  942. * 加载视频广告
  943. */
  944. public load(): Promise<void>;
  945. /**
  946. * 监听用户点击 关闭广告 按钮的事件
  947. */
  948. public onClose(callback: (res: { isEnded: boolean }) => void): void;
  949. /**
  950. * 监听用户点击 关闭广告 按钮的事件
  951. */
  952. public offClose(callback: (res: { isEnded: boolean }) => void): void;
  953. }
  954. declare class GameRecorder {
  955. /**
  956. * 获取是否支持录制游戏画面
  957. */
  958. public isFrameSupported(): boolean;
  959. /**
  960. * 放弃录制游戏画面。此时已经录制的内容会被丢弃
  961. */
  962. public abort(): Promise<void>;
  963. /**
  964. * 获取是否在录制游戏画面的同时支持录制游戏音频的信息
  965. */
  966. public isSoundSupported(): boolean;
  967. /**
  968. * 取消监听录制事件。当对应事件触发时,该回调函数不再执行。
  969. */
  970. public off(event: wx.types.gameRecorderEvent, callback: () => void);
  971. /**
  972. * 注册监听录制事件的回调函数。当对应事件触发时,回调函数会被执行
  973. * 除了 timeUpdate error stop 事件外,其他事件都是无参的
  974. * timeUpdate, currentTime(当前视频录制到第几秒)
  975. * error, error?: {code: number; message: string }
  976. * stop, duration 视频的时长,单位 ms 毫秒
  977. */
  978. public on(event: wx.types.gameRecorderEvent, callback: (res?: { currentTime?: number; error?: { code: number; message: string }; duration?: number }) => void);
  979. /**
  980. * 暂停录制游戏画面
  981. */
  982. public pause(): Promise<void>;
  983. /**
  984. * 恢复录制游戏画面
  985. */
  986. public resume(): Promise<void>;
  987. /**
  988. * 开始录制游戏画面
  989. * @param param {fps 视频 fps 默认: 24,
  990. * duration 视频的时长限制,单位为秒(s)。最大值 7200,最小值 5,到达指定时长后不会再录入。但还需要手动调用 GameRecorder.stop() 来结束录制,
  991. * bitrate 视频比特率(kbps) 默认: 1000,
  992. * gop 视频关键帧间隔 默认: 12}
  993. */
  994. public start(param: { fps?: number; duration?: number; bitrate?: number; gop?: number }): void;
  995. /**
  996. * 结束录制游戏画面。结束录制后可以发起分享
  997. */
  998. public stop(): Promise<void>;
  999. }
  1000. // --定时器
  1001. declare function clearTimeout(timeoutID: number): void;
  1002. declare function clearInterval(intervalID: number): void;
  1003. declare function setTimeout(fn: () => void, delay: number, ...rest: any[]): number;
  1004. declare function setInterval(fn: () => void, delay: number, ...rest: any[]): number;
  1005. // --渲染
  1006. declare function cancelAnimationFrame(requestID: number): void;
  1007. declare function requestAnimationFrame(callback: () => void): number;
  1008. declare namespace wx {
  1009. namespace types {
  1010. type gameRecorderEvent = 'start' | 'stop' | 'pause' | 'resume' | 'abort' | 'timeUpdate' | 'error';
  1011. type envVersion = 'develop' | 'trial' | 'release';
  1012. /**
  1013. * 打开另一个小程序
  1014. */
  1015. interface MiniProgram {
  1016. appId: string;
  1017. path?: string;
  1018. extraData?: object;
  1019. envVersion?: envVersion;
  1020. success?: () => void;
  1021. fail?: () => void;
  1022. complete?: () => void;
  1023. }
  1024. interface Callbacks {
  1025. success?: () => void;
  1026. fail?: () => void;
  1027. complete?: () => void;
  1028. }
  1029. interface CallbacksWithType<T> {
  1030. success?: (res: T) => void;
  1031. fail?: (res) => void;
  1032. complete?: () => void;
  1033. }
  1034. interface RenderingContextConfig {
  1035. /**
  1036. * 表示是否抗锯齿
  1037. */
  1038. antialias?: boolean;
  1039. /**
  1040. * 表示是否绘图完成后是否保留绘图缓冲区
  1041. */
  1042. preserveDrawingBuffer?: boolean;
  1043. /**
  1044. * 抗锯齿样本数。最小值为 2,最大不超过系统限制数量,仅 iOS 支持
  1045. */
  1046. antialiasSamples?: number;
  1047. }
  1048. interface ToTempFileSyncParams {
  1049. /**
  1050. * 截取 canvas 的左上角横坐标
  1051. */
  1052. x?: number;
  1053. /**
  1054. * 截取 canvas 的左上角纵坐标
  1055. */
  1056. y?: number;
  1057. /**
  1058. * 截取 canvas 的宽度
  1059. */
  1060. width?: number;
  1061. /**
  1062. * 截取 canvas 的高度
  1063. */
  1064. height?: number;
  1065. /**
  1066. * 目标文件的宽度,会将截取的部分拉伸或压缩至该数值
  1067. */
  1068. destWidth?: number;
  1069. /**
  1070. * 目标文件的高度,会将截取的部分拉伸或压缩至该数值
  1071. */
  1072. destHeight?: number;
  1073. /**
  1074. * 目标文件的类型
  1075. */
  1076. fileType?: 'jpg' | 'png';
  1077. /**
  1078. * jpg图片的质量,仅当 fileType 为 jpg 时有效。取值范围为 0.0(最低)- 1.0(最高),不含 0。不在范围内时当作 1.0
  1079. */
  1080. quality?: number;
  1081. }
  1082. interface ToTempFileParams extends ToTempFileSyncParams {
  1083. success?: (res: { tempFilePath: string }) => void;
  1084. fail?: () => void;
  1085. complete?: () => void;
  1086. }
  1087. interface RenameParams {
  1088. oldPath: string;
  1089. newPath: string;
  1090. success?: () => void;
  1091. fail?: (res: { errMsg: string }) => void;
  1092. complete?: () => void;
  1093. }
  1094. interface RmdirParams {
  1095. dirPath: string;
  1096. recursive?: boolean;
  1097. success?: () => void;
  1098. fail?: (res: { errMsg: string }) => void;
  1099. complete?: () => void;
  1100. }
  1101. interface ReaddirParams {
  1102. dirPath: string;
  1103. success?: (res: { files: ReadonlyArray<string> }) => void;
  1104. fail?: (res: { errMsg: string }) => void;
  1105. complete?: () => void;
  1106. }
  1107. interface MkdirParams {
  1108. dirPath: string;
  1109. recursive?: boolean;
  1110. success?: () => void;
  1111. fail?: (res: { errMsg: string }) => void;
  1112. complete?: () => void;
  1113. }
  1114. type FileContentEncoding =
  1115. 'ascii'
  1116. | 'base64'
  1117. | 'binary'
  1118. | 'hex'
  1119. | 'ucs2'
  1120. | 'ucs-2'
  1121. | 'utf16le'
  1122. | 'utf-16le'
  1123. | 'utf-8'
  1124. | 'utf8'
  1125. | 'latin1';
  1126. interface ReadfileParams {
  1127. filePath: string;
  1128. encoding?: FileContentEncoding;
  1129. success?: (res: { data: string | ArrayBuffer }) => void;
  1130. fail?: (res: { errMsg: string }) => void;
  1131. complete?: () => void;
  1132. }
  1133. interface StatParams {
  1134. path: string;
  1135. success?: (res: { stat: Stats }) => void;
  1136. fail?: (res: { errMsg: string }) => void;
  1137. complete?: () => void;
  1138. }
  1139. interface WritefileParams {
  1140. filePath: string;
  1141. data: string | ArrayBuffer;
  1142. encoding?: FileContentEncoding;
  1143. success?: () => void;
  1144. fail?: (res: { errMsg: string }) => void;
  1145. complete?: () => void;
  1146. }
  1147. interface UnlinkParams {
  1148. filePath: string;
  1149. success?: () => void;
  1150. fail?: (res: { errMsg: string }) => void;
  1151. complete?: () => void;
  1152. }
  1153. interface UnzipParams {
  1154. zipFilePath: string;
  1155. targetPath: string;
  1156. success?: () => void;
  1157. fail?: (res: { errMsg: string }) => void;
  1158. complete?: () => void;
  1159. }
  1160. interface AccessfileParams {
  1161. path: string;
  1162. success?: () => void;
  1163. fail?: (res: { errMsg: string }) => void;
  1164. complete?: () => void;
  1165. }
  1166. interface SavedfileList {
  1167. fileList: {
  1168. filePath: string;
  1169. size: number;
  1170. createTime: number;
  1171. };
  1172. }
  1173. interface CopyfileParams {
  1174. srcPath: string;
  1175. destPath: string;
  1176. success?: () => void;
  1177. fail?: (res: { errMsg: string }) => void;
  1178. complete?: () => void;
  1179. }
  1180. interface FileinfoParams {
  1181. filePath: string;
  1182. success?: (res: { size: number; digest: string }) => void;
  1183. fail?: (res: { errMsg: string }) => void;
  1184. complete?: () => void;
  1185. }
  1186. interface RemovefileParams {
  1187. filePath: string;
  1188. success?: () => void;
  1189. fail?: () => void;
  1190. complete?: () => void;
  1191. }
  1192. interface SavefileParams {
  1193. tempFilePath: string;
  1194. filePath?: string;
  1195. success?: (res: { savedFilePath: string }) => void;
  1196. fail?: (res: { errMsg: string }) => void;
  1197. complete?: () => void;
  1198. }
  1199. interface AppendfileParams {
  1200. filePath: string;
  1201. data: string | ArrayBuffer;
  1202. encoding?: FileContentEncoding;
  1203. success?: () => void;
  1204. fail?: (res: { errMsg: string }) => void;
  1205. complete?: () => void;
  1206. }
  1207. interface LineHeightParams {
  1208. fontStyle?: 'normal' | 'italic';
  1209. fontWeight?: 'normal' | 'bold';
  1210. fontSize?: number;
  1211. fontFamily: string;
  1212. text: string;
  1213. success?: (res: { lineHeight: number }) => void;
  1214. fail?: () => void;
  1215. complete?: () => void;
  1216. }
  1217. interface Image {
  1218. src: string;
  1219. width: number;
  1220. height: number;
  1221. onload: () => void;
  1222. onerror: (e?: any) => void;
  1223. }
  1224. // --启动参数
  1225. interface LaunchOption {
  1226. /**
  1227. * 场景值
  1228. */
  1229. scene: number;
  1230. /**
  1231. * 启动参数
  1232. */
  1233. query: any;
  1234. /**
  1235. * 当前小游戏是否被显示在聊天顶部
  1236. */
  1237. isSticky: boolean;
  1238. /**
  1239. * 票据
  1240. */
  1241. shareTicket: string;
  1242. }
  1243. // --系统信息
  1244. interface SystemInfo {
  1245. /**
  1246. * 手机品牌
  1247. */
  1248. brand: string;
  1249. /**
  1250. * 手机型号
  1251. */
  1252. model: string;
  1253. /**
  1254. * 设备像素比
  1255. */
  1256. pixelRatio: number;
  1257. /**
  1258. * 屏幕宽度
  1259. */
  1260. screenWidth: number;
  1261. /**
  1262. * 屏幕高度
  1263. */
  1264. screenHeight: number;
  1265. /**
  1266. * 可使用窗口宽度
  1267. */
  1268. windowWidth: number;
  1269. /**
  1270. * 可使用窗口高度
  1271. */
  1272. windowHeight: number;
  1273. /**
  1274. * 微信设置的语言
  1275. */
  1276. language: string;
  1277. /**
  1278. * 微信版本号
  1279. */
  1280. version: string;
  1281. /**
  1282. * 操作系统版本
  1283. */
  1284. system: string;
  1285. /**
  1286. * 客户端平台
  1287. */
  1288. platform: string;
  1289. /**
  1290. * 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位 px。
  1291. */
  1292. fontSizeSetting: string;
  1293. /**
  1294. * 客户端基础库版本
  1295. */
  1296. SDKVersion: string;
  1297. /**
  1298. * 性能等级
  1299. */
  1300. benchmarkLevel: number;
  1301. /**
  1302. * 电量,范围 1 - 100
  1303. */
  1304. battery: number;
  1305. /**
  1306. * wifi 信号强度,范围 0 - 4
  1307. */
  1308. wifiSignal: number;
  1309. }
  1310. // --触摸对象
  1311. interface Touch {
  1312. /**
  1313. * Touch 对象的唯一标识符,只读属性。一次触摸动作(我们值的是手指的触摸)在平面上移动的整个过程中, 该标识符不变。可以根据它来判断跟踪的是否是同一次触摸过程。
  1314. */
  1315. identifier: number;
  1316. /**
  1317. * 触点相对于整体页面的 X 轴距离。
  1318. */
  1319. pageX: number;
  1320. /**
  1321. * 触点相对于整体页面的 Y 轴距离。
  1322. */
  1323. pageY: number;
  1324. /**
  1325. * 触点相对于游戏窗口的 X 轴距离。
  1326. */
  1327. clientX: number;
  1328. /**
  1329. * 触点相对于游戏窗口的 Y 轴距离。
  1330. */
  1331. clientY: number;
  1332. }
  1333. interface TouchData {
  1334. /**
  1335. * 当前事件的类型
  1336. */
  1337. type: string;
  1338. /**
  1339. * 当前所有触摸点的列表
  1340. */
  1341. touches: ReadonlyArray<Touch>;
  1342. /**
  1343. * 触发此次事件的触摸点列表
  1344. */
  1345. changedTouches: ReadonlyArray<Touch>;
  1346. /**
  1347. * 事件触发时的时间戳
  1348. */
  1349. timeStamp: number;
  1350. }
  1351. // --电量
  1352. interface BatteryInfo {
  1353. /**
  1354. * 设备电量,范围 1 - 100
  1355. */
  1356. level: string;
  1357. /**
  1358. * 是否正在充电
  1359. */
  1360. isCharging: boolean;
  1361. }
  1362. // --剪切板
  1363. interface ClipboardData {
  1364. data: string;
  1365. }
  1366. interface SetClipboardDataParams {
  1367. success?: () => void;
  1368. fail?: () => void;
  1369. complete?: () => void;
  1370. data: string;
  1371. }
  1372. interface SetKeepScreenOnParams {
  1373. success?: () => void;
  1374. fail?: () => void;
  1375. complete?: () => void;
  1376. keepScreenOn: boolean;
  1377. }
  1378. interface SetScreenBrightnessParams {
  1379. success?: () => void;
  1380. fail?: () => void;
  1381. complete?: () => void;
  1382. /**
  1383. * 屏幕亮度值,范围 0 ~ 1,0 最暗,1 最亮
  1384. */
  1385. value: number;
  1386. }
  1387. interface DownfileParams {
  1388. url: string;
  1389. /**
  1390. * 在指定filePath之后success回调中将不会有res.tempFilePath路径值,下载的文件会直接写入filePath指定的路径(有写入权限的情况下,根目录请使用wx.env.USER_DATA_PATH,路径文件夹必须存在,否则写入失败)
  1391. */
  1392. filePath?: string;
  1393. /**
  1394. * HTTP 请求的 Header,Header 中不能设置 Referer
  1395. */
  1396. header?: { [key: string]: string };
  1397. /**
  1398. * res.tempFilePath 临时文件路径。如果没传入 filePath 指定文件存储路径,则下载后的文件会存储到一个临时文件
  1399. * res.statusCode 开发者服务器返回的 HTTP 状态码
  1400. */
  1401. success?: (res: { tempFilePath: string; statusCode: number }) => void;
  1402. fail?: (res: { errMsg: string }) => void;
  1403. complete?: () => void;
  1404. }
  1405. type NetworkType = 'wifi' | '2g' | '3g' | '4g' | 'unknown' | 'none';
  1406. type RequestMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT';
  1407. interface RequestParams {
  1408. /**
  1409. * 开发者服务器接口地址
  1410. */
  1411. url: string;
  1412. /**
  1413. * 请求的参数
  1414. */
  1415. data?: string | { [key: string]: any };
  1416. /**
  1417. * 设置请求的 header,header 中不能设置 Referer
  1418. */
  1419. header?: { [name: string]: string };
  1420. /**
  1421. * HTTP 请求方法
  1422. */
  1423. method?: RequestMethod;
  1424. /**
  1425. * 返回的数据格式
  1426. */
  1427. dataType?: 'json' | 'arraybuffer';
  1428. /**
  1429. * res.data usually can be string or ArrayBuffer
  1430. */
  1431. success?: (res: { data: any; statusCode: number; header?: { [key: string]: string } }) => void;
  1432. fail?: () => void;
  1433. complete?: () => void;
  1434. }
  1435. interface SocketSendParams {
  1436. data: string | ArrayBuffer;
  1437. success?: () => void;
  1438. fail?: () => void;
  1439. complete?: () => void;
  1440. }
  1441. interface SocketConnectParams {
  1442. url: string;
  1443. protocols?: string[];
  1444. header?: { [key: string]: string };
  1445. method?: RequestMethod;
  1446. success?: () => void;
  1447. fail?: () => void;
  1448. complete?: () => void;
  1449. }
  1450. interface SocketCloseParams {
  1451. /**
  1452. * 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。如果这个参数没有被指定,默认的取值是1000 (表示正常连接关闭)
  1453. */
  1454. code?: number;
  1455. /**
  1456. * 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于123字节的UTF-8 文本(不是字符)
  1457. */
  1458. reason?: string;
  1459. success?: () => void;
  1460. fail?: () => void;
  1461. complete?: () => void;
  1462. }
  1463. type SocketOpenCallback = (res: { header?: { [key: string]: string } }) => void;
  1464. type SocketMessageCallback = (res: { data: string | ArrayBuffer }) => void;
  1465. type SocketErrorCallback = (res: { errMsg: string }) => void;
  1466. /**
  1467. * wx.getUserInfo的旧版本API参数,随时会被删除,不推荐使用
  1468. */
  1469. interface OldUserInfoParam {
  1470. /**
  1471. * 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。
  1472. */
  1473. withCredentials?: boolean;
  1474. /**
  1475. * 显示用户信息的语言
  1476. */
  1477. lang?: 'en' | 'zh_CN' | 'zh_TW';
  1478. success?: (res: {
  1479. /**
  1480. * 用户信息对象,不包含 openid 等敏感信息
  1481. */
  1482. userInfo: UserInfo;
  1483. /**
  1484. * 不包括敏感信息的原始数据字符串,用于计算签名
  1485. */
  1486. rawData: string;
  1487. /**
  1488. * 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息,参考文档signature(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/http-signature.html?t=201822)
  1489. */
  1490. signature: string;
  1491. /**
  1492. * 包括敏感数据在内的完整用户信息的加密数据,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822)
  1493. */
  1494. encryptedData: string;
  1495. /**
  1496. * 加密算法的初始向量,详见加密数据解密算法(https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/signature.html?t=201822)
  1497. */
  1498. iv: string;
  1499. errMsg: string;
  1500. }) => void;
  1501. fail?: (res) => void;
  1502. complete?: () => void;
  1503. }
  1504. /**
  1505. * 新版本wx.getUserInfo的参数,需要在开放数据域内调用
  1506. */
  1507. interface NewUserInfoParam {
  1508. /**
  1509. * 要获取信息的用户的 openId 数组,如果要获取当前用户信息,则将数组中的一个元素设为 'selfOpenId'
  1510. */
  1511. openIdList?: string[];
  1512. /**
  1513. * 显示用户信息的语言
  1514. */
  1515. lang?: 'en' | 'zh_CN' | 'zh_TW';
  1516. success?: (res: { data: ReadonlyArray<UserInfo> }) => void;
  1517. fail?: () => void;
  1518. complete?: () => void;
  1519. }
  1520. interface UserInfo {
  1521. language: string;
  1522. nickName: string;
  1523. avatarUrl: string;
  1524. /**
  1525. * 0:未知、1:男、2:女
  1526. */
  1527. gender: 0 | 1 | 2;
  1528. country: string;
  1529. province: string;
  1530. city: string;
  1531. }
  1532. type ButtonType = 'text' | 'image';
  1533. interface ButtonStyle {
  1534. left?: number;
  1535. top?: number;
  1536. width?: number;
  1537. height?: number;
  1538. /**
  1539. * 格式#ff0000
  1540. */
  1541. backgroundColor?: string;
  1542. /**
  1543. * 格式#ff0000
  1544. */
  1545. borderColor?: string;
  1546. borderWidth?: number;
  1547. borderRadius?: number;
  1548. textAlign?: 'left' | 'center' | 'right';
  1549. fontSize?: number;
  1550. lineHeight?: number;
  1551. /**
  1552. * 图标和文本之间的距离,最小 8 逻辑像素
  1553. */
  1554. iconMarginRight?: number;
  1555. /** 文本的颜色 */
  1556. color?: string;
  1557. /** 按钮的左内边距,最小 16 逻辑像素 */
  1558. paddingLeft?: number;
  1559. /** 按钮的右内边距,最小 16 逻辑像素 */
  1560. paddingRight?: number;
  1561. }
  1562. type GameClubButtonIcon = 'green' | 'white' | 'dark' | 'light';
  1563. // --设置
  1564. interface AuthSetting {
  1565. /**
  1566. * 用户信息,对应接口 wx.getUserInfo
  1567. */
  1568. 'scope.userInfo'?: boolean;
  1569. /**
  1570. * 地理位置,对应接口 wx.getLocation wx.chooseLocation
  1571. */
  1572. 'scope.userLocation'?: boolean;
  1573. /**
  1574. * 通讯地址,对应接口 wx.chooseAddress
  1575. */
  1576. 'scope.address'?: boolean;
  1577. /**
  1578. * 发票抬头,对应接口 wx.chooseInvoiceTitle
  1579. */
  1580. 'scope.invoiceTitle'?: boolean;
  1581. /**
  1582. * 微信运动步数,对应接口 wx.getWeRunData
  1583. */
  1584. 'scope.werun'?: boolean;
  1585. /**
  1586. * 录音功能,对应接口 wx.startRecord
  1587. */
  1588. 'scope.record'?: boolean;
  1589. /**
  1590. * 保存到相册 wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum
  1591. */
  1592. 'scope.writePhotosAlbum'?: boolean;
  1593. /**
  1594. * 摄像头 wx.camera
  1595. */
  1596. 'scope.camera'?: boolean;
  1597. }
  1598. interface SetStorageParams {
  1599. key: string;
  1600. data: any;
  1601. success?: () => void;
  1602. fail?: () => void;
  1603. complete?: () => void;
  1604. }
  1605. interface RemoveStorageParams {
  1606. key: string;
  1607. success?: () => void;
  1608. fail?: () => void;
  1609. complete?: () => void;
  1610. }
  1611. interface GetStorageParams {
  1612. key: string;
  1613. success?: (res: { data: any }) => void;
  1614. fail?: () => void;
  1615. complete?: () => void;
  1616. }
  1617. interface StorageInfo {
  1618. /**
  1619. * 当前 storage 中所有的 key
  1620. */
  1621. keys: ReadonlyArray<string>;
  1622. /**
  1623. * 当前占用的空间大小, 单位 KB
  1624. */
  1625. currentSize: number;
  1626. /**
  1627. * 限制的空间大小,单位 KB
  1628. */
  1629. limitSize: number;
  1630. }
  1631. interface ShareOption {
  1632. /**
  1633. * 转发标题,不传则默认使用当前小游戏的昵称。
  1634. */
  1635. title?: string;
  1636. /**
  1637. * 转发显示图片的链接,可以是网络图片路径或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5:4
  1638. */
  1639. imageUrl?: string;
  1640. /**
  1641. * 查询字符串,必须是 key1=val1&key2=val2 的格式。从这条转发消息进入后,可通过 wx.getLaunchOptionsSync() 或 wx.onShow 获取启动参数中的 query。
  1642. */
  1643. query?: string;
  1644. /**
  1645. * 审核通过的图片 ID
  1646. */
  1647. imageUrlId?: string;
  1648. }
  1649. interface GameRecorderShareOption {
  1650. /**
  1651. * 分享的对局回放打开后跳转小游戏的 query
  1652. */
  1653. query: string;
  1654. /**
  1655. * 对局回放的标题的配置。对局回放标题不能随意设置,只能选择预设的文案模版和对应的参数
  1656. */
  1657. title: GameRecorderShareTitleOption;
  1658. /**
  1659. * 对局回放的按钮的配置。对局回放按钮的文案不能随意设置,只能选择预设的文案模版
  1660. */
  1661. button: GameRecorderShareButtonOption;
  1662. /**
  1663. * 对局回放背景音乐的地址。必须是一个代码包文件路径或者 wxfile:// 文件路径,不支持 http/https 开头的 url
  1664. */
  1665. bgm: string;
  1666. /**
  1667. * 对局回放的剪辑区间,是一个二维数组,单位 ms(毫秒)。[[1000, 3000], [4000, 5000]] 表示剪辑已录制对局回放的 1-3 秒和 4-5 秒最终合成为一个 3 秒的对局回放。对局回放剪辑后的总时长最多 60 秒,即 1 分钟
  1668. */
  1669. timeRange: Array<number>;
  1670. }
  1671. interface GameRecorderShareTitleOption {
  1672. template?: 'score' | 'level' | 'opponent' | 'cost';
  1673. data: object;
  1674. }
  1675. interface GameRecorderShareButtonOption {
  1676. template: 'enter' | 'challenge' | 'play';
  1677. }
  1678. interface AccelerometerParams {
  1679. interval: 'game' | 'ui' | 'normal';
  1680. success?: () => void;
  1681. fail?: () => void;
  1682. complete?: () => void;
  1683. }
  1684. type AudioSourceType = 'auto' | 'buildInMic' | 'headsetMic' | 'mic' | 'camcorder';
  1685. interface AdStyle {
  1686. /**
  1687. * 广告组件的左上角横坐标
  1688. */
  1689. left: number;
  1690. /**
  1691. * banner 广告组件的左上角纵坐标
  1692. */
  1693. top: number;
  1694. /**
  1695. * banner 广告组件的宽度。最小 300,最大至 屏幕宽度(屏幕宽度可以通过 wx.getSystemInfoSync() 获取)。
  1696. */
  1697. width?: number;
  1698. /**
  1699. * banner 广告组件的高度
  1700. */
  1701. height?: number;
  1702. /**
  1703. * banner 广告组件经过缩放后真实的宽度
  1704. */
  1705. realWidth?: number;
  1706. /**
  1707. * banner 广告组件经过缩放后真实的高度
  1708. */
  1709. realHeight?: number;
  1710. }
  1711. /**单个游戏icon的位置和样式信息 */
  1712. interface styleItem {
  1713. /**游戏名称是否隐藏 */
  1714. appNameHidden: boolean;
  1715. /**游戏名称的颜色色值 */
  1716. color: string;
  1717. /**游戏icon的宽高值 */
  1718. size: number;
  1719. /**游戏icon的border尺寸 */
  1720. borderWidth: number;
  1721. /**游戏icon的border颜色色值 */
  1722. borderColor: string;
  1723. /**游戏icon的X轴坐标 */
  1724. left: number;
  1725. /**游戏icon的Y轴坐标 */
  1726. top: number;
  1727. }
  1728. /**格子广告样式信息 */
  1729. interface GridStyle {
  1730. left: number;
  1731. top: number;
  1732. width: number;
  1733. opacity: number;
  1734. }
  1735. }
  1736. function createCustomAd(opt:any);
  1737. /**
  1738. * 创建一个画布对象。首次调用创建的是显示在屏幕上的画布,之后调用创建的都是离屏画布。
  1739. */
  1740. function createCanvas(): Canvas;
  1741. /**
  1742. * 只有开放数据域能调用,获取主域和开放数据域共享的 sharedCanvas
  1743. */
  1744. function getSharedCanvas(): Canvas;
  1745. /**
  1746. * 创建一个图片对象
  1747. */
  1748. function createImage(): types.Image;
  1749. /**
  1750. * 获取一行文本的行高
  1751. * @param p 字体参数
  1752. */
  1753. function getTextLineHeight(p: types.LineHeightParams): number;
  1754. /**
  1755. * 加载自定义字体文件
  1756. * @param path 字体文件路径。可以是代码包文件路径,也可以是 wxfile:// 协议的本地文件路径。
  1757. */
  1758. function loadFont(path: string): string;
  1759. /**
  1760. * 可以修改渲染帧率。默认渲染帧率为 60 帧每秒。修改后,requestAnimationFrame 的回调频率会发生改变。
  1761. * @param fps 帧率,有效范围 1 - 60。
  1762. */
  1763. function setPreferredFramesPerSecond(fps: number): void;
  1764. // --生命周期
  1765. function exitMiniProgram(cb?: types.Callbacks): void;
  1766. function getLaunchOptionsSync(): types.LaunchOption;
  1767. function onHide(cb: () => void): void;
  1768. function offHide(cb: () => void): void;
  1769. function onShow(cb: (res: { scene: string; query: any; shareTicket: string }) => void): void;
  1770. function offShow(cb: (res: { scene: string; query: any; shareTicket: string }) => void): void;
  1771. // --系统信息
  1772. function getSystemInfo(cb: types.CallbacksWithType<types.SystemInfo>): void;
  1773. function getSystemInfoSync(): types.SystemInfo;
  1774. function navigateToMiniProgram(param: types.MiniProgram);
  1775. /**
  1776. * 监听音频中断结束,在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功
  1777. */
  1778. function onAudioInterruptionEnd(cb: () => void): void;
  1779. /**
  1780. * 取消监听音频中断结束,在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功
  1781. */
  1782. function offAudioInterruptionEnd(cb: () => void): void;
  1783. /**
  1784. * 监听音频因为受到系统占用而被中断开始,以下场景会触发此事件:闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天。此事件触发后,小程序内所有音频会暂停。
  1785. */
  1786. function onAudioInterruptionBegin(cb: () => void): void;
  1787. /**
  1788. * 取消监听音频因为受到系统占用而被中断开始,以下场景会触发此事件:闹钟、电话、FaceTime 通话、微信语音聊天、微信视频聊天。此事件触发后,小程序内所有音频会暂停。
  1789. */
  1790. function offAudioInterruptionBegin(cb: () => void): void;
  1791. /**
  1792. * 监听全局错误事件
  1793. */
  1794. function onError(cb: (res: { message: string; stack: string }) => void): void;
  1795. function offError(cb: (res: { message: string; stack: string }) => void): void;
  1796. // --触摸事件
  1797. /**
  1798. * 监听开始始触摸事件
  1799. */
  1800. function onTouchStart(cb: (res: types.TouchData) => void): void;
  1801. function offTouchStart(cb: (res: types.TouchData) => void): void;
  1802. /**
  1803. * 监听触点移动事件
  1804. */
  1805. function onTouchMove(cb: (res: types.TouchData) => void): void;
  1806. function offTouchMove(cb: (res: types.TouchData) => void): void;
  1807. /**
  1808. * 监听触摸结束事件
  1809. */
  1810. function onTouchEnd(cb: (res: types.TouchData) => void): void;
  1811. function offTouchEnd(cb: (res: types.TouchData) => void): void;
  1812. /**
  1813. * 监听触点失效事件
  1814. */
  1815. function onTouchCancel(cb: (res: types.TouchData) => void): void;
  1816. function offTouchCancel(cb: (res: types.TouchData) => void): void;
  1817. // --加速计
  1818. /**
  1819. * 监听加速度数据,频率:5次/秒,接口调用后会自动开始监听,可使用 wx.stopAccelerometer 停止监听。
  1820. */
  1821. function onAccelerometerChange(cb: (res: { x: number; y: number; z: number }) => void): void;
  1822. /**
  1823. * 开始监听加速度数据。
  1824. */
  1825. function startAccelerometer(cb: types.AccelerometerParams): void;
  1826. /**
  1827. * 停止监听加速度数据。
  1828. */
  1829. function stopAccelerometer(cb?: types.Callbacks): void;
  1830. // --电量
  1831. /**
  1832. * 获取设备电量。同步 API wx.getBatteryInfoSync 在 iOS 上不可用。
  1833. */
  1834. function getBatteryInfo(cb: types.CallbacksWithType<types.BatteryInfo>): void;
  1835. /**
  1836. * IOS上这个同步API无法使用
  1837. */
  1838. function getBatteryInfoSync(): types.BatteryInfo;
  1839. // --剪贴板
  1840. /**
  1841. * 取得系统剪贴板的内容
  1842. */
  1843. function getClipboardData(cb: types.CallbacksWithType<types.ClipboardData>): void;
  1844. /**
  1845. * 设置系统剪贴板的内容
  1846. */
  1847. function setClipboardData(p: types.SetClipboardDataParams): void;
  1848. // --罗盘
  1849. /**
  1850. * 监听罗盘数据,频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
  1851. * @param cb.res.direction 面对的方向度数
  1852. */
  1853. function onCompassChange(cb: (res: { direction: number }) => void): void;
  1854. /**
  1855. * 开始监听罗盘数据
  1856. */
  1857. function startCompass(cb?: types.Callbacks): void;
  1858. /**
  1859. * 停止监听罗盘数据
  1860. */
  1861. function stopCompass(cb?: types.Callbacks): void;
  1862. // --网络
  1863. /**
  1864. * 获取网络类型
  1865. */
  1866. function getNetworkType(cb: types.CallbacksWithType<{ isConnected: boolean; networkType: types.NetworkType }>): void;
  1867. /**
  1868. * 监听网络状态变化事件
  1869. */
  1870. function onNetworkStatusChange(cb: (res: {
  1871. /**
  1872. * 当前是否有网络链接
  1873. */
  1874. isConnected: boolean;
  1875. /**
  1876. * none - 无网络, unknown - Android 下不常见的网络类型
  1877. */
  1878. networkType: types.NetworkType;
  1879. }) => void): void;
  1880. // --屏幕
  1881. /**
  1882. * 获取屏幕亮度
  1883. */
  1884. function getScreenBrightness(cb: types.CallbacksWithType<{ value: number }>): void;
  1885. /**
  1886. * 设置是否保持常亮状态。仅在当前小程序生效,离开小程序后设置失效。
  1887. */
  1888. function setKeepScreenOn(p: types.SetKeepScreenOnParams): void;
  1889. /**
  1890. * 设置屏幕亮度
  1891. */
  1892. function setScreenBrightness(p: types.SetScreenBrightnessParams): void;
  1893. // --转屏
  1894. /**
  1895. * 监听横竖屏切换事件
  1896. */
  1897. function onDeviceOrientationChange(callback: (res: { value: string }) => void): void;
  1898. /**
  1899. * 取消监听横竖屏切换事件
  1900. */
  1901. function offDeviceOrientationChange(callback: (res: { value: string }) => void): void;
  1902. // --振动
  1903. /**
  1904. * 使手机发生较短时间的振动(15 ms)
  1905. */
  1906. function vibrateShort(cb?: types.Callbacks): void;
  1907. /**
  1908. * 使手机发生较长时间的振动(400 ms)
  1909. */
  1910. function vibrateLong(cb?: types.Callbacks): void;
  1911. // --文件系统
  1912. function getFileSystemManager(): FileSystemManager;
  1913. /**
  1914. * 系统环境变量
  1915. */
  1916. const env: {
  1917. /**
  1918. * 用户下载数据根目录
  1919. */
  1920. USER_DATA_PATH: string;
  1921. };
  1922. // --位置
  1923. /**
  1924. * 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。
  1925. */
  1926. function getLocation(param: {
  1927. /**
  1928. * wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
  1929. */
  1930. type?: 'wgs84' | 'gcj02';
  1931. /**
  1932. * 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度 >= 1.6.0
  1933. */
  1934. altitude?: boolean;
  1935. success?: (res: {
  1936. /**
  1937. * 纬度,范围为 -90~90,负数表示南纬
  1938. */
  1939. latitude: number;
  1940. /**
  1941. * 经度,范围为 -180~180,负数表示西经
  1942. */
  1943. longitude: number;
  1944. /**
  1945. * 速度,单位 m/s
  1946. */
  1947. speed: number;
  1948. /**
  1949. * 位置的精确度
  1950. */
  1951. accuracy: number;
  1952. /**
  1953. * 高度,单位 m
  1954. */
  1955. altitude: number;
  1956. /**
  1957. * 垂直精度,单位 m(Android 无法获取,返回 0)
  1958. */
  1959. verticalAccuracy: number;
  1960. /**
  1961. * 水平精度,单位 m
  1962. */
  1963. horizontalAccuracy: number;
  1964. }) => void;
  1965. fail?: () => void;
  1966. complete?: () => void;
  1967. }): void;
  1968. // --网络
  1969. /**
  1970. * 下载文件
  1971. */
  1972. function downloadFile(param: types.DownfileParams): DownloadTask;
  1973. // --发起请求
  1974. function request(param: types.RequestParams): RequestTask;
  1975. // --websocket
  1976. /**
  1977. * 创建一个 WebSocket 连接。最多同时存在 5 个 WebSocket 连接。
  1978. */
  1979. function connectSocket(param: types.SocketConnectParams): SocketTask;
  1980. /**
  1981. * 关闭WebSocket
  1982. */
  1983. function closeSocket(param: types.SocketCloseParams): void;
  1984. /**
  1985. * 监听WebSocket 连接打开事件
  1986. */
  1987. function onSocketOpen(callback: types.SocketOpenCallback): void;
  1988. /**
  1989. * 监听WebSocket 连接关闭事件
  1990. */
  1991. function onSocketClose(callback: () => void): void;
  1992. /**
  1993. * 监听WebSocket 接受到服务器的消息事件
  1994. */
  1995. function onSocketMessage(callback: types.SocketMessageCallback): void;
  1996. /**
  1997. * 监听WebSocket 错误事件
  1998. */
  1999. function onSocketError(callback: types.SocketErrorCallback): void;
  2000. /**
  2001. * 通过 WebSocket 连接发送数据,需要先 wx.connectSocket,并在 wx.onSocketOpen 回调之后才能发送。
  2002. */
  2003. function sendSocketMessage(param: types.SocketSendParams): void;
  2004. // --上传
  2005. function uploadFile(param: {
  2006. /**
  2007. * 开发者服务器地址
  2008. */
  2009. url: string;
  2010. /**
  2011. * 要上传文件资源的路径
  2012. */
  2013. filePath: string;
  2014. /**
  2015. * 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容
  2016. */
  2017. name: string;
  2018. /**
  2019. * HTTP 请求 Header,Header 中不能设置 Referer
  2020. */
  2021. header?: { [key: string]: string };
  2022. /**
  2023. * HTTP 请求中其他额外的 form data
  2024. */
  2025. formData?: { [key: string]: any };
  2026. success?: (res: { data: string; statusCode: number }) => void;
  2027. fail?: () => void;
  2028. complete?: () => void;
  2029. }): UploadTask;
  2030. // --开放数据
  2031. /**
  2032. * 拉取当前用户所有同玩好友的托管数据。该接口只可在开放数据域下使用
  2033. */
  2034. function getFriendCloudStorage(param: {
  2035. /**
  2036. * 要拉取的 key 列表
  2037. */
  2038. keyList: string[];
  2039. success?: (res: { data: ReadonlyArray<UserGameData> }) => void;
  2040. fail?: () => void;
  2041. complete?: () => void;
  2042. }): void;
  2043. /**
  2044. * 获取当前用户托管数据当中对应 key 的数据。该接口只可在开放数据域下使用
  2045. */
  2046. function getUserCloudStorage(param: {
  2047. /**
  2048. * 要拉取的 key 列表
  2049. */
  2050. keyList: string[];
  2051. success?: (res: { KVDataList: ReadonlyArray<KVData> }) => void;
  2052. fail?: () => void;
  2053. complete?: () => void;
  2054. }): void;
  2055. /**
  2056. * 在无须用户授权的情况下,批量获取用户信息。该接口只在开放数据域下可用
  2057. * 请注意!!旧版本的该接口已过期,微信不允许主动弹出授权框,旧版本API会被逐渐作废,请使用wx.createUserInfoButton或在隔离数据区取得用户信息
  2058. * 如使用旧接口取得用户信息,withCredentials 为 true 时需要先调用 wx.login 接口。需要用户授权 scope.userInfo
  2059. */
  2060. function getUserInfo(param: types.NewUserInfoParam | types.OldUserInfoParam): void;
  2061. /**
  2062. * 在小游戏是通过群分享卡片打开的情况下,可以通过调用该接口获取群同玩成员的游戏数据。该接口只可在开放数据域下使用。
  2063. */
  2064. function getGroupCloudStorage(param: {
  2065. /**
  2066. * 群分享对应的 shareTicket
  2067. */
  2068. shareTicket: string;
  2069. /**
  2070. * 要拉取的 key 列表
  2071. */
  2072. keyList: string[];
  2073. success?: (res: { data: ReadonlyArray<UserGameData> }) => void;
  2074. fail?: () => void;
  2075. complete?: () => void;
  2076. }): void;
  2077. /**
  2078. * 删除用户托管数据当中对应 key 的数据。
  2079. */
  2080. function removeUserCloudStorage(param: {
  2081. /**
  2082. * 要删除掉 key 列表
  2083. */
  2084. keyList: string[];
  2085. success?: () => void;
  2086. fail?: () => void;
  2087. complete?: () => void;
  2088. }): void;
  2089. /**
  2090. * 对用户托管数据进行写数据操作,允许同时写多组 KV 数据。
  2091. * 托管数据的限制
  2092. * > 每个openid所标识的微信用户在每个游戏上托管的数据不能超过128个key-value对。
  2093. * > 上报的key-value列表当中每一项的key+value长度都不能超过1K(1024)字节。
  2094. * > 上报的key-value列表当中每一个key长度都不能超过128字节。
  2095. */
  2096. function setUserCloudStorage(param: {
  2097. /**
  2098. * 要修改的 KV 数据列表
  2099. */
  2100. KVDataList: KVData[];
  2101. success?: () => void;
  2102. fail?: () => void;
  2103. complete?: () => void;
  2104. }): void;
  2105. // --登录
  2106. /**
  2107. * 通过 wx.login 接口获得的用户登录态拥有一定的时效性。用户越久未使用小程序,用户登录态越有可能失效。反之如果用户一直在使用小程序,则用户登录态一直保持有效。具体时效逻辑由微信维护,对开发者透明。开发者只需要调用 wx.checkSession 接口检测当前用户登录态是否有效。登录态过期后开发者可以再调用 wx.login 获取新的用户登录态。
  2108. */
  2109. function checkSession(cb: types.Callbacks): void;
  2110. /**
  2111. * 调用接口获取登录凭证(code)进而换取用户登录态信息,包括用户的唯一标识(openid) 及本次登录的 会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。
  2112. */
  2113. function login(cb: types.CallbacksWithType<{
  2114. /**
  2115. * 用户登录凭证(有效期五分钟)。开发者需要在开发者服务器后台调用 code2accessToken,使用 code 换取 openid 和 session_key 等信息
  2116. */
  2117. code: string;
  2118. }>): void;
  2119. // --防沉迷
  2120. /**
  2121. * 根据用户当天游戏时间判断用户是否需要休息
  2122. */
  2123. function checkIsUserAdvisedToRest(param: {
  2124. /**
  2125. * 今天已经玩游戏的时间,单位:秒
  2126. */
  2127. todayPlayedTime: number;
  2128. success?: (res: {
  2129. /**
  2130. * 是否建议用户休息
  2131. */
  2132. result: boolean;
  2133. }) => void;
  2134. fail?: () => void;
  2135. complete?: () => void;
  2136. }): void;
  2137. // --用户信息
  2138. function createUserInfoButton(param: {
  2139. /**
  2140. * 按钮类型
  2141. */
  2142. type: types.ButtonType;
  2143. /**
  2144. * 按钮上的文本,仅当 type 为 text 时有效
  2145. */
  2146. text?: string;
  2147. /**
  2148. * 按钮的背景图片,仅当 type 为 image 时有效
  2149. */
  2150. image?: string;
  2151. /**
  2152. * 按钮的样式
  2153. */
  2154. style?: types.ButtonStyle;
  2155. /**
  2156. * 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。
  2157. */
  2158. withCredentials?: boolean;
  2159. lang?: 'en' | 'zh_CN' | 'zh_TW';
  2160. }): UserInfoButton;
  2161. // -- 游戏对局回放分享按钮。按钮在被用户点击后会发起对最近一次录制完成的游戏对局回放的分享
  2162. function createGameRecorderShareButton(param: {
  2163. /**
  2164. * 按钮的样式
  2165. */
  2166. style: wx.types.ButtonType;
  2167. share: wx.types.GameRecorderShareOption;
  2168. /*
  2169. * 图标的 url。支持 http/https 开头的网络资源和 wxfile:// 开头的本地资源。如果不设置则使用默认图标。
  2170. */
  2171. icon?: string;
  2172. /**
  2173. * 按钮的背景图片的 url。支持 http/https 开头的网络资源和 wxfile:// 开头的本地资源。如果不设置则使用默认图标
  2174. */
  2175. image?: string;
  2176. /**
  2177. * 按钮的文本
  2178. */
  2179. text?: string;
  2180. }): GameRecorderShareButton;
  2181. // --设置
  2182. /**
  2183. * 创建打开设置页面的按钮
  2184. */
  2185. function createOpenSettingButton(param: {
  2186. /**
  2187. * 按钮类型
  2188. */
  2189. type: types.ButtonType;
  2190. /**
  2191. * 按钮上的文本,仅当 type 为 text 时有效
  2192. */
  2193. text?: string;
  2194. /**
  2195. * 按钮的背景图片,仅当 type 为 image 时有效
  2196. */
  2197. image?: string;
  2198. /**
  2199. * 按钮的样式
  2200. */
  2201. style?: types.ButtonStyle;
  2202. }): OpenSettingButton;
  2203. /**
  2204. * 获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。
  2205. */
  2206. function getSetting(p: types.CallbacksWithType<{ authSetting: types.AuthSetting }>): void;
  2207. /**
  2208. * 调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。
  2209. * @deprecated
  2210. */
  2211. function openSetting(p: types.CallbacksWithType<{ authSetting: types.AuthSetting }>): void;
  2212. // --微信运动
  2213. /**
  2214. * 获取用户过去三十天微信运动步数,需要先调用 wx.login 接口。需要用户授权 scope.werun。
  2215. */
  2216. function getWeRunData(p: types.CallbacksWithType<{
  2217. /**
  2218. * 包括敏感数据在内的完整用户信息的加密数据,详细见加密数据解密算法
  2219. */
  2220. encryptedData: string;
  2221. /**
  2222. * 加密算法的初始向量
  2223. */
  2224. iv: string;
  2225. }>): void;
  2226. // --授权
  2227. /**
  2228. * 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。
  2229. */
  2230. function authorize(param: {
  2231. /**
  2232. * 需要获取权限的 scope
  2233. */
  2234. scope: string;
  2235. success?: () => void;
  2236. fail?: () => void;
  2237. complete?: () => void;
  2238. }): void;
  2239. // --游戏圈
  2240. /**
  2241. * 创建游戏圈按钮。游戏圈按钮被点击后会跳转到小游戏的游戏圈。更多关于游戏圈的信息见 游戏圈使用指南
  2242. */
  2243. function createGameClubButton(param: {
  2244. type?: types.ButtonType;
  2245. text?: string;
  2246. image?: string;
  2247. style?: types.ButtonStyle;
  2248. /**
  2249. * 游戏圈按钮的图标,仅当 object.type 参数为 image 时有效
  2250. * types.GameClubButtonIcon
  2251. */
  2252. icon?: string;
  2253. }): GameClubButton;
  2254. // --意见反馈
  2255. /**
  2256. * 用户点击后打开意见反馈页面的按钮
  2257. */
  2258. function createFeedbackButton(param: {
  2259. type: types.ButtonType;
  2260. text?: string;
  2261. image?: string;
  2262. style?: types.ButtonStyle;
  2263. }): FeedbackButton;
  2264. // --客服消息
  2265. /**
  2266. * 进入客服会话,要求在用户发生过至少一次 touch 事件后才能调用。后台接入方式与小程序一致,详见 客服消息接入
  2267. */
  2268. function openCustomerServiceConversation(param: {
  2269. /**
  2270. * 会话来源
  2271. */
  2272. sessionFrom?: string;
  2273. /**
  2274. * 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话之后会收到一个消息卡片,通过以下三个参数设置卡片的内容
  2275. */
  2276. showMessageCard?: boolean;
  2277. /**
  2278. * 会话内消息卡片标题
  2279. */
  2280. sendMessageTitle?: string;
  2281. /**
  2282. * 会话内消息卡片路径
  2283. */
  2284. sendMessagePath?: string;
  2285. /**
  2286. * 会话内消息卡片图片路径
  2287. */
  2288. sendMessageImg?: string;
  2289. success?: () => void;
  2290. fail?: () => void;
  2291. complete?: () => void;
  2292. }): void;
  2293. // --开放数据域
  2294. /**
  2295. * 获取开放数据域
  2296. */
  2297. function getOpenDataContext(): OpenDataContext;
  2298. /**
  2299. * 监听主域发送的消息
  2300. */
  2301. function onMessage(callback: (data: any) => void): void;
  2302. // --转发
  2303. /**
  2304. * 获取转发详细信息
  2305. */
  2306. function getShareInfo(param: {
  2307. shareTicket: string;
  2308. success?: (res: {
  2309. /**
  2310. * 错误信息
  2311. */
  2312. errMsg: string;
  2313. /**
  2314. * 包括敏感数据在内的完整转发信息的加密数据
  2315. */
  2316. encryptedData: string;
  2317. /**
  2318. * 加密算法的初始向量
  2319. */
  2320. iv: string;
  2321. }) => void;
  2322. fail?: () => void;
  2323. complete?: () => void;
  2324. }): void;
  2325. /**
  2326. * 隐藏转发按钮
  2327. */
  2328. function hideShareMenu(cb?: types.Callbacks): void;
  2329. /**
  2330. * 监听用户点击右上角菜单的“转发”按钮时触发的事件
  2331. */
  2332. function onShareAppMessage(cb: () => types.ShareOption): void;
  2333. function onShareTimeline(cb: () => types.ShareOption): void;
  2334. /**
  2335. * 取消监听用户点击右上角菜单的“转发”按钮时触发的事件
  2336. */
  2337. function offShareAppMessage(cb: () => types.ShareOption): void;
  2338. /**
  2339. * 显示当前页面的转发按钮
  2340. */
  2341. function showShareMenu(param?: {
  2342. /**
  2343. * 是否使用带 shareTicket 的转发
  2344. */
  2345. withShareTicket: boolean;
  2346. menus: Array<string>;
  2347. success?: () => void;
  2348. fail?: () => void;
  2349. complete?: () => void;
  2350. }): void;
  2351. /**
  2352. * 主动拉起转发,进入选择通讯录界面。
  2353. */
  2354. function shareAppMessage(param: types.ShareOption): void;
  2355. /**
  2356. * 更新转发属性
  2357. */
  2358. function updateShareMenu(param: {
  2359. /**
  2360. * 是否使用带 shareTicket 的转发详情
  2361. */
  2362. withShareTicket: boolean;
  2363. success?: () => void;
  2364. fail?: () => void;
  2365. complete?: () => void;
  2366. }): void;
  2367. // --性能
  2368. /**
  2369. * 获取性能管理器
  2370. */
  2371. function getPerformance(): WxPerformance;
  2372. /**
  2373. * 加快触发 JavaScriptCore Garbage Collection(垃圾回收),GC 时机是由 JavaScriptCore 来控制的,并不能保证调用后马上触发 GC。
  2374. */
  2375. function triggerGC(): void;
  2376. /**
  2377. * 监听内存不足告警
  2378. * @param callback.res.level 内存告警等级,只有 Android 才有,对应系统宏定义:
  2379. * 10 TRIM_MEMORY_RUNNING_LOW
  2380. * 15 TRIM_MEMORY_RUNNING_CRITICAL
  2381. */
  2382. function onMemoryWarning(callback: (res: { level: number }) => void): void;
  2383. // --调试
  2384. function setEnableDebug(p: {
  2385. enableDebug: boolean;
  2386. success?: () => void;
  2387. fail?: () => void;
  2388. complete?: () => void;
  2389. }): void;
  2390. // --数据缓存
  2391. /**
  2392. * 清理本地数据缓存
  2393. */
  2394. function clearStorage(param: types.Callbacks): void;
  2395. /**
  2396. * clearStorage的同步版本
  2397. */
  2398. function clearStorageSync(): void;
  2399. /**
  2400. * 从本地缓存中异步获取指定 key 的内容
  2401. */
  2402. function getStorage(param: types.GetStorageParams): void;
  2403. /**
  2404. * getStorage 的同步版本
  2405. */
  2406. function getStorageSync(key: string): any;
  2407. /**
  2408. * 异步获取当前storage的相关信息
  2409. */
  2410. function getStorageInfo(param: types.CallbacksWithType<types.StorageInfo>): void;
  2411. /**
  2412. * getStorageInfo 的同步版本
  2413. */
  2414. function getStorageInfoSync(): types.StorageInfo;
  2415. /**
  2416. * 从本地缓存中移除指定 key
  2417. */
  2418. function removeStorage(param: types.RemoveStorageParams): void;
  2419. /**
  2420. * removeStorage 的同步版本
  2421. * @param key 本地缓存中指定的 key
  2422. */
  2423. function removeStorageSync(key: string): void;
  2424. /**
  2425. * 将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容。
  2426. */
  2427. function setStorage(param: types.SetStorageParams): void;
  2428. /**
  2429. * setStorage 的同步版本
  2430. * @param key 本地缓存中指定的 key
  2431. * @param data 需要存储的内容
  2432. */
  2433. function setStorageSync(key: string, data: any): void;
  2434. // --分包加载
  2435. /**
  2436. * 触发分包加载,详见 分包加载
  2437. */
  2438. function loadSubpackage(param: {
  2439. /**
  2440. * 分包的名字,可以填 name 或者 root
  2441. */
  2442. name: string;
  2443. success?: () => void;
  2444. fail?: () => void;
  2445. complete?: () => void;
  2446. }): LoadSubpackageTask;
  2447. // --菜单
  2448. /**
  2449. * 获取菜单按钮的布局置信息
  2450. */
  2451. function getMenuButtonBoundingClientRect(): {
  2452. /**
  2453. * 宽度
  2454. */
  2455. width: number;
  2456. /**
  2457. * 高度
  2458. */
  2459. height: number;
  2460. /**
  2461. * 上边界坐标
  2462. */
  2463. top: number;
  2464. /**
  2465. * 右边界坐标
  2466. */
  2467. right: number;
  2468. /**
  2469. * 下边界坐标
  2470. */
  2471. bottom: number;
  2472. /**
  2473. * 左边界坐标
  2474. */
  2475. left: number;
  2476. };
  2477. function setMenuStyle(param: {
  2478. /**
  2479. * 样式风格
  2480. */
  2481. style: 'light' | 'dark';
  2482. success?: () => void;
  2483. fail?: () => void;
  2484. complete?: () => void;
  2485. }): void;
  2486. // --交互
  2487. /**
  2488. * 显示消息提示框
  2489. */
  2490. function showToast(param: {
  2491. /**
  2492. * 提示的内容
  2493. */
  2494. title?: string;
  2495. /**
  2496. * 图标
  2497. */
  2498. icon?: 'success' | 'loading';
  2499. /**
  2500. * 自定义图标的本地路径,image 的优先级高于 icon
  2501. */
  2502. image?: string;
  2503. /**
  2504. * 提示的延迟时间
  2505. */
  2506. duration?: number;
  2507. success?: () => void;
  2508. fail?: () => void;
  2509. complete?: () => void;
  2510. }): void;
  2511. /**
  2512. * 隐藏消息提示框
  2513. */
  2514. function hideToast(cb?: types.Callbacks): void;
  2515. /**
  2516. * 显示模态对话框
  2517. */
  2518. function showModal(param: {
  2519. /**
  2520. * 提示的标题
  2521. */
  2522. title?: string;
  2523. /**
  2524. * 提示的内容
  2525. */
  2526. content?: string;
  2527. /**
  2528. * 是否显示取消按钮,默认true
  2529. */
  2530. showCancel?: boolean;
  2531. /**
  2532. * 取消按钮的文字,最多 4 个字符串
  2533. */
  2534. cancelText?: string;
  2535. /**
  2536. * 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值#000000
  2537. */
  2538. cancelColor?: string;
  2539. /**
  2540. * 确认按钮的文字,最多 4 个字符串
  2541. */
  2542. confirmText?: string;
  2543. /**
  2544. * 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串,默认值#3cc51f
  2545. */
  2546. confirmColor?: string;
  2547. success?: (res: { confirm?: boolean; cancel?: boolean }) => void;
  2548. fail?: () => void;
  2549. complete?: () => void;
  2550. }): void;
  2551. /**
  2552. * 显示 loading 提示框, 需主动调用 wx.hideLoading 才能关闭提示框
  2553. */
  2554. function showLoading(prms?: {
  2555. /**
  2556. * 提示的内容
  2557. */
  2558. title?: string;
  2559. /**
  2560. * 是否显示透明蒙层
  2561. */
  2562. mask?: boolean;
  2563. success?: () => void;
  2564. fail?: () => void;
  2565. complete?: () => void;
  2566. }): void;
  2567. /**
  2568. * 隐藏 loading 提示框
  2569. */
  2570. function hideLoading(cb?: types.Callbacks): void;
  2571. /**
  2572. * 显示选择器
  2573. */
  2574. function showActionSheet(params: {
  2575. /**
  2576. * 按钮的文字数组,数组长度最大为 6
  2577. */
  2578. itemList: string[];
  2579. /**
  2580. * 按钮的文字颜色,默认值#000000
  2581. */
  2582. itemColor?: string;
  2583. success?: () => void;
  2584. fail?: () => void;
  2585. complete?: () => void;
  2586. }): void;
  2587. // --键盘
  2588. function hideKeyboard(): void;
  2589. /**
  2590. * 监听键盘输入事件
  2591. * @param callback.res.value 键盘输入的当前值
  2592. */
  2593. function onKeyboardInput(callback: (res: { value: string }) => void): void;
  2594. /**
  2595. * 取消监听键盘输入事件
  2596. */
  2597. function offKeyboardInput(callback: (res: { value: string }) => void): void;
  2598. /**
  2599. * 监听用户点击键盘 Confirm 按钮时的事件
  2600. * @param callback.res.value 键盘输入的当前值
  2601. */
  2602. function onKeyboardConfirm(callback: (res: { value: string }) => void): void;
  2603. /**
  2604. * 取消监听用户点击键盘 Confirm 按钮时的事件
  2605. */
  2606. function offKeyboardConfirm(callback: (res: { value: string }) => void): void;
  2607. /**
  2608. * 监听监听键盘收起的事件
  2609. * @param callback.res.value 键盘输入的当前值
  2610. */
  2611. function onKeyboardComplete(callback: (res: { value: string }) => void): void;
  2612. /**
  2613. * 取消监听监听键盘收起的事件
  2614. */
  2615. function offKeyboardComplete(callback: (res: { value: string }) => void): void;
  2616. /**
  2617. * 显示键盘
  2618. */
  2619. function showKeyboard(param: {
  2620. /**
  2621. * 键盘输入框显示的默认值
  2622. */
  2623. defaultValue: string;
  2624. /**
  2625. * 键盘中文本的最大长度
  2626. */
  2627. maxLength?: number;
  2628. /**
  2629. * 是否为多行输入
  2630. */
  2631. multiple?: boolean;
  2632. /**
  2633. * 当点击完成时键盘是否收起
  2634. */
  2635. confirmHold?: boolean;
  2636. /**
  2637. * 键盘右下角 confirm 按钮的类型,只影响按钮的文本内容
  2638. */
  2639. confirmType?: 'done' | 'next' | 'search' | 'go' | 'send';
  2640. }): void;
  2641. /**
  2642. * 更新键盘,只有当键盘处于拉起状态时才会产生效果
  2643. */
  2644. function updateKeyboard(param: {
  2645. /**
  2646. * 键盘输入框的当前值
  2647. */
  2648. value: string;
  2649. success?: () => void;
  2650. fail?: () => void;
  2651. complete?: () => void;
  2652. }): void;
  2653. // --状态栏
  2654. /**
  2655. * 当在配置中设置 showStatusBarStyle 时,屏幕顶部会显示状态栏。此接口可以修改状态栏的样式。
  2656. */
  2657. function setStatusBarStyle(param: {
  2658. style: 'white' | 'black';
  2659. success?: () => void;
  2660. fail?: () => void;
  2661. complete?: () => void;
  2662. }): void;
  2663. // --窗口
  2664. /**
  2665. * 监听窗口尺寸变化事件
  2666. */
  2667. function onWindowResize(cb: (res: { windowWidth: number; windowHeight: number }) => void): void;
  2668. /**
  2669. * 取消监听窗口尺寸变化事件
  2670. */
  2671. function offWindowResize(cb: (res: { windowWidth: number; windowHeight: number }) => void): void;
  2672. // --更新
  2673. function getUpdateManager(): UpdateManager;
  2674. // --Worker
  2675. /**
  2676. * 创建一个 Worker 线程,目前限制最多只能创建一个 Worker,创建下一个 Worker 前请调用 Worker.terminate
  2677. */
  2678. function createWorker(): WxWorker;
  2679. // --音频
  2680. /**
  2681. * 创建一个 InnerAudioContext 实例
  2682. */
  2683. function createInnerAudioContext(): InnerAudioContext;
  2684. /**
  2685. * 获取当前支持的音频输入源
  2686. */
  2687. function getAvailableAudioSources(param: types.CallbacksWithType<{
  2688. /**
  2689. * 音频输入源,每一项对应一种音频输入源
  2690. */
  2691. audioSources: ReadonlyArray<types.AudioSourceType>;
  2692. }>): void;
  2693. // --录音
  2694. function getRecorderManager(): RecorderManager;
  2695. // --图片
  2696. /**
  2697. * 从本地相册选择图片或使用相机拍照。
  2698. */
  2699. function chooseImage(param: {
  2700. count: number;
  2701. /**
  2702. * 所选的图片的尺寸
  2703. */
  2704. sizeType: ['original'] | ['compressed'] | ['original', 'compressed'];
  2705. /**
  2706. * 选择图片的来源
  2707. */
  2708. sourceType: ['album'] | ['camera'] | ['album', 'camera'];
  2709. success?: (res: { tempFilePaths: ReadonlyArray<string>; tempFiles: ReadonlyArray<ImageFile> }) => void;
  2710. fail?: () => void;
  2711. complete?: () => void;
  2712. }): void;
  2713. /**
  2714. * 预览图片,调用之后会在新打开的页面中全屏预览传入的图片,预览的过程中用户可以进行保存图片、发送给朋友等操作
  2715. */
  2716. function previewImage(param: {
  2717. /**
  2718. * 需要预览的图片链接列表
  2719. */
  2720. urls: string[];
  2721. /**
  2722. * 当前显示图片的链接,默认为urls的第一张
  2723. */
  2724. current?: string;
  2725. success?: () => void;
  2726. fail?: () => void;
  2727. complete?: () => void;
  2728. }): void;
  2729. /**
  2730. * 保存图片到系统相册。需要用户授权 scope.writePhotosAlbum
  2731. */
  2732. function saveImageToPhotosAlbum(param: {
  2733. /**
  2734. * 图片文件路径,可以是临时文件路径也可以是永久文件路径,不支持网络图片路径
  2735. */
  2736. filePath: string;
  2737. success?: () => void;
  2738. fail?: () => void;
  2739. complete?: () => void;
  2740. }): void;
  2741. // --视频
  2742. function createVideo(param: {
  2743. /**
  2744. * 视频的左上角横坐标
  2745. */
  2746. x?: number;
  2747. /**
  2748. * 视频的左上角纵坐标
  2749. */
  2750. y?: number;
  2751. /**
  2752. * 视频的宽度,默认值300
  2753. */
  2754. width?: number;
  2755. /**
  2756. * 默认值150
  2757. */
  2758. height?: number;
  2759. /**
  2760. * 视频的资源地址
  2761. */
  2762. src: string;
  2763. /**
  2764. * 视频的封面
  2765. */
  2766. poster?: string;
  2767. /**
  2768. * 视频的初始播放位置,单位为 s 秒,默认值0
  2769. */
  2770. initialTime?: number;
  2771. /**
  2772. * 视频的播放速率,有效值有 0.5、0.8、1.0、1.25、1.5默认值1.0
  2773. */
  2774. playbackRate?: number;
  2775. /**
  2776. * 视频是否为直播,默认值0
  2777. */
  2778. live?: number;
  2779. /**
  2780. * 视频的缩放模式
  2781. * fill - 填充,视频拉伸填满整个容器,不保证保持原有长宽比例
  2782. * contain - 包含,保持原有长宽比例。保证视频尺寸一定可以在容器里面放得下。因此,可能会有部分空白
  2783. * cover - 覆盖,保持原有长宽比例。保证视频尺寸一定大于容器尺寸,宽度和高度至少有一个和容器一致。因此,视频有部分会看不见
  2784. */
  2785. objectFit?: 'contain' | 'cover' | 'fill';
  2786. /**
  2787. * 视频是否显示控件,默认true
  2788. */
  2789. controls?: boolean;
  2790. /**
  2791. * 视频是否自动播放,默认false
  2792. */
  2793. autoplay?: boolean;
  2794. /**
  2795. * 视频是否是否循环播放,默认值false
  2796. */
  2797. loop?: boolean;
  2798. /**
  2799. * 视频是否禁音播放,默认值false
  2800. */
  2801. muted?: boolean;
  2802. }): Video;
  2803. // --广告
  2804. /**
  2805. * 创建 banner 广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.0.4 后再使用该 API。同时,开发者工具上暂不支持调试该 API,请直接在真机上进行调试。
  2806. */
  2807. function createBannerAd(param: {
  2808. /**
  2809. * 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 Banner 广告不会自动刷新)
  2810. */
  2811. adIntervals: number;
  2812. /**
  2813. * 广告单元 id
  2814. */
  2815. adUnitId: string;
  2816. /**
  2817. * banner 广告组件的样式
  2818. */
  2819. style: types.AdStyle;
  2820. }): BannerAd;
  2821. /**
  2822. * 创建激励视频广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.0.4 后再使用该 API。同时,开发者工具上暂不支持调试该 API,请直接在真机上进行调试。
  2823. */
  2824. function createRewardedVideoAd(param: {
  2825. /**
  2826. * 广告单元 id
  2827. */
  2828. adUnitId: string;
  2829. }): RewardedVideoAd;
  2830. /**
  2831. * 创建插屏广告组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号后再使用该 API。每次调用该方法创建插屏广告都会返回一个全新的实例(小程序端的插屏广告实例不允许跨页面使用)
  2832. * @param param
  2833. */
  2834. function createInterstitialAd(param: {
  2835. /**
  2836. * 广告单元 id
  2837. */
  2838. adUnitId: string;
  2839. }): RewardedVideoAd;
  2840. /**
  2841. * 创建小游戏推荐icon组件。请通过 wx.getSystemInfoSync() 返回对象的 SDKVersion 判断基础库版本号 >= 2.8.2 后再使用该 API。每次调用该方法都会返回一个全新的实例。
  2842. * @param param
  2843. */
  2844. function createGameIcon(param: {
  2845. /**
  2846. * 推荐单元 id
  2847. */
  2848. adUnitId: string;
  2849. /**
  2850. * 游戏icon的数量,请注意,正式版下面渲染出来的icon数量会小于等于count,请注册做好样式兼容
  2851. */
  2852. count: number;
  2853. /**
  2854. * 数组的每一项可以针对对应的icon设置位置和样式等信息,style的每一项称为styleItem
  2855. */
  2856. style: Array<types.styleItem>;
  2857. }): iconAd;
  2858. /**
  2859. * 建格子广告实例,提前初始化
  2860. * @param param
  2861. */
  2862. function createGridAd(param: {
  2863. adUnitId: string;
  2864. adIntervals: number;
  2865. adTheme: string;
  2866. gridCount: number;
  2867. style: types.GridStyle;
  2868. })
  2869. /**
  2870. * 获取全局唯一的游戏画面录制对象
  2871. */
  2872. function getGameRecorder(): GameRecorder;
  2873. // --虚拟支付
  2874. /**
  2875. * 发起米大师支付
  2876. */
  2877. function requestMidasPayment(param: {
  2878. /**
  2879. * 支付的类型,不同的支付类型有各自额外要传的附加参数。
  2880. * game - 购买游戏币
  2881. */
  2882. mode: 'game';
  2883. /**
  2884. * 环境配置,默认值0
  2885. * 0 - 米大师正式环境
  2886. * 1 - 米大师沙箱环境
  2887. */
  2888. env?: 0 | 1;
  2889. /**
  2890. * 在米大师侧申请的应用 id
  2891. */
  2892. offerId: string;
  2893. /**
  2894. * 币种
  2895. */
  2896. currencyType: 'CNY';
  2897. /**
  2898. * 申请接入时的平台,platform 与应用id有关。
  2899. */
  2900. platform?: 'android';
  2901. /**
  2902. * 购买数量。mode=game 时必填。购买数量。详见 buyQuantity 限制说明。
  2903. * mode为game(购买游戏币)时,buyQuantity不可任意填写。需满足 buyQuantity * 游戏币单价 = 限定的价格等级。如:游戏币单价为 0.1 元,一次购买最少数量是 10。
  2904. * 有效价格等级如下:
  2905. * 价格等级(单位:人民币)
  2906. * 1
  2907. * 3
  2908. * 6
  2909. * 8
  2910. * 12
  2911. * 18
  2912. * 25
  2913. * 30
  2914. * 40
  2915. * 45
  2916. * 50
  2917. * 60
  2918. * 68
  2919. * 73
  2920. * 78
  2921. * 88
  2922. * 98
  2923. * 108
  2924. * 118
  2925. * 128
  2926. * 148
  2927. * 168
  2928. * 188
  2929. * 198
  2930. * 328
  2931. * 648
  2932. */
  2933. buyQuantity?: number;
  2934. /**
  2935. * 分区 ID
  2936. */
  2937. zoneId?: string;
  2938. success?: () => void;
  2939. /**
  2940. * @param res.errCode 有如下值:
  2941. * -1 系统失败
  2942. * -2 支付取消
  2943. * -15001 虚拟支付接口错误码,缺少参数
  2944. * -15002 虚拟支付接口错误码,参数不合法
  2945. * -15003 虚拟支付接口错误码,订单重复
  2946. * -15004 虚拟支付接口错误码,后台错误
  2947. * -15006 虚拟支付接口错误码,appId 权限被封禁
  2948. * -15006 虚拟支付接口错误码,货币类型不支持
  2949. * -15007 虚拟支付接口错误码,订单已支付
  2950. * 1 虚拟支付接口错误码,用户取消支付
  2951. * 2 虚拟支付接口错误码,客户端错误, 判断到小程序在用户处于支付中时,又发起了一笔支付请求
  2952. * 3 虚拟支付接口错误码,Android 独有错误:用户使用 Google Play 支付,而手机未安装 Google Play
  2953. * 4 虚拟支付接口错误码,用户操作系统支付状态异常
  2954. * 5 虚拟支付接口错误码,操作系统错误
  2955. * 6 虚拟支付接口错误码,其他错误
  2956. * 1000 参数错误
  2957. * 1003 米大师 Portal 错误
  2958. */
  2959. fail?: (res: { errMsg: string; errCode: number }) => void;
  2960. complete?: () => void;
  2961. }): void;
  2962. /**
  2963. * 阿拉丁统计
  2964. * @param event
  2965. * @param value
  2966. */
  2967. function aldSendEvent(event: string, value?: any): void;
  2968. var aldStage: aldStage;
  2969. var uma: uma;
  2970. }