首页 > php集合paypal,关于IPN验证问题.

php集合paypal,关于IPN验证问题.

在集合paypal的时候,遇到了这样的问题,在使用fsockopen打开tsl://www.sandbox.paypal.com,不返回句柄,说明是没有打开这个链接吗?
当链接改成www.sandbox.paypal.com的时候,IPN会返回http 302的状态,说明服务器是支持fsockopen函数的.

header('HTTP/1.1 200 OK');
$req     = 'cmd=_notify-validate&'; 
$req    .= http_build_query($_POST);
$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("tls://www.sandbox.paypal.com",443, $errno, $errstr,30);
//将回复POST信息写入SOCKET端口 
fputs($fp,$header . $req);
//开始接受PayPal对回复POST信息的认证信息 
while(!feof($fp)) {
    $res = fgets($fp,1024);
    //判断是否通过认证
    if (strcmp($res, 'VERIFIED') == 0) {
        if(($this->_post('payment_status','trim') != 'Completed')
           OR ($this->_post('receiver_email','trim') != $this->config['business'])
           OR ($this->_post('mc_currency','trim')      != $this->config['currency_code'])) {
           //认证失败,参数不正确
                fclose($fp);
                return false;
        }else {
            // 认证通过,更改订单状态   
                  D('item_order')->pay_done($this->_post('txn_id','trim'),$this->_post('mc_gross','intval'));
        }
    }else if (strcmp($res, 'INVALID') == 0) {
        //未通过认证,有可能是编码错误或非法的POST信息
        fclose($fp);
        return false;
    }
}
【热门文章】
【热门文章】