Reverse() public static method

public static Reverse ( WxPayData inputObj, int timeOut = 6 ) : WxPayData
inputObj WxPayData
timeOut int
return WxPayData
Ejemplo n.º 1
0
        /// <summary>
        /// 撤销订单,如果失败会重复调用10次
        /// </summary>
        /// <param name="out_trade_no">商户订单号</param>
        /// <param name="depth">调用次数,这里用递归深度表示</param>
        /// <returns>alse表示撤销失败,true表示撤销成功</returns>
        public static bool Cancel(string out_trade_no, int depth = 0)
        {
            if (depth > 10)
            {
                return(false);
            }

            WxPayData reverseInput = new WxPayData();

            reverseInput.SetValue("out_trade_no", out_trade_no);
            WxPayData result = WxPayApi.Reverse(reverseInput);

            //接口调用失败
            if (result.GetValue("return_code").ToString() != "SUCCESS")
            {
                return(false);
            }

            //如果结果为success且不需要重新调用撤销,则表示撤销成功
            if (result.GetValue("result_code").ToString() != "SUCCESS" && result.GetValue("recall").ToString() == "N")
            {
                return(true);
            }
            else if (result.GetValue("recall").ToString() == "Y")
            {
                return(Cancel(out_trade_no, ++depth));
            }
            return(false);
        }