[M] all functional

This commit is contained in:
2024-08-16 00:56:24 +08:00
parent c355784122
commit 1a0af9d725
14 changed files with 1278 additions and 171 deletions

View File

@@ -21,6 +21,7 @@ public class ConfigManager {
public static final String UNITY_FACADE_NAME = "TYSdkFacade";
public static final String LOGIN_CALLBACK_FUNCTION_NAME = "LoginResult";
public static final String CHECKLINK_CALLBACK_FUNCTION_NAME = "CheckLinkResult";
public static final String PAY_CALLBACK_FUNCTION_NAME = "PayResult";
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
public static final String FCM_NOTICE_FUNCTION_NAME = "FCMCallback";

View File

@@ -65,7 +65,6 @@ public class SDKManager {
public static void parseLoginInfo(int i, String s) {
Log.e(TAG,"parseLoginInfo!!" );
try {
JSONObject result = new JSONObject();
result.put("code", i);
@@ -74,19 +73,15 @@ public class SDKManager {
JSONObject userInfo = serverResponse.getJSONObject("result");
JSONObject userInfoReorganization = new JSONObject();
userInfoReorganization.put("userId", userInfo.optString("userId"));
userInfoReorganization.put("authorCode", userInfo.optString("authorCode"));
userInfoReorganization.put("token", userInfo.optString("token"));
userInfoReorganization.put("jwttoken", userInfo.optString("jwttoken"));
userInfoReorganization.put("loginChannelTypeC", userInfo.optString("loginChannelTypeC"));
JSONObject userInfoResult = new JSONObject();
userInfoResult.put("result", userInfoReorganization);
result.put("respObj", userInfoResult);
Log.e(TAG,"userId:::::" + userInfo.optString("userId"));
Log.e(TAG,"token:::::" + userInfo.optString("token"));
} else {
Log.e(TAG,"errStr:::::" +s);
result.put("errStr", s);
Log.e(TAG,"errStrInfo:::::" +result.toString());
}
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, result.toString());
@@ -163,13 +158,59 @@ public class SDKManager {
});
}
public static void UnityLogOutByChannel(string type) {
public static void UnityLogOutByChannel(String type) {
// Log.e(TAG,"UnityLoginOut!!!");
SDKLog.i("UnityLoginOut : ");
handler.post(() -> SDKAPI.getIns().logout(type));
}
public static void UnityKnow(String userId, String productId, String productPrice, String productName, String productCount, String prodorderId, String appInfo) {
public static void LinkAccount(String type, String userId)
{
SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> {
if(code == SDKCallBack.CODE_SUCCESS && snsInfo != null){
SDKAPI.getIns().bindBySnsId(snsInfo, userId, mLogin);
}else {
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}}");
}
});
}
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");
}
});
}
public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo) {
SDKLog.i("UnityKnow : " + productId);
HashMap<String, String> extraInfo = new HashMap<String, String>();
extraInfo.put("appInfo", appInfo);

View File

@@ -218,24 +218,80 @@ extern "C" {
}
//广告相关
void UnitySetAdBoxUserInfo(char* userId)
void LinkGoogle(const int userId)
{
}
void UnityInitADSConfig()
{
}
void UnityLoadRvADS()
{
NSLog(@"TYSdkInterface LinkGoogle");
NSDictionary * userDic = [XYApi XYGetCurrentUserDict];
XYBindReq *bindReq = [XYBindReq initBindWithPlatform:XYBindGoodle UserId: [ [userDic objectForKey:@"userId"] unsignedIntegerValue]];
[XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull resp) {
if(resp.errCode == XYSuccess)
{
NSLog(@"TYSdkInterface LinkGoogle Success");
UnitySendMessage("TYSdkFacade","LinkAccoutResult", "1");
}
else
{
NSLog(@"TYSdkInterface LinkGoogle Faild");
UnityLogoutGoogle();
UnitySendMessage("TYSdkFacade","LinkAccoutResult", "0");
}
}];
}
void UnityShowRVAD()
void IsLinkedGoogle()
{
[XYApi CheckUserExist:XYBindGoodle completion:^(XYResp * _Nonnull resp) {
if (resp.errCode == XYSNSExist) {
UnitySendMessage("TYSdkFacade","CheckLinkResult", "1");
}else if (resp.errCode == XYSNSNotExist){
UnitySendMessage("TYSdkFacade","CheckLinkResult", "0");
} else {
UnitySendMessage("TYSdkFacade","CheckLinkResult", "-1");
}
}];
}
void UnlinkGoogle()
{
}
void LinkFacebook(const int userId)
{
NSLog(@"TYSdkInterface LinkFacebook");
NSDictionary * userDic = [XYApi XYGetCurrentUserDict];
XYBindReq *bindReq = [XYBindReq initBindWithPlatform:XYBindFB UserId: [ [userDic objectForKey:@"userId"] unsignedIntegerValue]];
[XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull resp) {
if(resp.errCode == XYSuccess)
{
NSLog(@"TYSdkInterface LinkFacebook Success");
UnitySendMessage("TYSdkFacade","LinkAccoutResult", "1");
}
else
{
NSLog(@"TYSdkInterface LinkFacebook Faild");
UnityLogoutFacebook();
UnitySendMessage("TYSdkFacade","LinkAccoutResult", "0");
}
}];
}
void IsLinkedFacebook()
{
[XYApi CheckUserExist:XYBindFB completion:^(XYResp * _Nonnull resp) {
if (resp.errCode == XYSNSExist) {
UnitySendMessage("TYSdkFacade","CheckLinkResult", "1");
}else if (resp.errCode == XYSNSNotExist){
UnitySendMessage("TYSdkFacade","CheckLinkResult", "0");
} else {
UnitySendMessage("TYSdkFacade","CheckLinkResult", "-1");
}
}];
}
void UnlinkFacebook()
{
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using asap.core;
using Newtonsoft.Json.Linq;
@@ -21,18 +22,44 @@ namespace tysdk
public string token;
public string jwtToken;
public string strUserId => userId.ToString();
public string channelstr;
public EAccoutType channel => accoutTypeMap[channelstr];
public string channelstr {
set{
channel = accoutTypeMap[value];
linkedAccout.Add(channel);
}
}
public HashSet<EAccoutType> linkedAccout = new HashSet<EAccoutType>();
public EAccoutType channel {get; private set;}
private const string KEY_ACCOUNT_INFO = "KEY_ACCOUNT_INFO";
public void AddLinkedAccount(EAccoutType accoutType)
{
if (!linkedAccout.Contains(accoutType))
{
linkedAccout.Add(accoutType);
}
}
public void AddLinkedAccount(string channel)
{
if(accoutTypeMap.TryGetValue(channel, out var accoutType))
{
if (!linkedAccout.Contains(accoutType))
{
linkedAccout.Add(accoutType);
}
}
}
public void Save()
{
JObject jInfo = new JObject();
jInfo["channel"] = channelstr;
jInfo["channel"] = accoutTypeMap.First(x => x.Value == channel).Key;
jInfo["token"] = token;
jInfo["userId"] = userId;
jInfo["jwtToken"] = jwtToken;
jInfo["linkedAccout"] = string.Join(",", linkedAccout.Select(x => x.ToString()));
PlayerPrefs.SetString(KEY_ACCOUNT_INFO, jInfo.ToString());
}
@@ -52,6 +79,7 @@ namespace tysdk
token = (string)jInfo["token"],
channelstr = (string)jInfo["channel"],
jwtToken = (string)jInfo["jwtToken"],
linkedAccout = jInfo["linkedAccout"].ToString().Split(',').Select(x => (EAccoutType)Enum.Parse(typeof(EAccoutType), x)).ToHashSet()
};
}
else
@@ -62,7 +90,7 @@ namespace tysdk
}
private static AccountInfo _accountInfo;
public AccountInfo TYAccountInfo => _accountInfo;
public static AccountInfo TYAccountInfo => _accountInfo;
private static IDictionary<string, Action<ITYSdkCallback>> callbacks = new Dictionary<string, Action<ITYSdkCallback>>();
@@ -177,16 +205,32 @@ namespace tysdk
{
var loginData = data["respObj"]["result"];
_accountInfo = new AccountInfo()
var userId = (int)loginData["userId"];
var token = (string)loginData["token"];
var jwtToken = (string)loginData["jwttoken"];
var channelstr = (string)loginData["loginChannelTypeC"];
var savedInfo = AccountInfo.GetSavedAccoutInfo();
if(savedInfo == null || savedInfo.userId != userId)
{
userId = (int)loginData["userId"],
token = (string)loginData["token"],
jwtToken = (string)loginData["jwttoken"],
channelstr = (string)loginData["loginChannelTypeC"]
};
_accountInfo.Save();
_accountInfo = new AccountInfo()
{
userId = (int)loginData["userId"],
token = (string)loginData["token"],
jwtToken = (string)loginData["jwttoken"],
channelstr = (string)loginData["loginChannelTypeC"]
};
_accountInfo.Save();
}
else
{
savedInfo.token = token;
savedInfo.jwtToken = jwtToken;
savedInfo.AddLinkedAccount(channelstr);
savedInfo.Save();
_accountInfo = savedInfo;
}
result.isSuccess = true;
result.userId = _accountInfo.userId;
@@ -207,5 +251,71 @@ namespace tysdk
UnityBridgeFunc.SetGaUserInfo(strUserId);
}
public async Task<bool> LinkAccount(EAccoutType accoutType)
{
if (_accountInfo == null) return false;
if( _accountInfo.linkedAccout.Contains(accoutType)) return true;
var taskSource = new TaskCompletionSource<LoginInfo>();
callbacks.Add("LoginResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((LoginInfo)callback);
});
UnityBridgeFunc.LinkAccount(accoutType);
var result = await taskSource.Task;
return result.isSuccess;
}
/// <summary>
/// 检查是否已经绑定
/// <returns>
/// 1 已经绑定
/// 0 未绑定
/// -1 失败
/// </returns>
/// </summary>
public async Task<bool> LinkCheck(EAccoutType accoutType)
{
if (_accountInfo == null) return false;
if( _accountInfo.linkedAccout.Contains(accoutType)) return true;
var taskSource = new TaskCompletionSource<LinkCheckInfo>();
callbacks.Add("CheckLinkResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((LinkCheckInfo)callback);
});
UnityBridgeFunc.LinkCheck(accoutType);
var code = (await taskSource.Task).code;
if (code == 1 && !_accountInfo.linkedAccout.Contains(accoutType))
{
_accountInfo.linkedAccout.Add(accoutType);
_accountInfo.Save();
}
if(code == -1)
{
Debug.LogError("[TYSdkFacade] CheckLinkResult error");
}
return code == 1;
}
public void CheckLinkResult(string codestr)
{
if (callbacks.TryGetValue("CheckLinkResult", out var action))
{
var result = new LinkCheckInfo();
result.code = int.Parse(codestr);
action.Invoke(result);
callbacks.Remove("CheckLinkResult");
}
}
}
}

