我在这两行中收到错误消息:
SignedData = verify.SignedDataverify;
Signature = verify.Signatureverify;
错误CS1061:“ IInAppBillingVerifyPurchase”不包含“ SignedDataverify”的定义,找不到可以接受类型为“ IInAppBillingVerifyPurchase”的第一个参数的扩展方法“ SignedDataverify”(是否缺少using指令或程序集引用?)
错误CS1061:“ IInAppBillingVerifyPurchase”不包含“ Signatureverify”的定义,找不到可以接受类型为“ IInAppBillingVerifyPurchase”的第一个参数的扩展方法“ Signatureverify”(您是否缺少using指令或程序集引用?)
如何获取两个字符串变量SignedDataverify
和Signatureverify
的值?我不知道如何获取值,因为它们不在同一类中。
在此类中,我想获取SignedDataverify
和Signatureverify
的值:
更新:此代码有效。
string SignedData = "", Signature = "";
public async Task<bool> PurchaseItem(string productId)
{
var purchaseSuccesful = false;
if (CrossInAppBilling.IsSupported == true)
{
var billing = CrossInAppBilling.Current;
try
{
var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
if (connected == true)
{
var verify = DependencyService.Get<IInAppBillingVerifyPurchase>();
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, "apppayload", verify);
SignedData = ((Verify)verify).SignedDataverify;
Signature = ((Verify)verify).Signatureverify;
...
Verify.cs:
using System.Threading.Tasks;
using Plugin.InAppBilling.Abstractions;
using InapppurchaseTest;
namespace InapppurchaseTest
{
public class Verify : IInAppBillingVerifyPurchase
{
const string key1 = @"XOR_key1";
const string key2 = @"XOR_key2";
const string key3 = @"XOR_key3";
public string SignedDataverify = "", Signatureverify = "";
public Task<bool> VerifyPurchase(string signedData, string signature, string productId = null, string transactionId = null)
{
#if __ANDROID__
var key1Transform = Plugin.InAppBilling.InAppBillingImplementation.InAppBillingSecurity.TransformString(key1, 1);
var key2Transform = Plugin.InAppBilling.InAppBillingImplementation.InAppBillingSecurity.TransformString(key2, 2);
var key3Transform = Plugin.InAppBilling.InAppBillingImplementation.InAppBillingSecurity.TransformString(key3, 3);
SignedDataverify = signedData;
Signatureverify = signature
return Task.FromResult(Plugin.InAppBilling.InAppBillingImplementation.InAppBillingSecurity.VerifyPurchase(key1Transform + key2Transform + key3Transform, signedData, signature));
#else
SignedDataverify = signedData;
Signatureverify = signature;
return Task.FromResult(true);
#endif
}
}
}
https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/docs/SecuringPurchases.md
答案 0 :(得分:0)
如果“ DependencyService.Get()”方法返回对“ IInAppBillingVerifyPurchase”的引用,则“验证”需要转换为“验证”类,因为“ SignedDataverify”和“ Signatureverify”是该类的成员。
尝试:
SignedData = ((Verify)verify).SignedDataverify;
Signature = ((Verify)verify).Signatureverify;
或
SignedData = (verify as Verify)?.SignedDataverify;
Signature = (verify as Verify)?.Signatureverify;
(如果强制转换失败,后一种方法将返回null,前一种方法将引发异常-由于您的代码位于try-catch语句中,因此您可能会乐于捕捉异常或更喜欢使用null检查)