2012-03-16 55 views
0

我正在做Zend Framework的PayPal IPN,我想发送ipn的验证网址。如何提交在Zend的后端要求?Zend后端网址发布

例如:

$this->_helper->layout()->disableLayout(); 
$formData = $this->getRequest()->getParams(); 

    $url="www.sandbox.paypal.com?cmd=_notify-validate&transaction_subject=Zhopenemr Plan Subscription&txn_type=subscr_payment&payment_date=04:02:32 Mar 16, 2012 PDT&subscr_id=I-XFD23RR8DT6G&last_name=T P&residence_country=US&pending_reason=echeck&item_name=Zhopenemr Plan Subscription&payment_gross=4169.90&mc_currency=USD&[email protected]&payment_type=echeck&protection_eligibility=Ineligible&verify_sign=AGkW.2d.KC8Af-bSXQHFoo4g-LvfAmXI1BIIEMPHZZem9-oQOwopoG4i&payer_status=verified&test_ipn=1&[email protected]&txn_id=98J32260FL8930534&[email protected]&first_name=Pradeep&payer_id=LVQGVA8WRESRN&receiver_id=U6AEZTRXA6L4U&payment_status=Pending&mc_gross=4169.90&charset=windows-1252&notify_version=3.4&ipn_track_id=ff7d0a9a6f2d2"; 



    $request = new zHTTPRequest($url, HTTP_METH_GET); 
    // $request->setRawPostData($xml); 
    $request->send(); 
    $response = $request->getResponseBody(); 

    $ipnval=""; 
    foreach($formData as $key=>$value){ 
      $ipnval.= "".$key." = ".$value." <br>"; 
    } 

我要提交的$网址到PayPal和检验状态。我怎样才能做到这一点在后端?

$request = new zHTTPRequest($url, HTTP_METH_GET); 
    // $request->setRawPostData($xml); 
    $request->send(); 
    $response = $request->getResponseBody(); 

这个声明可以用简单的php来完成。这与Zend如何工作?

在此先感谢。

回答

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

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 
     } else if (strcmp ($res, "INVALID") == 0) { 
      // log for manual investigation 
     } 
    } 
    fclose ($fp); 
} 
exit;