提交 977975a1 作者: wj

更新抖音SDK

上级 f38ca34a
const SDKConfig:SDKCONFIG = {
appid: "tt08807e3d97bcb9da02", // 换openid
appName: "推广部测试应用", // 应用名称
productCode: "60d2d227d2ee4d0b15104306ff036710", // 产品code
productKey: "7f106e865646c5077229c015c8e84a81", // 产品key,用于生成签名
appVersion: "产品版本号(cp)", // 产品版本号
}
declare interface SDKCONFIG {
appid: string
appName: string
productCode: string
productKey: string
appVersion?: string
}
\ No newline at end of file
/** /**
* 鲸鱼游戏头条/抖音小游戏接入库 * 鲸鱼游戏头条/抖音小游戏接入库
* @author 推广技术部 * @author 推广技术部
* @time: 2023-07-21 * @time: 2023-07-25
*/ */
export class TTSDK { class TTSDK {
private static sdkVersion: string = '2.0.1'; private sdkVersion: string = '2.0.2';
private static appInfo: AppInfo; private appInfo: AppInfo;
private static isBind = 0; // 是否已经绑定过其他角色 private isBind = 0; // 是否已经绑定过其他角色
public static LaunchOptions: any; // 启动参数对象 public LaunchOptions: any; // 启动参数对象
public static SystemInfo: any; // 设备信息 public SystemInfo: any; // 设备信息
public static LoginData: any; // 登录信息 public LoginData: any; // 登录信息
private static clickCounter = 0; // 当前用户点击次数 private clickCounter: number = 0; // 当前用户点击次数
private static contrlShareMenu: number = 0; // 右上角分享开关 private contrlShareMenu: number = 0; // 右上角分享开关
/** constructor() {
* SDK初始化接口 console.log("当前加载SDK版本号为:", this.sdkVersion);
* @param appInfo 必传产品参数 this.sdkInit();
* @param retry 重连次数 }
* @returns { code:number, message:string }
*/ private sdkInit = async () => {
public static SDKInit = async (appInfo: AppInfo, retry = 0): Promise<any> => {
this.appInfo = appInfo;
this.SDKCOMMDATA["product_code"] = appInfo.productCode;
if (retry == 0) {
console.info("当前加载SDK版本号为:", TTSDK.sdkVersion);
this.LaunchOptions = await this.getOptionsInfo(); this.LaunchOptions = await this.getOptionsInfo();
this.SystemInfo = await this.getSystemInfo(); this.SystemInfo = await this.getSystemInfo();
this.SystemInfo["networkType"] = await this.getNetworkType(); this.SystemInfo["networkType"] = await this.getNetworkType();
this.SDKCOMMDATA["os"] = this.SystemInfo["system"].split(" ")[0].toLowerCase(); this.SDKCOMMDATA["os"] = this.SystemInfo["system"].split(" ")[0].toLowerCase();
} }
public Login = async (retry = 0) => {
if (retry > 2) { if (retry > 2) {
this.showMsg("登录异常,请联系客服."); this.showMsg("登录异常,请联系客服.");
return { error: "登录超时.." }; return { error: "登录超时.." };
...@@ -37,9 +34,9 @@ export class TTSDK { ...@@ -37,9 +34,9 @@ export class TTSDK {
const ttUser = await this.ttLogin(false); const ttUser = await this.ttLogin(false);
let { code, data, msg } = await this.sdkRequest(ttLinks.init, { let { code, data, msg } = await this.sdkRequest(ttLinks.init, {
...this.SDKCOMMDATA, ...this.SDKCOMMDATA,
appid: appInfo.appid, appid: SDKConfig.appid,
anonymous_code: ttUser.anonymousCode || '', anonymous_code: ttUser.anonymousCode || '',
code: ttUser.code, code: ttUser.code || '',
}); });
if (!code) { if (!code) {
this.LoginData = { ...data }; this.LoginData = { ...data };
...@@ -50,25 +47,22 @@ export class TTSDK { ...@@ -50,25 +47,22 @@ export class TTSDK {
console.error("SDK初始化异常:", msg); console.error("SDK初始化异常:", msg);
// 登录失败发起重连 // 登录失败发起重连
retry += 1; retry += 1;
this.SDKInit(appInfo, retry); this.Login(retry);
} }
private static SDKActive = async (): Promise<any> => { private SDKActive = async (): Promise<any> => {
const { code, data, msg } = await this.sdkRequest(ttLinks.active, { ...this.SDKCOMMDATA, ...this.LoginData }); const { data } = await this.sdkRequest(ttLinks.active, { ...this.SDKCOMMDATA, ...this.LoginData });
if (!code) {
this.LoginData["pay_channel"] = data.default_pay_channel; this.LoginData["pay_channel"] = data.default_pay_channel;
this.LoginData["ad_unit_id"] = data.ad_unit_id; this.LoginData["ad_unit_id"] = data.ad_unit_id;
this.LoginData["game_club"] = data.game_club; this.LoginData["game_club"] = data.game_club;
this.contrlShareMenu = data.share; this.contrlShareMenu = data.share;
this.ActiReport(); // 上报激活 this.ActiReport(); // 上报激活
return { code: 0, message: 'SDK激活完成.' }; return this.SDKLogin();
} else
return { code: code, message: msg };
} }
/** /**
* SDK登录接口 * SDK登录接口
* @returns SDK登录信息 * @returns SDK登录信息
*/ */
public static SDKLogin = async (): Promise<any> => { private SDKLogin = async (): Promise<any> => {
delete this.LoginData["token"]; // 强制清空登录toekn delete this.LoginData["token"]; // 强制清空登录toekn
const { data, msg, code } = await this.sdkRequest(ttLinks.login, { ...this.SDKCOMMDATA, ...this.LoginData }); const { data, msg, code } = await this.sdkRequest(ttLinks.login, { ...this.SDKCOMMDATA, ...this.LoginData });
if (Object.keys(data).length == 0) { if (Object.keys(data).length == 0) {
...@@ -90,22 +84,19 @@ export class TTSDK { ...@@ -90,22 +84,19 @@ export class TTSDK {
origin_open_id, origin_open_id,
}))(this.LoginData); }))(this.LoginData);
return { return {
code: 0,
data: {
...filters, ...filters,
os: this.SDKCOMMDATA["os"], // 返回系统类型IOS或者android os: this.SDKCOMMDATA["os"], // 返回系统类型IOS或者android
scene: this.LaunchOptions["scene"], // 用户来源场景值 scene: this.LaunchOptions["scene"], // 用户来源场景值
from_appid: this.LaunchOptions["appId"] || this.LaunchOptions["appid"], from_appid: this.LaunchOptions["appId"] || this.LaunchOptions["appid"],
launchOptions: this.LaunchOptions, launchOptions: this.LaunchOptions,
user_status: data.user_status || 0, user_status: data.user_status || 0,
}
}; };
} }
/** /**
* SDK支付接口 * SDK支付接口
* @returns { code: number, message: string } * @returns { code: number, message: string }
*/ */
public static payOrder = async (Params: PaymentData): Promise<any> => { public payOrder = async (Params: PaymentData): Promise<any> => {
if (this.isBind == 1) { if (this.isBind == 1) {
const msg = { const msg = {
title: '提示', title: '提示',
...@@ -176,12 +167,12 @@ export class TTSDK { ...@@ -176,12 +167,12 @@ export class TTSDK {
} }
} }
// 通知服务端扣费 // 通知服务端扣费
private static getCoins = async (orderParams: any) => { private getCoins = async (orderParams: any) => {
console.log("通知扣费:", orderParams); console.log("通知扣费:", orderParams);
return await this.sdkRequest(ttLinks.pay, orderParams); return await this.sdkRequest(ttLinks.pay, orderParams);
}; };
private static SDKQuickLogin = async (): Promise<any> => { private SDKQuickLogin = async (): Promise<any> => {
let ttLoginData = await this.ttLogin(true); let ttLoginData = await this.ttLogin(true);
if (ttLoginData.status == -1) { if (ttLoginData.status == -1) {
this.showMsg("用户取消登录."); this.showMsg("用户取消登录.");
...@@ -204,7 +195,7 @@ export class TTSDK { ...@@ -204,7 +195,7 @@ export class TTSDK {
} }
} }
private static checkUserLogin = async (): Promise<any> => { private checkUserLogin = async (): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(tt as any).checkSession({ (tt as any).checkSession({
success(res: any) { success(res: any) {
...@@ -217,7 +208,7 @@ export class TTSDK { ...@@ -217,7 +208,7 @@ export class TTSDK {
}); });
} }
// 头条登录逻辑 // 头条登录逻辑
private static ttLogin = (showLoginView: boolean): Promise<any> => { private ttLogin = (showLoginView: boolean): Promise<any> => {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
(tt as any).login({ (tt as any).login({
success: (res: any) => { success: (res: any) => {
...@@ -231,7 +222,7 @@ export class TTSDK { ...@@ -231,7 +222,7 @@ export class TTSDK {
}); });
} }
public static getOptionsInfo = async (): Promise<any> => { public getOptionsInfo = async (): Promise<any> => {
const options: any = (tt as any).getLaunchOptionsSync(); const options: any = (tt as any).getLaunchOptionsSync();
console.log("游戏启动参数--->", options); console.log("游戏启动参数--->", options);
if (options.query && Object.keys(options.query).length > 0) { if (options.query && Object.keys(options.query).length > 0) {
...@@ -244,7 +235,7 @@ export class TTSDK { ...@@ -244,7 +235,7 @@ export class TTSDK {
return { ...options.referrerInfo.extraData, scene: options["scene"] || "", appId: options.referrerInfo.appId }; // 小程序跳转附带参数 return { ...options.referrerInfo.extraData, scene: options["scene"] || "", appId: options.referrerInfo.appId }; // 小程序跳转附带参数
} else return {}; } else return {};
} }
public static getSystemInfo = (): Promise<any> => { public getSystemInfo = (): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(tt as any).getSystemInfo({ (tt as any).getSystemInfo({
success: (res: any) => { success: (res: any) => {
...@@ -253,7 +244,7 @@ export class TTSDK { ...@@ -253,7 +244,7 @@ export class TTSDK {
}); });
}); });
}; };
public static getNetworkType = (): Promise<any> => { public getNetworkType = (): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(tt as any).getNetworkType({ (tt as any).getNetworkType({
success: (res: any) => { success: (res: any) => {
...@@ -263,28 +254,28 @@ export class TTSDK { ...@@ -263,28 +254,28 @@ export class TTSDK {
}); });
}; };
private static sdkRequest = async (link: string, portData: any, method?: any): Promise<any> => { private sdkRequest = async (link: string, portData: any, method?: any): Promise<any> => {
portData = this.md5_sign(portData); // 附上签名参数 portData = this.md5_sign(portData); // 附上签名参数
// console.log("SDK接口:", portData); // console.log("SDK接口:", portData);
return await this.request(link, portData, method); return await this.request(link, portData, method);
}; };
// SDK接口签名方法 // SDK接口签名方法
private static md5_sign(obj: any) { private md5_sign(obj: any) {
obj.time = Date.parse(new Date().toString()) // 获取请求的时间戳秒 obj.time = Date.parse(new Date().toString()) // 获取请求的时间戳秒
let keys = Object.keys(obj).sort(); let keys = Object.keys(obj).sort();
let key_url = ""; let key_url = "";
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
if (keys[i] != 'sign') key_url += keys[i] + '=' + obj[keys[i]] + '&' if (keys[i] != 'sign') key_url += keys[i] + '=' + obj[keys[i]] + '&'
} }
key_url = key_url + this.appInfo.productKey key_url = key_url + SDKConfig.productKey
obj.sign = md5(key_url) obj.sign = md5(key_url)
return obj return obj
} }
private static request = async (URI: string, Params: any, Method = "GET") => { private request = async (URI: string, Params: any, Method = "GET") => {
const { code, data, msg } = await this.fetchUri(URI, Params, Method); const { code, data, msg } = await this.fetchUri(URI, Params, Method);
return { code, data: !data ? {} : data, msg }; return { code, data: !data ? {} : data, msg };
}; };
private static fetchUri = (URI: string, DATA: any, METHOD: string): Promise<any> => { private fetchUri = (URI: string, DATA: any, METHOD: string): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
(tt as any).request({ (tt as any).request({
...@@ -305,7 +296,7 @@ export class TTSDK { ...@@ -305,7 +296,7 @@ export class TTSDK {
}); });
}; };
//把字符串转换成json //把字符串转换成json
private static toJson = (str: string) => { private toJson = (str: string) => {
let json: any = {}; let json: any = {};
const jsonArr = str.split("&"); const jsonArr = str.split("&");
for (let i = 0; i < jsonArr.length; i++) { for (let i = 0; i < jsonArr.length; i++) {
...@@ -315,21 +306,21 @@ export class TTSDK { ...@@ -315,21 +306,21 @@ export class TTSDK {
return json; return json;
}; };
private static showModal(DATA: any) { private showModal(DATA: any) {
(tt as any).showModal({ (tt as any).showModal({
...DATA, ...DATA,
cancelText: "取消", cancelText: "取消",
confirmText: "确认", confirmText: "确认",
}); });
} }
public static showMsg = (str: string, duration = 3000) => { public showMsg = (str: string, duration = 3000) => {
(tt as any).showToast({ (tt as any).showToast({
title: str, title: str,
icon: "none", icon: "none",
duration: duration, duration: duration,
}); });
}; };
private static loadingView(show: boolean) { private loadingView(show: boolean) {
if (show) { if (show) {
(tt as any).showLoading({ (tt as any).showLoading({
title: '请稍候..', title: '请稍候..',
...@@ -342,42 +333,42 @@ export class TTSDK { ...@@ -342,42 +333,42 @@ export class TTSDK {
} }
// 上报激活 // 上报激活
public static ActiReport() { public ActiReport() {
this.ReportData({ action: "activation" }); this.ReportData({ action: "activation" });
this.heartBeatReport(); this.heartBeatReport();
} }
// 上报注册 // 上报注册
public static RegisterReport() { public RegisterReport() {
this.ReportData({ action: 'register' }); this.ReportData({ action: 'register' });
} }
// 上报登录 // 上报登录
public static LoginReport() { public LoginReport() {
this.ReportData({ action: 'login' }) this.ReportData({ action: 'login' })
} }
// 上报等级 // 上报等级
public static RoleLevelReport(roleInfo: any) { public RoleLevelReport(roleInfo: any) {
this.ReportData({ ...roleInfo, action: "roleUpgrade" }); this.ReportData({ ...roleInfo, action: "roleUpgrade" });
} }
// 自定义上报 // 自定义上报
public static CustomReport(custInfo: any) { public CustomReport(custInfo: any) {
this.ReportData({ ...custInfo, action: "customevent" }); this.ReportData({ ...custInfo, action: "customevent" });
} }
public static userClickEvent() { public userClickEvent() {
this.clickCounter++; this.clickCounter++;
} }
private static heartBeatReport() { private heartBeatReport() {
setTimeout(() => { setTimeout(() => {
this.clickReport(); this.clickReport();
this.heartBeatReport(); this.heartBeatReport();
}, 60 * 1000); }, 60 * 1000);
} }
private static clickReport = async () => { private clickReport = async () => {
this.ReportData({ action: "heartBeat" }); this.ReportData({ action: "heartBeat" });
this.clickCounter > 0 && this.ReportData({ action: "userappclick", click_times: this.clickCounter }); this.clickCounter > 0 && this.ReportData({ action: "userappclick", click_times: this.clickCounter });
this.clickCounter = 0; // 上报后归零 this.clickCounter = 0; // 上报后归零
}; };
// 上报支付异常 // 上报支付异常
private static reportPaymentError(err: Object) { private reportPaymentError(err: Object) {
let portData = { let portData = {
...this.SDKCOMMDATA, ...this.SDKCOMMDATA,
uid: this.LoginData["uid"], uid: this.LoginData["uid"],
...@@ -387,32 +378,32 @@ export class TTSDK { ...@@ -387,32 +378,32 @@ export class TTSDK {
this.sdkRequest(ttLinks.paymentErrorReport, portData, "POST"); this.sdkRequest(ttLinks.paymentErrorReport, portData, "POST");
} }
// 数据上报接口,外部调用,参数中必须含有action值 // 数据上报接口,外部调用,参数中必须含有action值
public static ReportData(portData: any) { public ReportData(portData: any) {
portData["launchOptions"] = this.LaunchOptions; portData["launchOptions"] = this.LaunchOptions;
portData["userInfo"] = { ...portData["userInfo"], ...{ userId: this.LoginData["uid"] || "", open_id: this.LoginData["openid"] || "", anonymous_openid: this.LoginData["anonymous_openid"] } }; portData["userInfo"] = { ...portData["userInfo"], ...{ userId: this.LoginData["uid"] || "", open_id: this.LoginData["openid"] || "", anonymous_openid: this.LoginData["anonymous_openid"] } };
portData["systemInfo"] = this.SystemInfo; portData["systemInfo"] = this.SystemInfo;
portData["product_code"] = this.appInfo.productCode; portData["product_code"] = SDKConfig.productCode;
portData["time"] = Date.parse(new Date().toString()); // 获取当前时间戳秒 portData["time"] = Date.parse(new Date().toString()); // 获取当前时间戳秒
console.log("--SDK上报:", portData); console.log("--SDK上报:", portData);
this.request(reportDomain, portData, "POST"); this.request(reportDomain, portData, "POST");
} }
public static sendPhoneCode = async (phoneInfo: any): Promise<any> => { public sendPhoneCode = async (phoneInfo: any): Promise<any> => {
// 发送验证码接口 // 发送验证码接口
const { code } = await this.sdkRequest(ttLinks.sendCode, { ...this.SDKCOMMDATA, ...phoneInfo, type: "SDK.BIND_MOBILE" }); const { code } = await this.sdkRequest(ttLinks.sendCode, { ...this.SDKCOMMDATA, ...phoneInfo, type: "SDK.BIND_MOBILE" });
return { code: code == 0 }; return { code: code == 0 };
} }
public static bindPhone = async (phoneInfo: any): Promise<any> => { public bindPhone = async (phoneInfo: any): Promise<any> => {
// 绑定手机 // 绑定手机
const { code } = await this.sdkRequest(ttLinks.saveNum, { ...this.SDKCOMMDATA, open_id: this.LoginData["openid"], ...phoneInfo, source: "WEIXIN" }); const { code } = await this.sdkRequest(ttLinks.saveNum, { ...this.SDKCOMMDATA, open_id: this.LoginData["openid"], ...phoneInfo, source: "WEIXIN" });
return { code: code == 0 }; return { code: code == 0 };
} }
public static checkUserPhoneBind = async (): Promise<any> => { public checkUserPhoneBind = async (): Promise<any> => {
// 查询用户绑定状态 // 查询用户绑定状态
const { code } = await this.sdkRequest(ttLinks.bindPhone, { ...this.SDKCOMMDATA, uid: this.LoginData["uid"] }); const { code } = await this.sdkRequest(ttLinks.bindPhone, { ...this.SDKCOMMDATA, uid: this.LoginData["uid"] });
return { code: code == 0 }; return { code: code == 0 };
} }
// 获取用户信息 // 获取用户信息
public static getUserInfo = (): Promise<any> => { public getUserInfo = (): Promise<any> => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const userInfo = await this._getUserInfo(); const userInfo = await this._getUserInfo();
if (userInfo.nickname) { if (userInfo.nickname) {
...@@ -425,7 +416,7 @@ export class TTSDK { ...@@ -425,7 +416,7 @@ export class TTSDK {
resolve(userInfo); resolve(userInfo);
}); });
}; };
private static async _getUserInfo(): Promise<any> { private async _getUserInfo(): Promise<any> {
return new Promise(async function (resolve, reject) { return new Promise(async function (resolve, reject) {
(tt as any).getUserInfo({ (tt as any).getUserInfo({
withCredentials: false, //获取用户信息,withCredentials 为 true 时需要先调用 wx.login 接口。需要用户授权 scope.userInfo。 withCredentials: false, //获取用户信息,withCredentials 为 true 时需要先调用 wx.login 接口。需要用户授权 scope.userInfo。
...@@ -440,7 +431,7 @@ export class TTSDK { ...@@ -440,7 +431,7 @@ export class TTSDK {
}); });
}); });
} }
public static addShareEvent = (shareInfo: ShareInfo) => { public addShareEvent = (shareInfo: ShareInfo) => {
if (!this.contrlShareMenu) return; if (!this.contrlShareMenu) return;
(tt as any).onShareAppMessage(() => { (tt as any).onShareAppMessage(() => {
const ShareParams = { const ShareParams = {
...@@ -455,7 +446,7 @@ export class TTSDK { ...@@ -455,7 +446,7 @@ export class TTSDK {
(tt as any).showShareMenu({ withShareTicket: true }); (tt as any).showShareMenu({ withShareTicket: true });
}; };
public static ShareGame = (shareInfo: ShareInfo) => { public ShareGame = (shareInfo: ShareInfo) => {
// 参数,记录分享的用户openid // 参数,记录分享的用户openid
const ShareParams = { const ShareParams = {
title: shareInfo.title, title: shareInfo.title,
...@@ -465,7 +456,7 @@ export class TTSDK { ...@@ -465,7 +456,7 @@ export class TTSDK {
}; };
return this._share(ShareParams); return this._share(ShareParams);
}; };
private static _share = (DATA: any): Promise<any> => { private _share = (DATA: any): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(tt as any).shareAppMessage({ (tt as any).shareAppMessage({
...DATA, ...DATA,
...@@ -484,7 +475,7 @@ export class TTSDK { ...@@ -484,7 +475,7 @@ export class TTSDK {
}); });
}; };
// 客服 // 客服
public static Customer = (_orderInfo?: any) => { public Customer = (_orderInfo?: any) => {
try { try {
(tt as any).openCustomerServiceConversation(_orderInfo); (tt as any).openCustomerServiceConversation(_orderInfo);
} catch (err) { } catch (err) {
...@@ -493,17 +484,65 @@ export class TTSDK { ...@@ -493,17 +484,65 @@ export class TTSDK {
} }
}; };
// 添加桌面按钮(安卓) // 添加桌面按钮(安卓)
public static addShortcut = (iconParam: ShortCut) => { public addShortcut = (iconParam: ShortCut) => {
(tt as any).addShortcut({ (tt as any).addShortcut({
...iconParam ...iconParam
}); });
} }
// 头条必接录屏功能
private GameRecorder: any = null;
private videoPath: string = "";
// 创建录屏对象
public createGameRecorder = (startEventCallBack?: any, stopEventCallBack?: any) => {
try {
this.GameRecorder = (tt as any).getGameRecorderManager();
this.GameRecorder.onStart((res: any) => {
console.log("开始录屏:", res);
if (startEventCallBack) startEventCallBack();
});
this.GameRecorder.onStop((res: any) => {
console.log("结束录屏:", res);
if (res) this.videoPath = res.videoPath;
if (stopEventCallBack) stopEventCallBack();
})
} catch (err) {
console.log("SDK录屏异常:", err);
}
}
public startGameRecorder = (recorderInfo: ttRecorderInfo) => {
this.GameRecorder.start({
...recorderInfo
});
}
public stopGameRecorder() {
this.GameRecorder.stop();
}
public shareVideo = async (shareInfo: ShareInfo) => {
return new Promise((resolve, reject) => {
(tt as any).shareAppMessage({
channel: 'video',
query: "fromOpenId=" + this.LoginData["openid"] + "&from=share&tag=0&" + (shareInfo.query ? shareInfo.query : ""),
title: shareInfo.title,
extra: {
videoPath: this.videoPath
},
success: function () {
console.log("分享视频成功.");
resolve({ code: 0, msg: '分享视频成功' });
},
fail: function () {
console.log("分享视频失败.");
resolve({ code: 1, msg: '分享视频失败' });
}
});
});
}
// SDK接口通用参数 // SDK接口通用参数
private static SDKCOMMDATA: any = { private SDKCOMMDATA: any = {
source: "TOUTIAO", source: "TOUTIAO",
product_code: "", product_code: SDKConfig.productCode,
uuid: "", uuid: "",
equipmentos: "", equipmentos: "",
package_code: "", package_code: "",
...@@ -514,7 +553,7 @@ export class TTSDK { ...@@ -514,7 +553,7 @@ export class TTSDK {
}; };
// 米大师支付参数 // 米大师支付参数
private static paymentData = { private paymentData = {
mode: 'game', // 支付的类型 mode: 'game', // 支付的类型
env: 0, // 米大师支付环境 0:正式环境, 1:沙盒模式 env: 0, // 米大师支付环境 0:正式环境, 1:沙盒模式
currencyType: 'CNY', // 币种 currencyType: 'CNY', // 币种
...@@ -523,7 +562,7 @@ export class TTSDK { ...@@ -523,7 +562,7 @@ export class TTSDK {
customId: '', customId: '',
extraInfo: '' extraInfo: ''
} }
private static PaymentErrorCode: any = { private PaymentErrorCode: any = {
"-1": "系统失败", "-1": "系统失败",
"-2": "支付取消", "-2": "支付取消",
"3023": "当前设备不支持", "3023": "当前设备不支持",
...@@ -603,5 +642,9 @@ declare interface ShortCut { ...@@ -603,5 +642,9 @@ declare interface ShortCut {
fail?: Function fail?: Function
complete?: Function complete?: Function
} }
declare interface ttRecorderInfo {
duration: number
frameRate?: number
}
// md5加密 // md5加密
const ttrotateLeft = (lValue: any, iShiftBits: any) => { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)) }; var addUnsigned = function (lX: any, lY: any) { var lX4, lY4, lX8, lY8, lResult; lX8 = (lX & 2147483648); lY8 = (lY & 2147483648); lX4 = (lX & 1073741824); lY4 = (lY & 1073741824); lResult = (lX & 1073741823) + (lY & 1073741823); if (lX4 & lY4) { return (lResult ^ 2147483648 ^ lX8 ^ lY8) } if (lX4 | lY4) { if (lResult & 1073741824) { return (lResult ^ 3221225472 ^ lX8 ^ lY8) } else { return (lResult ^ 1073741824 ^ lX8 ^ lY8) } } else { return (lResult ^ lX8 ^ lY8) } }; var F = function (x: any, y: any, z: any) { return (x & y) | ((~x) & z) }; var G = function (x: any, y: any, z: any) { return (x & z) | (y & (~z)) }; var H = function (x: any, y: any, z: any) { return (x ^ y ^ z) }; var I = function (x: any, y: any, z: any) { return (y ^ (x | (~z))) }; var FF = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var GG = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var HH = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var II = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var convertToWordArray = function (string: any) { var lWordCount; var lMessageLength = string.length; var lNumberOfWordsTempOne = lMessageLength + 8; var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64; var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16; var lWordArray = Array(lNumberOfWords - 1); var lBytePosition = 0; var lByteCount = 0; while (lByteCount < lMessageLength) { lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition)); lByteCount++ } lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = lWordArray[lWordCount] | (128 << lBytePosition); lWordArray[lNumberOfWords - 2] = lMessageLength << 3; lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; return lWordArray }; var wordToHex = function (lValue: any) { var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount; for (lCount = 0; lCount <= 3; lCount++) { lByte = (lValue >>> (lCount * 8)) & 255; WordToHexValueTemp = "0" + lByte.toString(16); WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2) } return WordToHexValue }; var uTF8Encode = function (string: any) { string = string.replace(/\x0d\x0a/g, "\x0a"); var output = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { output += String.fromCharCode(c) } else { if ((c > 127) && (c < 2048)) { output += String.fromCharCode((c >> 6) | 192); output += String.fromCharCode((c & 63) | 128) } else { output += String.fromCharCode((c >> 12) | 224); output += String.fromCharCode(((c >> 6) & 63) | 128); output += String.fromCharCode((c & 63) | 128) } } } return output }; function md5(string: any) { var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; var S11 = 7, S12 = 12, S13 = 17, S14 = 22; var S21 = 5, S22 = 9, S23 = 14, S24 = 20; var S31 = 4, S32 = 11, S33 = 16, S34 = 23; var S41 = 6, S42 = 10, S43 = 15, S44 = 21; string = uTF8Encode(string); x = convertToWordArray(string); a = 1732584193; b = 4023233417; c = 2562383102; d = 271733878; for (k = 0; k < x.length; k += 16) { AA = a; BB = b; CC = c; DD = d; a = FF(a, b, c, d, x[k + 0], S11, 3614090360); d = FF(d, a, b, c, x[k + 1], S12, 3905402710); c = FF(c, d, a, b, x[k + 2], S13, 606105819); b = FF(b, c, d, a, x[k + 3], S14, 3250441966); a = FF(a, b, c, d, x[k + 4], S11, 4118548399); d = FF(d, a, b, c, x[k + 5], S12, 1200080426); c = FF(c, d, a, b, x[k + 6], S13, 2821735955); b = FF(b, c, d, a, x[k + 7], S14, 4249261313); a = FF(a, b, c, d, x[k + 8], S11, 1770035416); d = FF(d, a, b, c, x[k + 9], S12, 2336552879); c = FF(c, d, a, b, x[k + 10], S13, 4294925233); b = FF(b, c, d, a, x[k + 11], S14, 2304563134); a = FF(a, b, c, d, x[k + 12], S11, 1804603682); d = FF(d, a, b, c, x[k + 13], S12, 4254626195); c = FF(c, d, a, b, x[k + 14], S13, 2792965006); b = FF(b, c, d, a, x[k + 15], S14, 1236535329); a = GG(a, b, c, d, x[k + 1], S21, 4129170786); d = GG(d, a, b, c, x[k + 6], S22, 3225465664); c = GG(c, d, a, b, x[k + 11], S23, 643717713); b = GG(b, c, d, a, x[k + 0], S24, 3921069994); a = GG(a, b, c, d, x[k + 5], S21, 3593408605); d = GG(d, a, b, c, x[k + 10], S22, 38016083); c = GG(c, d, a, b, x[k + 15], S23, 3634488961); b = GG(b, c, d, a, x[k + 4], S24, 3889429448); a = GG(a, b, c, d, x[k + 9], S21, 568446438); d = GG(d, a, b, c, x[k + 14], S22, 3275163606); c = GG(c, d, a, b, x[k + 3], S23, 4107603335); b = GG(b, c, d, a, x[k + 8], S24, 1163531501); a = GG(a, b, c, d, x[k + 13], S21, 2850285829); d = GG(d, a, b, c, x[k + 2], S22, 4243563512); c = GG(c, d, a, b, x[k + 7], S23, 1735328473); b = GG(b, c, d, a, x[k + 12], S24, 2368359562); a = HH(a, b, c, d, x[k + 5], S31, 4294588738); d = HH(d, a, b, c, x[k + 8], S32, 2272392833); c = HH(c, d, a, b, x[k + 11], S33, 1839030562); b = HH(b, c, d, a, x[k + 14], S34, 4259657740); a = HH(a, b, c, d, x[k + 1], S31, 2763975236); d = HH(d, a, b, c, x[k + 4], S32, 1272893353); c = HH(c, d, a, b, x[k + 7], S33, 4139469664); b = HH(b, c, d, a, x[k + 10], S34, 3200236656); a = HH(a, b, c, d, x[k + 13], S31, 681279174); d = HH(d, a, b, c, x[k + 0], S32, 3936430074); c = HH(c, d, a, b, x[k + 3], S33, 3572445317); b = HH(b, c, d, a, x[k + 6], S34, 76029189); a = HH(a, b, c, d, x[k + 9], S31, 3654602809); d = HH(d, a, b, c, x[k + 12], S32, 3873151461); c = HH(c, d, a, b, x[k + 15], S33, 530742520); b = HH(b, c, d, a, x[k + 2], S34, 3299628645); a = II(a, b, c, d, x[k + 0], S41, 4096336452); d = II(d, a, b, c, x[k + 7], S42, 1126891415); c = II(c, d, a, b, x[k + 14], S43, 2878612391); b = II(b, c, d, a, x[k + 5], S44, 4237533241); a = II(a, b, c, d, x[k + 12], S41, 1700485571); d = II(d, a, b, c, x[k + 3], S42, 2399980690); c = II(c, d, a, b, x[k + 10], S43, 4293915773); b = II(b, c, d, a, x[k + 1], S44, 2240044497); a = II(a, b, c, d, x[k + 8], S41, 1873313359); d = II(d, a, b, c, x[k + 15], S42, 4264355552); c = II(c, d, a, b, x[k + 6], S43, 2734768916); b = II(b, c, d, a, x[k + 13], S44, 1309151649); a = II(a, b, c, d, x[k + 4], S41, 4149444226); d = II(d, a, b, c, x[k + 11], S42, 3174756917); c = II(c, d, a, b, x[k + 2], S43, 718787259); b = II(b, c, d, a, x[k + 9], S44, 3951481745); a = addUnsigned(a, AA); b = addUnsigned(b, BB); c = addUnsigned(c, CC); d = addUnsigned(d, DD) } var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); return tempValue.toLowerCase() }; const ttrotateLeft = (lValue: any, iShiftBits: any) => { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)) }; var addUnsigned = function (lX: any, lY: any) { var lX4, lY4, lX8, lY8, lResult; lX8 = (lX & 2147483648); lY8 = (lY & 2147483648); lX4 = (lX & 1073741824); lY4 = (lY & 1073741824); lResult = (lX & 1073741823) + (lY & 1073741823); if (lX4 & lY4) { return (lResult ^ 2147483648 ^ lX8 ^ lY8) } if (lX4 | lY4) { if (lResult & 1073741824) { return (lResult ^ 3221225472 ^ lX8 ^ lY8) } else { return (lResult ^ 1073741824 ^ lX8 ^ lY8) } } else { return (lResult ^ lX8 ^ lY8) } }; var F = function (x: any, y: any, z: any) { return (x & y) | ((~x) & z) }; var G = function (x: any, y: any, z: any) { return (x & z) | (y & (~z)) }; var H = function (x: any, y: any, z: any) { return (x ^ y ^ z) }; var I = function (x: any, y: any, z: any) { return (y ^ (x | (~z))) }; var FF = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var GG = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var HH = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var II = function (a: any, b: any, c: any, d: any, x: any, s: any, ac: any) { a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac)); return addUnsigned(ttrotateLeft(a, s), b) }; var convertToWordArray = function (string: any) { var lWordCount; var lMessageLength = string.length; var lNumberOfWordsTempOne = lMessageLength + 8; var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64; var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16; var lWordArray = Array(lNumberOfWords - 1); var lBytePosition = 0; var lByteCount = 0; while (lByteCount < lMessageLength) { lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition)); lByteCount++ } lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = lWordArray[lWordCount] | (128 << lBytePosition); lWordArray[lNumberOfWords - 2] = lMessageLength << 3; lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; return lWordArray }; var wordToHex = function (lValue: any) { var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount; for (lCount = 0; lCount <= 3; lCount++) { lByte = (lValue >>> (lCount * 8)) & 255; WordToHexValueTemp = "0" + lByte.toString(16); WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2) } return WordToHexValue }; var uTF8Encode = function (string: any) { string = string.replace(/\x0d\x0a/g, "\x0a"); var output = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { output += String.fromCharCode(c) } else { if ((c > 127) && (c < 2048)) { output += String.fromCharCode((c >> 6) | 192); output += String.fromCharCode((c & 63) | 128) } else { output += String.fromCharCode((c >> 12) | 224); output += String.fromCharCode(((c >> 6) & 63) | 128); output += String.fromCharCode((c & 63) | 128) } } } return output }; function md5(string: any) { var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; var S11 = 7, S12 = 12, S13 = 17, S14 = 22; var S21 = 5, S22 = 9, S23 = 14, S24 = 20; var S31 = 4, S32 = 11, S33 = 16, S34 = 23; var S41 = 6, S42 = 10, S43 = 15, S44 = 21; string = uTF8Encode(string); x = convertToWordArray(string); a = 1732584193; b = 4023233417; c = 2562383102; d = 271733878; for (k = 0; k < x.length; k += 16) { AA = a; BB = b; CC = c; DD = d; a = FF(a, b, c, d, x[k + 0], S11, 3614090360); d = FF(d, a, b, c, x[k + 1], S12, 3905402710); c = FF(c, d, a, b, x[k + 2], S13, 606105819); b = FF(b, c, d, a, x[k + 3], S14, 3250441966); a = FF(a, b, c, d, x[k + 4], S11, 4118548399); d = FF(d, a, b, c, x[k + 5], S12, 1200080426); c = FF(c, d, a, b, x[k + 6], S13, 2821735955); b = FF(b, c, d, a, x[k + 7], S14, 4249261313); a = FF(a, b, c, d, x[k + 8], S11, 1770035416); d = FF(d, a, b, c, x[k + 9], S12, 2336552879); c = FF(c, d, a, b, x[k + 10], S13, 4294925233); b = FF(b, c, d, a, x[k + 11], S14, 2304563134); a = FF(a, b, c, d, x[k + 12], S11, 1804603682); d = FF(d, a, b, c, x[k + 13], S12, 4254626195); c = FF(c, d, a, b, x[k + 14], S13, 2792965006); b = FF(b, c, d, a, x[k + 15], S14, 1236535329); a = GG(a, b, c, d, x[k + 1], S21, 4129170786); d = GG(d, a, b, c, x[k + 6], S22, 3225465664); c = GG(c, d, a, b, x[k + 11], S23, 643717713); b = GG(b, c, d, a, x[k + 0], S24, 3921069994); a = GG(a, b, c, d, x[k + 5], S21, 3593408605); d = GG(d, a, b, c, x[k + 10], S22, 38016083); c = GG(c, d, a, b, x[k + 15], S23, 3634488961); b = GG(b, c, d, a, x[k + 4], S24, 3889429448); a = GG(a, b, c, d, x[k + 9], S21, 568446438); d = GG(d, a, b, c, x[k + 14], S22, 3275163606); c = GG(c, d, a, b, x[k + 3], S23, 4107603335); b = GG(b, c, d, a, x[k + 8], S24, 1163531501); a = GG(a, b, c, d, x[k + 13], S21, 2850285829); d = GG(d, a, b, c, x[k + 2], S22, 4243563512); c = GG(c, d, a, b, x[k + 7], S23, 1735328473); b = GG(b, c, d, a, x[k + 12], S24, 2368359562); a = HH(a, b, c, d, x[k + 5], S31, 4294588738); d = HH(d, a, b, c, x[k + 8], S32, 2272392833); c = HH(c, d, a, b, x[k + 11], S33, 1839030562); b = HH(b, c, d, a, x[k + 14], S34, 4259657740); a = HH(a, b, c, d, x[k + 1], S31, 2763975236); d = HH(d, a, b, c, x[k + 4], S32, 1272893353); c = HH(c, d, a, b, x[k + 7], S33, 4139469664); b = HH(b, c, d, a, x[k + 10], S34, 3200236656); a = HH(a, b, c, d, x[k + 13], S31, 681279174); d = HH(d, a, b, c, x[k + 0], S32, 3936430074); c = HH(c, d, a, b, x[k + 3], S33, 3572445317); b = HH(b, c, d, a, x[k + 6], S34, 76029189); a = HH(a, b, c, d, x[k + 9], S31, 3654602809); d = HH(d, a, b, c, x[k + 12], S32, 3873151461); c = HH(c, d, a, b, x[k + 15], S33, 530742520); b = HH(b, c, d, a, x[k + 2], S34, 3299628645); a = II(a, b, c, d, x[k + 0], S41, 4096336452); d = II(d, a, b, c, x[k + 7], S42, 1126891415); c = II(c, d, a, b, x[k + 14], S43, 2878612391); b = II(b, c, d, a, x[k + 5], S44, 4237533241); a = II(a, b, c, d, x[k + 12], S41, 1700485571); d = II(d, a, b, c, x[k + 3], S42, 2399980690); c = II(c, d, a, b, x[k + 10], S43, 4293915773); b = II(b, c, d, a, x[k + 1], S44, 2240044497); a = II(a, b, c, d, x[k + 8], S41, 1873313359); d = II(d, a, b, c, x[k + 15], S42, 4264355552); c = II(c, d, a, b, x[k + 6], S43, 2734768916); b = II(b, c, d, a, x[k + 13], S44, 1309151649); a = II(a, b, c, d, x[k + 4], S41, 4149444226); d = II(d, a, b, c, x[k + 11], S42, 3174756917); c = II(c, d, a, b, x[k + 2], S43, 718787259); b = II(b, c, d, a, x[k + 9], S44, 3951481745); a = addUnsigned(a, AA); b = addUnsigned(b, BB); c = addUnsigned(c, CC); d = addUnsigned(d, DD) } var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); return tempValue.toLowerCase() };
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论