kunpolibrary/libs/lib.wx.api.d.ts

662 lines
27 KiB
TypeScript
Raw Normal View History

/**
* @Author: Gongxh
* @Date: 2025-03-28
* @Description:
*/
declare namespace WechatMiniprogram {
type IAnyObject = Record<string, any>
interface ICommonCallBack {
/**
*
*/
success?: () => void;
/**
*
*/
fail?: () => void;
/**
*
*/
complete?: () => void;
}
interface GeneralCallbackResult {
/** 错误信息 */
errMsg: string
}
interface ConnectSocketOption extends ICommonCallBack {
/** 开发者服务器 wss 接口地址 */
url: string
/** HTTP HeaderHeader 中不能设置 Referer */
header?: IAnyObject
/**
* : '1.4.0'
*
*/
protocols?: string[]
/**
* : '2.4.0'
* TCP TCP_NODELAY
*/
tcpNoDelay?: boolean
/**
* : '2.8.0'
*
*/
perMessageDeflate?: boolean
/**
* : '2.10.0'
*
*/
timeout?: number
/**
* : '2.29.0'
* 使
*/
forceCellularNetwork?: boolean
}
/**
* `2.10.4`
*
*/
interface SocketProfile {
/** 组件准备好使用 SOCKET 建立请求的时间,这发生在检查本地缓存之前 */
fetchStart: number;
/** DNS 域名查询开始的时间,如果使用了本地缓存(即无 DNS 查询)或持久连接,则与 fetchStart 值相等 */
domainLookupStart: number;
/** DNS 域名查询完成的时间,如果使用了本地缓存(即无 DNS 查询)或持久连接,则与 fetchStart 值相等 */
domainLookupEnd: number;
/** 开始建立连接的时间,如果是持久连接,则与 fetchStart 值相等。注意如果在传输层发生了错误且重新建立连接,则这里显示的是新建立的连接开始的时间 */
connectStart: number;
/** 完成建立连接的时间(完成握手),如果是持久连接,则与 fetchStart 值相等。注意如果在传输层发生了错误且重新建立连接则这里显示的是新建立的连接完成的时间。注意这里握手结束包括安全连接建立完成、SOCKS 授权通过 */
connectEnd: number;
/** 单次连接的耗时,包括 connect tls */
rtt: number;
/** 握手耗时 */
handshakeCost: number;
/** 上层请求到返回的耗时 */
cost: number;
}
interface SocketSendOption extends ICommonCallBack {
/** 需要发送的消息 */
data: string | ArrayBuffer;
}
interface SocketCloseOption extends ICommonCallBack {
/**
* 1000
*
*/
code?: number;
/**
*
* 123 UTF-8
*/
reason?: string;
}
interface SocketTask {
/**
*
* @param data
*/
send(res: SocketSendOption): void
/**
* WebSocket
* @param code
* @param reason
*/
close(res: SocketCloseOption): void
/**
* WebSocket
* @param listener
*/
onOpen(listener: (res: { header: IAnyObject, profile: SocketProfile }) => void): void
/**
* WebSocket
* @param listener
* @param res.data
*/
onMessage(listener: (res: { data: string | ArrayBuffer }) => void): void
/**
* WebSocket
* @param listener
* @param res.errMsg
*/
onError(listener: (res: { errMsg: string }) => void): void
/**
* WebSocket
* @param listener
* @param res.code
* @param res.reason
*/
onClose(listener: (res: { code: number, reason: string }) => void): void
}
interface Wx {
connectSocket(option: ConnectSocketOption): SocketTask
}
/** 启动参数 */
interface LaunchOptionsApp {
/** `2.20.0`
*
* API
*
*
* - 'default': ;
* - 'nativeFunctionalized': ;
* - 'browseOnly': ;
* - 'embedded': ; */
apiCategory:
| 'default'
| 'nativeFunctionalized'
| 'browseOnly'
| 'embedded'
/** 打开的文件信息数组只有从聊天素材场景打开scene为1173才会携带该参数 */
forwardMaterials: ForwardMaterials[]
/** 启动小程序的路径 (代码包路径) */
path: string
/** 启动小程序的 query 参数 */
query: Record<string, string>
/** 来源信息。从另一个小程序、公众号或 App 进入小程序时返回。否则返回 `{}`。(参见后文注意) */
referrerInfo: ReferrerInfo
/** 启动小程序的[场景值](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/scene.html) */
scene: number
/** /chatType /
*
*
* - 1: 微信联系人单聊;
* - 2: 企业微信联系人单聊;
* - 3: 普通微信群聊;
* - 4: 企业微信互通群聊; */
chatType?: 1 | 2 | 3 | 4
/** shareTicket详见[获取更多转发信息](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
shareTicket?: string
}
/** 当前小程序运行的宿主环境 */
interface AppBaseInfoHost {
/** 宿主 app第三方App 对应的 appId 当小程序运行在第三方App环境时才返回 */
appId: string
}
interface AppBaseInfo {
/** 客户端基础库版本 */
SDKVersion: string
/** 是否已打开调试。可通过右上角菜单或 [wx.setEnableDebug](https://developers.weixin.qq.com/miniprogram/dev/api/base/debug/wx.setEnableDebug.html) 打开调试。 */
enableDebug: boolean
/** 当前小程序运行的宿主环境 */
host: AppBaseInfoHost
/** 微信设置的语言 */
language: string
/** 微信版本号 */
version: string
/** `light``dark``"darkmode":true` undefined
*
*
* - 'dark': ;
* - 'light': ; */
theme?: 'dark' | 'light'
}
interface SafeArea {
/** 安全区域右下角纵坐标 */
bottom: number
/** 安全区域的高度,单位逻辑像素 */
height: number
/** 安全区域左上角横坐标 */
left: number
/** 安全区域右下角横坐标 */
right: number
/** 安全区域左上角纵坐标 */
top: number
/** 安全区域的宽度,单位逻辑像素 */
width: number
}
interface WindowInfo {
/** 设备像素比 */
pixelRatio: number
/** 在竖屏正方向下的安全区域。部分机型没有安全区域概念,也不会返回 safeArea 字段,开发者需自行兼容。 */
safeArea: SafeArea
/** 屏幕高度单位px */
screenHeight: number
/** 窗口上边缘的y值 */
screenTop: number
/** 屏幕宽度单位px */
screenWidth: number
/** 状态栏的高度单位px */
statusBarHeight: number
/** 可使用窗口高度单位px */
windowHeight: number
/** 可使用窗口宽度单位px */
windowWidth: number
}
interface SystemInfo {
/** `1.1.0`
*
* */
SDKVersion: string
/** `2.6.0`
*
* 使 iOS */
albumAuthorized: boolean
/** `1.8.0`
*
* Android-2 0-1>=1<br> IDE */
benchmarkLevel: number
/** `2.6.0`
*
* */
bluetoothEnabled: boolean
/** `1.5.0`
*
* */
brand: string
/** `2.6.0`
*
* 使 */
cameraAuthorized: boolean
/**
*
*
* - 'portrait': ;
* - 'landscape': ; */
deviceOrientation: 'portrait' | 'landscape'
/** `2.15.0`
*
* [wx.setEnableDebug](https://developers.weixin.qq.com/miniprogram/dev/api/base/debug/wx.setEnableDebug.html) 打开调试。 */
enableDebug: boolean
/** `1.5.0`
*
* px--- */
fontSizeSetting: number
/** `2.12.3`
*
* 宿 */
host: SystemInfoHost
/** 微信设置的语言 */
language: string
/** `2.6.0`
*
* 使 */
locationAuthorized: boolean
/** `2.6.0`
*
* */
locationEnabled: boolean
/** `true` 表示模糊定位,`false` 表示精确定位,仅 iOS 支持 */
locationReducedAccuracy: boolean
/** `2.6.0`
*
* 使 */
microphoneAuthorized: boolean
/** 设备型号。新机型刚推出一段时间会显示unknown微信会尽快进行适配。 */
model: string
/** `2.6.0`
*
* iOS */
notificationAlertAuthorized: boolean
/** `2.6.0`
*
* */
notificationAuthorized: boolean
/** `2.6.0`
*
* iOS */
notificationBadgeAuthorized: boolean
/** `2.6.0`
*
* iOS */
notificationSoundAuthorized: boolean
/** `2.19.3`
*
* 使 */
phoneCalendarAuthorized: boolean
/** 设备像素比 */
pixelRatio: number
/**
*
*
* - 'ios': iOS微信 iPhoneiPad;
* - 'android': Android微信;
* - 'windows': Windows微信;
* - 'mac': macOS微信;
* - 'devtools': ; */
platform: 'ios' | 'android' | 'windows' | 'mac' | 'devtools'
/** `2.7.0`
*
* safeArea */
safeArea: SafeArea
/** `1.1.0`
*
* px */
screenHeight: number
/** `1.1.0`
*
* px */
screenWidth: number
/** `1.9.0`
*
* px */
statusBarHeight: number
/** 操作系统及版本 */
system: string
/** 微信版本号 */
version: string
/** `2.6.0`
*
* Wi-Fi */
wifiEnabled: boolean
/** 可使用窗口高度单位px */
windowHeight: number
/** 可使用窗口宽度单位px */
windowWidth: number
/** `2.11.0`
*
* `light``dark``"darkmode":true` undefined
*
*
* - 'dark': ;
* - 'light': ; */
theme?: 'dark' | 'light'
}
interface DeviceInfo {
/** 应用微信APP二进制接口类型仅 Android 支持) */
abi: string
/** 设备性能等级(仅 Android 支持)。取值为:-2 或 0该设备无法运行小游戏-1性能未知>=1设备性能值该值越高设备性能越好目前最高不到50 */
benchmarkLevel: number
/** 设备品牌 */
brand: string
/** `2.29.0`
*
* CPU Android Tips: GPU WebGLRenderingContext.getExtension('WEBGL_debug_renderer_info') */
cpuType: string
/** `2.25.1`
*
* Android */
deviceAbi: string
/** `2.30.0`
*
* MB */
memorySize: string
/** 设备型号。新机型刚推出一段时间会显示unknown微信会尽快进行适配。 */
model: string
/** 客户端平台 */
platform: string
/** 操作系统及版本 */
system: string
}
/** 小程序账号信息 */
interface MiniProgram {
/** 小程序 appId */
appId: string
/** `2.10.0`
*
*
*
*
* - 'develop': ;
* - 'trial': ;
* - 'release': ; */
envVersion: 'develop' | 'trial' | 'release'
/** `2.10.2`
*
* 线 */
version: string
}
/** 插件账号信息(仅在插件中调用时包含这一项) */
interface Plugin {
/** 插件 appId */
appId: string
/** 插件版本号 */
version: string
}
/** 账号信息 */
interface AccountInfo {
/** 小程序账号信息 */
miniProgram: MiniProgram
/** 插件账号信息(仅在插件中调用时包含这一项) */
plugin: Plugin
}
interface MidasPaymentOption {
/** 支付的类型,不同的支付类型有各自额外要传的附加参数 */
mode: "game",
/** 是否为沙盒环境 0: 正式环境 1: 沙盒环境 */
env?: 0 | 1,
/** 商户号 在米大师侧申请的应用id */
offerId: string,
/** 货币类型 */
currencyType: "CNY",
/** 申请接入时的平台platform 与应用id有关 */
platform?: "android" | "windows",
/** 购买数量。mode=game 时必填。购买数量 */
buyQuantity: number,
/** 分区ID 默认1 */
zoneId?: string,
/**
* 使使32_-|*线)wx.requestMidasPayment都换新的outTradeNo线
*/
outTradeNo: string,
/** 接口调用成功的回调函数 */
success?: (res: { errMsg: string }) => void,
/** 接口调用失败的回调函数 */
fail?: (res: { errCode: number, errMsg: string, errno: number }) => void,
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: () => void;
}
interface RewardedVideoAdOnCloseListenerResult {
/** `2.1.0`
*
* */
isEnded: boolean
}
interface RewardedVideoAdOnErrorListenerResult {
/** `2.2.2`
*
*
*
*
* - 1000: 后端接口调用失败;
* - 1001: 参数错误;
* - 1002: 广告单元无效;
* - 1003: 内部错误;
* - 1004: 无合适的广告;
* - 1005: 广告组件审核中;
* - 1006: 广告组件被驳回;
* - 1007: 广告组件被封禁;
* - 1008: 广告单元已关闭; */
errCode: 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008
/** 错误信息 */
errMsg: string
}
/** onClose 传入的监听函数。不传此参数则移除所有监听函数。 */
type RewardedVideoAdOffCloseCallback = (
result: RewardedVideoAdOnCloseListenerResult
) => void
/** onError 传入的监听函数。不传此参数则移除所有监听函数。 */
type RewardedVideoAdOffErrorCallback = (
result: RewardedVideoAdOnErrorListenerResult
) => void
/** 用户点击 `关闭广告` 按钮的事件的监听函数 */
type RewardedVideoAdOnCloseCallback = (
result: RewardedVideoAdOnCloseListenerResult
) => void
/** 激励视频错误事件的监听函数 */
type RewardedVideoAdOnErrorCallback = (
result: RewardedVideoAdOnErrorListenerResult
) => void
/** onLoad 传入的监听函数。不传此参数则移除所有监听函数。 */
type OffLoadCallback = (res: GeneralCallbackResult) => void
type OnLoadCallback = (res: GeneralCallbackResult) => void
interface RewardedVideoAd {
/**
* [Promise RewardedVideoAd.load()](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.load.html)
* 使
* 广 */
load(): Promise<any>
/**
* [Promise RewardedVideoAd.show()](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.show.html)
* 使
* 广广 */
show(): Promise<any>
/**
* [RewardedVideoAd.destroy()](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.destroy.html)
* `2.8.0`
* 使
* 广 */
destroy(): void
/**
* [RewardedVideoAd.offClose(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.offClose.html)
* 使
* `关闭广告`
*
* ****
*
* ```js
* const listener = function (res) { console.log(res) }
*
* RewardedVideoAd.onClose(listener)
* RewardedVideoAd.offClose(listener) // 需传入与监听时同一个的函数对象
* ```
*/
offClose(
/** onClose 传入的监听函数。不传此参数则移除所有监听函数。 */
listener?: RewardedVideoAdOffCloseCallback
): void
/**
* [RewardedVideoAd.offError(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.offError.html)
* 使
*
*
* ****
*
* ```js
* const listener = function (res) { console.log(res) }
*
* RewardedVideoAd.onError(listener)
* RewardedVideoAd.offError(listener) // 需传入与监听时同一个的函数对象
* ```
*/
offError(
/** onError 传入的监听函数。不传此参数则移除所有监听函数。 */
listener?: RewardedVideoAdOffErrorCallback
): void
/**
* [RewardedVideoAd.offLoad(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.offLoad.html)
* 使
* 广
* ****
* ```js
* const listener = function (res) { console.log(res) }
*
* RewardedVideoAd.onLoad(listener)
* RewardedVideoAd.offLoad(listener) // 需传入与监听时同一个的函数对象
* ```
*/
offLoad(
/** onLoad 传入的监听函数。不传此参数则移除所有监听函数。 */
listener?: OffLoadCallback
): void
/**
* [RewardedVideoAd.onClose(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.onClose.html)
* 使
* `关闭广告` */
onClose(
/** 用户点击 `关闭广告` 按钮的事件的监听函数 */
listener: RewardedVideoAdOnCloseCallback
): void
/**
* [RewardedVideoAd.onError(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.onError.html)
* 使
*
*
* ****
*
* onError获取到的错误信息
* 线[](https://mp.weixin.qq.com/)里面搜寻错误日志,还可以针对异常返回加上适当的监控信息。
*
* | | | | |
* | ------ | -------------- | --------------- | -------------------------- |
* | 1000 | | | |
* | 1001 | | 使 | developers.weixin.qq.com确认具体教程|
* | 1002 | 广 | APP的广告ID | mp.weixin.qq.com确认广告位ID |
* | 1003 | | | |
* | 1004 | 广 | 广广 | |
* | 1005 | 广 | 广广 | mp.weixin.qq.com确认审核状态|
* | 1006 | 广 | 广广 | mp.weixin.qq.com确认审核状态|
* | 1007 | 广 | 广广 | mp.weixin.qq.com确认小程序广告封禁状态 |
* | 1008 | 广 | 广广 | mp.weixin.qq.com重新打开对应广告位的展现| */
onError(
/** 激励视频错误事件的监听函数 */
listener: RewardedVideoAdOnErrorCallback
): void
/**
* [RewardedVideoAd.onLoad(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.onLoad.html)
* 使
* 广 */
onLoad(
/** 激励视频广告加载事件的监听函数 */
listener: OnLoadCallback
): void
}
interface CreateRewardedVideoAdOption {
/** 广告单元 id */
adUnitId: string
/**
* `2.8.0`
* false
*/
multiton?: boolean
}
interface Wx {
getLaunchOptionsSync(): LaunchOptionsApp;
getEnterOptionsSync(): LaunchOptionsApp;
getWindowInfo(): WindowInfo;
getAppBaseInfo(): AppBaseInfo;
getSystemInfoSync(): SystemInfo;
getDeviceInfo(): DeviceInfo;
getAccountInfoSync(): AccountInfo;
exitMiniProgram(): void;
setClipboardData(res: { data: string, fail: (res: GeneralCallbackResult) => void }): void;
requestMidasPayment(res: MidasPaymentOption): void;
/**
* [[RewardedVideoAd](https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.html) wx.createRewardedVideoAd(Object object)](https://developers.weixin.qq.com/miniprogram/dev/api/ad/wx.createRewardedVideoAd.html)
* `2.0.4`
* 使 `2.8.1`
*
* 广 [wx.getSystemInfoSync()](https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html) 返回对象的 SDKVersion 判断基础库版本号后再使用该 API小游戏端要求 >= 2.0.4 小程序端要求 >= 2.6.0)。调用该方法创建的激励视频广告是一个单例(小游戏端是全局单例,小程序端是页面内单例,在小程序端的单例对象不允许跨页面使用)。
*/
createRewardedVideoAd(option: CreateRewardedVideoAdOption): RewardedVideoAd
}
}
declare const wx: WechatMiniprogram.Wx