View File

@@ -1,61 +0,0 @@
using System;
using asap.core;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
_ ____
/ \ | _ \
/ _ \ | | | |
/ ___ \| |_| |
/_/ \_\____/
=================================================*/
public void InitAdCallback(string jstr)
{
try{
var jobj = JObject.Parse(jstr);
if(jobj["code"].ToString() == "0")
UnityEngine.Debug.Log($"[TYSdkFacade] InitAdCallback Success");
else
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback Failed ");
}
catch(Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] InitAdCallback error: {e.Message}");
}
}
public void LoadAdCallback(string jstr)
{
try
{
var adLoadinfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ADLoadInfo>(jstr);
GContext.Publish(adLoadinfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] LoadAdCallback error: {e.Message}");
}
}
public void ShowAdCallback(string jstr)
{
try
{
var adShowInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ShowADInfo>(jstr);
GContext.Publish(adShowInfo);
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[TYSdkFacade] ShowAdCallback error: {e.Message}");
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 179ddafea9354cadbfabca342e552139
timeCreated: 1722855804

View File

@@ -18,18 +18,26 @@ namespace tysdk
|___/
=================================================*/
public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count, string pType)
//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)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
var orderId = System.Guid.NewGuid().ToString();
var extraDic = new Dictionary<string, object>() {
Dictionary<string, object> extraDic = new Dictionary<string, object>() {
{"paytime" , System.DateTime.UtcNow.Ticks},
{"sum" , float.Parse(prodPrice) * count},
{"sum" , prod.ProdPrice * count},
};
string extraInfo = Newtonsoft.Json.JsonConvert.SerializeObject(extraDic);
//to base64
extraInfo = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(extraInfo));
var prodId = prod.ProdID;
var prodPrice = prod.price;
var prodName = prod.title;
var pType = "googleiab.global.app";
#if UNITY_EDITOR
@@ -44,6 +52,7 @@ namespace tysdk
price = prodPrice
};
return result;
#elif UNITY_ANDROID
@@ -52,7 +61,10 @@ namespace tysdk
{
taskSource.SetResult((PaymentInfo)callback);
});
//UnityBridgeFunc.UnityKnow(prodId, prodName, count.ToString(), orderId, extraInfo);
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo,pType);
var result = await taskSource.Task;
result.count = count;
result.orderId = orderId;

