微信支付常见问题一:CURLOP_TIMEOUT和curl_close()报错

  • Jesse
  • 2016-02-26 10:45:00
  • 648

刚下载的PHP版的"微信帐号支付DEMO"配置好“WxPay.pub.config.php”里的所有参数,调试时却发现报一大堆错误:


Notice: Use of undefined constant CURLOP_TIMEOUT - assumed 'CURLOP_TIMEOUT' in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 821 Warning: curl_setopt() expects parameter 2 to be long, string given in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 821 Notice: Use of undefined constant CURLOP_TIMEOUT - assumed 'CURLOP_TIMEOUT' in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 155 Warning: curl_setopt() expects parameter 2 to be long, string given in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 155 Warning: curl_close(): 6 is not a valid cURL handle resource in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 175

检查再三,发现如上的三个问题其实完全是微信团队马虎所致
问题一:Notice: Use of undefined constant CURLOP_TIMEOUT - assumed 'CURLOP_TIMEOUT' in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 821 Warning: curl_setopt() expects parameter 2 to be long, string given in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 821
找到WxPayPubHelper.php文件的821行
curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);
将其改成:
curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
原因:"CURLOPT_TIMEOUT"少写了一个"T"

问 题二:Notice: Use of undefined constant CURLOP_TIMEOUT - assumed 'CURLOP_TIMEOUT' in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 155 Warning: curl_setopt() expects parameter 2 to be long, string given in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 155
找到WxPayPubHelper.php文件的155行
curl_setopt($ch, CURLOP_TIMEOUT, $second);
将其改成:
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
原因:一样是少写了一个"T"

问 题三:Warning: curl_close(): 6 is not a valid cURL handle resource in /www/web/other/freyun/public_html/pay/cs/WxPayPubHelper/WxPayPubHelper.php on line 175
将注释“返回结果”前面的那一行注释起来即可
$data = curl_exec($ch);
//curl_close($ch);
//返回结果
if($data)
原因:在注释“返回结果”前面的那一行,已经将$ch连接关闭了,后面的if..else语句中又对它进行了关闭操作,很明显,第二次调用的时候这个连接已经不存在了,肯定会报错。