Directly on the code:
1 /** 2 * Submit XML to the corresponding interface URL by post3 * 4 * @param string $xml XML data that requires post5 * @param string $url URL6 * @param bool $useCert Whether a certificate is required and is not required by default7 * @param int $second URL Execution time-out, default 30s8 * @throws wxpayexception9 */Ten Private Static functionPostxmlcurl ($xml,$url,$useCert=false,$second= 30) One { A $ch=curl_init (); - //Set Timeout -curl_setopt ($ch, Curlopt_timeout,$second); the - //If you have a configuration agent, set up proxy here - if(Wxpayconfig::curl_proxy_host! = "0.0.0.0" -&& Wxpayconfig::curl_proxy_port! = 0){ +curl_setopt ($ch, Curlopt_proxy, Wxpayconfig::curl_proxy_host); -curl_setopt ($ch, Curlopt_proxyport, Wxpayconfig::curl_proxy_port); + } Acurl_setopt ($ch, Curlopt_url,$url); atcurl_setopt ($ch, Curlopt_ssl_verifypeer,TRUE); -curl_setopt ($ch, curlopt_ssl_verifyhost,2);//Strict Calibration - //Set Header -curl_setopt ($ch, Curlopt_header,FALSE); - //request result As string and output to screen -curl_setopt ($ch, Curlopt_returntransfer,TRUE); in - if($useCert==true){ to //Setting up Certificates + //Use Certificate: Cert and key belong to two. Pem files respectively -curl_setopt ($ch, Curlopt_sslcerttype, ' PEM '); thecurl_setopt ($ch, Curlopt_sslcert, Wxpayconfig::Sslcert_path); *curl_setopt ($ch, Curlopt_sslkeytype, ' PEM '); $curl_setopt ($ch, Curlopt_sslkey, Wxpayconfig::Sslkey_path);Panax Notoginseng } - //Post Submission Method thecurl_setopt ($ch, Curlopt_post,TRUE); +curl_setopt ($ch, Curlopt_postfields,$xml); A //Run Curl the $data= Curl_exec ($ch); + //return Results - if($data){ $Curl_close ($ch); $ return $data; -}Else { - $error= Curl_errno ($ch); theCurl_close ($ch); - Throw NewWxpayexception ("Curl Error, error code:$error");Wuyi } the}
response.php
1 <? PHP 2 if (isset($_post[' name ')]) {3 if (! Empty ($_post[' name '])) {4 echo ' Hello, ',$_post[' name ']. '! '; 5 }6}7 ?>
Curl's post submission XML