View File

@@ -23,6 +23,11 @@ namespace tysdk
public int code;
}
public class LinkCheckInfo : ITYSdkCallback
{
public int code;
}
public class PaymentInfo : ITYSdkCallback
{
public bool isSuccess => code == "0";
@@ -56,7 +61,7 @@ namespace tysdk
LocaleCurrencyCode = x["LocaleCurrencyCode"].ToString(),
localeCurrencySymbol = x["localeCurrencySymbol"].ToString(),
localizedDescription = x["localizedDescription"].ToString(),
localizedTitle = x["localizedTitle"].ToString()
title = x["localizedTitle"].ToString()
};
}).ToList();
products = prodList;
@@ -81,6 +86,10 @@ namespace tysdk
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
public string ProdPriceStr => price;
public float ProdPrice => float.Parse(price_amount_micros) / 1000000;
public string ProdID => ourProductId;
}
#elif UNITY_IOS
public class SKUDetail
@@ -90,7 +99,12 @@ namespace tysdk
public string LocaleCurrencyCode;
public string localeCurrencySymbol;
public string localizedDescription;
public string localizedTitle;
public string title;
public string type;
public string ProdPriceStr => price;
public float ProdPrice => float.Parse(price);
public string ProdID => productId;
public override string ToString()
{
@@ -104,41 +118,4 @@ namespace tysdk
{
public bool isAccepted;
}
public class ADLoadInfo
{
public bool isSuccess => code == "0";
public string code;
public string errStr;
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
public enum EShowAdState : byte
{
StartShow = 1,
Reward = 2,
Loading = 3,
LoadFaild = 4,
ShowFaild = 5,
Closed = 6,
Finished = 7,
TimeOut = 8
}
public class ShowADInfo
{
public string code;
public string message;
public string reward;
public EShowAdState state => (EShowAdState)int.Parse(code);
public override string ToString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
}
}
}

