Home  >  Article  >  Backend Development  >  Call WeChat Pay API interface verification

Call WeChat Pay API interface verification

小云云
小云云Original
2018-05-19 13:47:382264browse

Because the root CA certificate of the WeChat Pay HTTPS server certificate will expire on August 23, 2018, WeChat Pay plans to replace the server certificate on May 29, 2018. If a new root CA certificate is not deployed on your server, your order placement, refund and other functions may not work properly.

The following methods are provided for testing, for reference only.

public function check_wx() {
        $mch_id = '1234567891'; // 商户号
        $key = 'rKVuqAv2zlum1JQkfR7OSeRHc1Bg7poD'; // 商户支付密钥
        $nonce_str = strtoupper(md5('3123123131')); // 随机字符串

        // 开始生成sign
        $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 = &#39;{"mch_id":"1495281252","nonce_str":"4E74A5EC8F10C3E7EECE6D8D574CB861","sign":"BFB9329EC7B027DF83AFB848F08E8077"}&#39;;*/
        // $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, &#39;8.8.8.8&#39;);
        //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=&#39;http://curl.haxx.se/libcurl/c/libcurl-errors.html&#39;>错误原因查询</a></br>";
            curl_close($ch);
            return false;
        }
    }

The above is the detailed content of Call WeChat Pay API interface verification. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn