duanhui4160
2012-07-14 15:34
浏览 59

PHP中的iOS收据验证

This is a painful topic which has been discussed many times on stack, however, with all the posts I read and things I tried, I was not able to get the IAP verification using PHP working and I'll be damned if I know why.

This is how I get the receipt on the iOS:

purchaseReceipt = [[NSString alloc] initWithData:transaction.transactionReceipt encoding:NSUTF8StringEncoding];

I send it to my PHP script, which encodes it and sends it to the server:

$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);

The problem I'm getting is quite baffling. All receipts tested return as invalid with status -42352 . Yes, I'm sending them to proper environment. Receipt JSON seems to be properly encoded, since if I make any changes to $receipt after encoding, the script returns error 21002 (The data in the receipt-data property was malformed). So it looks like a genuine bad receipt, which can't be since it's from the purchase I'm making on the Sandbox.

I would appreciate any help, as I'm out of ideas.

Here is the value of $_POST["rcpt"] from example purchase made on the Sandbox:

{
    "signature" = "Aqi3Y/UKAYEJUqtFxjRx0DDQ1BV7W/3VtLpVq/l85SIxGXTJOF9WrlBVryQTVgWvUWY6poJVpWQjXrgoSQEjGapN4RmaBChWmHNUgyBy03HKzZ5gQupfHxvxK I3xRaoqyb0jJC4VOmTavU46LqjDfqNuMQvwdT9Y57zoIplBylVAAADVzCCA1MwggI7oAMCAQICCGUUkU3ZWAS1MA0GCSqGSIb3DQEBBQUAMH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSYwJAYDVQQLDB1BcHBsZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEzMDEGA1UEAwwqQXBwbGUgaVR1bmVzIFN0b3JlIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA5MDYxNTIyMDU1NloXDTE0MDYxN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SJidnJzIiA9ICIxLjIuMCI7CgkidHJhbnNhY3Rpb24taWQiID0gIjEwMDAwMDAwNTI4MjE3OTUiOwoJInF1YW50aXR5IiA9ICIxIjsKCSJvcmlnaW5hbC1wdXJjaGFzZS1kYXRlLW1zIiA9ICIxMzQyMjcwOTY4Njg1IjsKCSJwcm9kdWN0LWlkIiA9ICJjb20uZHJhZ29ubG9yZHNtb2JpbGUuVDFfMzBjb2lucyI7CgkiaXRlbS1pZCIgPSAiNDUzMDEzMDUzIjsKCSJiaWQiID0gImNvbS5kcmFnb25sb3Jkc21vYmlsZS5kcmFnb25sb3JkcyI7CgkicHVyY2hhc2UtZGF0ZS1tcyIgPSAiMTM0MjI3MDk2ODY4NSI7CgkicHVyY2hhc2UtZGF0ZSIgPSAiMjAxMi0wNy0xNCAxMzowMjo0OCBFdGMvR01UIjsKCSJwdXJjaGFzZS1kYXRlLXBzdCIgPSAiMjAxMi0wNy0xNCAwNjowMjo0OCBBbWVyaWNhL0xvc19BbmdlbGVzIjsKCSJvcmlnaW5hbC1wdXJjaGFzZS1kYXRlIiA9ICIyMDEyLTA3LTE0IDEzOjAyOjQ4IEV0Yy9HTVQiOwp9";
    "environment" = "Sandbox";
    "pod" = "100";
    "signing-status" = "0";
}
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucan8246326 2012-07-14 21:46
    已采纳

    Have you tried encoding the receipt before sending it to the server?

    Base64 iOS sample code

    Chars such as + were being interpreted as a space char.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题