View File

@@ -18,6 +18,9 @@ namespace tysdk
//登录
public static void UnityLoginByTokenFun(string token){}
public static void UnityLogin(EAccoutType accoutType){}
public static void LinkAccount(EAccoutType accoutType){}
public static void UnlinkAccount(EAccoutType accoutType){}
public static void LinkCheck(EAccoutType accoutType){}
public static void UnityGetIdentityFun(string type){}
@@ -27,8 +30,9 @@ namespace tysdk
string productCount, string prodorderId, string appInfo, string pType) { }
//支付
public static void UnityKnow(string userId, string productId, string productPrice, string productName,
string productCount, string prodorderId, string appInfo){}
public static void UnityKnow(String productId, String productName, String productCount,
String prodorderId, String appInfo) {}
//获取商品列表
public static void GetSKUList() { }
@@ -81,11 +85,9 @@ namespace tysdk
public static void UnityLogin(EAccoutType accoutType)
{
var typeName = GetLoginTypeName(accoutType);
Debug.LogError("typeName:::" + typeName);
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLogin", typeName);
sdkManager.CallStatic("UnityLogin", accoutType.ToString());
}
}
@@ -99,7 +101,36 @@ namespace tysdk
public static void UnityLogOutByChannel(EAccoutType accoutType)
{
sdkManager.CallStatic("UnityLogOutByChannel", accoutType.ToString());
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLogOutByChannel", accoutType.ToString());
}
}
public static void LinkAccount(EAccoutType accoutType)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
string userId = TYSdkFacade.TYAccountInfo.strUserId;
sdkManager.CallStatic("LinkAccount", accoutType.ToString(), userId);
}
}
public static void UnlinkAccount(EAccoutType accoutType)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnlinkAccount", accoutType.ToString());
}
}
public static void LinkCheck(EAccoutType accoutType)
{
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("LinkCheck", accoutType.ToString());
}
}
//支付new
@@ -113,20 +144,21 @@ namespace tysdk
productCount, prodorderId, appInfo,pType);
}
}
//支付
public static void UnityKnow(string userId, string productId, string productPrice, 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))
{
sdkManager.CallStatic("UnityKnow",userId, productId, productPrice, 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))
{
sdkManager.CallStatic("thirdExtend");
@@ -231,6 +263,54 @@ namespace tysdk
[DllImport("__Internal")]
private static extern void UnityLogoutGuest();
public static void LinkAccount(EAccoutType accoutType)
{
switch (accoutType)
{
case EAccoutType.hwGoogle:
LinkGoogle();
break;
case EAccoutType.hwFacebook:
LinkFacebook();
break;
}
}
public static void UnlinkAccount(EAccoutType accoutType)
{
switch (accoutType)
{
case EAccoutType.hwGoogle:
UnlinkGoogle();
break;
case EAccoutType.hwFacebook:
UnlinkFacebook();
break;
}
}
[DllImport("__Internal")] private static extern void LinkGoogle();
[DllImport("__Internal")] private static extern void UnlinkGoogle();
[DllImport("__Internal")] private static extern void LinkFacebook();
[DllImport("__Internal")] private static extern void UnlinkFacebook();
public static void LinkCheck(EAccoutType accoutType)
{
switch (accoutType)
{
case EAccoutType.hwGoogle:
IsLinkedGoogle();
break;
case EAccoutType.hwFacebook:
IsLinkedFacebook();
break;
}
}
[DllImport("__Internal")] private static extern void IsLinkedGoogle();
[DllImport("__Internal")] private static extern void IsLinkedFacebook();
//支付
[DllImport("__Internal")]
public static extern void UnityKnow(string userId, string productId, string productPrice, string productName,