[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:
2024-08-13 23:53:35 +08:00
parent 7f576df319
commit c355784122
10 changed files with 663 additions and 112 deletions

View File

@@ -52,10 +52,22 @@ public class BuildTool
bundleType = Enum.Parse<EBundleType>(args[args.IndexOf(Param_Bundle_Type) + 1])
};
BuildAndroid(bparams);
BuildiOS(bparams);
}
private static void BuildAndroid(BuildParams buildParams)
[MenuItem("Tools/Build iOS")]
public static void BuildiOS()
{
BuildParams bparams = new BuildParams()
{
outPath = "../Bin"
};
BuildiOS(bparams);
}
private static void BuildiOS(BuildParams buildParams)
{
var buildPlayerOptions = new BuildPlayerOptions

View File

@@ -886,6 +886,285 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 816060983}
m_CullTransparentMesh: 1
--- !u!1 &834002868
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 834002869}
- component: {fileID: 834002872}
- component: {fileID: 834002871}
- component: {fileID: 834002870}
m_Layer: 5
m_Name: LoginToken
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &834002869
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 834002868}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 942378169}
m_Father: {fileID: 1044920373}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &834002870
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 834002868}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 834002871}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!114 &834002871
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 834002868}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &834002872
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 834002868}
m_CullTransparentMesh: 1
--- !u!1 &867219627
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 867219628}
- component: {fileID: 867219630}
- component: {fileID: 867219629}
m_Layer: 5
m_Name: Text (Legacy)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &867219628
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 867219627}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1064161794}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &867219629
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 867219627}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 33
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 0
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: ATT
--- !u!222 &867219630
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 867219627}
m_CullTransparentMesh: 1
--- !u!1 &942378168
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 942378169}
- component: {fileID: 942378171}
- component: {fileID: 942378170}
m_Layer: 5
m_Name: Text (Legacy)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &942378169
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 942378168}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 834002869}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &942378170
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 942378168}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 33
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 0
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Token
--- !u!222 &942378171
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 942378168}
m_CullTransparentMesh: 1
--- !u!1 &1033367769
GameObject:
m_ObjectHideFlags: 0
@@ -998,11 +1277,13 @@ RectTransform:
- {fileID: 1910171036}
- {fileID: 1188788676}
- {fileID: 1627053315}
- {fileID: 834002869}
- {fileID: 1304993149}
- {fileID: 29523099}
- {fileID: 1110300853}
- {fileID: 120435830}
- {fileID: 1574191670}
- {fileID: 1064161794}
m_Father: {fileID: 1451597222}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@@ -1034,6 +1315,127 @@ MonoBehaviour:
m_Spacing: {x: 50, y: 50}
m_Constraint: 0
m_ConstraintCount: 2
--- !u!1 &1064161793
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1064161794}
- component: {fileID: 1064161796}
- component: {fileID: 1064161795}
- component: {fileID: 1064161797}
m_Layer: 5
m_Name: ATT
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1064161794
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1064161793}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 867219628}
m_Father: {fileID: 1044920373}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1064161795
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1064161793}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1064161796
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1064161793}
m_CullTransparentMesh: 1
--- !u!114 &1064161797
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1064161793}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1064161795}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1071692829
GameObject:
m_ObjectHideFlags: 0
@@ -2012,11 +2414,13 @@ MonoBehaviour:
_loginGuestBtn: {fileID: 1910171037}
_loginGoogleBtn: {fileID: 1188788679}
_loginFbBtn: {fileID: 1627053318}
_loginTokenBtn: {fileID: 834002870}
_logOutBtn: {fileID: 1304993150}
_payTestBtn: {fileID: 120435831}
_payListBtn: {fileID: 1110300854}
_gaTestBtn: {fileID: 29523100}
_gaAppMaxBtn: {fileID: 1574191671}
_ATTBtn: {fileID: 1064161797}
_messageTxt: {fileID: 2070325010}
--- !u!4 &1788702880
Transform:

View File

