APP苹果内购支付

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

你可能感兴趣的:(APP苹果内购支付)