V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
mejinke
V2EX  ›  问与答

接入微信平台,通过商户号向微信用户付款, CURL 请求微信的 API 时 NGINX 404

  •  
  •   mejinke · 2017-01-02 13:10:39 +08:00 · 1772 次点击
    这是一个创建于 2664 天前的主题,其中的信息可能已经有所发展或是发生改变。

    CURL 中添加证书请求微信 API 时, NGINX 直接 404 了,各位有遇到过的吗? 不添加证书就不会404,但这个接口一定要证书。证书地址也是对的。 CURL:

    $ch = curl_init();
    		//设置超时
    		curl_setopt($ch, CURLOPT_TIMEOUT, $second);
    		
    		//如果有配置代理这里就设置代理
    		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);
    		}
    		curl_setopt($ch,CURLOPT_URL, $url);
    		curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
    		curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
    		//设置 header
    		curl_setopt($ch, CURLOPT_HEADER, FALSE);
    		//要求结果为字符串且输出到屏幕上
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    	
    		if($useCert == true){
    			//设置证书
    			//使用证书: cert 与 key 分别属于两个.pem 文件
    			curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
    			curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
    			curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
    			curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
    		}
    		//post 提交方式
    		curl_setopt($ch, CURLOPT_POST, TRUE);
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    		//运行 curl 就会出现下面的 404
    		$data = curl_exec($ch);
    		//返回结果
    		if($data){
    			curl_close($ch);
    			return $data;
    		} else { 
    			$error = curl_errno($ch);
    			curl_close($ch);
    			throw new WxPayException("curl 出错,错误码:$error");
    		}
    
    <html>
    <head><title>404 Not Found</title></head>
    <body bgcolor="white">
    <center><h1>404 Not Found</h1></center>
    <hr><center>nginx/1.8.0</center>
    </body>
    </html>
    <!-- a padding to disable MSIE and Chrome friendly error page -->
    <!-- a padding to disable MSIE and Chrome friendly error page -->
    <!-- a padding to disable MSIE and Chrome friendly error page -->
    <!-- a padding to disable MSIE and Chrome friendly error page -->
    <!-- a padding to disable MSIE and Chrome friendly error page -->
    <!-- a padding to disable MSIE and Chrome friendly error page -->
    
    ``
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2842 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:32 · PVG 10:32 · LAX 19:32 · JFK 22:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.