0

我正在尝试从 iOS 收据中获取原始交易 ID,但是当我对从苹果返回的数据使用 json_decode 时,它​​的格式很奇怪。这是一个例子:

//来自苹果的对象

   {
        "in_app" =  
         (
                 {
                    "is_trial_period" = false;
                    "original_purchase_date" = "2014-04-24 15:15:19 Etc/GMT";
                    "original_purchase_date_ms" = 1398352519000;
                    "original_purchase_date_pst" = "2014-04-24 08:15:19 America/Los_Angeles";
                    "original_transaction_id" = 1000000108799609;
                    "product_id" = Gems500;
                    "purchase_date" = "2014-04-24 15:15:20 Etc/GMT";
                    "purchase_date_ms" = 1398352520000;
                    "purchase_date_pst" = "2014-04-24 08:15:20 America/Los_Angeles";
                    quantity = 1;
                   "transaction_id" = 1000000108799609;
                 }
        );
    }

我在其他示例中看到 in_app 是一个数组,但我用圆括号得到它。不知道发生了什么。这是我的服务器方法:

  // parse the response data
        $data = json_decode($response);

 $data = json_decode($response);

        // ensure response data was a valid JSON string
        if (!is_object($data)) {
            return 'Invalid response data';
        }

        // ensure the expected data is present
        if (!isset($data->status) || $data->status != 0) {
            return "Apple return with error ".$data->status;
        }

       $in_app = $data->receipt->in_app; //works fine
       $original_transaction_id = $in_app['original_transaction_id'];//does not work

不知道为什么我得到圆括号或该怎么做,但如果你认识到这种类型的 JSON 响应或者我做错了什么,我全神贯注。

我可以访问收据中的所有其他字段,我不能访问它在 in_app 中的唯一字段。

4

0 回答 0