如何获取不在同一类中的字符串的值? [英] How can I get the value of a string that is not in the same class?
问题描述
我在这两行中收到错误消息:
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 = "";公共异步任务采购项目(字符串 productId){var purchaseSuccesful = false;如果(CrossInAppBilling.IsSupported == true){var billing = CrossInAppBilling.Current;尝试{var connected = await billing.ConnectAsync(ItemType.InAppPurchase);如果(连接 == 真){var verify = DependencyService.Get();var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, "apppayload", verify);SignedData = ((Verify)verify).SignedDataverify;签名 = ((Verify)verify).Signatureverify;...
Verify.cs:
使用 System.Threading.Tasks;使用 Plugin.InAppBilling.Abstractions;使用 InapppurchaseTest;命名空间 InapppurchaseTest{公共类验证:IInAppBillingVerifyPurchase{const string key1 = @"XOR_key1";const string key2 = @"XOR_key2";const string key3 = @"XOR_key3";公共字符串 SignedDataverify = "", Signatureverify = "";公共任务验证购买(字符串签名数据,字符串签名,字符串 productId = null,字符串 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;签名验证 = 签名return Task.FromResult(Plugin.InAppBilling.InAppBillingImplementation.InAppBillingSecurity.VerifyPurchase(key1Transform + key2Transform + key3Transform, signedData, signature));#别的SignedDataverify = signedData;Signatureverify = 签名;返回 Task.FromResult(true);#万一}}}
https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/docs/SecuringPurchases.md
如果DependencyService.Get()"方法返回对IInAppBillingVerifyPurchase"的引用,则verify"需要将Verify"类转换为SignedDataverify"" &Signatureverify"是该类的成员.
试试:
SignedData = ((Verify)verify).SignedDataverify;签名 = ((Verify)verify).Signatureverify;
或
SignedData = (verify as Verify)?.SignedDataverify;Signature = (verify as Verify)?.Signatureverify;
(如果转换失败,后一种方法将返回 null,前者会抛出异常 - 因为您的代码在 try-catch 语句中,您可能很乐意捕获异常或更喜欢空检查)
I get error messages in these two lines:
SignedData = verify.SignedDataverify;
Signature = verify.Signatureverify;
Error CS1061: 'IInAppBillingVerifyPurchase' does not contain a definition for 'SignedDataverify' and no extension method 'SignedDataverify' accepting a first argument of type 'IInAppBillingVerifyPurchase' could be found (are you missing a using directive or an assembly reference?)
Error CS1061: 'IInAppBillingVerifyPurchase' does not contain a definition for 'Signatureverify' and no extension method 'Signatureverify' accepting a first argument of type 'IInAppBillingVerifyPurchase' could be found (are you missing a using directive or an assembly reference?)
How can I get the value of the two string variables SignedDataverify
and Signatureverify
? I don't know how to get the values because they are not in the same class.
In this class, I want to get the values of SignedDataverify
and Signatureverify
:
UPDATE: This code works.
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
If the "DependencyService.Get()" method returns a reference to "IInAppBillingVerifyPurchase", then "verify" needs casting to the "Verify" class as "SignedDataverify" & "Signatureverify" are members of that class.
Try :
SignedData = ((Verify)verify).SignedDataverify;
Signature = ((Verify)verify).Signatureverify;
or
SignedData = (verify as Verify)?.SignedDataverify;
Signature = (verify as Verify)?.Signatureverify;
(The latter method will return null if the cast fails, the former will throw an exception - as your code is in a try-catch statement you may be happy to catch the exception or prefer null checking)
这篇关于如何获取不在同一类中的字符串的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!