PayPal第三方支付



            
              
            
             
              
            
             
              
             
            
            
            
             !-- 付款说明 -->
            
            
            
            
        

 

php SDK 地址 :https://github.com/paypal/PayPal-PHP-SDK

 

//pay回调地址
public function pay(){
    $data = $_POST;
    file_put_contents("./log/paylog.log",$_SERVER["SERVER_NAME"].",".$_SERVER['REMOTE_ADDR'].",".date("Y-m-d H:i:s",time()).",".var_export($_GET, true).",".var_export($_POST, true)."\r\n",FILE_APPEND);
    $data["cmd"] = "_notify-validate";
    $pay=Db::name('pay_type')->where(['pay_id'=>3])->find();
    $payInfo=json_decode($pay['pay_json'],true);
    $url=$payInfo['pay_url'];
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    $res = curl_exec($ch);
    curl_close($ch);

   // file_put_contents('./log/aaaaaaa.log',$res);
    if (strcmp ($res, "VERIFIED") == 0) {

        $item_number = $data["item_number1"];
        $payment_status = $data["payment_status"];
        //$payment_status = "Completed";
        $pay_check = 0;
        if ($payment_status == "Pending") {
            if ($data["pending_reason"] == "paymentreview") {
                $pay_check = 1;
            } else {
                $pay_check = 0;
            }
        } else if ($payment_status == "Completed") {
            $pay_check = 1;
        }
        $order_id=Db::name('pay_tc_orders')->where(['order_number'=>$item_number,'order_prc'=>$data['payment_gross']])->field('order_id')->find();
        //检测价格
        if(empty($order_id['order_id'])){
            file_put_contents("./log/paylogerror.log",$_SERVER["SERVER_NAME"].",".$_SERVER['REMOTE_ADDR'].",".date("Y-m-d H:i:s",time()).",".$item_number.'信息有误'."\r\n",FILE_APPEND);
        }
        if ($pay_check == 1) {
             $Buy=new Buy();
           $status=  $Buy->updateMoney($item_number);
           if($status){
               echo 'SUCCESS';
           }else{
               echo "Fail";
           }
        }

    }else{
        echo "Fail";
    }
}

你可能感兴趣的:(PHP)