gpt4 book ai didi

iphone - 应用内购买收据验证

转载 作者:行者123 更新时间:2023-12-03 21:19:01 26 4
gpt4 key购买 nike

我无法从应用内购买的收据验证中获得响应。您能看一下下面的代码并告诉我为什么我没有得到任何返回吗?另外,如果有任何关于测试收据验证的好方法的建议,请告诉我们!

非常感谢!

Xcode:

- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction {

NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];
NSString *completeString = [NSString stringWithFormat:@"http://www.myURL.com/vReceipt.php?receipt=%@", jsonObjectString];
NSURL *urlForValidation = [NSURL URLWithString:completeString];
NSMutableURLRequest *validationRequest = [[NSMutableURLRequest alloc] initWithURL:urlForValidation];
[validationRequest setHTTPMethod:@"GET"];
NSData *responseData = [NSURLConnection sendSynchronousRequest:validationRequest returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding];
NSInteger response = [responseString intValue];
NSLog(@"Response String: %@", jsonObjectString);
NSLog(@"Response Integer: %@", response);
return (response = 0);}

- (NSString *)encode:(const uint8_t *)input length:(NSInteger)length {
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

NSMutableData *data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t *output = (uint8_t *)data.mutableBytes;

for (NSInteger i = 0; i < length; i += 3) {
NSInteger value = 0;
for (NSInteger j = i; j < (i + 3); j++) {
value <<= 8;

if (j < length) {
value |= (0xFF & input[j]);
}
}

NSInteger index = (i / 3) * 4;
output[index + 0] = table[(value >> 18) & 0x3F];
output[index + 1] = table[(value >> 12) & 0x3F];
output[index + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[index + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}

return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];}

PHP 代码:

<?php

$myreceipt = json_encode(array('receipt-data' => $_GET['receipt']));
$url = "https://sandbox.itunes.apple.com/verifyReceipt";

//create cURL Request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myreceipt);

//execute cURL Request
$response = curl_exec($ch);
$errno = curl_errno($ch);
$errmsg = curl_error($ch);
curl_close($ch);

$response_json = json_decode($response);

print $response_json->{'status'};

?>

最佳答案

该字符串始终返回 0:

return (response = 0);}

更正一个:

return (response == 0);}

关于iphone - 应用内购买收据验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6808695/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com