APP蘋果內購支付
阿新 • • 發佈:2018-11-28
$user_id = $_SESSION['user_id'];/* = 1024 */ if ($user_id <= 0) { return new ecjia_error(100, 'Invalid session'); } $url_buy = "https://buy.itunes.apple.com/verifyReceipt"; $url_sandbox = "https://sandbox.itunes.apple.com/verifyReceipt"; $receipt = $this->requestData('receipt-data'); $sandbox= $this->requestData('sandbox'); $jsonData = array('receipt-data'=>$receipt); $jsonData = json_encode($jsonData); $url = $sandbox ? $url_sandbox : $url_buy; $response = http_post_data($url,$jsonData); if($response['status']== 0){ $transaction_id=$response['receipt']['in_app'][0]['transaction_id'];//蘋果訂單號 $product_id=$response['receipt']['in_app'][0]['product_id'];//商品價格 $money=explode('musicStudy', $product_id); $addtime=RC_Time::gmtime(); //使用者原始金額 $userinfo = RC_DB::table('users')->where('user_id', $user_id)->first(); //使用者總金額 $money_sum=(int)$money[1]+$userinfo['qianbao']; //更新用金額 RC_DB::table('users')->where('user_id', $user_id)->update(array('qianbao'=>$money_sum)); //插入充值記錄 $data = array( 'user_id' => $user_id, 'status' => 1, 'transaction_id' => $transaction_id, 'message' => '充值成功', 'money' =>$money[1], 'add_time' =>$addtime ); $ad_id = RC_DB::table('ios_chongzhi_log')->insertGetId($data); $result=array( 'message'=>'success' ); }else{ $result=array( 'message'=>'false status:'.$response['status'] ); } return $result;