php
  • paypal
  • paypal-sandbox
  • 2013-10-24 24 views 0 likes 
    0

    有人可以告訴我這段代碼有什麼問題。貝寶sandbox notify_url文件不能正常工作

    我正在嘗試與支付與HTML表單的貝寶整合。我已經指定了notify_url,支付去所有的權利,但我不能夠在此塊進入if (strcmp($res, "VERIFIED") == 0){}

    // Response from Paypl 
    // read the post from PayPal system and add 'cmd' 
    $req = 'cmd=_notify-validate'; 
    foreach ($_POST as $key => $value) { 
        $value = urlencode(stripslashes($value)); 
        $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i', '${1}%0D%0A${3}', $value); // IPN fix 
        $req .= "&$key=$value"; 
    } 
    
    // assign posted variables to local variables 
    $data['item_name'] = $_POST['item_name']; 
    
    // post back to PayPal system to validate 
    $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
    
    $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 
    
    if (!$fp) { 
        // HTTP ERROR 
        echo 'HTTP ERROR'; 
    } else { 
    
        file_put_contents('test1.txt', 'test'); 
        fputs($fp, $header . $req); 
        while (!feof($fp)) { 
         $res = fgets($fp, 1024); 
         if (strcmp($res, "VERIFIED") == 0) { 
          echo 'SUCCESS'; 
         } else if (strcmp($res, "INVALID") == 0) {     
          echo 'INVALID'; 
         } 
        } 
        fclose($fp); 
    } 
    

    回答

    1

    使用捲曲方法到後回,而不是fsock數據這裏是鏈接:https://developer.paypal.com/webapps/developer/docs/classic/ipn/ht_ipn/或我的建議是使用AngellaEye庫這是更有效和有用的貝寶整合在這裏是鏈接:http://www.angelleye.com/how-to-integrate-paypal-with-php-class-library/ 從這個鏈接下載並去throgh它。

    相關問題