87 lines
2.4 KiB
C#
87 lines
2.4 KiB
C#
|
#if UNITY_PURCHASE
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace WZ
|
||
|
{
|
||
|
public class IAPGoogleJsonInfo
|
||
|
{
|
||
|
public struct GoogleToken
|
||
|
{
|
||
|
public string packageName;
|
||
|
public string productId;
|
||
|
public string token;
|
||
|
public string projectId;
|
||
|
}
|
||
|
|
||
|
public class ProductData
|
||
|
{
|
||
|
public string productId;
|
||
|
public int checkStatus;
|
||
|
public string timestamp;
|
||
|
public string sign;
|
||
|
}
|
||
|
|
||
|
public class GooglePurchaseData
|
||
|
{
|
||
|
// INAPP_PURCHASE_DATA
|
||
|
public string inAppPurchaseData;
|
||
|
|
||
|
// INAPP_DATA_SIGNATURE
|
||
|
public string inAppDataSignature;
|
||
|
|
||
|
public GooglePurchaseJson json;
|
||
|
|
||
|
[System.Serializable]
|
||
|
private struct GooglePurchaseReceipt
|
||
|
{
|
||
|
public string Payload;
|
||
|
}
|
||
|
|
||
|
[System.Serializable]
|
||
|
private struct GooglePurchasePayload
|
||
|
{
|
||
|
public string json;
|
||
|
public string signature;
|
||
|
}
|
||
|
|
||
|
[System.Serializable]
|
||
|
public struct GooglePurchaseJson
|
||
|
{
|
||
|
public string packageName;
|
||
|
public string productId;
|
||
|
public long purchaseTime;
|
||
|
public int purchaseState;
|
||
|
public string purchaseToken;
|
||
|
public string orderId;
|
||
|
|
||
|
public bool autoRenewing;
|
||
|
}
|
||
|
|
||
|
public GooglePurchaseData(string receipt)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var purchaseReceipt = JsonUtility.FromJson<GooglePurchaseReceipt>(receipt);
|
||
|
var purchasePayload = JsonUtility.FromJson<GooglePurchasePayload>(purchaseReceipt.Payload);
|
||
|
var inAppJsonData = JsonUtility.FromJson<GooglePurchaseJson>(purchasePayload.json);
|
||
|
|
||
|
inAppPurchaseData = purchasePayload.json;
|
||
|
inAppDataSignature = purchasePayload.signature;
|
||
|
json = inAppJsonData;
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
Debug.Log("Could not parse receipt: " + receipt);
|
||
|
inAppPurchaseData = "";
|
||
|
inAppDataSignature = "";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif
|