refactor: 支付链路规范化 — 统一命名/层次/传参
- ISDKHelper.pay() 增加 productPrice 参数,与 UnityKnowNew 签名对齐 - FlexionSDKHelper: prodPrice/prodCount 从参数直接写入 developerPayload - playerId → userId 统一命名 (SDKTest/Java payload) - pfId → pfid 统一小写 (服务端 JSON key) - PaymentInfo 序列化替代 StringBuilder 手拼 JSON - FlexionPaymentVerifier.Consume 走 UnityBridgeFunc.ConsumePurchase 桥接层 - UnityBridgeFunc 新增 ConsumePurchase 通用方法,移除渠道特定方法 - SDKManager.ConsumeFlexionPurchase → ConsumePurchase 通用化 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
@@ -90,20 +90,21 @@ namespace tysdk
|
||||
Debug.Log($"[FlexionPaymentVerifier] HTTP retry {attempt}/{MaxRetries}, waiting {delay.TotalSeconds}s");
|
||||
await Task.Delay(delay);
|
||||
}
|
||||
lastResult = await SendVerifyRequest(BuildRequestBody(info));
|
||||
lastResult = await SendVerifyRequest(info);
|
||||
if (lastResult.success) return lastResult;
|
||||
Debug.LogWarning($"[FlexionPaymentVerifier] HTTP attempt {attempt + 1} failed: {lastResult.msg}");
|
||||
}
|
||||
return lastResult;
|
||||
}
|
||||
|
||||
private async Task<VerifyResult> SendVerifyRequest(string body)
|
||||
private async Task<VerifyResult> SendVerifyRequest(PaymentInfo info)
|
||||
{
|
||||
var cts = new CancellationTokenSource(Timeout);
|
||||
try
|
||||
{
|
||||
Debug.Log("[FlexionPaymentVerifier] Sending verification request");
|
||||
|
||||
var body = JsonConvert.SerializeObject(info);
|
||||
using var req = new UnityWebRequest(VERIFY_URL, "POST");
|
||||
req.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(body));
|
||||
req.downloadHandler = new DownloadHandlerBuffer();
|
||||
@@ -139,35 +140,15 @@ namespace tysdk
|
||||
cts.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildRequestBody(PaymentInfo info)
|
||||
{
|
||||
var body = new StringBuilder();
|
||||
body.Append('{');
|
||||
body.Append("\"purchaseJson\":").Append(Escape(info.purchaseJson)).Append(',');
|
||||
body.Append("\"signature\":").Append(Escape(info.signature)).Append(',');
|
||||
body.Append("\"orderId\":").Append(Escape(info.orderId)).Append(',');
|
||||
body.Append("\"productId\":").Append(Escape(info.productId)).Append(',');
|
||||
body.Append("\"purchaseToken\":").Append(Escape(info.purchaseToken));
|
||||
body.Append('}');
|
||||
return body.ToString();
|
||||
}
|
||||
#endif
|
||||
|
||||
private static string Escape(string s)
|
||||
{
|
||||
if (s == null) return "null";
|
||||
return '"' + s.Replace("\\", "\\\\").Replace("\"", "\\\"") + '"';
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void Consume(string token) { }
|
||||
#elif UNITY_ANDROID
|
||||
public void Consume(string token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(token)) return;
|
||||
using var sdkManager = new AndroidJavaClass("com.unity3d.player.SDKManager");
|
||||
sdkManager.CallStatic("ConsumeFlexionPurchase", token);
|
||||
UnityBridgeFunc.ConsumePurchase(token);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace tysdk
|
||||
|
||||
if (purchaseInfo == null)
|
||||
purchaseInfo = new JObject();
|
||||
// purchaseInfo["playerId"] = _accountInfo.strUserId;
|
||||
|
||||
string extraInfo = purchaseInfo.ToString(Newtonsoft.Json.Formatting.None);
|
||||
extraInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(extraInfo));
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace tysdk
|
||||
|
||||
public static void Review() { }
|
||||
|
||||
public static void ConsumePurchase(string token) { }
|
||||
|
||||
public static void FBShareLink(string title, string content, string url) { }
|
||||
public static void MessengerShareLink(string title, string content, string url) { }
|
||||
|
||||
@@ -168,6 +170,14 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
public static void ConsumePurchase(string token)
|
||||
{
|
||||
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
{
|
||||
sdkManager.CallStatic("ConsumePurchase", token);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo)
|
||||
{
|
||||
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
|
||||
Reference in New Issue
Block a user