商品列表处理
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user