/** * * 撤销订单,如果失败会重复调用10次 * @param string $out_trade_no * @param 调用深度 $depth */ public function cancel($out_trade_no, $depth = 0) { if ($depth > 10) { return false; } $clostOrder = new WxPayReverse(); $clostOrder->SetOut_trade_no($out_trade_no); $result = WxPayApi::reverse($clostOrder); //接口调用失败 if ($result["return_code"] != "SUCCESS") { return false; } //如果结果为success且不需要重新调用撤销,则表示撤销成功 if ($result["result_code"] != "SUCCESS" && $result["recall"] == "N") { return true; } else { if ($result["recall"] == "Y") { return $this->cancel($out_trade_no, ++$depth); } } return false; }