update:更新flexion 以及sdk 接入

This commit is contained in:
2026-04-29 20:43:16 +08:00
parent c0b6ccf7ed
commit 66aa7a931b
52 changed files with 2100 additions and 568 deletions

View File

@@ -0,0 +1,9 @@
package com.unity3d.player;
public class ChannelHelpers {
public static final String CHANNEL = "GooglePlay";
static void register() {
// GooglePlay uses default behavior, no additional SDKHelper
}
}

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: 576805d2d0194634b8d235fd6837195e
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,7 @@
package com.unity3d.player;
public class ConfigManager {
//通用参数
// Common SDK parameters
public static int SDK_APPID = 20587;
public static String SDK_GAMEID = "20587";
public static String SDK_PROJECTID = "20587";
@@ -11,14 +10,12 @@ public class ConfigManager {
public static String SDK_LOGIN_SERVER_URL = "https://128-hwsfsdk-sdk-online01.qijihdhk.com";
// 防沉迷 - nameSpace
// FCM (anti-addiction system)
public static String FCM_NAMESPACE = "128";
// 防沉迷 - 长连接服务地址+端口
public static String FCM_IAM_HOST = "tcp://fcmtcp.tuyoo.com:3563";
// 防沉迷 - 防沉迷服务地址
public static String FCM_ANTISERVERURL = "https://fcmapi.tuyoo.com";
// Unity Facade callback names
public static final String UNITY_FACADE_NAME = "TYSdkFacade";
public static final String LOGIN_CALLBACK_FUNCTION_NAME = "LoginResult";
public static final String LINKACCOUT_CALLBACK_FUNCTION_NAME = "LinkAccoutResult";

View File

@@ -7,7 +7,7 @@ PluginImporter:
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:

View File

@@ -1,4 +1,3 @@
package com.unity3d.player;
import android.app.Activity;
@@ -29,31 +28,71 @@ import com.tuyoo.gamesdk.api.SDKAPI;
import com.tuyoo.gamesdk.api.SDKCallBack;
import com.tuyoo.gamesdk.api.SDKWrapper;
import com.tuyoo.gamesdk.api.TuYooClientID;
import com.tuyoo.gamesdk.event.EventBus;
import com.tuyoo.gamesdk.event.EventConsts;
import com.tuyoo.gamesdk.event.data.PayEventData;
import com.tuyoo.gamesdk.event.data.WeixinShareData;
import com.tuyoo.gamesdk.login.model.SnsInfo;
import com.tuyoo.gamesdk.model.InitParam;
import com.tuyoo.gamesdk.pay.model.PayType;
import com.tuyoo.gamesdk.util.SDKLog;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlinx.serialization.json.Json;
/**
* Unified SDKManager for all channels (GooglePlay / Flexion / RuStore).
* C# passes the channel string via InitSDK(activity, channel); Java dispatches
* internally via switch. All login/link/GA/share logic is shared.
* Channel-specific behaviour is limited to: Init, Pay, thirdExtend, Review.
*/
public class SDKManager {
private final static Handler handler = new Handler(Looper.getMainLooper());
private static final Handler handler = new Handler(Looper.getMainLooper());
private static IGASDK gasdk;
private static final String TAG = com.unity3d.player.SDKManager.class.getSimpleName();
private static final String TAG = SDKManager.class.getSimpleName();
private static String curType = TuYooClientID.tyGuest;
public static void InitSDK(Activity activity)
{
private static SnsInfo tmpSnsInfo;
private static String channel = "GooglePlay";
// Channel helper registry
public interface ISDKHelper {
void init(Activity activity);
void pay(Activity activity, String productId, String productName,
String productCount, String prodorderId, String appInfo);
void queryProducts();
}
private static final java.util.Map<String, ISDKHelper> helperMap = new java.util.HashMap<>();
private static ISDKHelper sdkHelper;
public static void registerHelper(String ch, ISDKHelper helper) {
helperMap.put(ch, helper);
}
// -------------------------------------------------------------------------
// Init — with channel helper support
// -------------------------------------------------------------------------
public static void InitSDK(Activity activity, String ch) {
channel = ch != null ? ch : "GooglePlay";
ChannelHelpers.register();
if (!channel.equals(ChannelHelpers.CHANNEL)) {
Log.e(TAG, "Channel mismatch! Helpers=" + ChannelHelpers.CHANNEL + " expected=" + channel);
}
sdkHelper = helperMap.get(channel);
Log.i(TAG, "InitSDK channel=" + channel + " helper=" + (sdkHelper != null ? sdkHelper.getClass().getSimpleName() : "none"));
if (sdkHelper != null) {
sdkHelper.init(activity);
} else {
initDefault(activity);
}
}
private static void initDefault(Activity activity) {
activity.runOnUiThread(() -> {
SDKAPI.getIns().lightModeEnable();
try {
@@ -67,11 +106,14 @@ public class SDKManager {
SDKAPI.getIns().onActivityStart(activity);
SDKAPI.getIns().onActivityResume(activity);
} catch (Exception e) {
System.out.println("initSDK Exception " + e);
System.out.println("initSDK Exception " + e);
}
});
}
// -------------------------------------------------------------------------
// Login / Callbacks (shared)
// -------------------------------------------------------------------------
public static void parseLoginInfo(int i, String s) {
try {
@@ -80,21 +122,21 @@ public class SDKManager {
if (i == 0) {
JSONObject serverResponse = new JSONObject(s);
JSONObject userInfo = serverResponse.getJSONObject("result");
result.put("loginData", userInfo );
result.put("loginData", userInfo);
} else {
result.put("errStr", s);
}
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, result.toString());
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, result.toString());
} catch (Exception e) {
Log.e(TAG,"SDKManager-parseLoginInfo-Exception" + e);
Log.e(TAG, "SDKManager-parseLoginInfo-Exception" + e);
SDKLog.e("SDKManager-parseLoginInfo-Exception" + e);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
}
}
//登录回调-统一的回调方法(保持回调仅有一个,否则可能会出现多次回调的情况)
static SDKCallBack.Login mLogin = new SDKCallBack.Login() {
protected static SDKCallBack.Login mLogin = new SDKCallBack.Login() {
@Override
public void callback(int i, String s) {
SDKLog.i("SDKCallBack.Login callback: " + i + " \n" + s);
@@ -103,21 +145,22 @@ public class SDKManager {
}
};
static SDKCallBack.Pay mPay = new SDKCallBack.Pay() {
protected static SDKCallBack.Pay mPay = new SDKCallBack.Pay() {
@Override
public void callback(int i, String s) {
SDKLog.i("SDKCallBack.Pay callback: " + i + " \n" + s);
try {
JSONObject result = new JSONObject();
result.put("code", i);
result.put("respObj", s);
result.put("errStr", s);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_CALLBACK_FUNCTION_NAME, result.toString());
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.PAY_CALLBACK_FUNCTION_NAME, result.toString());
} catch (Exception e) {
Log.e(TAG,"SDKManager-SDKCallBack.Pay-Exception" + e);
Log.e(TAG, "SDKManager-SDKCallBack.Pay-Exception" + e);
SDKLog.e("SDKManager-SDKCallBack.Pay-Exception" + e);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.PAY_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
}
}
};
@@ -132,18 +175,15 @@ public class SDKManager {
handler.post(() -> SDKAPI.getIns().loginByToken(token, mLogin));
}
public static String UnityLoginBySnsInfo()
{
if(tmpSnsInfo == null)
{
handler.post(() -> UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}"));
public static String UnityLoginBySnsInfo() {
if (tmpSnsInfo == null) {
handler.post(() -> UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}"));
return "";
}
SDKLog.i("UnityLoginBySns : " + tmpSnsInfo);
handler.post(() -> SDKAPI.getIns().loginBySnsInfo(tmpSnsInfo, mLogin));
return tmpSnsInfo.type;
}
public static void UnityGetIdentityFun(String type) {
@@ -161,15 +201,15 @@ public class SDKManager {
handler.post(() -> SDKAPI.getIns().logout(type));
}
private static SnsInfo tmpSnsInfo;
public static void LinkAccount(String type, String userId)
{
SDKAPI.getIns().getSnsInfo(type, (snscode, snsInfo, snsmsg) ->{
if(snscode == SDKCallBack.CODE_SUCCESS && snsInfo !=null)
{
SDKAPI.getIns().bindBySnsId(snsInfo, userId, (bindcode, bindmsg)->{
if(bindcode == SDKCallBack.CODE_SUCCESS)
{
// -------------------------------------------------------------------------
// Account linking (shared)
// -------------------------------------------------------------------------
public static void LinkAccount(String type, String userId) {
SDKAPI.getIns().getSnsInfo(type, (snscode, snsInfo, snsmsg) -> {
if (snscode == SDKCallBack.CODE_SUCCESS && snsInfo != null) {
SDKAPI.getIns().bindBySnsId(snsInfo, userId, (bindcode, bindmsg) -> {
if (bindcode == SDKCallBack.CODE_SUCCESS) {
try {
JSONObject result = new JSONObject();
result.put("code", bindcode);
@@ -178,41 +218,28 @@ public class SDKManager {
JSONObject serverResponse = new JSONObject(bindmsg);
JSONObject userInfo = serverResponse.getJSONObject("result");
result.put("loginData", userInfo);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, result.toString());
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, result.toString());
} catch (JSONException e) {
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
}
}
else if(bindcode == SDKCallBack.CODE_FAILED)
{
try
{
} else if (bindcode == SDKCallBack.CODE_FAILED) {
try {
JSONObject bindMsgObj = new JSONObject(bindmsg);
JSONObject bindMsgResult = bindMsgObj.getJSONObject("result");
int bindMsgResultCode = bindMsgResult.getInt("code");
if(bindMsgResultCode == 4)
{
SDKAPI.getIns().checkSnsInfo(snsInfo, (checkcode, checkMsg ) -> {
if(checkcode != SDKCallBack.CODE_SUCCESS)
{
if (bindMsgResultCode == 4) {
SDKAPI.getIns().checkSnsInfo(snsInfo, (checkcode, checkMsg) -> {
if (checkcode != SDKCallBack.CODE_SUCCESS) {
Log.w(TAG, checkMsg);
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
return;
}
try {
//{
// "track":"128:10:28654792:1766569516",
// "result":{
// "bindInfo":"{ // \"guest\": \"guest:devidmap3:bf12a8a28b663548e368ebe8742368b7\", // \"google\": \"google:118182347502471840780\" // }",
// "code":0,
// "info":"user exist",
// "exist":1,
// "userId":10030
// }
// }
tmpSnsInfo = snsInfo;
JSONObject checkMsgObj = new JSONObject(checkMsg);
JSONObject checkResult = checkMsgObj.getJSONObject("result");
@@ -222,165 +249,143 @@ public class SDKManager {
callbackMsg.put("code", -1);
callbackMsg.put("userId", bindUserId);
callbackMsg.put("bindInfo", bindInfo);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, callbackMsg.toString());
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME,
callbackMsg.toString());
} catch (JSONException e) {
Log.i(TAG, e.toString());
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
}
});
}
else
{
} else {
Log.w(TAG, bindmsg);
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
}
}
catch (JSONException e)
{
} catch (JSONException e) {
Log.i(TAG, e.toString());
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
}
}
else
{
} else {
Log.w(TAG, bindmsg);
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
}
});
}
else
{
} else {
Log.w(TAG, snsmsg);
String msg = "{\"code\":1, \"userId\": 0}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
}
});
}
public static void CleanLinkTmpSnsInfo()
{
tmpSnsInfo = null;
}
public static void ChangeLinkAccount(String type, int oldUserId, int newUserId)
{
if(tmpSnsInfo == null)
{
public static void CleanLinkTmpSnsInfo() {
tmpSnsInfo = null;
}
public static void ChangeLinkAccount(String type, int oldUserId, int newUserId) {
if (tmpSnsInfo == null) {
String msg = "{\"code\":1, \"userId\": 0, \"msg\": \"tmpSnsInfo is null\"}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
return;
}
SDKAPI.getIns().unbindBySnsId(tmpSnsInfo, String.valueOf(oldUserId), (unbindCode, unbindMsg) -> {
Log.i(TAG, "unbindBySnsId code: " + unbindCode + " msg: " + unbindMsg);
if(unbindCode == SDKCallBack.CODE_SUCCESS)
{
if (unbindCode == SDKCallBack.CODE_SUCCESS) {
SDKAPI.getIns().bindBySnsId(tmpSnsInfo, String.valueOf(newUserId), (bindCode, bindMsg) -> {
Log.i(TAG, "bindBySnsId code: " + bindCode + " msg: " + bindMsg);
if(bindCode == SDKCallBack.CODE_SUCCESS)
{
if (bindCode == SDKCallBack.CODE_SUCCESS) {
String msg = "{\"code\":0, \"userId\": " + newUserId + ", \"msg\": \"success\"}";
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
}
else
{
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
} else {
String msg = String.format("{\"code\":-1, \"userId\": 0, \"msg\": \"%s\"}", bindMsg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
}
});
}
else
{
} else {
String msg = String.format("{\"code\":1, \"userId\": 0, \"msg\": \"%s\"}", unbindMsg);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
}
});
}
public static void LinkCheck(String type)
{
SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> {
if(code == SDKCallBack.CODE_SUCCESS && snsInfo != null){
SDKAPI.getIns().checkSnsInfo(snsInfo, (code1, msg1) -> {
if(code1 == SDKCallBack.CODE_SUCCESS && !TextUtils.isEmpty(msg1)){
try {
JSONObject jsonObject = new JSONObject(msg1).optJSONObject("result");
//返回信息中code为0时表示服务端查询成功exit为1表示此渠道用户信息已产生过途游账号可直接进行登录exit为0表示此渠道用户信息未产生过途游账号可以进行绑定
if(jsonObject.optString("code").equals("0")
&& jsonObject.optString("exist").equals("0")){
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "0");
}
else
{
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "1");
}
} catch (JSONException e) {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1");
e.printStackTrace();
}
}
else
{
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1");
}
});
}
else
{
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1");
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
}
});
}
public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo) {
public static void LinkCheck(String type) {
SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> {
if (code == SDKCallBack.CODE_SUCCESS && snsInfo != null) {
SDKAPI.getIns().checkSnsInfo(snsInfo, (code1, msg1) -> {
if (code1 == SDKCallBack.CODE_SUCCESS && !TextUtils.isEmpty(msg1)) {
try {
JSONObject jsonObject = new JSONObject(msg1).optJSONObject("result");
if (jsonObject.optString("code").equals("0")
&& jsonObject.optString("exist").equals("0")) {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "0");
} else {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "1");
}
} catch (JSONException e) {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1");
e.printStackTrace();
}
} else {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1");
}
});
} else {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.CHECKLINK_CALLBACK_FUNCTION_NAME, "-1");
}
});
}
// -------------------------------------------------------------------------
// Payment — channel dispatch
// -------------------------------------------------------------------------
public static void UnityKnow(String productId, String productName, String productCount,
String prodorderId, String appInfo) {
if (sdkHelper != null) {
sdkHelper.pay(UnityPlayer.currentActivity, productId, productName, productCount, prodorderId, appInfo);
return;
}
SDKLog.i("UnityKnow : " + productId);
HashMap<String, String> extraInfo = new HashMap<String, String>();
extraInfo.put("appInfo", appInfo);
SDKAPI.getIns().pay(productId, productName, productCount, Integer.parseInt(ConfigManager.SDK_GAMEID), mPay, prodorderId, extraInfo);
SDKAPI.getIns().pay(productId, productName, productCount,
Integer.parseInt(ConfigManager.SDK_GAMEID), mPay, prodorderId, extraInfo);
}
public static void UnityGetKnowTypeList(String productId)
{
Log.e(TAG,"UnityGetKnowTypeList:" + productId );
final PayEventData.PayReq mPayReq = new PayEventData.PayReq();
mPayReq.prodId = productId;
SDKAPI.getIns().charge(mPayReq , new SDKCallBack.Base1() {
@Override
public void callback(int code, String msg) {
SDKLog.e("====> code= " + code + " msg= " + msg);
try {
JSONObject result = new JSONObject();
result.put("code", code);
if(code == 0){
result.put("respObj", msg);
}else {
result.put("errStr", msg);
}
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, result.toString());
} catch (Exception e) {
SDKLog.e("SDKManager-UnityGetKnowTypeList-Exception" + e);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
}
}
});
}
public static void UnityKnowNew(String productId, String productPrice, String productName, String productCount, String prodorderId, String appInfo, String ptype)
{
public static void UnityKnowNew(String productId, String productPrice, String productName,
String productCount, String prodorderId, String appInfo,
String ptype) {
if (sdkHelper != null) {
sdkHelper.pay(UnityPlayer.currentActivity, productId, productName, productCount, prodorderId, appInfo);
return;
}
PayEventData.PayData payData = new PayEventData.PayData();
final PayEventData.PayReq mPayReq = new PayEventData.PayReq();
mPayReq.prodId = productId;
mPayReq.prodPrice = productPrice;
mPayReq.prodName = productName;
mPayReq.prodCount = productCount;
// 此字段与服务端回调接口内的appInfo不对应与orderId相对应
mPayReq.appInfo = prodorderId;
HashMap<String, String> map = new HashMap<String, String>();
// 此字段appInfo可用于传递透传信息此信息与服务端回调接口内的appInfo相对应
map.put("appInfo", appInfo);
mPayReq.extra = map;
payData.payReq = mPayReq;
@@ -389,41 +394,56 @@ public class SDKManager {
SDKAPI.getIns().payNew(payData, payType, mPay);
}
// -------------------------------------------------------------------------
// thirdExtend — with channel helper support
// -------------------------------------------------------------------------
public static void thirdExtend()
{
Log.e(TAG,"====>java thirdExtend");
public static void thirdExtend() {
if (sdkHelper != null) {
sdkHelper.queryProducts();
return;
}
defaultThirdExtend();
}
private static void defaultThirdExtend() {
Log.e(TAG, "====>java thirdExtend");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action","ACTION_GET_SKU_DETAILS_LIST");
jsonObject.put("action", "ACTION_GET_SKU_DETAILS_LIST");
} catch (JSONException e) {
throw new RuntimeException(e);
}
SDKAPI.getIns().thirdExtend(jsonObject.toString(), new SDKCallBack.Extend() {
@Override public void callback(int code, String msg) {
Log.e(TAG,"====>thirdExtend code= " + code + " msg= " + msg );
@Override
public void callback(int code, String msg) {
Log.e(TAG, "====>thirdExtend code= " + code + " msg= " + msg);
try {
//获取成功msg即为对应的json字符串
JSONObject result = new JSONObject();
result.put("code", code);
if(code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS){
if (code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS) {
result.put("respObj", msg);
}else {
Log.e(TAG,"获取商品列表失败啦:" + msg);
} else {
Log.e(TAG, "thirdExtend failed: " + msg);
result.put("thirdExtend_errStr", msg);
}
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, result.toString());
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, result.toString());
} catch (Exception e) {
SDKLog.e("SDKManager-UnityGetKnowTypeList-Exception" + e);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
SDKLog.e("SDKManager-thirdExtend-Exception" + e);
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
ConfigManager.PAY_TYPE_CALLBACK_FUNCTION_NAME, "{\"code\":1}");
}
}
});
}
private static IGASDK GetGameGa(){
if(gasdk == null){
// -------------------------------------------------------------------------
// GA (shared)
// -------------------------------------------------------------------------
protected static IGASDK GetGameGa() {
if (gasdk == null) {
GAConfiguration.Builder builder = new GAConfiguration.Builder()
.withBaseUrl(BaseUrl.INTERNATIONAL)
.withContext(SDKWrapper.getInstance().getContext())
@@ -435,82 +455,61 @@ public class SDKManager {
return gasdk;
}
public static void SetGaUserInfo(String userId)
{
Log.e(TAG,"SetGaUserInfo : " + userId);
public static void SetGaUserInfo(String userId) {
Log.e(TAG, "SetGaUserInfo : " + userId);
SDKLog.i("SetGaUserInfo : " + userId);
GetGameGa().setUserId(userId);
}
public static void SetGaCommonInfo(String SetGaCommonInfo)
{
Log.e(TAG,"SetGaCommonInfo : " + SetGaCommonInfo);
public static void SetGaCommonInfo(String SetGaCommonInfo) {
Log.e(TAG, "SetGaCommonInfo : " + SetGaCommonInfo);
SDKLog.i("SetGaCommonInfo : " + SetGaCommonInfo);
Gson gson = new Gson();
Map<String, Object> map = gson.fromJson(SetGaCommonInfo, new TypeToken<Map<String, Object>>(){}.getType());
Map<String, Object> map = gson.fromJson(SetGaCommonInfo,
new TypeToken<Map<String, Object>>() {}.getType());
for (String key : map.keySet()) {
System.out.println("Key = " + key + ", Value = " + map.get(key));
if(!TextUtils.isEmpty(key) && map.get(key) != null){
if (!TextUtils.isEmpty(key) && map.get(key) != null) {
GetGameGa().addCommonParameter(key, map.get(key).toString());
}
}
}
public static void GAReportParams(int type, String eventstr, String paramstr)
{
public static void GAReportParams(int type, String eventstr, String paramstr) {
ParamsBuilder paramsBuilder = ParamsBuilder.newInstance();
Gson gson = new Gson();
Map<String, Object> map = gson.fromJson(paramstr, new TypeToken<Map<String, Object>>(){}.getType());
Map<String, Object> map = gson.fromJson(paramstr,
new TypeToken<Map<String, Object>>() {}.getType());
for (String key : map.keySet()) {
if(!TextUtils.isEmpty(key) && map.get(key) != null){
if (!TextUtils.isEmpty(key) && map.get(key) != null) {
paramsBuilder.append(key, map.get(key).toString());
}
}
// GA_TRACK = 1, //默认类型
// GA_CION = 2, //金流相关事件
// GA_PAY = 3, //支付相关事件
// GA_GAME = 4, //游戏行为
// GA_LOGIN = 5, //登录注册相关事件
// GA_PUSH = 6, //推送相关事件
// GA_ADBOX = 7, //adbox相关事件
// GA_PREFORMANCE = 8, //性能上报相关事件
// GA_SDK = 9, //SDK相关事件
// GA_ABTest = 10, //abtest相关事件
switch (type)
{
case 2:
GetGameGa().track(EventType.COIN , eventstr, paramsBuilder);
break;
case 3:
GetGameGa().track(EventType.PAY , eventstr, paramsBuilder);
break;
case 4:
GetGameGa().track(EventType.GAME , eventstr, paramsBuilder);
break;
case 5:
GetGameGa().track(EventType.LOGIN , eventstr, paramsBuilder);
break;
case 6:
GetGameGa().track(EventType.PUSH , eventstr, paramsBuilder);
break;
case 7:
GetGameGa().track(EventType.ADBOX , eventstr, paramsBuilder);
break;
case 8:
GetGameGa().track(EventType.PREFORMANCE , eventstr, paramsBuilder);
break;
case 9:
GetGameGa().track(EventType.SDK , eventstr, paramsBuilder);
break;
default:
GetGameGa().track(EventType.TRACK , eventstr, paramsBuilder);
break;
switch (type) {
case 2: GetGameGa().track(EventType.COIN, eventstr, paramsBuilder); break;
case 3: GetGameGa().track(EventType.PAY, eventstr, paramsBuilder); break;
case 4: GetGameGa().track(EventType.GAME, eventstr, paramsBuilder); break;
case 5: GetGameGa().track(EventType.PAY, eventstr, paramsBuilder); break;
case 6: GetGameGa().track(EventType.PUSH, eventstr, paramsBuilder); break;
case 7: GetGameGa().track(EventType.ADBOX, eventstr, paramsBuilder); break;
case 8: GetGameGa().track(EventType.PREFORMANCE, eventstr, paramsBuilder); break;
case 9: GetGameGa().track(EventType.SDK, eventstr, paramsBuilder); break;
default: GetGameGa().track(EventType.TRACK, eventstr, paramsBuilder); break;
}
}
public static void Review()
{
// -------------------------------------------------------------------------
// Review — channel dispatch
// -------------------------------------------------------------------------
public static void Review() {
if ("Rustore".equals(channel)) {
RuStoreReview();
} else {
GooglePlayReview();
}
}
private static void GooglePlayReview() {
ReviewManager manager = ReviewManagerFactory.create(SDKWrapper.getInstance().getContext());
Task<ReviewInfo> request = manager.requestReviewFlow();
request.addOnCompleteListener(reqTask -> {
@@ -519,16 +518,59 @@ public class SDKManager {
Activity activity = UnityPlayer.currentActivity;
manager.launchReviewFlow(activity, reviewInfo);
} else {
@ReviewErrorCode int reviewErrorCode = ((ReviewException) request.getException()).getErrorCode();
Log.e(TAG,"Review Error code: " + reviewErrorCode);
@ReviewErrorCode int reviewErrorCode =
((ReviewException) request.getException()).getErrorCode();
Log.e(TAG, "Review Error code: " + reviewErrorCode);
}
});
}
public static void FBShareLink(String title, String content, String url)
{
Log.e(TAG,"FBShareLink : " + title + " " + content + " " + url);
// RuStore two-step review
public interface ReviewResultCallback {
void onReviewSuccess(JSONObject result);
void onReviewError(int code, String msg);
}
public static void RequestRustoreReView(ReviewResultCallback callback) {
JSONObject json = new JSONObject();
try { json.put("action", "ACTION_REQUEST_REVIEW"); } catch (JSONException e) { throw new RuntimeException(e); }
SDKAPI.getIns().thirdExtend(json.toString(), (code, msg) -> {
Log.e(TAG, "RequestRustoreReView code=" + code + " msg=" + msg);
try {
JSONObject result = new JSONObject();
result.put("code", code);
if (code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS) {
if (callback != null) callback.onReviewSuccess(result);
} else {
result.put("thirdExtend_errStr", msg);
if (callback != null) callback.onReviewError(code, msg);
}
} catch (Exception e) {
SDKLog.e("RequestRustoreReView Exception: " + e);
}
});
}
public static void LaunchRustoreView() {
JSONObject json = new JSONObject();
try { json.put("action", "ACTION_LAUNCH_REVIEW"); } catch (JSONException e) { throw new RuntimeException(e); }
SDKAPI.getIns().thirdExtend(json.toString(), (code, msg) ->
Log.e(TAG, "LaunchRustoreView code=" + code + " msg=" + msg));
}
public static void RuStoreReview() {
RequestRustoreReView(new ReviewResultCallback() {
@Override public void onReviewSuccess(JSONObject result) { LaunchRustoreView(); }
@Override public void onReviewError(int code, String msg) { }
});
}
// -------------------------------------------------------------------------
// Facebook / Messenger share (shared)
// -------------------------------------------------------------------------
public static void FBShareLink(String title, String content, String url) {
Log.e(TAG, "FBShareLink : " + title + " " + content + " " + url);
if (ShareDialog.canShow(ShareLinkContent.class)) {
Activity activity = UnityPlayer.currentActivity;
ShareDialog dialog = new ShareDialog(activity);
@@ -537,30 +579,22 @@ public class SDKManager {
.setContentUrl(Uri.parse(url))
.build();
dialog.show(linkContent);
}
else
{
} else {
Log.e(TAG, "FBShareDialog can not show");
}
}
public static void MessengerShareLink(String title, String content, String url)
{
Log.e(TAG,"MessengerShareLink : " + title + " " + content + " " + url);
public static void MessengerShareLink(String title, String content, String url) {
Log.e(TAG, "MessengerShareLink : " + title + " " + content + " " + url);
if (MessageDialog.canShow(ShareLinkContent.class)) {
Activity activity = UnityPlayer.currentActivity;
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setQuote(content)
.setContentUrl(Uri.parse(url))
.build();
MessageDialog.show(activity,linkContent);
}
else
{
MessageDialog.show(activity, linkContent);
} else {
Log.e(TAG, "Messenger ShareDialog can not show");
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b4630fc5c78457748a2f763ac5168df6
guid: 1f7e4cbb67a383441bd126c06021a072
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,18 @@
namespace tysdk
{
public static class ChannelConfig
{
public static string Channel { get; private set; } = "GooglePlay";
public static string PayType => Channel switch
{
"Rustore" => "rustore.global.app",
"Flexion" => "flexion.global.app",
_ => "googleiab.global.app"
};
public static int LoginTimeoutSeconds => Channel == "Rustore" ? 120 : 30;
public static void SetChannel(string channel) { Channel = channel; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6dcc4e666f5907a47b1843de49da6f67
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 292a655e788d84d34aac4f83c57706ff
guid: cca93fc1d8dde744a86aff3c3a1b73ed
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,53 @@
using System.Collections.Generic;
namespace tysdk
{
// TYSdkFacade 的登录/链接/ATT 等方法要依赖这些 POCO。
public enum EAccoutType
{
hwGoogle,
hwFacebook,
hwGuest,
hwVkid,
Apple,
none
}
public class LoginInfo
{
public bool isSuccess;
public int userId;
public string StrUserId => userId.ToString();
public string msg;
public int code;
}
public class LinkResult
{
// 0: success, 1: fail, -1 exists
public int code;
// when success and fail userId is current user
// when exists userId is 0
public int userId;
// not none when exists
public Dictionary<string, string> bindInfo;
}
public class ChangeLinkResult
{
public int code;
public int userId;
public string msg;
}
public class LinkCheckInfo
{
public int code;
}
public class ATTInfo
{
public bool isAccepted;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2d36f2094aa5783423ab1ef40a88ccbe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -34,14 +34,20 @@ namespace tysdk
}
}
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>(){
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>()
{
{"google", EAccoutType.hwGoogle},
{"fb", EAccoutType.hwFacebook},
{"tyGuest", EAccoutType.hwGuest},
{"ios13", EAccoutType.Apple},
{AccountString.hwVkid, EAccoutType.hwVkid}
{"vk.global.app", EAccoutType.hwVkid},
};
public static void AddAccoutType(string key, EAccoutType value)
{
accoutTypeMap[key] = value;
}
private static EAccoutType ConvertAccoutType(string accountType)
{
if (accoutTypeMap.ContainsKey(accountType))
@@ -102,10 +108,11 @@ namespace tysdk
}
}
private static AccountInfo _accountInfo;
public static AccountInfo TYAccountInfo => _accountInfo;
// ================== Singleton ==================
private static TYSdkFacade _instance;
public static AccountInfo TYAccountInfo => _accountInfo;
protected static AccountInfo _accountInfo;
public static TYSdkFacade Instance
{
get
@@ -118,26 +125,27 @@ namespace tysdk
return _instance;
}
}
public static string Channel => ChannelConfig.Channel;
private int LoginTimeoutSeconds => ChannelConfig.LoginTimeoutSeconds;
// ================== Init ==================
public void Init()
{
#if UNITY_ANDROID
UnityBridgeFunc.InitSDK();
#endif
}
/*================================================
_ _
/ \ ___ ___ ___ _ _ _ __ | |_
/ _ \ / __/ __/ _ \| | | | '_ \| __|
/ ___ \ (_| (_| (_) | |_| | | | | |_
/_/ \_\___\___\___/ \__,_|_| |_|\__|
=================================================*/
public static bool IsLoggedIn => _accountInfo != null;
public void Logout()
@@ -154,7 +162,7 @@ namespace tysdk
public async Task<LoginInfo> Login(EAccoutType accoutType)
{
#if UNITY_EDITOR
#if UNITY_EDITOR
await Task.Yield();
var deviceId = UnityEngine.Device.SystemInfo.deviceUniqueIdentifier.Split('-')[0].Substring(0, 8);
@@ -172,25 +180,25 @@ namespace tysdk
};
#elif UNITY_ANDROID || UNITY_IOS
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(30));
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(LoginTimeoutSeconds));
UnityBridgeFunc.UnityLogin(accoutType);
try
{
var loginInfo = await task;
if(loginInfo.isSuccess)
{
_accountInfo.channel = accoutType;
_accountInfo.AddLinkedAccount(accoutType);
_accountInfo.Save();
}
return loginInfo;
var loginInfo = await task;
if (loginInfo.isSuccess)
{
_accountInfo.channel = accoutType;
_accountInfo.AddLinkedAccount(accoutType);
_accountInfo.Save();
}
return loginInfo;
}
catch(Exception e)
catch (Exception e)
{
Debug.LogWarning($"[TYSdkFacade] Login failed: {e}");
return new LoginInfo(){isSuccess = false};
Debug.LogWarning($"[TYSdkFacade] Login failed: {e}");
return new LoginInfo() { isSuccess = false };
}
#endif
}
@@ -219,7 +227,7 @@ namespace tysdk
return new LoginInfo() { isSuccess = false };
}
}
public async Task<LoginInfo> LoginBySns()
{
Debug.Log("[TYSdkFacade] LoginBySns");
@@ -304,18 +312,17 @@ namespace tysdk
UnityBridgeFunc.SetGaUserInfo(strUserId);
}
#if UNITY_EDITOR
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
{
await Task.Delay(300);
return new LinkResult(){code = 1};
return new LinkResult() { code = 1 };
}
#elif UNITY_IOS || UNITY_ANDROID
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
{
if (_accountInfo == null) return new LinkResult(){ code = 1};
if (_accountInfo.linkedAccout.Contains(accoutType)) return new LinkResult(){ code = 0};
if (_accountInfo == null) return new LinkResult() { code = 1 };
if (_accountInfo.linkedAccout.Contains(accoutType)) return new LinkResult() { code = 0 };
var task = TYSDKCallbackManager.Instance.RegisterCallback<LinkResult>(TimeSpan.FromMinutes(1));
UnityBridgeFunc.LinkAccount(accoutType);
@@ -337,6 +344,7 @@ namespace tysdk
return new LinkResult() { code = 1 };
}
}
#endif
public void LinkAccoutResult(string message)
{
@@ -359,7 +367,7 @@ namespace tysdk
}
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
#endif
public void CleanLinkTempSnSInfo()
{
UnityBridgeFunc.CleanLinkTmpSnsInfo();
@@ -367,6 +375,10 @@ namespace tysdk
public async Task<ChangeLinkResult> ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
{
#if UNITY_EDITOR
await Task.Delay(300);
return new ChangeLinkResult() { code = 1 };
#else
var task = TYSDKCallbackManager.Instance.RegisterCallback<ChangeLinkResult>(TimeSpan.FromSeconds(30));
UnityBridgeFunc.ChangeLinkAccount(accoutType, oldUserId, newUserId);
try
@@ -388,6 +400,7 @@ namespace tysdk
{
CleanLinkTempSnSInfo();
}
#endif
}
public void ChangeLinkAccountResult(string message)
@@ -402,14 +415,6 @@ namespace tysdk
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
/// <summary>
/// 检查是否已经绑定
/// <returns>
/// 1 已经绑定
/// 0 未绑定
/// -1 失败
/// </returns>
/// </summary>
public async Task<bool> LinkCheck(EAccoutType accoutType)
{
if (_accountInfo == null) return false;
@@ -435,7 +440,7 @@ namespace tysdk
return result.code == 1;
}
catch(Exception e)
catch (Exception e)
{
Debug.LogWarning($"[TYSdkFacade] CheckLinkResult error: {e}");
return false;
@@ -457,7 +462,6 @@ namespace tysdk
IConfig config = GContext.container.Resolve<IConfig>();
var tyurl = config.Get<string>("AGG_SERVER", defaultTyurl);
string tycs = tyurl == defaultTyurl ?
"https://hwcsh.tygameworld.com/template/appCancel/note.html"
:
@@ -479,23 +483,12 @@ namespace tysdk
string uid = $"uid={_accountInfo.userId}";
list.Add(uid);
string roleid = "roleid=0";
list.Add(roleid);
string gameid = "gameid=20587";
list.Add(gameid);
string cloudid = "cloudid=128";
list.Add(cloudid);
string gamename = "gamename=FishingTravel";
list.Add(gamename);
string certification = "certification=0";
list.Add(certification);
string ischannel = "ischannel=1";
list.Add(ischannel);
list.Add("roleid=0");
list.Add("gameid=20587");
list.Add("cloudid=128");
list.Add("gamename=FishingTravel");
list.Add("certification=0");
list.Add("ischannel=1");
string tysdktoken = $"tysdktoken={_accountInfo.token}";
list.Add(tysdktoken);
@@ -505,7 +498,6 @@ namespace tysdk
string listStr = string.Join("&", list.ToArray());
string sign = listStr +
"csh-api-6dfa879490a249be9fbc92e97e4d898d-api-csh";
//对sign进行MD5加密
string signMd5 = CalculateMD5Hash(sign);
string url = $"{tycs}?{listStr}&sign={signMd5}&isAbroad=1&lan=en";
Debug.Log($"[TYSdkFacade:Signout] url \n{url}");
@@ -514,25 +506,16 @@ namespace tysdk
private string CalculateMD5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: db12db58fbcc54046aa4dac203cd4971
guid: f2fa4b960a2b4594d80ea8b8caa2912d
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -4,17 +4,17 @@ using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
public partial class TYSdkFacade
{
/*================================================
_ _____ _____
_ _____ _____
/ \|_ _|_ _|
/ _ \ | | | |
/ ___ \| | | |
/_/ \_\_| |_|
=================================================*/
/ _ \ | | | |
/ ___ \| | | |
/_/ \_\_| |_|
=================================================*/
public bool IsAttAccepted()
{
@@ -25,25 +25,25 @@ namespace tysdk
{
#if UNITY_EDITOR || UNITY_ANDROID
await Task.Yield();
return new ATTInfo(){isAccepted = true};
return new ATTInfo() { isAccepted = true };
#elif UNITY_IOS
var task = tysdk.TYSDKCallbackManager.Instance.RegisterCallback<ATTInfo>();
var task = TYSDKCallbackManager.Instance.RegisterCallback<ATTInfo>();
UnityBridgeFunc.RequestATT();
try{
return await task;
}
catch(Exception e)
try
{
Debug.LogWarning(e.Message);
return new ATTInfo(){isAccepted = false};
return await task;
}
catch (Exception e)
{
Debug.LogWarning(e.Message);
return new ATTInfo() { isAccepted = false };
}
#endif
}
public void RequestATTResult(string r)
{
TYSDKCallbackManager.Instance.TryTriggerCallback(new ATTInfo(){isAccepted = r == "1"});
TYSDKCallbackManager.Instance.TryTriggerCallback(new ATTInfo() { isAccepted = r == "1" });
}
}
}

View File

@@ -1,3 +1,11 @@
fileFormatVersion: 2
guid: 8f92075f5f98490ca94ae4984ac0aa21
timeCreated: 1722855901
fileFormatVersion: 2
guid: 280d33ff6fcb3a342ab9683a01841b78
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,14 +2,14 @@ using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
public partial class TYSdkFacade
{
/*================================================
_____ _ _____ _
_____ _ _____ _
| ____|_ _____ _ __ | |_ |_ _| __ __ _ ___| | __
| _| \ \ / / _ \ '_ \| __| | || '__/ _` |/ __| |/ /
| |___ \ V / __/ | | | |_ | || | | (_| | (__| <
| |___ \ V / __/ | | | |_ | || | | (_| | (__| <
|_____| \_/ \___|_| |_|\__| |_||_| \__,_|\___|_|\_\
=================================================*/
@@ -21,18 +21,18 @@ namespace tysdk
#endif
}
}
public enum GATrackType
{
GA_TRACK = 1, //默认类型
GA_CION = 2, //金流相关事件
GA_PAY = 3, //支付相关事件
GA_GAME = 4, //游戏行为
GA_LOGIN = 5, //登录注册相关事件
GA_PUSH = 6, //推送相关事件
GA_ADBOX = 7, //adbox相关事件
GA_PREFORMANCE = 8, //性能上报相关事件
GA_SDK = 9, //SDK相关事件
GA_ABTest = 10, //abtest相关事件
GA_TRACK = 1,
GA_CION = 2,
GA_PAY = 3,
GA_GAME = 4,
GA_LOGIN = 5,
GA_PUSH = 6,
GA_ADBOX = 7,
GA_PREFORMANCE = 8,
GA_SDK = 9,
GA_ABTest = 10,
}
}

View File

@@ -1,3 +1,11 @@
fileFormatVersion: 2
guid: 18459dcf8d5a40dc80ffae5333a6b0c9
timeCreated: 1722855439
fileFormatVersion: 2
guid: aa58ede4826973c4bbe3a5ebfdcd4b43
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,32 +8,30 @@ using System.Text;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
public partial class TYSdkFacade
{
/*================================================
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
| |_) / _` | | | | '_ ` _ \ / _ \ '_ \| __|
| __/ (_| | |_| | | | | | | __/ | | | |_
| __/ (_| | |_| | | | | | | __/ | | | |_
|_| \__,_|\__, |_| |_| |_|\___|_| |_|\__|
|___/
|___/
=================================================*/
private bool _payFirstNegativeHandled;
//public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count, string pType, string price_amount_micros =null)
public async Task<PaymentInfo> Pay(SKUDetail prod, int count, float usdprice, JObject purchaseInfo)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
var orderId = System.Guid.NewGuid().ToString();
if(purchaseInfo == null)
if (purchaseInfo == null)
purchaseInfo = new JObject();
string extraInfo = purchaseInfo.ToString(Newtonsoft.Json.Formatting.None);
//to base64
extraInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(extraInfo));
Debug.Log("[TYSdk] extraInfo: " + extraInfo);
var prodId = prod.ProdID;
@@ -57,14 +55,13 @@ namespace tysdk
return result;
#elif UNITY_ANDROID
var pType = "googleiab.global.app";
var pType = ChannelConfig.PayType;
var task = TYSDKCallbackManager.Instance.RegisterCallback<PaymentInfo>(TimeSpan.FromSeconds(30));
try
{
//UnityBridgeFunc.UnityKnow(prodId, prodName, count.ToString(), orderId, extraInfo);
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo,pType);
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo, pType);
var result = await task;
result.count = count;
@@ -108,7 +105,6 @@ namespace tysdk
#endif
}
//支付的回调
public void PayResult(string json)
{
Debug.Log("[TYSdkFacade] pay callback:" + json);
@@ -116,7 +112,7 @@ namespace tysdk
var result = new PaymentInfo();
result.code = jresult["code"].ToString();
result.msg = jresult["errStr"].ToString();
if(result.code == "-1")
if (result.code == "-1")
{
if (!_payFirstNegativeHandled)
{
@@ -133,12 +129,11 @@ namespace tysdk
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
// Get Pay list
public async Task<ProductListInfo> GetSKUList()
{
if (!IsLoggedIn) return new ProductListInfo() { code = -1, msg = "未登录" };
#if UNITY_EDITOR
#if UNITY_EDITOR
await Task.Yield();
var result = new ProductListInfo();
@@ -151,7 +146,6 @@ namespace tysdk
#endif
}
//商品列表的回调
public void SKUListResult(string json)
{
Debug.Log("[TYSdkFacade] GetSKUList callback");
@@ -174,7 +168,3 @@ namespace tysdk
}
}
}

View File

@@ -1,3 +1,11 @@
fileFormatVersion: 2
guid: 41b6dc16dbab43388317bf9ff032cdca
timeCreated: 1722855703
fileFormatVersion: 2
guid: e05900a4aa124d746bfe9c15328fd0e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,62 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace tysdk
{
public enum EAccoutType
{
hwGoogle,
hwFacebook,
hwGuest,
hwVkid,
Apple,
none
}
public static class AccountString
{
public const string hwVkid = "vk.global.app";
}
public class LoginInfo
{
public bool isSuccess;
public int userId;
public string StrUserId => userId.ToString();
public string msg;
public int code;
}
public class LinkResult
{
// 0: success, 1: fail, -1 exists
public int code;
// when success and fail userId is current user
// when exists userId is 0
public int userId;
// not none when exists
public Dictionary<string, string> bindInfo;
}
public class ChangeLinkResult
{
public int code;
public int userId;
public string msg;
}
public class LinkCheckInfo
{
public int code;
}
public class PaymentInfo
{
public bool isSuccessFromSdk => code == "0";
public bool isSuccess => isSuccessFromSdk && confirmed;
private bool confirmed {get; set;} = false;
private bool confirmed { get; set; } = false;
public int count;
public string orderId;
public string productId;
@@ -65,21 +17,26 @@ namespace tysdk
public string code;
public string msg;
// Flexion: purchase.getOriginalJson(), used by server for RSA signature verification
public string purchaseJson;
// Flexion: purchase.getSignature(), used by server for RSA signature verification
public string signature;
public bool Check(string orderId, string productId)
{
confirmed = orderId == this.orderId && productId == this.productId;
if(!confirmed)
if (!confirmed)
UnityEngine.Debug.LogWarning("[TYSdk Pay] order not confirmed");
return confirmed;
}
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
return JsonConvert.SerializeObject(this);
}
}
public class ProductListInfo
{
public int code = 1;
@@ -103,7 +60,6 @@ namespace tysdk
products = prodList;
}
#endif
}
#if UNITY_IOS
@@ -124,7 +80,7 @@ namespace tysdk
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
return JsonConvert.SerializeObject(this);
}
}
#else
@@ -132,28 +88,30 @@ namespace tysdk
{
public string description;
public string ourProductId;
public string productId;
public string price;
public string price_amount_micros;
public string price_currency_code;
public string productId;
public string title;
public string type;
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
// RuStore specific
public string currency;
public string price_amount;
public string ProdPriceStr => price;
public float ProdPrice => float.Parse(price_amount_micros) / 1000000;
public string ProdPriceStr => ChannelConfig.Channel == "Rustore"
? $"₽{ProdPrice}"
: price;
public float ProdPrice => ChannelConfig.Channel == "Rustore"
? float.Parse(price) / 100
: float.Parse(price_amount_micros) / 1000000;
public string ProdID => ourProductId;
public string ProdKey => productId;
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
#endif
public class ATTInfo
{
public bool isAccepted;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b94c8e87cc23b4053a4cbf592ff14db3
guid: ebabed604bd06e44099073951d667658
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -4,64 +4,46 @@ using UnityEngine;
namespace tysdk
{
public static class UnityBridgeFunc
{
#if UNITY_EDITOR || UNITY_ANDROID
private static string EAccountTypeToStr(EAccoutType accountType)
{
return accountType == EAccoutType.hwVkid ? AccountString.hwVkid : accountType.ToString();
}
#if UNITY_EDITOR
public static void InitSDK() { }
#endif
#if UNITY_EDITOR
//初始化sdk
public static void InitSDK(){}
//更新登录支付域名
public static void UnityResetServerUrl(string url){}
public static void UnityResetServerUrl(string url) { }
//登录
public static void UnityLoginByTokenFun(string token){}
public static void UnityLoginByTokenFun(string token) { }
public static string UnityLoginBySnsInfoFun() => null;
public static void UnityLogin(EAccoutType accoutType){}
public static void UnityLogin(EAccoutType accoutType) { }
public static void CleanLinkTmpSnsInfo() { }
public static void LinkAccount(EAccoutType accoutType){}
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId){}
public static void LinkCheck(EAccoutType accoutType){}
public static void LinkAccount(EAccoutType accoutType) { }
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId) { }
public static void LinkCheck(EAccoutType accoutType) { }
public static void UnityGetIdentityFun(string type){}
public static void UnityGetIdentityFun(string type) { }
public static void UnityLogOutByChannel(EAccoutType accoutType) { }
public static void UnityLogOutByChannel(EAccoutType accoutType){}
//支付new
public static void UnityKnowNew(string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo, string pType) { }
//支付
public static void UnityKnow(String productId, String productName, String productCount,
String prodorderId, String appInfo) {}
//获取商品列表
String prodorderId, String appInfo) { }
public static void GetSKUList() { }
//打点
public static void SetGaUserInfo(string userId){}
public static void SetGaUserInfo(string userId) { }
public static void SetGaCommonInfo(string SetGaCommonInfo){}
public static void SetGaCommonInfo(string SetGaCommonInfo) { }
public static void GAReportParams(int type, string eventstr, string paramstr){}
public static void GAReportParams(int type, string eventstr, string paramstr) { }
//ATT
public static void RequestATT(){}
public static void RequestATT() { }
public static int GetATT() {return 1;}
public static int GetATT() { return 1; }
public static void Review() { }
@@ -72,30 +54,34 @@ namespace tysdk
private static string SDK_CLASS = "com.unity3d.player.SDKManager";
//初始化sdk
public static void InitSDK(){
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
private static string EAccountTypeToStr(EAccoutType accoutType)
{
return accoutType == EAccoutType.hwVkid ? "vk.global.app" : accoutType.ToString();
}
public static void InitSDK()
{
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
using(var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var activity = activityCls.GetStatic<AndroidJavaObject>("currentActivity");
sdkManager.CallStatic("InitSDK", activity);
sdkManager.CallStatic("InitSDK", activity, ChannelConfig.Channel);
}
}
}
//更新登录支付域名
public static void UnityResetServerUrl(string url)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityResetServerUrl", url);
}
}
//登录
public static void UnityLoginByTokenFun(string token)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLoginByTokenFun", token);
}
@@ -103,7 +89,7 @@ namespace tysdk
public static String UnityLoginBySnsInfoFun()
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
return sdkManager.CallStatic<string>("UnityLoginBySnsInfo");
}
@@ -112,16 +98,15 @@ namespace tysdk
public static void UnityLogin(EAccoutType accoutType)
{
var accountInfo = EAccountTypeToStr(accoutType);
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLogin",accountInfo);
sdkManager.CallStatic("UnityLogin", accountInfo);
}
}
public static void UnityGetIdentityFun(string type)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityGetIdentityFun", type);
}
@@ -129,9 +114,8 @@ namespace tysdk
public static void UnityLogOutByChannel(EAccoutType accoutType)
{
var accountInfo = EAccountTypeToStr(accoutType);
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLogOutByChannel", accountInfo);
}
@@ -140,20 +124,18 @@ namespace tysdk
public static void LinkAccount(EAccoutType accoutType)
{
string userId = TYSdkFacade.TYAccountInfo.strUserId;
var accountInfo = EAccountTypeToStr(accoutType);
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
var accountInfo = EAccountTypeToStr(accoutType);
sdkManager.CallStatic("LinkAccount",accountInfo,userId);
sdkManager.CallStatic("LinkAccount", accountInfo, userId);
}
}
public static void CleanLinkTmpSnsInfo(){
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
public static void CleanLinkTmpSnsInfo()
{
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
using(var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
sdkManager.CallStatic("CleanLinkTmpSnsInfo");
}
sdkManager.CallStatic("CleanLinkTmpSnsInfo");
}
}
@@ -169,47 +151,42 @@ namespace tysdk
public static void LinkCheck(EAccoutType accoutType)
{
var accountInfo = EAccountTypeToStr(accoutType);
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("LinkCheck",accountInfo);
sdkManager.CallStatic("LinkCheck", accountInfo);
}
}
//支付new
public static void UnityKnowNew(string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo,string pType)
string productCount, string prodorderId, string appInfo, string pType)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityKnowNew", productId, productPrice, productName,
productCount, prodorderId, appInfo,pType);
productCount, prodorderId, appInfo, pType);
}
}
//支付
public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo)
public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityKnow", productId, productName, productCount, prodorderId, appInfo);
sdkManager.CallStatic("UnityKnow", productId, productName, productCount, prodorderId, appInfo);
}
}
//获取商品列表
public static void GetSKUList()
{
UnityEngine.Debug.Log("UnityBridgeFunc.GetSKUList()");
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("thirdExtend");
}
}
//打点
public static void SetGaUserInfo(string userId)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("SetGaUserInfo", userId);
}
@@ -217,7 +194,7 @@ namespace tysdk
public static void SetGaCommonInfo(string SetGaCommonInfo)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("SetGaCommonInfo", SetGaCommonInfo);
}
@@ -225,38 +202,35 @@ namespace tysdk
public static void GAReportParams(int type, string eventstr, string paramstr)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("GAReportParams", type, eventstr, paramstr);
}
}
public static void RequestATT() { }
//ATT
public static void RequestATT(){}
public static int GetATT() {return 1;}
public static int GetATT() { return 1; }
public static void Review()
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("Review");
// sdkManager.CallStataic("RuStoreReview");
}
}
public static void FBShareLink(string title, string content, string url)
public static void FBShareLink(string title, string content, string url)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("FBShareLink", title, content, url);
}
}
public static void MessengerShareLink(string title, string content, string url)
public static void MessengerShareLink(string title, string content, string url)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("MessengerShareLink", title, content, url);
}
@@ -264,11 +238,9 @@ namespace tysdk
#elif UNITY_IOS
//更新登录支付域名
[DllImport("__Internal")]
public static extern void UnityResetServerUrl(string url);
//登录
[DllImport("__Internal")]
public static extern void UnityLoginByTokenFun(string token);
@@ -284,7 +256,6 @@ namespace tysdk
return string.Empty;
}
// Convert C string to C# string
string result = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr);
return result ?? string.Empty;
}
@@ -375,7 +346,6 @@ namespace tysdk
}
}
[DllImport("__Internal")] private static extern void LinkGoogle(int userId);
[DllImport("__Internal")] private static extern void LinkFacebook(int userId);
[DllImport("__Internal")] private static extern void LinkApple(int userId);
@@ -393,31 +363,25 @@ namespace tysdk
case EAccoutType.hwFacebook:
IsLinkedFacebook();
break;
case EAccoutType.Apple:
IsLinkedApple();
break;
}
}
[DllImport("__Internal")] public static extern void CleanLinkTmpSnsInfo();
[DllImport("__Internal")] private static extern void IsLinkedGoogle();
[DllImport("__Internal")] private static extern void IsLinkedFacebook();
[DllImport("__Internal")] private static extern void IsLinkedApple();
//支付
[DllImport("__Internal")]
public static extern void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo);
//获取商品列表
[DllImport("__Internal")]
public static extern void GetSKUList();
//打点
[DllImport("__Internal")]
public static extern void SetGaUserInfo(string userId);
@@ -427,7 +391,6 @@ namespace tysdk
[DllImport("__Internal")]
public static extern void GAReportParams(int type, string eventstr, string paramstr);
//ATT
[DllImport("__Internal")]
public static extern void RequestATT();

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 16335dd05906d48bf81e297920aecf31
guid: e24b3b915d94468419519a81bb69e269
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -14,4 +14,4 @@
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
}