Exemplo n.º 1
0
 /**
  *
  * 撤销订单,如果失败会重复调用10次
  * @param string $out_trade_no
  */
 public function cancel($out_trade_no)
 {
     $depth = 0;
     while ($depth++ < 10) {
         $input = new Reverse();
         $input->setOutTradeNo($out_trade_no);
         $result = $this->api->reverse($input);
         //接口调用失败
         if ($result['return_code'] != 'SUCCESS') {
             continue;
         }
         //如果结果为success且不需要重新调用撤销,则表示撤销成功
         if ($result['result_code'] != 'SUCCESS' && $result['recall'] == 'N') {
             return true;
         } elseif ($result['recall'] == 'Y') {
             continue;
         }
         return false;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  *
  * 撤销订单API接口,Reverse中参数out_trade_no和transaction_id必须填写一个
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param Reverse $input
  * @param int $time_out
  * @throws WxPayException
  */
 public function reverse($input, $time_out = 6)
 {
     $url = 'https://api.mch.weixin.qq.com/secapi/pay/reverse';
     //检测必填参数
     if (!$input->isOutTradeNoSet() && !$input->isTransactionIdSet()) {
         throw new WxPayException('撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!');
     }
     $input->setAppid(Wxpay::getConfig('appid'));
     //公众账号ID
     $input->setMchId(Wxpay::getConfig('mchid'));
     //商户号
     $input->setSubMchId(Wxpay::getConfig('sub_mch_id'));
     //子商户号
     $input->setNonceStr($this->getNonceStr());
     //随机字符串
     $input->setSign();
     //签名
     $xml = $input->toXml();
     $start_time_stamp = $this->getMillisecond();
     //请求开始时间
     $response = $this->postXmlCurl($xml, $url, true, $time_out);
     $result = Results::Init($response);
     $this->reportCostTime($url, $start_time_stamp, $result);
     //上报请求花费时间
     return $result;
 }