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

375 lines
13 KiB
TypeScript
Raw Normal View History

/**
* @Author: Gongxh
* @Date: 2025-04-11
* @Description: API
*/
declare namespace BytedanceMiniprogram {
type IAnyObject = Record<string, any>
type GeneralSuccessCallback = (res: GeneralSuccessResult) => void;
type GeneralFailCallback = (res: GeneralFailResult) => void;
type GeneralCompleteCallback = (res: any) => void;
interface GeneralSuccessResult {
errMsg: string;
}
interface GeneralFailCodeResult {
errCode: number;
errMsg: string;
}
interface GeneralFailResult {
errMsg: string;
errNo?: number;
}
/** 获取版本信息和环境变量 */
interface EnvInfo {
/** 小程序信息 */
microapp: {
/** 小程序版本号 */
mpVersion: string;
/** 小程序环境 */
envType: string;
/** 小程序appId */
appId: string;
};
/** 插件信息 */
plugin: Record<string, unknown>;
/** 通用参数 */
common: {
/** 用户数据存储的路径 */
USER_DATA_PATH: string;
/** 校验白名单属性中的appInfoLaunchFrom后返回额外信息 */
location: string | undefined;
launchFrom: string | undefined;
schema: string | undefined;
};
}
interface SystemInfo {
/** 操作系统版本 */
system: string;
/** 操作系统类型 */
platform: string;
/** 手机品牌 */
brand: string;
/** 手机型号 */
model: string;
/** 宿主 App 版本号 */
version: string;
/**
* 宿 APP
*
* - Toutiao
* - Douyin )
* - news_article_lite )
* - live_stream
* - XiGua 西
* - PPX
*/
appName: string;
/** 客户端基础库版本 */
SDKVersion: string;
/** 屏幕宽度 */
screenWidth: number;
/** 屏幕高度 */
screenHeight: number;
/** 可使用窗口宽度 */
windowWidth: number;
/** 可使用窗口高度 */
windowHeight: number;
/** 设备像素比 */
pixelRatio: number;
/** 状态栏的高度,单位 px */
statusBarHeight: number;
/** 在竖屏正方向下的安全区域 */
safeArea: {
/** 安全区域左上角横坐标 */
left: number;
/** 安全区域右下角横坐标 */
right: number;
/** 安全区域左上角纵坐标 */
top: number;
/** 安全区域右下角纵坐标 */
bottom: number;
/** 安全区域的宽度,单位逻辑像素 */
width: number;
/** 安全区域的高度,单位逻辑像素 */
height: number;
};
}
interface LaunchParams {
/**
*
* @version 1.12.0
*/
path: string;
/**
*
* @version 1.12.0
*/
scene: string;
/**
*
* @version 1.12.0
*/
query: object;
/**
* {}
* @version 1.15.0
*/
referrerInfo: {
/** 来源小程序的 appId */
appId: string;
/** 来源小程序传过来的数据,场景值为 011009 或 011010 时支持。 */
extraData: object;
};
/**
* 10 schema0
* @version 1.90.0
*/
showFrom: number;
}
interface SocketTask {
/**
* Socket code
* , undefined
*/
readonly readyState?: 0 | 1 | 2 | 3;
/** 表示 Socket 正在连接的常量 */
readonly CONNECTING: 0;
/** 表示 Socket 连接已经打开的常量 */
readonly OPEN: 1;
/** 表示 Socket 连接关闭中的常量 */
readonly CLOSING: 2;
/** 表示 Socket 连接已关闭的常量 */
readonly CLOSED: 3;
/**
* ### WebSocket
*/
send: (res: {
data: string | ArrayBuffer,
success?: GeneralSuccessCallback,
fail?: GeneralFailCallback,
complete?: GeneralCompleteCallback
}) => void;
/** ### 关闭 WebSocket 连接的方法。 */
close: (res: {
code?: number,
reason?: string,
success?: GeneralSuccessCallback,
fail?: GeneralFailCallback,
complete?: GeneralCompleteCallback
}) => void;
/**
* ### WebSocket
* WebSocket open
*/
onOpen: (
callback: (res: {
/** 连接服务器返回的 Response Header */
header: Record<string, unknown>;
/** 使用的网络传输层协议 */
protocolType: string;
/** websocket 类型 */
socketType: "ttnet" | "tradition";
}) => void
) => void;
/** 监听 WebSocket 与服务器的连接断开的事件 */
onClose: (
callback: (res: {
/** 使用的网络传输层协议 */
protocolType: string;
/** websocket 类型 */
socketType: string;
/** 错误信息 */
errMsg: string;
/** 关闭原因 */
reason: string;
/** 关闭 code */
code: string;
}) => void
) => void;
/** ### 监听 WebSocket 接收到服务器发送信息的事件。 */
onMessage: (
callback: (res: {
/** 接收到的服务器消息 */
data: string | ArrayBuffer;
/** websocket 使用的协议 */
protocolType: string;
/** websocket 类型 */
socketType: "ttnet" | "tradition";
}) => void
) => void;
/** ### 监听 WebSocket 发生错误的事件 */
onError: (
callback: (res: {
/** 错误信息 */
errMsg: string;
}) => void
) => void;
}
interface RewardedVideoAd {
/** 广告创建后默认是隐藏的,可以通过该方法显示广告 */
show: () => Promise<any>;
/** 当广告素材加载出现错误时,可以通过 load 方法手动加载 */
load: () => Promise<any>;
/** 绑定广告 load 事件的监听器 */
onLoad: (fn: Callback) => void;
/** 解除绑定 load 事件的监听器 */
offLoad: (fn: Callback) => void;
/** 绑定 error 事件的监听器 */
onError: (fn: (data: GeneralFailCodeResult) => void) => void;
/** 解除绑定 error 事件的监听器 */
onClose: (fn: (data: { isEnded: boolean, count?: number }) => void) => void;
/** 绑定 close 事件的监听器 */
offClose: (fn: Callback) => void;
}
interface CreateRewardedVideoAdOption {
/** 广告位 id */
adUnitId: string;
/** 是否开启再得广告模式(只支持安卓系统的抖音和抖音极速版) */
multiton?: boolean;
/**
* 广广1xx
* xx multitonRewardMsg 7
* multiton true
*/
multitonRewardMsg?: string[];
/**
* 广 1-4multiton true
*/
multitonRewardTimes?: number;
/**
* 广N个获得xx 1xx
* N 广
*/
progressTip?: boolean;
}
interface IPaymentOptions {
/** 支付的类型, 目前仅为"game" */
mode: "game";
/** 环境配置,目前合法值仅为"0" */
env: 0;
/** 货币类型,目前合法值仅为"CNY" */
currencyType: "CNY";
/** 申请接入时的平台,目前仅为"android" */
platform: "android";
/**
* * =
* goodType为游戏币场景时必传
*/
buyQuantity?: number;
/**
* id"1" ID ID "_"
*/
zoneId?: string;
/**
*
*
*/
customId: string;
/** 游戏开发者自定义的其他信息,订单支付成功后通过服务端支付结果回调回传。字符串长度最大不能超过 256。 */
extraInfo?: string;
/** 支付场景 默认:0 */
goodType?: number;
/** goodType为道具直购场景时必传代表道具现金价格单位为【分】如道具价格为0.1元则回传10 */
orderAmount?: string;
/** goodType为道具直购场景时代表道具名称长度限制小于等于10个字符用于区分道具类型 */
goodName?: string;
success?: (res: GeneralSuccessResult) => void;
fail?: (res: GeneralFailCodeResult) => void;
complete?: (res: any) => void;
}
interface IAwemeCustomerOptions {
/** 游戏开发者自定义的其他信息,订单支付成功后通过服务端支付结果回调回传。字符串长度最大不能超过 256。强烈建议传入 */
extraInfo?: string;
/**
* id"1" ID ID "_"
*/
zoneId?: string;
/** 币种目前仅为“DIAMOND” */
currencyType: "DIAMOND" | "CNY";
/**
* * =
* goodType为游戏币场景时必传
*/
buyQuantity?: number;
/** 支付场景 默认:0 */
goodType?: number;
/** goodType为道具直购场景时必传代表道具现金价格单位为【分】如道具价格为0.1元则回传10 */
orderAmount?: string;
/** goodType为道具直购场景时代表道具名称长度限制小于等于10个字符用于区分道具类型 */
goodName?: string;
/**
*
*
*/
customId: string;
success?: (res: GeneralSuccessResult) => void;
fail?: (res: GeneralFailResult) => void;
complete?: (res: any) => void;
}
interface TT {
getEnvInfoSync(): EnvInfo;
getSystemInfoSync(): SystemInfo;
getLaunchOptionsSync(): LaunchParams;
exitMiniProgram(res: {
success?: GeneralSuccessCallback,
fail?: GeneralFailCallback,
complete?: GeneralCompleteCallback
}): void;
setClipboardData(res: {
data: string,
success?: GeneralSuccessCallback,
fail?: GeneralFailCallback,
complete?: GeneralCompleteCallback
}): void;
connectSocket(res: {
/** Socket 连接地址 */
url: string;
/** 请求头 */
header?: Record<string, string>;
/** 子协议 */
protocols?: string[];
success?: (res: { socketTaskId: number }) => void,
fail?: GeneralFailCallback,
complete?: GeneralCompleteCallback
}): SocketTask;
// requestMidasPayment(res: MidasPaymentOption): void;
createRewardedVideoAd(option: CreateRewardedVideoAdOption): RewardedVideoAd;
/** 支付 */
requestGamePayment(res: IPaymentOptions): void;
/** 发起抖音钻石支付 */
openAwemeCustomerService(res: IAwemeCustomerOptions): void;
}
}
declare const tt: BytedanceMiniprogram.TT