src/Common/Weixin/WxBaseStrategy.php
protected function sendReq($xml)
    {
        $url = $this->reqUrl;
        if (is_null($url)) {
            throw new PayException('目前不支持该接口。请联系开发者添加');
        }

        if ($this->config->useSandbox) {
            $url = str_ireplace('{debug}', WxConfig::SANDBOX_PRE, $url);
        } else {
            $url = str_ireplace('{debug}/', '', $url);
        }

        $client = new Client([
            'timeout' => '10.0'
        ]);
        // @note: 微信部分接口并不需要证书支持。这里为了统一，全部携带证书进行请求
        $options = [
            'body' => $xml,
            'cert' => $this->config->appCertPem,
            'ssl_key' => $this->config->appKeyPem,
            'verify' => $this->config->cacertPath,
            'http_errors' => false
        ];
        $response = $client->request('POST', $url, $options);
        if ($response->getStatusCode() != '200') {
            throw new PayException('网络发生错误，请稍后再试curl返回码：' . $response->getReasonPhrase());
        }

        $body = $response->getBody()->getContents();
        // 格式化为数组
        $retData = DataParser::toArray($body);
        if (strtoupper($retData['return_code']) != 'SUCCESS') {
            throw new PayException('微信返回错误提示：' . $retData['return_msg']);
        }
        if (strtoupper($retData['result_code']) != 'SUCCESS') {
            $msg = $retData['err_code_des'] ? $retData['err_code_des'] : $retData['err_msg'];
            throw new PayException('微信返回错误提示：' . $msg);
        }

        return $retData;
    }
protected function sendReq($xml)
    {
        $url = $this->reqUrl;
        if (is_null($url)) {
            throw new PayException('目前不支持该接口。请联系开发者添加');
        }

        if ($this->config->useSandbox) {
            $url = str_ireplace('{debug}', WxConfig::SANDBOX_PRE, $url);
        } else {
            $url = str_ireplace('{debug}/', '', $url);
        }

        $client = new Client([
            'timeout' => '10.0'
        ]);
        // @note: 微信部分接口并不需要证书支持。这里为了统一，全部携带证书进行请求
        $options = [
            'body' => $xml,
            'cert' => $this->config->appCertPem,
            'ssl_key' => $this->config->appKeyPem,
            'verify' => $this->config->cacertPath,
            'http_errors' => false
        ];
        $response = $client->request('POST', $url, $options);
        if ($response->getStatusCode() != '200') {
            throw new PayException('网络发生错误，请稍后再试curl返回码：' . $response->getReasonPhrase());
        }

        $body = $response->getBody()->getContents();
        // 格式化为数组
        $retData = DataParser::toArray($body);
        if (strtoupper($retData['return_code']) != 'SUCCESS') {
            throw new PayException('微信返回错误提示：' . $retData['return_msg']);
        }
        if (strtoupper($retData['result_code']) != 'SUCCESS') {
            $msg = $retData['err_code_des'] ? $retData['err_code_des'] : $retData['err_msg'];
            throw new PayException('微信返回错误提示：' . $msg);
        }

        return $retData;
    }
protected function sendReq ( $ xml ) { $ url = $ this -> reqUrl ; if ( is_null ( $ url ) ) { throw new PayException ( '目前不支持该接口。请联系开发者添加'); } if ( $ this -> config -> useSandbox ) { $ url = str_ireplace ( '{debug}' , WxConfig :: SANDBOX_PRE , $ url ) ; } else { $ url = str_ireplace ( '{debug}/' , '' , $ url ) ; } $ client = new Client ( [ 'timeout' => '10.0' ] ) ; // @note: 微信部分接口并不需要证书支持。这里为了统一，全部携带证书进行请求 $ options = [ 'body' => $ xml , 'cert' => $ this -> config -> appCertPem , 'ssl_key' => $ this -> config -> appKeyPem , 'verify' => $ this -> config -> cacertPath , 'http_errors' => false ] ; $ response = $ client -> request ( 'POST' , $ url , $ options ) ; if ( $ response -> getStatusCode ( ) != '200' ) { throw new PayException ( '网络发生错误，请稍后再试curl返回码：' . $response->getReasonPhrase()) } $ body = $ response -> getBody ( ) -> getContents ( ) ; // 格式化为数组 $ retData = DataParser :: toArray ( $ body ) ; if ( strtoupper ( $ retData [ 'return_code' ] ) != 'SUCCESS' ) { throw new PayException ( '微信返回错误提示：' . $retData['retur _ s g']); } if ( strtoupper ( $ retData [ 'result_code' ] ) != 'SUCCESS' ) { $ msg = $ retData [ 'err_code_des' ] ? $ retData [ 'err_code_des' ] : $ retData [ 'err_msg' ] ; throw new PayException ( '微信返回错误提示：' . $msg); } return $ retData ; }
发送完了请求
@param string $xml
@return mixed
@throws PayException
@author helei
发送完了请求