商品列表处理

This commit is contained in:
LYP
2024-08-09 11:24:07 +08:00
parent 6a25f92182
commit 2419cfb216
4 changed files with 51 additions and 31 deletions

View File

@@ -95,8 +95,16 @@ public class SDKTest : MonoBehaviour
public async void OnPayListBtn()
{
Debug.LogError("PayList ask");
var result = await TYSdkFacade.Instance.ThirdExtend();
ProductListInfo result = await TYSdkFacade.Instance.ThirdExtend();
if (result.code == 0)
{
Debug.LogError("products count:::" + result.products.Count);
}
else
{
Debug.LogError("get products fail ,code:" + result.code);
}
}
public void OnGaBtn()

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
{
/*================================================
____ _
@@ -16,13 +16,13 @@ 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)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
var orderId = System.Guid.NewGuid().ToString();
var extraDic = new Dictionary<string,object>() {
var extraDic = new Dictionary<string, object>() {
{"paytime" , System.DateTime.UtcNow.Ticks},
{"sum" , float.Parse(prodPrice) * count},
};
@@ -31,7 +31,7 @@ namespace tysdk
extraInfo = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(extraInfo));
#if UNITY_EDITOR
await Task.Yield();
var result = new PaymentInfo()
{
@@ -91,42 +91,45 @@ namespace tysdk
callbacks.Remove("PayResult");
}
}
// Get Pay list
public async Task<ProductListInfo> ThirdExtend()
{
if (!IsLoggedIn) return new ProductListInfo() { code = "-1", msg = "未登录" };
if (!IsLoggedIn) return new ProductListInfo() { code = -1, msg = "未登录" };
#if UNITY_EDITOR || UNITY_IOS
#if UNITY_EDITOR
await Task.Yield();
var result = new ProductListInfo();
return result;
#elif UNITY_ANDROID
var taskSource = new TaskCompletionSource<ProductListInfo>();
var taskSource = new TaskCompletionSource<ProductListInfo>();
callbacks.Add("PayTypeResult", (ITYSdkCallback callback) =>
{
Debug.LogError("(ProductListInfo)callback.msg:::" + ((ProductListInfo) callback).msg);
var productInfos = Newtonsoft.Json.JsonConvert.DeserializeObject<SKUDetail>(((ProductListInfo)callback).msg);
Debug.LogError("productInfos:::" + productInfos);
taskSource.SetResult((ProductListInfo) callback);
});
UnityBridgeFunc.ThirdExtend();
var result = await taskSource.Task;
return result;
#elif UNITY_IOS
var result = new ProductListInfo();
return result;
#endif
}
//商品列表的回调
public void PayTypeResult(string json)
{
Debug.Log("[thirdExtend] pay callback:");
var jresult = JObject.Parse(json);
var result = new ProductListInfo();
result.code = jresult["code"].ToString();
result.msg = jresult["thirdExtend_errStr"].ToString();
var jresult = JObject.Parse(json);
int code = int.Parse(jresult["code"].ToString());
if (code == 0)
{
string productStr = jresult["respObj"].ToString();
result.code = code;
var jsonObjList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SKUDetail>>(productStr);
result.products = jsonObjList;
}
if (callbacks.TryGetValue("PayTypeResult", out var action))
{
@@ -136,3 +139,7 @@ namespace tysdk
}
}
}

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
namespace tysdk
{
public enum EAccoutType
@@ -45,20 +47,21 @@ namespace tysdk
public class ProductListInfo: ITYSdkCallback
{
public string code;
public string msg;
public int code = 1;
public string msg = string.Empty;
public List<SKUDetail> products;
}
public class SKUDetail: ITYSdkCallback
public class SKUDetail
{
public string code;
public string msg;
public string name;
public string description;
public string price;
public string productId;
public string ourProductId;
public string currency_code;
public string price;
public string price_amount_micros;
public string price_currency_code;
public string productId;
public string title;
public string type;
}
public class ATTInfo : ITYSdkCallback

View File

@@ -3,4 +3,6 @@
<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>