wangguan
2020-12-23 26d9e8feaa2b91c05a7645c732146c1068a2a9b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.unity3d.player;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import android.app.Activity;
import android.content.Context;
import android.util.Log;
 
import com.bytedance.applog.AppLog;
import com.bytedance.applog.GameReportHelper;
import com.bytedance.applog.InitConfig;
import com.bytedance.applog.UriConfig;
import com.bytedance.applog.util.UriConstants;
 
 
public class SJToutiaoSDK  {
 
    private final String TTAPPNAME = "TOUTIAO_APPNAME";
    private final String TTAPPID = "TOUTIAO_APPID";
    private final String TTCHANNEL = "TOUTIAO_CHANNEL";
    private final String TTDEBUG = "TOUTIAO_DEBUG";
 
    private final String TAG = SJToutiaoSDK.class.getSimpleName();
 
 
    private String mTTAppName;
    private int mTTAppId;
    private String mChannel;
    private boolean mDebug = true;
 
    public SJToutiaoSDK() {
    }
 
    public static SJToutiaoSDK Instanc;
 
    public static SJToutiaoSDK getInstanc() {
        if (Instanc == null){
            Instanc = new SJToutiaoSDK();
        }
        return Instanc;
    }
 
 
    public void init(Context context) {
        Log.d(TAG, "SJTouTiaoSDK Init!");
 
        final InitConfig config = new InitConfig(ConstantsUtils.ToutTiaoAppId+"", ConstantsUtils.ToutTiaoAppChannalId);
        /*  
        11      域名默认国内: DEFAULT, 新加坡:SINGAPORE, 美东:AMERICA
        12      注意:国内外不同vendor服务注册的did不⼀样。由DEFAULT切换到SINGAPORE或者AMERICA,
        会发⽣变化, 
        13      切回来也会发⽣变化。因此vendor的切换⼀定要慎重,随意切换导致⽤⼾新增和统计的问题,需
        要⾃⾏评估。 
        14      */
        
        config.setUriConfig(UriConstants.DEFAULT);
 
//        ? 2.2.远端引⽤
//        ? 3.?初始化SDK
//        17     // 是否在控制台输出⽇志,可⽤于观察⽤⼾⾏为⽇志上报情况,建议仅在调试时使⽤,release版
//        本请设置为false !
//        AppLog.setEnableLog(true);
         // 游戏模式,YES会开始 playSession 上报,每隔⼀分钟上报⼼跳⽇志
        config.setEnablePlay(true);
 
 
        config.setLogger ((msg, t) -> Log.d (TAG, msg, t)); // 是否在控制台输出日志,可用于观察用户行为日志上报情况,建议仅在调试时使用
        config.setEnablePlay(true); // 是否开启游戏模式,游戏APP建议设置为 true
        config.setAbEnable(true); // 是否开启A/B Test功能
 
        config.setAutoStart(true);
        AppLog.init(context, config);
        /* 初始化结束 */
        
    }
 
 
    public void setEvent(Context context, String eventName, String eventContent) {
        Log.d(TAG, "SJTouTiaoSDK setEvent!"+eventContent);
        
        JSONObject paramsObj =null;
        try {
             paramsObj = new JSONObject(eventContent);
              } catch (JSONException e) {
            e.printStackTrace();
           }
         AppLog.onEventV3(eventName, paramsObj);
 
    }
 
    public void setLoginSuccess(Context context, String userId) {
        Log.d(TAG, "SJTouTiaoSDK loginSuccess!");
         AppLog.setUserUniqueID(userId);
    }
 
    public void setOrder(Context context, String orderId, String currencyType, String currencyAmount) {
    }
 
    public void setPayment(Context context, String orderId, String paymentType, String currencyType,
            String currencyAmount, String productId, String productName, String productDesc, String productNum) {
        Log.d(TAG,
                "setPayment  orderId:" + orderId + "  paymentType:" + paymentType + "  currencyType:" + currencyType
                        + "  currencyAmount:" + currencyAmount + "  productId:" + productId + "  productName:"
                        + productName + "  productDesc:" + productDesc + "  productNum:" + productNum);
//        float price = Float.valueOf(currencyAmount);
        
        
        try {
            
             float price = Float.valueOf(currencyAmount);
                Log.d(TAG,
                        "price" +  (int)price  );
 
             GameReportHelper.onEventPurchase("元宝",productName,productId, Integer.valueOf(productNum),paymentType,currencyType, true,  (int)price);
             } catch (Exception e) {
            e.printStackTrace();
           }
        
        //内置事件 “⽀付”,属性:商品类型,商品名称,商品ID,商品数量,⽀付渠道,币种,是否成功(必
//        传),⾦额(必传)
    
     }
 
    public void setRegister(Context context, String userId, String method, boolean isSuccess) {
        Log.d(TAG, "setRegister  userId:" + userId + "  method:" + method + "  isSuccess:" + isSuccess);
         //内置事件: “注册” ,属性:注册⽅式,是否成功,属性值为:wechat ,true
         GameReportHelper.onEventRegister(method,isSuccess);
        
 
 
    }
 
}