微信支付HTTPS服務器證書驗證(php)


微信支付更換CA證書,提示有可能影響支付。
/**請求方式 post

* 請求格式 xml
* 測試微信支付證書
* @param mch_id 微信商戶號
* @param nonce_str 隨機數
* @param sign 簽名
*/
public function index()
{
$data=array(
"mch_id"=>'商戶號',
"nonce_str"=> md5(time()),
);
$newdata = http_build_query ($data)."&key=支付密鑰";
$sign = strtoupper(md5($newdata));
$data["sign"] = $sign;

$postdata = arrayToXml($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

//curl 60 錯誤時加上一下的兩行
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER,0);
$returncode =curl_exec($ch);
if($error=curl_errno($ch)){
echo $error;
}
curl_close($ch);

$toXml = simplexml_load_string($returncode, 'SimpleXMLElement', LIBXML_NOCDATA);
$arrXml = (array)$toXml;
if ($arrXml['return_code'] == 'SUCCESS') {

die('你的服務器通過微信支付HTTPS服務器證書驗證');
}
if ($arrXml['return_code'] == 'FAIL') {
die("你的服務器無法通過驗證:" . $arrXml['return_msg'] . ";" . "<a hre='https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=23_4'>點我查看如何安裝微信要求的根CA證書</a>");
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM