【发布时间】:2014-04-08 09:37:41
【问题描述】:
我正在使用 C# 网络服务在我的服务器上验证我的 ios in app purchase 收据
通过在 Xcode 中执行以下操作,我得到了字符串形式的收据:
- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
NSString* receiptString = [[NSString alloc] initWithString:transaction.payment.productIdentifier];
NSLog(@"%@",receiptString);
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
NSString *jsonObjectString = [receipt base64EncodedStringWithOptions:0];
}
我将该字符串(收据)作为参数发送到我的C# Web 服务。
这是我的网络服务方法:
[WebMethod(Description = "Purchase Item Verify")]
public string PurchaseItem(string receiptData)
{
string returnmessage = "";
try
{
var json = "{ 'receipt-data': '" + receiptData + "'}";
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] postBytes = Encoding.UTF8.GetBytes(json);
HttpWebRequest request;
request = WebRequest.Create("https://sandbox.itunes.apple.com/verifyReceipt") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = postBytes.Length;
Stream postStream = request.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Close();
var sendresponse = (HttpWebResponse)request.GetResponse();
string sendresponsetext = "";
using (var streamReader = new StreamReader(sendresponse.GetResponseStream()))
{
sendresponsetext = streamReader.ReadToEnd();
}
returnmessage = sendresponsetext;
}
catch (Exception ex)
{
ex.Message.ToString();
}
return returnmessage;
}
它总是返回{"status":21002}。
我已经搜索了两天,但仍然找不到解决方案。有人可以帮助我,我错了吗?
**我正在沙盒上进行测试,这就是我使用沙盒 URL 的原因。我可以在我的应用中验证交易收据。
【问题讨论】:
-
嗨,Jerry,您是否将 jsonObjectString 发送到 Web 服务?其实我也遇到了同样的问题。
标签: c# ios objective-c in-app-purchase