【问题标题】:Auto-renewable subscriptions for iOS: How to get Server-side receipt validation?iOS 的自动更新订阅:如何获得服务器端收据验证?
【发布时间】:2018-06-02 05:34:38
【问题描述】:

我刚刚完成开发我的应用程序,创建我的 Apple 组织帐户,在 iTunes 连接端创建我需要的所有内容,但我现在的问题是开发 server-side receipt validation(因为 @ 987654322@ 似乎有一些潜在的中间人安全问题)。

...
    // Load the receipt from the app bundle.
    NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
    if (!receipt) { /* No local receipt -- handle the error. */ }

    /* ... Send the receipt data to your server ... */
...

我非常了解该图片上描述的验证过程:

我的主要问题是我不是服务器问题的专家,如果您有一些示例说明我必须为收据验证编写什么代码以及我必须使用什么技术(PHP、Angular 或其他... )。

第一个例子:关于ticket,服务器端的代码是否足以完成验证?)

(第二个例子: 使用 JSON 将 UDID 和 Base64 编码的收据发送到服务器,服务器请求应用商店,应用商店发送好的,服务器发送好的给应用程序。如果是好的过程,我可以轻松完成。Ticket 2 提前致谢。

【问题讨论】:

    标签: php ios server app-store app-store-connect


    【解决方案1】:

    这是我的解决方案:

    我使用我的服务器来验证我的收据,如下所示:

    https://github.com/aporat/store-receipt-validator

    use ReceiptValidator\iTunes\Validator as iTunesValidator;
    
    $validator = new iTunesValidator(iTunesValidator::ENDPOINT_PRODUCTION); // Or iTunesValidator::ENDPOINT_SANDBOX if sandbox testing
    
    $receiptBase64Data = 'ewoJ
    ......
    OVG8xTlNCRmRHTXZSMDFVSWpzS2ZRPT0iOwoJImVudmlyb25tZW50IiA9ICJTYW5kYm94IjsKCSJwb2QiID0gIjEwMCI7Cgkic2lnbmluZy1zdGF0dXMiID0gIjAiOwp9';
    
    try {
      $response = $validator->setReceiptData($receiptBase64Data)->validate();
      // $sharedSecret = '1234...'; // Generated in iTunes Connect's In-App Purchase menu
      // $response = $validator->setSharedSecret($sharedSecret)->setReceiptData($receiptBase64Data)->validate(); // use setSharedSecret() if for recurring subscriptions
    } catch (Exception $e) {
      echo 'got error = ' . $e->getMessage() . PHP_EOL;
    }
    
    if ($response->isValid()) {
      echo 'Receipt is valid.' . PHP_EOL;
      echo 'Receipt data = ' . print_r($response->getReceipt()) . PHP_EOL;
    } else {
      echo 'Receipt is not valid.' . PHP_EOL;
      echo 'Receipt result code = ' . $response->getResultCode() . PHP_EOL;
    }
    

    我服务器上的 WS 发送给我是否正常。

    (对于iPad上的本地进程不建议使用,您可以在这里找到它:I'm getting 21004 as status value in reply from apple's sandbox server testing auto-renewable subscriptions in ios?

    【讨论】:

      猜你喜欢
      • 2014-11-10
      • 2023-03-29
      • 2021-02-06
      • 1970-01-01
      • 2020-08-23
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多