收藏
回答

php 微信支付退款返回值

public function weixin_refund($order,$price,$refund_data){
                $nonce_str=rand(0,99999).time();  //随机字符串
                $wx_appid=$this->wx_appid;  //应用id
                $merchant_key=$this->merchant_key;  //商户key
                $merchant_id=$this->merchant_id;  //商户id
                $total_fee=$order['price']*100;  //订单总金额  需乘以100转换为分
                $refund_fee_price=$price*100;  //退款金额  需乘以100转换为分
                $out_refund_no=$refund_data['id'];//商户退款单号
                $url="https://api.mch.weixin.qq.com/secapi/pay/refund";
                $notify_url="http://www.showscenic.com/index.php/Index/weixin_refund_api.html";  //回调地址
                $out_trade_no=$order['order_id'];
                $ref = strtoupper(md5("appid=$wx_appid&mch_id=$merchant_id&nonce_str=$nonce_str&out_refund_no=$out_refund_no&out_trade_no=$out_trade_no&refund_fee=$refund_fee_price&total_fee=$total_fee"));
               $refund = array(
                  'appid' =>$wx_appid, //应用ID,固定
                  'mch_id' => $merchant_id, //商户号,固定
                  'nonce_str' => $nonce_str, //随机字符串
                  'out_refund_no' => $out_refund_no, //商户内部唯一退款单号
                  'out_trade_no' => $out_trade_no, //商户订单号,pay_sn码 1.1二选一,微信生成的订单号,在支付通知中有返回
                  'refund_fee' => $refund_fee_price, //退款金额
                  'total_fee' => $total_fee, //总金额
                  'sign' => $ref//签名
                  );
              $xml = $this->arrayToXml($refund);
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, $url);
              curl_setopt($ch, CURLOPT_HEADER, 1);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); //证书检查
                // 设置证书
                curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
                curl_setopt($ch, CURLOPT_SSLCERT, $_SERVER['SERVER_NAME']. '/gzcAPI/apiclient_cert.pem');
                curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
                curl_setopt($ch, CURLOPT_SSLKEY, $_SERVER['SERVER_NAME']. '/gzcAPI/apiclient_key.pem');
                curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
                curl_setopt($ch, CURLOPT_CAINFO, $_SERVER['SERVER_NAME']. '/gzcAPI/rootca.pem');
              // var_dump($_SERVER['SERVER_NAME']. '/gzcAPI/rootca.pem');
              curl_setopt($ch, CURLOPT_POST, 1);
              curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
              curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
              $xml = curl_exec($ch);
                // var_dump(11);
                
                  // 返回结果0的时候能只能表明程序是正常返回不一定说明退款成功而已
                  if ($xml) {
                    curl_close($ch);
                    // 把xml转化成数组
                    libxml_disable_entity_loader(true);
                    $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
                   var_dump($xmlstring);
                    $result['errNum'] = 0;
                    $result['info'] = $this->object_to_array($xmlstring);
                   var_dump($result);
                    // return $result;
                  } else {
                    $error = curl_errno($ch);
                    var_dump($error);
                    curl_close($ch);
                    // // 错误的时候返回错误码。
                    // $result['errNum'] = $error;
                    // return $result;
                  }
    }

返回值 var_dump($xml); 返回 bool(false) var_dump($error); 返回 77

注掉下面两段代码

 curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'pem');
 curl_setopt($ch, CURLOPT_CAINFO, $_SERVER['SERVER_NAME']. '/gzcAPI/rootca.pem');

返回值 var_dump($xml); 返回 bool(false) var_dump($error); 返回 52

 看了半天没看出毛病在哪  求解决 谢谢

回答关注问题邀请回答
收藏

1 个回答

  • 微信支付技术助手7
    微信支付技术助手7
    2019-03-19

     您好,请参考:

    解决方法:扎到文件Wxpay.api.php。在该文件中找到 “postXmlCurl”这个方法,然后将证书路径修改为绝对路径即可。 

    下面说明修改内容:

    将证书路径替换为绝对路径:

    //使用证书:cert 与 key 分别属于两个.pem文件 

    curl_setopt($ch, CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH); 

    curl_setopt($ch, CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);


    修改为(这里的代码指的是PHP代码,如果是其他语言请进行相应的修改):

    curl_setopt($ch,CURLOPT_SSLCERT, dirname(__FILE__).'/'.WxPayConfig::SSLCERT_PATH);

    curl_setopt($ch,CURLOPT_SSLKEY, dirname(__FILE__).'/'.WxPayConfig::SSLKEY_PATH);

    2019-03-19
    有用
    回复 1
登录 后发表内容