WeChat Pay HTTPS server certificate verification (php)

WeChat Pay replaces the CA certificate, indicating that it may affect the payment. 
/**Request method post

*Request format xml
*Test WeChat payment certificate
* @param mch_id WeChat merchant number
* @param nonce_str random number
* @param sign signature
*/
public function index()
{
$data=array(
"mch_id"= >'Merchant ID',
"nonce_str"=> md5(time()),
);
$newdata = http_build_query ($data)."&key=payment 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);

//add the following two lines when curl 60 is wrong
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('Your server is verified by WeChat Pay HTTPS server certificate') ;
}
if ($arrXml['return_code'] == 'FAIL') {
die("Your server failed to authenticate: " . $arrXml['return_msg'] . ";" . "<a hre='https://pay.weixin.qq.com/wiki/doc/api/micropay. php?chapter=23_4'>Click me to see how to install the root CA certificate required by WeChat</a>");
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324931244&siteId=291194637