2011-10-25 44 views
0

我试图捕获订户ID。一旦客户订阅并发送到ipn页面,订阅者ID就不会回显!这是用IPN捕获paypal用户id的正确方法吗?

<?php 
     // read the post from PayPal system and add 'cmd' 
    $req = 'cmd=_notify-validate'; 

    foreach ($_POST as $key => $value) { 
    $value = urlencode(stripslashes($value)); 
    $req .= "&$key=$value"; 
    } 

    // 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.paypal.com', 443, $errno, $errstr, 30); 

    // assign posted variables to local variables 



     ////////////////////////////////////////////HERE 
    $payer_id= $_POST['subscr_id']; 
     echo 'id='.$payer_id; 


     /////////////////////////////////////////// 



    $item_number = $_POST['item_number']; 
    $payment_status = $_POST['payment_status']; 
    $payment_amount = $_POST['mc_gross']; 
    $payment_currency = $_POST['mc_currency']; 
    $txn_id = $_POST['txn_id']; 
    $receiver_email = $_POST['receiver_email']; 
    $payer_email = $_POST['payer_email']; 
     if("subscr_cancel" == $_POST['txn_type']){ 

    if (!$fp) { 
    // HTTP ERROR 
    } else { 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
    $res = fgets ($fp, 1024); 
    if (strcmp ($res, "VERIFIED") == 0) { 
    // check the payment_status is Completed 
    // check that txn_id has not been previously processed 
    // check that receiver_email is your Primary PayPal email 
    // check that payment_amount/payment_currency are correct 
    // process payment 

        $websites= "websites"; 
     $database = "k29803_1"; 
     mysql_connect("localhost", $username, $password) or die(mysql_error()); 
     mysql_select_db($database); 

     $query = "SELECT * FROM users WHERE username= secret AND password = secret "; 
     $results = mysql_query($query)or die(mysql_error()); 
     if(mysql_num_rows($results)==1){ 
      $add_credits = "UPDATE users SET credits = credits -5000 
      WHERE username= 'drahoslava' AND password = 'drah0slava'"; 
      mysql_query($add_credits) or die(mysql_error()); 


      } 

    } 
    else if (strcmp ($res, "INVALID") == 0) { 
    // log for manual investigation 
    } 
    } 
    fclose ($fp); 
    } 
     } 
     ?> 

的按钮看起来像这样

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
<input type="hidden" name="cmd" value="_s-xclick"> 
<input type="hidden" name="hosted_button_id" value="NQMGM2LCZUQRE"> 

    <input type="hidden" name="item_name" value="1" /> 
    <input type="hidden" name="item_number" value="01" /> 
    <input type="hidden" name="amount" value="1.99" /> 
    <input type="hidden" name="currency_code" value="USD" /> 
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> 
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> 
</form> 

我怎样才能获得订阅ID来呼应?按钮有问题吗?它应该有一个notify_url?

这是我所得到的回发

http://www.germcode.kodingen.com/ipn.php?tx=7ND09573SF680804M&st=Completed&amt=2.99&cc=USD&cm=&item_number=&sig=J1J%2f4phZ1VlJI1NcHAU3HxEjMgvWbv8aenml17e0GEGWfOy1CbyvaTQw60qXMf6l%2bL0LZ4GESLX6VikG%2f6UronEGf5lmKzWoXePPYdd%2bV3ep%2fXwTplJlez3NuNAxWYUHr0FGd35s15ZdTp4bOaA2yZfpWg2iLGDMQi6IN9%2f%2f8N0%3d 

回答

0

你要发布什么时候回来不IPN数据。您需要在PayPal表单中设置notify_url以接收IPN数据。

<input type="hidden" name="notify_url" value="http://www.germcode.kodingen.com/ipn.php"> 

注:如果您使用的是所谓的“托管按钮”(所有详细信息都存储与贝宝),还可以设置IPN您的PayPal档案内,或者去键管理工具,点击在步骤3中,勾选“添加高级变量”并在textarea中添加notify_url=http://www.germcode.kodingen.com/ipn.php