|
|
@@ -1,6 +1,7 @@
|
|
|
import { sys } from "cc";
|
|
|
+import { DataSdk } from "./datasdk";
|
|
|
|
|
|
-export class ttZtSdk {
|
|
|
+export class TTZtSdk {
|
|
|
private static SaveKey = "ttzt_ext"
|
|
|
private static ReportURL = "https://api.zt.y73s.cn/api/v1/conversion"
|
|
|
|
|
|
@@ -8,62 +9,75 @@ export class ttZtSdk {
|
|
|
public static get openid() { return this.extend && this.extend.openid }
|
|
|
public static get clickid() { return this.extend && this.extend.clickid }
|
|
|
|
|
|
- public static reportActive() {
|
|
|
+ public static reportActive(openid?: string) {
|
|
|
if (typeof window.tt === 'undefined' || !tt) {
|
|
|
- console.log("#### ttZtSdk #### 非字节平台不初始化")
|
|
|
+ console.log("#### TTZtSdk #### 非字节平台不初始化")
|
|
|
return;
|
|
|
}
|
|
|
- console.log("#### ttZtSdk #### 初始化")
|
|
|
+ console.log("#### TTZtSdk #### 初始化")
|
|
|
// 加载历史记录
|
|
|
let savedata = sys.localStorage.getItem(this.SaveKey);
|
|
|
- console.log("#### ttZtSdk #### 读取旧数据", savedata)
|
|
|
+ console.log("#### TTZtSdk #### 读取旧数据", savedata)
|
|
|
if (savedata) {
|
|
|
this.extend = JSON.parse(savedata)
|
|
|
}
|
|
|
|
|
|
// 如果已经激活, 不重复上报
|
|
|
- if (ttZtSdk.openid) {
|
|
|
- console.log("#### ttZtSdk #### 激活已经上报,不重复上报, openid:", ttZtSdk.openid, "clickid:", ttZtSdk.clickid)
|
|
|
+ if (TTZtSdk.openid) {
|
|
|
+ console.log("#### TTZtSdk #### 激活已经上报,不重复上报, openid:", TTZtSdk.openid, "clickid:", TTZtSdk.clickid)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- tt.login({
|
|
|
- force: true,
|
|
|
- success: (res: any) => {
|
|
|
- console.debug(`#### ttZtSdk #### login 调用成功code:${res.code} a_code:${res.anonymousCode}`);
|
|
|
- let options = tt.getLaunchOptionsSync();
|
|
|
- let queryStr = JSON.stringify(options.query)
|
|
|
- let appid = options.extra.appId || options.query.appId
|
|
|
- console.debug("#### ttZtSdk #### appid:", appid, "query:", queryStr);
|
|
|
- tt.request({
|
|
|
- url: ttZtSdk.ReportURL,
|
|
|
- data: {
|
|
|
+ let options = tt.getLaunchOptionsSync();
|
|
|
+ let queryStr = JSON.stringify(options.query)
|
|
|
+ let appid = options.extra.appId || options.query.appId
|
|
|
+ console.debug("#### TTZtSdk #### appid:", appid, "query:", queryStr);
|
|
|
+ if (openid) {
|
|
|
+ this.reportActive$({
|
|
|
+ appid: appid, // 请求来源:appid
|
|
|
+ openid: openid,
|
|
|
+ active_data: queryStr, // 激活相关数据 json字符串
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ tt.login({
|
|
|
+ force: true,
|
|
|
+ success: (res: any) => {
|
|
|
+ console.debug(`#### TTZtSdk #### login 调用成功code:${res.code} a_code:${res.anonymousCode}`);
|
|
|
+ this.reportActive$({
|
|
|
+ appid: appid, // 请求来源:appid
|
|
|
code: res.code,
|
|
|
anonvmous_code: res.anonymousCode,
|
|
|
- appid: appid, // 请求来源:appid
|
|
|
active_data: queryStr, // 激活相关数据 json字符串
|
|
|
- },
|
|
|
- header: { "content-type": "application/json" },
|
|
|
- method: "POST",
|
|
|
- success: (res: any) => {
|
|
|
- console.log("#### ttZtSdk #### 数据上报成功", res.data)
|
|
|
- if (res.data.code == 0) {
|
|
|
- ttZtSdk.extend = {}
|
|
|
- ttZtSdk.extend.openid = res.data.data.openid;
|
|
|
- ttZtSdk.extend.clickid = res.data.data.clickid;
|
|
|
- let extStr = JSON.stringify(ttZtSdk.extend)
|
|
|
- console.log("#### ttZtSdk #### ext:", extStr)
|
|
|
- sys.localStorage.setItem(this.SaveKey, extStr)
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (res: any) => {
|
|
|
- console.log("#### ttZtSdk #### 数据上报失败", res.errMsg)
|
|
|
- },
|
|
|
- })
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (res: any) => {
|
|
|
+ console.debug(`#### TTZtSdk #### login调用失败`, res);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static reportActive$(param: any) {
|
|
|
+ tt.request({
|
|
|
+ url: TTZtSdk.ReportURL,
|
|
|
+ data: param,
|
|
|
+ header: { "content-type": "application/json" },
|
|
|
+ method: "POST",
|
|
|
+ success: (res: any) => {
|
|
|
+ console.log("#### TTZtSdk #### 数据上报成功", res.data)
|
|
|
+ if (res.data.code == 0) {
|
|
|
+ TTZtSdk.extend = {}
|
|
|
+ TTZtSdk.extend.openid = res.data.data.openid;
|
|
|
+ TTZtSdk.extend.clickid = res.data.data.clickid;
|
|
|
+ let extStr = JSON.stringify(TTZtSdk.extend)
|
|
|
+ console.log("#### TTZtSdk #### ext:", extStr)
|
|
|
+ sys.localStorage.setItem(this.SaveKey, extStr)
|
|
|
+ DataSdk.initReport(res.data.data.openid)
|
|
|
+ }
|
|
|
},
|
|
|
fail: (res: any) => {
|
|
|
- console.debug(`#### ttZtSdk #### login调用失败`, res);
|
|
|
+ console.log("#### TTZtSdk #### 数据上报失败", res.errMsg)
|
|
|
},
|
|
|
- });
|
|
|
+ })
|
|
|
}
|
|
|
}
|