这是一个痛苦的话题,已经在堆栈上多次讨论过了,然而,随着我阅读的所有帖子和我尝试的内容,我无法使用PHP工作获得IAP验证,如果我,我会被诅咒知道原因。
这就是我在iOS上获得收据的方式:
purchaseReceipt = [[NSString alloc] initWithData:transaction.transactionReceipt encoding:NSUTF8StringEncoding];
我将它发送到我的PHP脚本,该脚本对其进行编码并将其发送到服务器:
$receipt = base64_encode($_POST["rcpt"]);
$postData = json_encode(
array('receipt-data' => $receipt)
);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
$errno = curl_errno($ch);
$errmsg = curl_error($ch);
curl_close($ch);
我遇到的问题非常令人困惑。测试的所有收据均以无效状态返回,状态为-42352。是的,我将他们送到适当的环境。收据JSON似乎是正确编码的,因为如果我在编码后对$ receipt进行任何更改,脚本将返回错误21002(receipt-data属性中的数据格式错误)。因此它看起来像是一张真正的坏收据,因为它来自我在沙盒上的购买。
我很感激任何帮助,因为我没有想法。
以下是在沙盒上购买示例的$ _POST [“rcpt”]的值:
{
"signature" = "Aqi3Y/UKAYEJUqtFxjRx0DDQ1BV7W/3VtLpVq/l85SIxGXTJOF9WrlBVryQTVgWvUWY6poJVpWQjXrgoSQEjGapN4RmaBChWmHNUgyBy03HKzZ5gQupfHxvxK I3xRaoqyb0jJC4VOmTavU46LqjDfqNuMQvwdT9Y57zoIplBylVAAADVzCCA1MwggI7oAMCAQICCGUUkU3ZWAS1MA0GCSqGSIb3DQEBBQUAMH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSYwJAYDVQQLDB1BcHBsZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEzMDEGA1UEAwwqQXBwbGUgaVR1bmVzIFN0b3JlIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA5MDYxNTIyMDU1NloXDTE0MDYxND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