// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2022-02-10
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using F;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace G
{
///
/// 支付
///
public class PayProxy : F.GameProxy
{
///
///
///
public class PayInfo
{
public int payId
{
get;
set;
}
public string payName
{
get;
set;
}
public string payType
{
get;
set;
}
public string payKey
{
get { return payType + payId; }
}
///
///
///
public int rmbPrice
{
get;
set;
}
///
///
///
public int buyAmount
{
get;
set;
}
public string userId => UserProxy.UserId;
public string platform => KPlatform.Instance.platform;
///
/// 0 内购 或1小程序拉起 或2客服
///
public int payMethod
{
get;
set;
}
///
/// 账单
///
public string trade_no
{
get;
set;
}
}
#region Field
#endregion
#region Method
///
/// 支付接口
///
///
///
public void Pay(PayInfo payInfo, Callback2 callback)
{
#if UNITY_EDITOR
KPlatform.Instance.Pay(payInfo, (payError, payMessage) =>
{
if (payError == 0)
{
if (payInfo.payMethod != 0)
{
GetPayResult(callback);
}
else
{
string key = payInfo.payKey;
var lastCount = ArchiveProxy.Instance.GetInt(key, 0);
ArchiveProxy.Instance.SetInt(key, lastCount + 1);
callback?.Invoke(0, "");
ArchiveProxy.Instance.UploadImmediate();
}
}
else
{
callback?.Invoke(payError, payMessage);
}
});
#else
ServerProxy.Instance.CreateOrder(payInfo.payKey, 1, payInfo.payName, (error, message, data) =>
{
if (error == 0)
{
if (data is IDictionary dataT)
{
var order_id = dataT.GetString("order_id");
payInfo.trade_no = order_id;
Debug.Log("创建订单 " + order_id);
}
KPlatform.Instance.Pay(payInfo, (payError, payMessage) =>
{
if (payError == 0)
{
if (payInfo.payMethod != 0)
{
GetPayResult(callback);
}
else
{
string key = payInfo.payKey;
var lastCount = ArchiveProxy.Instance.GetInt(key, 0);
ArchiveProxy.Instance.SetInt(key, lastCount + 1);
GetPayResult(callback);
//callback?.Invoke(0, "");
//ArchiveProxy.Instance.UploadImmediate();
//KStatistics.Instance.ReportEvent_Pay(payInfo.payKey, KPlatform.Instance.platform, "success");
}
}
else
{
callback?.Invoke(payError, payMessage);
}
});
}
else
{
callback?.Invoke(error, message);
}
});
#endif
}
///
///
///
///
private void GetPayResult(Callback2 callback)
{
ServerProxy.Instance.GetOrderResult((resultError, resultMessage, resultData) =>
{
if (resultError == 0)
{
Debug.Log("查询订单成功");
var result = CheckOrder(resultData as IList