/** * 21000 App Store不能读取你提供的JSON对象 * 21002 receipt-data域的数据有问题 * 21003 receipt无法通过验证 * 21004 提供的shared secret不匹配你账号中的shared secret * 21005 receipt服务器当前不可用 * 21006 receipt合法,但是订阅已过期。服务器接收到这个状态码时,receipt数据仍然会解码并一起发送 * 21007 receipt是Sandbox receipt,但却发送至生产系统的验证服务 * 21008 receipt是生产receipt,但却发送至Sandbox环境的验证服务 * * $receipt_data 苹果返回的支付凭证 * $sandbox 为1时$url为测试地址,为0时为正试地址 */ function acurl($receipt_data, $sandbox=0){ //小票信息 $POSTFIELDS = array("receipt-data" => $receipt_data); $POSTFIELDS = json_encode($POSTFIELDS); //正式购买地址 沙盒购买地址 $url_buy = "https://buy.itunes.apple.com/verifyReceipt"; $url_sandbox = "https://sandbox.itunes.apple.com/verifyReceipt"; $url = $sandbox ? $url_sandbox : $url_buy; //简单的curl $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS); $result = curl_exec($ch); curl_close($ch); $data = json_decode($result,true); // $data[‘status‘]==0 成功 // $data[‘receipt‘][‘in_app‘][0][‘transaction_id‘] 苹果订单号 // $data[‘receipt‘][‘in_app‘][0][‘product_id‘]; 商品价格 return $data; }
原文:http://www.cnblogs.com/diguaer/p/5719041.html