微信支付错误两个问题的解决:curl出错,错误码:60
如下是运行微信支付测试代码时出错代码:
Warning: curl_setopt() expects parameter 2 to be long, string given in D:\wwwroot\weixinpaytest\pay\WxPay.JsApiPay.php on line 99
Fatal error: Uncaught exception 'WxPayException' with message 'curl出错,错误码:60' in D:\wwwroot\weixinpaytest\lib\WxPay.Api.php:564 Stack trace: #0 D:\wwwroot\weixinpaytest\lib\WxPay.Api.php(62):
WxPayApi::postXmlCurl('<xml><appid><![...', 'https://api.mch...', false, 6) #1 D:\wwwroot\weixinpaytest\pay\jsapi.php(36):
WxPayApi::unifiedOrder(Object(WxPayUnifiedOrder)) #2 {main} thrown in D:\wwwroot\weixinpaytest\lib\WxPay.Api.php on line 564
第一个问题,这个问题完全是微信团队的问题,给出的example就是错的:
Warning: curl_setopt() expects parameter 2 to be long, string given in D:\wwwroot\weixinpaytest\pay\WxPay.JsApiPay.php on line 99
找到WxPay.JsApiPay.php文件的99行,curl_setopt($ch, CURLOP_TIMEOUT, 30);
微信团队example代码里少了一个“T”,正确代码应该是 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
这样,这一个问题就解决了。
下面说第二个问题:
Fatal error: Uncaught exception 'WxPayException' with message 'curl出错,错误码:60' in D:\wwwroot\weixinpaytest\lib\WxPay.Api.php:564 Stack trace: #0 D:\wwwroot\weixinpaytest\lib\WxPay.Api.php(62):
WxPayApi::postXmlCurl('<xml><appid><![...', 'https://api.mch...', false, 6) #1 D:\wwwroot\weixinpaytest\pay\jsapi.php(36):
WxPayApi::unifiedOrder(Object(WxPayUnifiedOrder)) #2 {main} thrown in D:\wwwroot\weixinpaytest\lib\WxPay.Api.php on line 564
这个错误通过修改文件WxPay.Api.php 解决,具体如下:
第537行
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
to
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);//严格校验2
这样,这两个问题就解决了!祝你好运!