Exemplo n.º 1
0
 /**
  *
  * 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
  * out_refund_no、total_fee、refund_fee、op_user_id为必填参数
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayRefund $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public function refund($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
     //检测必填参数
     if (!$inputObj->isOutTradeNoSet() && !$inputObj->isTransactionIdSet()) {
         throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
     } else {
         if (!$inputObj->isOutRefundNoSet()) {
             throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
         } else {
             if (!$inputObj->isTotalFeeSet()) {
                 throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
             } else {
                 if (!$inputObj->isRefundFeeSet()) {
                     throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
                 } else {
                     if (!$inputObj->isOpUserIdSet()) {
                         throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
                     }
                 }
             }
         }
     }
     $inputObj->setAppid($this->apiConfig->appid);
     //公众账号ID
     $inputObj->setMchId($this->apiConfig->mchid);
     //商户号
     $inputObj->setMchKey($this->apiConfig->mchkey);
     //商户密钥
     $inputObj->setNonceStr($this->getNonceStr());
     //随机字符串
     $inputObj->setSign();
     //签名
     $xml = $inputObj->toXml();
     $startTimeStamp = $this->getMillisecond();
     //请求开始时间
     $response = $this->postXmlCurl($xml, $url, true, $timeOut);
     $result = WxPayResults::init($response, $this->apiConfig->mchkey);
     $this->reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }