Exemplo n.º 1
0
 /**
  * @param $out_trade_no
  * @return bool
  * @throws \WxPayException
  */
 public function refund($out_trade_no, $fee)
 {
     $WxPayRefund = new \WxPayRefund();
     $WxPayRefund->setWxPayApi($this->wxPayApi);
     $WxPayRefund->SetOut_trade_no($out_trade_no);
     $WxPayRefund->SetOut_refund_no($out_trade_no);
     $WxPayRefund->SetTotal_fee($fee);
     $WxPayRefund->SetRefund_fee($fee);
     $WxPayRefund->SetOp_user_id($this->wxPayApi->getWxPayConfig()['MCHID']);
     $result = $this->wxPayApi->refund($WxPayRefund, $this->wxPayConfig['CURL_TIMEOUT']);
     if ($result['return_code'] == 'FAIL') {
         //系统出错
         throw new \WxPayException("接口调用失败!" . $result['return_msg']);
     }
     if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
         //退款申请 接收成功 ,结果通过退款查询接口查询
         return true;
     }
     if ($result['result_code'] == 'FAIL') {
         //业务提交失败
         throw new \WxPayException("业务提交失败!");
     }
     return false;
 }