因微信支付HTTPS服务器证书的根CA证书将于2018年8月23日到期失效,微信支付计划于2018年5月29日, 更换服务器证书。若你的服务器上没有部署新的根CA证书,将可能导致你的下单、退款等功能无法正常使用。
现提供以下方法进行测试,仅供参考。
public function check_wx() {
$mch_id = '1234567891'; // 商户号$key = 'rKVuqAv2zlum1JQkfR7OSeRHc1Bg7poD'; // 商户支付密钥
$nonce_str = strtoupper(md5('3123123131')); // 随机字符串
$str = "mch_id=".$mch_id."&nonce_str=".$nonce_str."&key=".$key;
$sign = strtoupper(md5( $str ));
// 打印字符串和签名
echo $nonce_str;
echo "<br />";
echo $sign;
$xml = "<xml>
<mch_id>1495281252</mch_id>
<nonce_str>4E74A5EC8F10C3E7EECE6D8D574CB861</nonce_str>
<sign>BFB9329EC7B027DF83AFB848F08E8077</sign>
</xml>";
$url = "https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
/*$a = '{"mch_id":"1495281252","nonce_str":"4E74A5EC8F10C3E7EECE6D8D574CB861","sign":"BFB9329EC7B027DF83AFB848F08E8077"}';*/
// $result = http_request($url,$xml);
$result = $this->postXmlCurl($xml,$url);
dump($result);
}
/**
* 作用:以post方式提交xml到对应的接口url
*/
public function postXmlCurl($xml,$url,$second=30)
{
//初始化curl
$ch = curl_init();
//设置超时 CURLOP_TIMEOUT
//curl_setopt($ch, CURLOP_TIMEOUT, $second);
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
//这里设置代理,如果有的话
//curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
//运行curl
$data = curl_exec($ch);
//curl_close($ch);
//返回结果
if($data)
{
curl_close($ch);
return $data;
}
else
{
$error = curl_errno($ch);
//echo "curl出错,错误码:$error"."<br>";
//echo "<a href='http://curl.haxx.se/libcurl/c/libcurl-errors.html'>错误原因查询</a></br>";
curl_close($ch);
return false;
}
}