[M] login & logout & payment
- login by token - save account info - logout remove accout info - iOS SKU list parser - iOS Pay
This commit is contained in:
@@ -142,7 +142,6 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
public static void UnityGetIdentityFun(String type) {
|
||||
curType = type;
|
||||
Log.e(TAG,"UnityGetIdentityFun : " + type);
|
||||
SDKLog.i("UnityGetIdentityFun : " + type);
|
||||
handler.post(new Runnable() {
|
||||
@@ -154,7 +153,6 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
public static void UnityLogin(String type) {
|
||||
curType = type;
|
||||
Log.e(TAG,"UnityLogin : " + type);
|
||||
SDKLog.i("UnityLogin : " + type);
|
||||
handler.post(new Runnable() {
|
||||
@@ -165,10 +163,10 @@ public class SDKManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static void UnityLoginOut() {
|
||||
public static void UnityLogOutByChannel(string type) {
|
||||
// Log.e(TAG,"UnityLoginOut!!!");
|
||||
SDKLog.i("UnityLoginOut : ");
|
||||
handler.post(() -> SDKAPI.getIns().logout(curType));
|
||||
handler.post(() -> SDKAPI.getIns().logout(type));
|
||||
}
|
||||
|
||||
public static void UnityKnow(String userId, String productId, String productPrice, String productName, String productCount, String prodorderId, String appInfo) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <XYSDK/XYSDK.h>
|
||||
#import <GASDK/GAConstants.h>
|
||||
#import <GASDK/GASDK.h>
|
||||
#import "TYConfig.h"
|
||||
|
||||
#define TOKEN_ERROR @"-8"
|
||||
extern "C" {
|
||||
@@ -118,6 +121,23 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnityLogoutGoogle()
|
||||
{
|
||||
NSLog(@"TYSdkInterface UnityLogOut Google");
|
||||
[XYApi XYLogoutChannelWithType:XYLoginWithGoogle];
|
||||
}
|
||||
void UnityLogoutFacebook()
|
||||
{
|
||||
NSLog(@"TYSdkInterface UnityLogOut Facebook");
|
||||
[XYApi XYLogoutChannelWithType:XYLoginWithFB];
|
||||
}
|
||||
|
||||
void UnityLogoutGuest()
|
||||
{
|
||||
NSLog(@"TYSdkInterface UnityLogOutGuset");
|
||||
[XYApi XYLogoutChannelWithType:XYLoginWithGuest];
|
||||
}
|
||||
|
||||
//支付
|
||||
void UnityKnow(const char* userId,const char* productId,const char* productPrice,const char* productName,const char* productCount,const char* orderid,const char* appinfo)
|
||||
{
|
||||
@@ -171,16 +191,30 @@ extern "C" {
|
||||
//打点
|
||||
void SetGaUserInfo(const char* userId)
|
||||
{
|
||||
|
||||
NSString *userid = [[NSString alloc] initWithCString:userId encoding:NSUTF8StringEncoding];
|
||||
[[GASDK getGAlog:SDK_PROJECTID] setUserId:userid];
|
||||
}
|
||||
|
||||
void SetGaCommonInfo(const char* SetGaCommonInfo)
|
||||
{
|
||||
|
||||
NSString * jsonString = [NSString stringWithFormat:@"%s", SetGaCommonInfo];
|
||||
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError* err;
|
||||
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
|
||||
if(!err){
|
||||
[[GASDK getGAlog:SDK_PROJECTID] initWithGameId:SDK_GAMEID clientId:SDK_CLIENTID withCommonParams:dic serverUrl:GA_INTERNATIONAL];
|
||||
}
|
||||
}
|
||||
|
||||
void GAReportParams(int type, const char* eventstr, const char* paramstr)
|
||||
{
|
||||
NSString * jsonString = [NSString stringWithFormat:@"%s", paramstr];
|
||||
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError* err;
|
||||
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
|
||||
if(!err){
|
||||
[[GASDK getGAlog:SDK_PROJECTID] initWithGameId:SDK_GAMEID clientId:SDK_CLIENTID withCommonParams:dic serverUrl:GA_INTERNATIONAL];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,54 @@ namespace tysdk
|
||||
{
|
||||
public class AccountInfo
|
||||
{
|
||||
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>(){
|
||||
{"google", EAccoutType.hwGoogle},
|
||||
{"fb", EAccoutType.hwFacebook},
|
||||
{"tyGuest", EAccoutType.hwGuest}
|
||||
};
|
||||
|
||||
public int userId;
|
||||
public string token;
|
||||
public string jwtToken;
|
||||
public string strUserId => userId.ToString();
|
||||
public string channelstr;
|
||||
public EAccoutType channel => accoutTypeMap[channelstr];
|
||||
|
||||
private const string KEY_ACCOUNT_INFO = "KEY_ACCOUNT_INFO";
|
||||
|
||||
public void Save()
|
||||
{
|
||||
JObject jInfo = new JObject();
|
||||
jInfo["channel"] = channelstr;
|
||||
jInfo["token"] = token;
|
||||
jInfo["userId"] = userId;
|
||||
jInfo["jwtToken"] = jwtToken;
|
||||
PlayerPrefs.SetString(KEY_ACCOUNT_INFO, jInfo.ToString());
|
||||
}
|
||||
|
||||
public static void Remove()
|
||||
{
|
||||
PlayerPrefs.DeleteKey(KEY_ACCOUNT_INFO);
|
||||
}
|
||||
|
||||
public static AccountInfo GetSavedAccoutInfo()
|
||||
{
|
||||
if (PlayerPrefs.HasKey(KEY_ACCOUNT_INFO))
|
||||
{
|
||||
var jInfo = JObject.Parse(PlayerPrefs.GetString(KEY_ACCOUNT_INFO));
|
||||
return new AccountInfo()
|
||||
{
|
||||
userId = (int)jInfo["userId"],
|
||||
token = (string)jInfo["token"],
|
||||
channelstr = (string)jInfo["channel"],
|
||||
jwtToken = (string)jInfo["jwtToken"],
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AccountInfo _accountInfo;
|
||||
@@ -45,31 +89,29 @@ namespace tysdk
|
||||
}
|
||||
|
||||
|
||||
/*================================================
|
||||
/*================================================
|
||||
|
||||
_ _
|
||||
/ \ ___ ___ ___ _ _ _ __ | |_
|
||||
/ _ \ / __/ __/ _ \| | | | '_ \| __|
|
||||
/ ___ \ (_| (_| (_) | |_| | | | | |_
|
||||
/_/ \_\___\___\___/ \__,_|_| |_|\__|
|
||||
_ _
|
||||
/ \ ___ ___ ___ _ _ _ __ | |_
|
||||
/ _ \ / __/ __/ _ \| | | | '_ \| __|
|
||||
/ ___ \ (_| (_| (_) | |_| | | | | |_
|
||||
/_/ \_\___\___\___/ \__,_|_| |_|\__|
|
||||
|
||||
=================================================*/
|
||||
=================================================*/
|
||||
|
||||
|
||||
public bool IsLoggedIn => _accountInfo != null;
|
||||
public bool IsLoggedIn => _accountInfo != null;
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
UnityEngine.Debug.Log("Logout");
|
||||
UnityBridgeFunc.UnityLoginOut();
|
||||
_accountInfo = null;
|
||||
}
|
||||
|
||||
public void LogoutByChannel()
|
||||
public void Logout()
|
||||
{
|
||||
UnityEngine.Debug.Log("LogoutByChannel");
|
||||
UnityBridgeFunc.UnityLoginOut();
|
||||
UnityEngine.Debug.Log("Logout");
|
||||
if(_accountInfo != null) return;
|
||||
{
|
||||
UnityBridgeFunc.UnityLogOutByChannel(_accountInfo.channel);
|
||||
}
|
||||
|
||||
_accountInfo = null;
|
||||
AccountInfo.Remove();
|
||||
}
|
||||
|
||||
public async Task<LoginInfo> Login(EAccoutType accoutType)
|
||||
@@ -107,6 +149,22 @@ namespace tysdk
|
||||
|
||||
}
|
||||
|
||||
public async Task<LoginInfo> LoginByToken()
|
||||
{
|
||||
var accoutInfo = AccountInfo.GetSavedAccoutInfo();
|
||||
if(accoutInfo == null) new LoginInfo();
|
||||
|
||||
var taskSource = new TaskCompletionSource<LoginInfo>();
|
||||
callbacks.Add("LoginResult", (ITYSdkCallback callback) =>
|
||||
{
|
||||
taskSource.SetResult((LoginInfo)callback);
|
||||
});
|
||||
|
||||
UnityBridgeFunc.UnityLoginByTokenFun(accoutInfo.token);
|
||||
|
||||
return await taskSource.Task;
|
||||
}
|
||||
|
||||
public void LoginResult(string json)
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] Login callback:");
|
||||
@@ -124,8 +182,11 @@ namespace tysdk
|
||||
userId = (int)loginData["userId"],
|
||||
token = (string)loginData["token"],
|
||||
jwtToken = (string)loginData["jwttoken"],
|
||||
channelstr = (string)loginData["loginChannelTypeC"]
|
||||
};
|
||||
|
||||
_accountInfo.Save();
|
||||
|
||||
|
||||
result.isSuccess = true;
|
||||
result.userId = _accountInfo.userId;
|
||||
@@ -145,8 +206,6 @@ namespace tysdk
|
||||
var strUserId = _accountInfo.strUserId;
|
||||
|
||||
UnityBridgeFunc.SetGaUserInfo(strUserId);
|
||||
UnityBridgeFunc.UnitySetAdBoxUserInfo(strUserId);
|
||||
UnityBridgeFunc.UnityInitADSConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine;
|
||||
@@ -117,16 +118,20 @@ namespace tysdk
|
||||
//商品列表的回调
|
||||
public void SKUListResult(string json)
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] GetSKUList callback:");
|
||||
var result = new ProductListInfo();
|
||||
Debug.Log("[TYSdkFacade] GetSKUList callback");
|
||||
var jresult = JObject.Parse(json);
|
||||
int code = int.Parse(jresult["code"].ToString());
|
||||
var result = new ProductListInfo();
|
||||
if (code == 0)
|
||||
{
|
||||
string productStr = jresult["respObj"].ToString();
|
||||
result.code = code;
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
var jsonObjList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SKUDetail>>(productStr);
|
||||
result.products = jsonObjList;
|
||||
#elif UNITY_IOS && !UNITY_EDITOR
|
||||
result.ReadSKUFromJson(productStr);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (callbacks.TryGetValue("SKUListResult", out var action))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace tysdk
|
||||
{
|
||||
@@ -11,12 +12,6 @@ namespace tysdk
|
||||
none
|
||||
}
|
||||
|
||||
public class EAccoutTypeName
|
||||
{
|
||||
public static string hwGoogle = "hwGoogle";
|
||||
public static string hwFacebook = "hwFacebook";
|
||||
public static string hwGuest = "hwGuest";
|
||||
}
|
||||
public interface ITYSdkCallback { }
|
||||
|
||||
public class LoginInfo : ITYSdkCallback
|
||||
@@ -50,8 +45,27 @@ namespace tysdk
|
||||
public int code = 1;
|
||||
public string msg = string.Empty;
|
||||
public List<SKUDetail> products;
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
public void ReadSKUFromJson(string json)
|
||||
{
|
||||
var prodList = Newtonsoft.Json.Linq.JArray.Parse(json).Select(x => {
|
||||
return new SKUDetail() {
|
||||
price = x["price"].ToString(),
|
||||
productId = x["productId"].ToString(),
|
||||
LocaleCurrencyCode = x["LocaleCurrencyCode"].ToString(),
|
||||
localeCurrencySymbol = x["localeCurrencySymbol"].ToString(),
|
||||
localizedDescription = x["localizedDescription"].ToString(),
|
||||
localizedTitle = x["localizedTitle"].ToString()
|
||||
};
|
||||
}).ToList();
|
||||
products = prodList;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID || UNITY_EDITOR
|
||||
public class SKUDetail
|
||||
{
|
||||
public string description;
|
||||
@@ -62,7 +76,29 @@ namespace tysdk
|
||||
public string productId;
|
||||
public string title;
|
||||
public string type;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
#elif UNITY_IOS
|
||||
public class SKUDetail
|
||||
{
|
||||
public string price;
|
||||
public string productId;
|
||||
public string LocaleCurrencyCode;
|
||||
public string localeCurrencySymbol;
|
||||
public string localizedDescription;
|
||||
public string localizedTitle;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public class ATTInfo : ITYSdkCallback
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace tysdk
|
||||
|
||||
public static void UnityGetIdentityFun(string type){}
|
||||
|
||||
public static void UnityLoginOut(){}
|
||||
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) { }
|
||||
@@ -46,15 +46,6 @@ namespace tysdk
|
||||
|
||||
public static int GetATT() {return 1;}
|
||||
|
||||
//广告相关
|
||||
public static void UnitySetAdBoxUserInfo(string userId){}
|
||||
|
||||
public static void UnityInitADSConfig(){}
|
||||
|
||||
public static void UnityLoadRvADS(){}
|
||||
|
||||
public static void UnityShowRVAD() { }
|
||||
|
||||
#elif UNITY_ANDROID
|
||||
|
||||
private static string SDK_CLASS = "com.unity3d.player.SDKManager";
|
||||
@@ -106,23 +97,9 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnityLoginOut()
|
||||
public static void UnityLogOutByChannel(EAccoutType accoutType)
|
||||
{
|
||||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
{
|
||||
sdkManager.CallStatic("UnityLoginOut");
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnityLogOutByChannel()
|
||||
{
|
||||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
{
|
||||
if(PlayerPrefs.HasKey("last_login_channel"))
|
||||
{
|
||||
sdkManager.CallStatic("UnityLogOutByChannel", PlayerPrefs.GetString("last_login_channel"));
|
||||
}
|
||||
}
|
||||
sdkManager.CallStatic("UnityLogOutByChannel", accoutType.ToString());
|
||||
}
|
||||
|
||||
//支付new
|
||||
@@ -187,15 +164,6 @@ namespace tysdk
|
||||
|
||||
public static int GetATT() {return 1;}
|
||||
|
||||
//广告相关
|
||||
public static void UnitySetAdBoxUserInfo(string userId){}
|
||||
|
||||
public static void UnityInitADSConfig(){}
|
||||
|
||||
public static void UnityLoadRvADS(){}
|
||||
|
||||
public static void UnityShowRVAD(){}
|
||||
|
||||
|
||||
#elif UNITY_IOS
|
||||
|
||||
@@ -238,6 +206,31 @@ namespace tysdk
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityLoginOut();
|
||||
|
||||
public static void UnityLogOutByChannel(EAccoutType accoutType)
|
||||
{
|
||||
switch (accoutType)
|
||||
{
|
||||
case EAccoutType.hwGoogle:
|
||||
UnityLogoutGoogle();
|
||||
break;
|
||||
case EAccoutType.hwFacebook:
|
||||
UnityLogoutFacebook();
|
||||
break;
|
||||
case EAccoutType.hwGuest:
|
||||
UnityLogoutGuest();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UnityLogoutGoogle();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UnityLogoutFacebook();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UnityLogoutGuest();
|
||||
|
||||
//支付
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityKnow(string userId, string productId, string productPrice, string productName,
|
||||
@@ -257,19 +250,6 @@ namespace tysdk
|
||||
[DllImport("__Internal")]
|
||||
public static extern void GAReportParams(int type, string eventstr, string paramstr);
|
||||
|
||||
//广告相关
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnitySetAdBoxUserInfo(string userId);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityInitADSConfig();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityLoadRvADS();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityShowRVAD();
|
||||
|
||||
//ATT
|
||||
[DllImport("__Internal")]
|
||||
public static extern void RequestATT();
|
||||
@@ -277,24 +257,5 @@ namespace tysdk
|
||||
[DllImport("__Internal")]
|
||||
public static extern int GetATT();
|
||||
#endif
|
||||
|
||||
public static string GetLoginTypeName(EAccoutType accoutType)
|
||||
{
|
||||
string str = String.Empty;
|
||||
switch (accoutType)
|
||||
{
|
||||
case EAccoutType.hwGoogle:
|
||||
str = EAccoutTypeName.hwGoogle;
|
||||
break;
|
||||
case EAccoutType.hwFacebook:
|
||||
str = EAccoutTypeName.hwFacebook;
|
||||
break;
|
||||
case EAccoutType.hwGuest:
|
||||
str = EAccoutTypeName.hwGuest;
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user