[已解决]微信ca证书更新后openssl报错




客户一服务器环境是windows server2008R2+IIS7+PHP5.6,月初按照微信的提示,更新了ca证书,但最近一直说有问题,页面经常报错。看了下报错内容:

PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in D:\........
PHP Warning:  file_get_contents(): Failed to enable crypto in D:\.......
PHP Warning:  file_get_contents(https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=...&secret=....): failed to open stream: operation failed in D:\..... 
PHP Notice:  Undefined variable: ticket in D:\........
PHP Notice:  Undefined variable: timestamp in D:\........
PHP Notice:  Undefined variable: wxnonceStr in D:\........
PHP Notice:  Undefined variable: wxSha1 in D:\........

 

百度了以后有说是“file_get_contents方法获取https协议的地址报错”的,说把php.ini里的 ;extension=php_openssl.dll前的分号去掉就可以了,检查了下客户服务器的配置, extension=php_openssl.dll是开启了的。

 

后来在stackoverflow上找到个方法,尝试了下,问题解决了。解决方法如下:

<?php
$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  
$response = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=........&amp;secret=......", false, stream_context_create($arrContextOptions));
echo $response;
?>

 

stackoverflow链接:https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more

标签: none