@@ -17,6 +17,8 @@ public class SDKTest : MonoBehaviour
[SerializeField]
private Button _loginFbBtn;
[SerializeField]
private Button _loginTokenBtn;
[SerializeField]
private Button _logOutBtn;
[SerializeField]
private Button _payTestBtn;
@@ -27,6 +29,8 @@ public class SDKTest : MonoBehaviour
[SerializeField]
private Button _gaAppMaxBtn;
[SerializeField]
private Button _ATTBtn;
[SerializeField]
private Text _messageTxt;
void Start()
@@ -41,11 +45,13 @@ public class SDKTest : MonoBehaviour
_loginGuestBtn.onClick.AddListener(() => OnLogin(EAccoutType.hwGuest));
_loginGoogleBtn.onClick.AddListener(() => OnLogin(EAccoutType.hwGoogle));
_loginFbBtn.onClick.AddListener(() => OnLogin(EAccoutType.hwFacebook));
_loginTokenBtn.onClick.AddListener(OnLoginByToken);
_logOutBtn.onClick.AddListener(OnLogout);
_payTestBtn.onClick.AddListener(OnPayTestBtn);
_payListBtn.onClick.AddListener(OnPayListBtn);
_gaTestBtn.onClick.AddListener(OnGaBtn);
_gaAppMaxBtn.onClick.AddListener(OnAppMaxBtn);
_ATTBtn.onClick.AddListener(OnATTBtn);
}
void Init()
@@ -99,6 +105,19 @@ public class SDKTest : MonoBehaviour
}
}
private async void OnLoginByToken()
{
_messageTxt.text = string.Empty;
Debug.LogError("[AggSdk::OnLoginByToken]");
var info = await TYSdkFacade.Instance.LoginByToken();
_messageTxt.text = $"Login: {info.isSuccess}";
if (info.isSuccess)
{
_messageTxt.text += $"\n{info.msg}";
_messageTxt.text += $"\n{TYSdkFacade.Instance.TYAccountInfo.token}";
}
}
private void OnLogout()
{
TYSdkFacade.Instance.Logout();
@@ -106,23 +125,45 @@ public class SDKTest : MonoBehaviour
public async void OnPayTestBtn()
{
string prodId = "comarkgameft1chooseone0199";
string pType = "googleiab.global.app";
string prodPrice = "2,616";
string prodName = "test:₩2,616";
_messageTxt.text = "";
if (sku == null){
_messageTxt.text = "no product";
return;
}
string prodId = sku.productId;
string pType = string.Empty;
#if UNITY_ANDROID
pType = sku.type;
#endif
string prodPrice = sku.price;
#if UNITY_EDITOR
string prodName = string.Empty;
#elif UNITY_ANDROID
string prodName = sku.title;
#elif UNITY_IOS
string prodName = sku.localizedTitle;
#endif
int count = 1;
Debug.LogError($"[AggSdk::Pay] prodId : {prodId} prodPrice : {prodPrice} prodName : {prodName} ");
PaymentInfo payResult = await TYSdkFacade.Instance.Pay(prodId, prodPrice, prodName, count, pType);
_messageTxt.text = "\n" + $"Success : {payResult.isSuccess}";
_messageTxt.text += "\n" + $"message : {payResult.msg}";
}
SKUDetail sku = null;
public async void OnPayListBtn()
{
Debug.Log("[AggSdk::PayList]");
_messageTxt.text = "";
ProductListInfo result = await TYSdkFacade.Instance.GetSKUList();
if (result.code == 0)
{
_messageTxt.text = "products count:::" + result.products.Count;
_messageTxt.text += "\n" + result.products[0].ToString();
sku = result.products[0];
}
else
{
@@ -155,6 +196,11 @@ public class SDKTest : MonoBehaviour
}
}
public void OnATTBtn()
{
UnityBridgeFunc.RequestATT();
}
private void LoadAd()
{
Debug.Log($"[AD LOG] LoadAd {AD_ID}");

View File

@@ -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) {

View File

@@ -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];
}
}

View File

@@ -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();
}
}
}

View File

@@ -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))

View File

@@ -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
{

View File

@@ -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;
}
}
}

View File

@@ -1,8 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<projectSettings>
<projectSetting name="Google.IOSResolver.VerboseLoggingEnabled" value="False" />
<projectSetting name="Google.PackageManagerResolver.VerboseLoggingEnabled" value="False" />
<projectSetting name="Google.VersionHandler.VerboseLoggingEnabled" value="False" />
<projectSetting name="GooglePlayServices.PromptBeforeAutoResolution" value="False" />
<projectSetting name="GooglePlayServices.UseJetifier" value="True" />
</projectSettings>