示例#1
0
        /// <summary>
        /// 订单退款
        /// </summary>
        /// <param name="tradeno">商户订单号</param>
        /// <param name="alipayTradeNo">支付宝交易号</param>
        /// <param name="refundAmount">退款金额</param>
        /// <param name="refundReason">退款原因</param>
        /// <param name="refundNo">退款单号</param>
        public ActionResult RefundInfo(string tradeno, string alipayTradeNo, string refundAmount, string refundReason, string refundNo)
        {
            DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, Config.app_id, Config.private_key, "json", "1.0", Config.sign_type, Config.alipay_public_key, Config.charset, false);

            AlipayTradeRefundModel model = new AlipayTradeRefundModel();

            // 商户订单号,和交易号不能同时为空
            model.OutTradeNo = tradeno;
            // 支付宝交易号,和商户订单号不能同时为空
            model.TradeNo = alipayTradeNo;
            // 退款金额,不能大于订单总金额
            model.RefundAmount = refundAmount;
            // 退款原因
            model.RefundReason = refundReason;
            // 退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
            model.OutRequestNo = refundNo;

            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.SetBizModel(model);

            AlipayTradeRefundResponse response = null;

            try
            {
                response = client.Execute(request);
                return(Json(response.Body));
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
示例#2
0
        protected void BtnAlipay_Click(object sender, EventArgs e)
        {
            ////////////////////////////////////////////请求参数////////////////////////////////////////////

            //支付宝交易号
            string trade_no = WIDtrade_no.Text.Trim();
            //支付宝交易号与商户网站订单号不能同时为空

            string out_request_no = WIDout_request_no.Text.Trim();
            //退款金额
            string refund_amount = WIDrefund_amount.Text.Trim();
            //退款金额不能大于订单金额

            //商户网站订单系统中唯一订单号,必填

            StringBuilder sb = new StringBuilder();

            sb.Append("{\"out_request_no\":\"" + out_request_no + "\",");
            sb.Append("\"trade_no\":\"" + trade_no + "\",");
            sb.Append("\"refund_amount\":\"" + refund_amount + "\"}");

            AlipayTradeRefundResponse refundResponse = Refund(sb.ToString());

            //请在这里加上商户的业务逻辑程序代码
            //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
            string result = refundResponse.Body;

            Response.Redirect("Default2.aspx?Text=" + result);
        }
示例#3
0
        /// <summary>
        /// 发起订单退款
        /// </summary>
        /// <param name="refundRequest">退款申请参数</param>
        /// <returns></returns>
        public override ApiResultModel <string> RefundPay(RefundBaseRequest refundRequest)
        {
            var res = new ApiResultModel <string>()
            {
                Code = ApiResultCode.Fail, Message = "fail"
            };

            string total_fee  = refundRequest.OrderMoney.ToString("#0.00");
            string refund_fee = refundRequest.RefundMoney.ToString("#0.00");
            //退款请求
            IAopClient client = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.AppId, AliPayConfig.privatekey, "json", "1.0", AliPayConfig.sign_type, AliPayConfig.alipublickey, AliPayConfig.charset, false);
            AlipayTradeRefundRequest request     = new AlipayTradeRefundRequest();
            AlipayTradeRefundModel   alipayModel = new AlipayTradeRefundModel()
            {
                OutTradeNo   = refundRequest.OrderCode,
                TradeNo      = refundRequest.TradeNo,
                RefundAmount = refund_fee,
                RefundReason = "用户申请退款",
            };

            request.SetBizModel(alipayModel);
            AlipayTradeRefundResponse response = client.Execute(request);

            //2.2、记录请求日志
            //记录支付宝退款调用的日志
            //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderRefund.OrderCode, ThirdPlatformType.Alipay, AliPayConfig.gatewayUrl, request.BizContent, DateTime.Now, response.Body, DateTime.Now, true);
            if (response.Code != "10000")
            {
                res.Message = response.Msg;
                return(res);
            }
            res.Code    = ApiResultCode.Success;
            res.Message = "ok";
            return(res);
        }
示例#4
0
        /// <summary>
        /// 退款
        /// </summary>
        public bool Refund(decimal amount, string orderNo, string requestNo, string reason = null, string tradeNo = null)
        {
            bool success = false;

            //组装业务参数
            var model = new AlipayTradeRefundModel()
            {
                OutTradeNo   = orderNo,
                TradeNo      = tradeNo,
                RefundAmount = amount.ToString(),
                RefundReason = reason,
                OutRequestNo = requestNo //退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
            };

            var request = new AlipayTradeRefundRequest();

            request.SetBizModel(model);

            AlipayTradeRefundResponse response = aopClient.Execute(request);

            if (response != null && response.Code == "10000")
            {
                success = true;
            }

            //记日志response.ToJson();

            return(success);
        }
示例#5
0
 /// <summary>
 /// 退款请求
 /// </summary>
 /// <param name="out_trade_no">订单编号</param>
 /// <param name="trade_no">交易单好</param>
 /// <param name="refund_amount">退款金额(元)</param>
 /// <param name="refund_reason">原因</param>
 /// <param name="out_request_no">退款订单号</param>
 /// <returns></returns>
 public static bool RefundRequest(string companyId, string out_trade_no, string trade_no, string refund_amount, string refund_reason, string out_request_no)
 {
     try
     {
         AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
         request.BizContent = "{" +
                              "\"out_trade_no\":\"" + out_trade_no + "\"," +
                              "\"trade_no\":\"" + trade_no + "\"," +
                              "\"refund_amount\":" + refund_amount + "," +
                              "\"refund_reason\":\"" + refund_reason + "\"," +
                              "\"out_request_no\":\"" + out_request_no + "\"" +
                              "}";
         AlipayTradeRefundResponse response = GetDefaultAopClient(companyId).Execute(request);
         if (response.IsError)
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("退款请求失败:{0}", response.Body));
             return(false);
         }
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("退款请求结果:{0}", response.Body));
         return(response.Code == "10000");
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("退款请求失败:{0}", ex.Message));
         return(false);
     }
 }
示例#6
0
        public static string TradeRefund(string outTradeNo, string refundAmount)
        {
            //https://docs.open.alipay.com/api_1/alipay.trade.refund
            IAopClient client = new DefaultAopClient(ServerUrl, AppId, AppPrivateKey, "json", "1.0", SignType, AlipayPublicKey, Charset, false);
            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.BizContent = "{" +
                                 "\"out_trade_no\":\"" + outTradeNo + "\"," +
                                 "\"trade_no\":\"\"," +
                                 "\"refund_amount\":" + refundAmount + "," +
                                 "\"refund_reason\":\"正常退款\"," +
                                 "\"out_request_no\":\"HZ01RF001\"," +
                                 "\"operator_id\":\"OP001\"," +
                                 "\"store_id\":\"NJ_S_001\"," +
                                 "\"terminal_id\":\"NJ_T_001\"" +
                                 "  }";
            AlipayTradeRefundResponse response = client.Execute(request);

            if (response.Code == "10000")
            {
                return("10000");
            }
            else
            {
                return(response.Body);
            }
        }
示例#7
0
        /// <summary>
        /// 申请退款
        /// </summary>
        /// <param name="requestModel">请求内容</param>
        /// <returns></returns>
        public static RefundResponseModel Refund(RefundModel requestModel)
        {
            AlipayTradeRefundRequest queryRequset = new AlipayTradeRefundRequest();

            queryRequset.BizContent = JsonConvert.SerializeObject(requestModel);
            LogUtil.WriteAlipayLog("申请退款请求", "请求参数", queryRequset.BizContent);
            Dictionary <string, string> paramsDict     = (Dictionary <string, string>)queryRequset.GetParameters();
            AlipayTradeRefundResponse   refundResponse = _client.Execute(queryRequset);

            LogUtil.WriteAlipayLog("申请退款响应", "响应参数", refundResponse.Body);
            return(new RefundResponseModel
            {
                msg = refundResponse.Msg,
                code = refundResponse.Code,
                subcode = refundResponse.SubCode,
                submsg = refundResponse.SubMsg,
                trade_no = refundResponse.TradeNo,
                send_back_fee = refundResponse.SendBackFee,
                store_name = refundResponse.StoreName,
                fund_change = refundResponse.FundChange,
                buyer_logon_id = refundResponse.BuyerLogonId,
                amount = refundResponse.RefundDetailItemList == null || refundResponse.RefundDetailItemList.Count == 0 ? "0.0" : refundResponse.RefundDetailItemList[0].Amount,
                fund_channel = refundResponse.RefundDetailItemList == null || refundResponse.RefundDetailItemList.Count == 0 ? "": refundResponse.RefundDetailItemList[0].FundChannel,
                out_trade_no = refundResponse.OutTradeNo,
                buyer_user_id = refundResponse.BuyerUserId,
                gmt_refund_pay = refundResponse.GmtRefundPay,
                refund_fee = refundResponse.RefundFee
            });
        }
示例#8
0
 public void SetAlipayResult(AlipayTradeRefundResponse response)
 {
     base.SetAlipayResult(response);
     if (!IsError)
     {
         this.OnlineTradeNo = response.TradeNo;
         this.OutTradeNo    = response.OutTradeNo;
         this.RefundAmount  = response.RefundFee;
     }
 }
        public void TestRefund()
        {
            AlipayTradeRefundResponse response = Factory.Payment.Common().Refund(CreateNewAndReturnOutTradeNo(), "0.01");

            Assert.AreEqual(response.Code, "40004");
            Assert.AreEqual(response.Msg, "Business Failed");
            Assert.AreEqual(response.SubCode, "ACQ.TRADE_STATUS_ERROR");
            Assert.AreEqual(response.SubMsg, "交易状态不合法");
            Assert.NotNull(response.HttpBody);
        }
示例#10
0
        private AlipayTradeRefundResponse DoRefund(string biz_content, AlipayDomain alipay)
        {
            AlipayTradeRefundRequest payRequst = new AlipayTradeRefundRequest();

            payRequst.BizContent = biz_content;
            payRequst.SetNotifyUrl("");
            Dictionary <string, string> paramsDict = (Dictionary <string, string>)payRequst.GetParameters();
            IAopClient client = new DefaultAopClient(serverUrl, alipay.APP_ID, alipay.APP_PRIVATE_KEY, "", version,
                                                     sign_type, alipay.ALIPAY_PUBLIC_KEY, charset);

            AlipayTradeRefundResponse payResponse = client.Execute(payRequst);

            return(payResponse);
        }
示例#11
0
        private AlipayTradeRefundResponse Refund(string biz_content)
        {
            AlipayTradeRefundRequest payRequst = new AlipayTradeRefundRequest();

            payRequst.BizContent = biz_content;

            Dictionary <string, string> paramsDict = (Dictionary <string, string>)payRequst.GetParameters();
            IAopClient client = new DefaultAopClient(Config.serverUrl, Config.appId, Config.merchant_private_key, "", Config.version,
                                                     Config.sign_type, Config.alipay_public_key, Config.charset);
            //new DefaultAopClient(Config.serverUrl, Config.appId, Config.merchant_private_key);

            AlipayTradeRefundResponse payResponse = client.Execute(payRequst);

            return(payResponse);
        }
示例#12
0
        private void btnRefund_Click(object sender, EventArgs e)
        {
            AlipayTradeRefundResponse refundResponse = null;

            try
            {
                if (m_TradeNoStr != null)
                {
                    refundResponse = m_Alipay.RefundByTradeNo(m_TradeNoStr, m_RefundAmount, "原麦山丘退款");
                }
                else
                {
                    refundResponse = m_Alipay.RefundByOutTradeNo(m_OutTradeNoStr, m_RefundAmount, "原麦山丘退款");
                }
            }
            catch (System.Net.WebException wex)
            {
                Message(wex.Message);
                MessageBox.Show("发生网络错误, 无法连至支付宝服务器!");
                this.DialogResult = DialogResult.Cancel;
                Close();
                return;
            }
            catch (Exception ex)
            {
                Message(ex.Message);
                MessageBox.Show("发生错误!");
                this.DialogResult = DialogResult.Cancel;
                Close();
                return;
            }
            switch (refundResponse.Code)
            {
            case ResultCode.SUCCESS:
                Message("退款成功! 交易号<" + refundResponse.TradeNo + ">");
                m_Alipay.RefundedOrCanceled = true;
                MessageBox.Show("本單退款成功!");
                break;

            case ResultCode.FAIL: Message("本單退款失敗! <" + refundResponse.Msg + ">");
                Message("");
                Message(refundResponse.SubMsg);
                Message("");
                return;
            }
            this.DialogResult = DialogResult.OK;
            Close();
        }
示例#13
0
        public override bool Refund(PaylineEntity info)
        {
            var builder = new StringBuilder("{");

            //订单支付时传入的商户订单号,不能和 trade_no同时为空。
            builder.AppendFormat("\"out_trade_no\":\"{0}\",", info.Number);
            //支付宝交易号,和商户订单号不能同时为空  2017开头
            builder.AppendFormat("\"trade_no\":\"{0}\",", info.OutNumber);
            //需要退款的金额,该金额不能大于订单金额,单位为元,支持两位小数
            builder.AppendFormat("\"refund_amount\":\"{0}\",", 0 - info.Amount);
            //	退款的原因说明
            builder.AppendFormat("\"refund_reason\":\"{0}\",", "测试退款");
            //	标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传。
            builder.AppendFormat("\"out_request_no\":\"{0}\"", info.Number);
            ////商户的操作员编号
            //builder.AppendFormat("\"operator_id\":\"{0}\"", "FAST_INSTANT_TRADE_PAY");
            ////	商户的门店编号
            //builder.AppendFormat("\"store_id\":\"{0}\"", "FAST_INSTANT_TRADE_PAY");
            ////商户的终端编号
            //builder.AppendFormat("\"terminal_id\":\"{0}\"", "FAST_INSTANT_TRADE_PAY");
            builder.Append("}");

            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.BizContent = builder.ToString();

            AlipayTradeRefundResponse response = AopClient.Execute(request);

            info.Request = response.Body;
            LogHelper.AddEcho(new EchoEntity
            {
                Method   = "Beeant.Repository.Services.Finance.AliPaylineRepository.Refund",
                Request  = request.BizContent,
                Response = response.Body,
                Remark   = "",
                Url      = HttpContext.Current.Request.Url.ToString(),
                Key      = info.Number,
                SaveType = SaveType.Add
            });
            if (response.Msg == "Success")
            {
                info.OutNumber = response.TradeNo;
                info.Status    = PaylineStatusType.Success;
                return(true);
            }

            return(false);
        }
示例#14
0
        public IActionResult Refund(string WIDout_trade_no, string WIDtrade_no, string WIDrefund_amount, string WIDrefund_reason, string WIDout_request_no)
        {
            DefaultAopClient client = new DefaultAopClient(_settings.Value.gateway_url, _settings.Value.app_id, _settings.Value.private_key, _settings.Value.format, _settings.Value.version, _settings.Value.sign_type, _settings.Value.alipay_public_key, _settings.Value.charset, false);

            // 商户订单号,和交易号不能同时为空
            string out_trade_no = WIDout_trade_no;

            // 支付宝交易号,和商户订单号不能同时为空
            string trade_no = WIDtrade_no;

            // 退款金额,不能大于订单总金额
            string refund_amount = WIDrefund_amount;

            // 退款原因
            string refund_reason = WIDrefund_reason;

            // 退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
            string out_request_no = WIDout_request_no;

            AlipayTradeRefundModel model = new AlipayTradeRefundModel
            {
                OutTradeNo   = out_trade_no,
                TradeNo      = trade_no,
                RefundAmount = refund_amount,
                RefundReason = refund_reason,
                OutRequestNo = out_request_no
            };

            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.SetBizModel(model);

            AlipayTradeRefundResponse response = null;

            try
            {
                response = client.Execute(request);
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return(Content(response.Body));
        }
示例#15
0
    protected void BtnAlipay_Click(object sender, EventArgs e)
    {
        DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, Config.app_id, Config.merchant_private_key, "json", "1.0", Config.sign_type, Config.alipay_public_key, Config.charset, false);

        // 商户订单号,和交易号不能同时为空
        string out_trade_no = WIDout_trade_no.Text.Trim();

        // 支付宝交易号,和商户订单号不能同时为空
        string trade_no = WIDtrade_no.Text.Trim();

        // 退款金额,不能大于订单总金额
        string refund_amount = WIDrefund_amount.Text.Trim();

        // 退款原因
        string refund_reason = WIDrefund_reason.Text.Trim();

        // 退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
        string out_request_no = WIDout_request_no.Text.Trim();

        AlipayTradeRefundModel model = new AlipayTradeRefundModel();

        model.OutTradeNo   = out_trade_no;
        model.TradeNo      = trade_no;
        model.RefundAmount = refund_amount;
        model.RefundReason = refund_reason;
        model.OutRequestNo = out_request_no;

        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

        request.SetBizModel(model);

        AlipayTradeRefundResponse response = null;

        try
        {
            response       = client.Execute(request);
            WIDresule.Text = response.Body;
        }
        catch (Exception exp)
        {
            throw exp;
        }
    }
示例#16
0
        public static bool AliPayRefundRequest(string trade_no, string total_fee, string out_refund_no, out string response)
        {
            IAopClient client = new DefaultAopClient(AlipayConfig.mobile_gatewayUrl, AlipayConfig.mobile_app_id, AlipayConfig.mobile_private_key_value, "json", "1.0", AlipayConfig.sign_type, AlipayConfig.mobile_public_key_value, AlipayConfig.charset, false);
            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.BizContent = "{" +
                                 "\"out_trade_no\":\"" + trade_no + "\"," +
                                 "\"refund_amount\":" + total_fee + "," +
                                 "\"out_request_no\":\"" + out_refund_no + "\"" +
                                 "  }";
            AlipayTradeRefundResponse responsed = client.Execute(request);

            response = responsed.Body;
            if (responsed.Code == "10000")
            {
                return(true);
            }
            return(false);
        }
示例#17
0
        public IHttpActionResult kkk(dynamic data)
        {
            IAopClient client = new DefaultAopClient(URL, APPID, APP_PRIVATE_KEY, FORMAT, "2.0", "RSA2", ALIPAY_PUBLIC_KEY, CHARSET, false);
            // 商户订单号,和交易号不能同时为空
            string out_trade_no = "20200709104925";

            // 支付宝交易号,和商户订单号不能同时为空
            string trade_no = "2020070922001450210500981173";

            // 退款金额,不能大于订单总金额
            string refund_amount = "110.00";

            // 退款原因
            string refund_reason = "我就是想退款";

            // 退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
            string out_request_no = "16541";

            AlipayTradeRefundModel model = new AlipayTradeRefundModel();

            model.OutTradeNo   = data.data.OutTradeNo;
            model.TradeNo      = data.data.TradeNo;
            model.RefundAmount = data.data.RefundAmount;
            model.RefundReason = data.data.RefundReason;
            model.OutRequestNo = DateTime.Now.ToString("yyyyMMddHHmmss");

            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.SetBizModel(model);

            AlipayTradeRefundResponse response = null;

            response = client.SdkExecute(request);
            using (SmartRentalSystemEntities db = new SmartRentalSystemEntities())
            {
                var ode = db.Order.Where(t => t.OrderNumber == model.OutTradeNo).ToList().FirstOrDefault();
                ode.OrderState = "退款";
                db.SaveChanges();
            }
            //Execute(request);
            return(Ok(response.Body));
        }
 /// <summary>
 /// 申请退款接口
 /// </summary>
 /// <param name="outTradeNo">订单号</param>
 /// <param name="amount">订单金额</param>
 /// <returns>接口调用成功返回 “SUCCESS” 否则返回失败原因</returns>
 public string Refund(string outTradeNo, string amount)
 {
     try
     {
         // 2. 发起API调用
         AlipayTradeRefundResponse response = Factory.Payment.Common().Refund(outTradeNo, amount);
         // 3. 处理响应或异常
         if ("10000".Equals(response.Code))
         {
             return("SUCCESS");
         }
         else
         {
             return(response.Msg + "," + response.SubMsg);
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
示例#19
0
        public string Get(string tradeNo, string fee)
        {
            IAopClient client = new DefaultAopClient(ConfigurationManager.AppSettings["alipay.port"], ConfigurationManager.AppSettings["alipay.appId"], ConfigurationManager.AppSettings["alipay.privateKey"]);
            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.BizContent = "{" + string.Format(
                "    \"out_trade_no\":\"{0}\"," +
                "    \"trade_no\":\"{1}\"," +
                "    \"refund_amount\":{2}," +
                "    \"refund_reason\":\"正常退款\"", tradeNo, string.Empty, fee) + "  }";
            AlipayTradeRefundResponse response = client.Execute(request);

            if (!response.IsError)
            {
                return("支付宝退款成功:" + tradeNo);
            }
            else
            {
                return("支付宝退款失败:" + tradeNo + "-" + response.SubMsg);
            }
        }
示例#20
0
        /// <summary>
        /// 退款申请
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public RefundResult Refund(RefundDTO dto)
        {
            RefundResult result = new RefundResult();

            try
            {
                AlipayTradeRefundDTO refundDto = new AlipayTradeRefundDTO();
                refundDto.out_request_no = dto.OutRefundNo;
                refundDto.out_trade_no   = dto.OutTradeNo;
                refundDto.refund_amount  = dto.RefundFee;
                refundDto.refund_reason  = dto.RefundReason;
                refundDto.trade_no       = dto.OnlineTradeNo;
                AlipayTradeRefundRequest refundRequest = new AlipayTradeRefundRequest();
                refundRequest.BizContent = refundDto.BuildJson();
                AlipayTradeRefundResponse response = Execute(refundRequest);
                result.SetAlipayResult(response);
                return(result);
            }
            catch (Exception e)
            {
                throw new F2FPayException(e.Message);
            }
        }
示例#21
0
        public static JObject execute(string from, string out_trade_no, string trade_no, string refund_amount, JObject result)
        {
            // 标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传。
            var        now                   = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            var        out_request_no        = now + CommonBusiness.CreateRandom();
            var        amount                = (double.Parse(refund_amount) / 100).ToString();
            IAopClient client                = new DefaultAopClient(ConfigurationManager.AppSettings["alipay.port"], ConfigurationManager.AppSettings["alipay.appId"], ConfigurationManager.AppSettings["alipay.privateKey"]);
            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.BizContent = "{" + string.Format(
                "    \"out_trade_no\":\"{0}\"," +
                "    \"trade_no\":\"{1}\"," +
                "    \"refund_amount\":{2}," +
                "    \"refund_reason\":\"正常退款\"," +
                "    \"out_request_no\":{3}", out_trade_no, trade_no, amount, out_request_no) + "  }";
            AlipayTradeRefundResponse response = client.Execute(request);

            if (!response.IsError)
            {
                WebApiConfig.log.Error("支付宝退款成功:" + out_trade_no + "," + out_request_no + "," + amount);
                JObject localResult;
                if (!TradeBusiness.UpdateTradeStatusSeveralTimes(out_trade_no, response.TradeNo, PaymentType.Alipay, string.Empty, TradeStatus.REFUND, out localResult))
                {
                    WebApiConfig.log.Error(out_trade_no + "-" + trade_no + "支付宝退款成功,本地数据库状态维护失败:" + out_trade_no);
                    return(new JObject(new JProperty("Trade", result)));
                }
                else
                {
                    return(new JObject(new JProperty("Trade", localResult)));
                }
            }
            else
            {
                WebApiConfig.log.Error("支付宝退款失败:" + out_trade_no + "," + out_request_no + "," + amount + "-" + response.SubMsg);
                throw new Exception("支付宝退款失败:" + response.SubMsg);
            }
        }
示例#22
0
        /// <summary>
        /// 退款操作
        /// </summary>
        /// <param name="out_trade_no"></param>
        /// <param name="refund_amount"></param>
        /// <param name="refund_reason"></param>
        /// <returns></returns>
        public bool Refund2(string trade_no, decimal refund_amount, out string errmsg, out string code)
        {
            errmsg = "";
            code   = "";
            bool result = false;

            try
            {
                IAopClient client = new DefaultAopClient(https_url, Config.app_id, Config.private_key, "json", "1.0", sign_type, Config.alipay_public_key, charset, false);
                AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
                request.BizContent = "{" +
                                     "\"trade_no\":\"" + trade_no + "\"," +
                                     "\"refund_amount\":" + refund_amount.ToString("N2") + "," +
                                     "\"refund_reason\":\"押金正常退款\"," +
                                     "\"body\":\"押金退款\"" +
                                     "  }";
                AlipayTradeRefundResponse response = client.Execute(request);
                code = response.Code;
                if ("10000".Equals(code))
                {
                    errmsg = "退款成功";
                    result = true;
                }
                else
                {
                    errmsg = response.SubMsg;
                }
                //支付宝押金退款失败(2018041021001004160529711545):40004交易已结束
                Logger.Warn(string.Format("支付宝押金退款{0}({1}):{2},{3}", result?"成功":"失败", trade_no, code, errmsg));
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Warn(string.Format("支付宝押金退款失败({0}):{1}", trade_no, ex.Message));
                return(false);
            }
        }
示例#23
0
        public Refund BuildRefund(Refund refund)
        {
            IAopClient alipayClient = GetAopClient();
            AlipayTradeRefundRequest alipayRequest = new AlipayTradeRefundRequest();
            AlipayTradeRefundModel   model         = new AlipayTradeRefundModel();

            model.OutTradeNo = refund.OrderNo;
            if (!string.IsNullOrEmpty(refund.TradeNo))
            {
                model.TradeNo = refund.TradeNo;
            }
            model.OutRequestNo = refund.OutRefundNo;
            model.RefundAmount = refund.RefundAmount.ToString();
            model.RefundReason = refund.RefundDesc;
            alipayRequest.SetBizModel(model);
            AlipayTradeRefundResponse response = alipayClient.Execute(alipayRequest);

            if (response.Code == "10000")
            {
                refund.TradeNo      = response.TradeNo;
                refund.RefundStatus = true;
            }
            return(refund);
        }
示例#24
0
 // 全额交易退款接口
 public static bool Refund(string outTradeNo, string amount)
 {
     try
     {
         // 2. 发起API调用
         AlipayTradeRefundResponse response = Factory.Payment.Common().Refund(outTradeNo, amount);
         // 3. 处理响应或异常
         if ("10000".Equals(response.Code))
         {
             Console.WriteLine("调用成功");
             return(true);
         }
         else
         {
             Console.WriteLine("调用失败,原因:" + response.Msg + "," + response.SubMsg);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("调用遭遇异常,原因:" + ex.Message);
         throw ex;
     }
     return(false);
 }
示例#25
0
        public int PostRefundA(List <SaleModel> lstSaleModel)
        {
            try
            {
                if (lstSaleModel.Count == 0)
                {
                    return(1);
                }

                PayService pay = new PayService();
                //移动支付配置赋值
                Config config = pay.GenerateConfigModelA(lstSaleModel[0].MachineId);
                /****************************旧支付宝退款接口*******************************/

                /*
                 * string detail_data = string.Empty;
                 * int batch_num = 1;
                 * foreach (SaleModel saleModel in lstSaleModel)
                 * {
                 *  if (saleModel.RealitySaleNumber == 0)
                 *  {
                 *      detail_data = detail_data + saleModel.ComId + "^" + saleModel.TradeAmount + "^出货失败退款" + "#";
                 *  }
                 *  else
                 *  {
                 *      detail_data = detail_data + saleModel.ComId + "^" + saleModel.TradeAmount * ((saleModel.SalesNumber - saleModel.RealitySaleNumber) / saleModel.SalesNumber) + "^出货失败退款" + "#";
                 *  }
                 * }
                 * if (!string.IsNullOrEmpty(detail_data))
                 * {
                 *
                 *  detail_data = detail_data.TrimEnd('#');
                 *  batch_num = detail_data.Split('#').Length;
                 *  //把请求参数打包成数组
                 *  SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
                 *  sParaTemp.Add("service", config.refund_service);
                 *  sParaTemp.Add("partner", config.partner);
                 *  sParaTemp.Add("_input_charset", config.refund_input_charset.ToLower());
                 *  sParaTemp.Add("notify_url", config.refund_notify_url);
                 *  sParaTemp.Add("seller_user_id", config.seller_id);
                 *  sParaTemp.Add("refund_date", config.refund_date);
                 *  sParaTemp.Add("batch_no", PayHelper.GeneraterTradeNo());
                 *  sParaTemp.Add("batch_num", batch_num.ToString());//退款笔数,必填,参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的数量999个)
                 *  sParaTemp.Add("detail_data", detail_data);  //退款详细数据,必填,格式(支付宝交易号^退款金额^备注),多笔请用#隔开
                 *  //sParaTemp.Add("sign_type", Config.refund_sign_type);
                 *  //sParaTemp.Add("sign", Config.rsa_sign);
                 *
                 *  //建立请求
                 *  try
                 *  {
                 *      string sHtmlText = config.GateWay + new Submit(config).BuildRequestParaToString(sParaTemp, Encoding.UTF8);
                 *      HttpHelper.CreateGetHttpResponse(sHtmlText, 2000, "", null);
                 *  }
                 *  catch (Exception ex)
                 *  {
                 *      throw ex;
                 *  }
                 *
                 *  //string sHtmlText = Submit.BuildRequest(sParaTemp, "get", "确认");
                 *  //HttpContext.Current.Response.Write(sHtmlText);
                 * }
                 *
                 */
                /************************新支付宝退款接口****************************/

                DefaultAopClient client = new DefaultAopClient(config.new_gatewayUrl, config.refund_appid, config.private_key, "json", "1.0", config.refund_sign_type, config.rsa_sign, config.new_charset, false);

                foreach (SaleModel saleModel in lstSaleModel)
                {
                    Alipay.AopSdk.Core.Domain.AlipayTradeRefundModel model = new Alipay.AopSdk.Core.Domain.AlipayTradeRefundModel();
                    model.OutTradeNo = saleModel.TradeNo;
                    model.TradeNo    = saleModel.ComId;
                    if (saleModel.RealitySaleNumber == 0)
                    {
                        model.RefundAmount = saleModel.TradeAmount.ToString();
                    }
                    else
                    {
                        model.RefundAmount = (saleModel.TradeAmount * ((saleModel.SalesNumber - saleModel.RealitySaleNumber) / saleModel.SalesNumber)).ToString();
                    }
                    if (saleModel.TradeStatus == 1)
                    {
                        model.RefundReason = "待出货";
                    }
                    else if (saleModel.TradeStatus == 3)
                    {
                        model.RefundReason = "全部出货失败";
                    }
                    else if (saleModel.TradeStatus == 5)
                    {
                        model.RefundReason = "部分出货失败";
                    }

                    model.OutRequestNo = new PayHelper().GeneraterTradeNo();

                    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
                    //request.SetNotifyUrl(config.refund_notify_url);
                    request.SetBizModel(model);

                    AlipayTradeRefundResponse response = null;
                    try
                    {
                        response = client.Execute(request);
                        if (string.IsNullOrEmpty(response.OutTradeNo))
                        {
                            return(0);
                        }
                        MachineHelper.ClearCacheOrder(response.OutTradeNo);
                        UpdateOrderStatusForAli(response.TradeNo);

                        //插入退款信息表
                        RefundModel refundInfo = new RefundModel();
                        refundInfo.TradeNo = response.OutTradeNo;

                        refundInfo.RefundDetail = response.Body;
                        PostRefundDetail(refundInfo);

                        //WIDresule.Text = response.Body;
                    }
                    catch (Exception exp)
                    {
                        Log.Write("zhifubao1", exp.Message);
                        throw exp;
                    }
                }

                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
示例#26
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            DefaultAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", config.sign_type, config.alipay_public_key, config.charset, false);

            // 商户订单号,和交易号不能同时为空
            string out_trade_no = orderid.ToString();

            // 支付宝交易号,和商户订单号不能同时为空
            string trade_no = "";

            // 退款金额,不能大于订单总金额
            string refund_amount = totalprice.Text.Trim();

            // 退款原因
            string refund_reason = "退款";

            // 退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
            string out_request_no = "";

            AlipayTradeRefundModel model = new AlipayTradeRefundModel();

            model.OutTradeNo   = out_trade_no;
            model.TradeNo      = trade_no;
            model.RefundAmount = refund_amount;
            model.RefundReason = refund_reason;
            model.OutRequestNo = out_request_no;

            AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();

            request.SetBizModel(model);

            AlipayTradeRefundResponse response = null;

            try
            {
                response = client.Execute(request);

                string str   = response.Body;
                string mark  = "\"msg\":\"";
                int    count = str.IndexOf(mark);
                string flag  = str.Substring(count + 7, 7);
                System.Diagnostics.Debug.WriteLine(flag);
                if (flag == "Success")
                {
                    string sql = "update [Order] set State='已退款' where OrderID=" + orderid;
                    if (db.exsql(sql))
                    {
                        Response.Write("<script>alert('退款成功')</script>");
                        Bind();
                    }
                }
                else
                {
                    Response.Write("<script>alert('退款失败')</script>");
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
示例#27
0
        public void ProcessRequest(HttpContext context)
        {
            var result = new Message();

            try
            {
                logger.Info("----------------支付宝退款---------------------");
                string appid         = context.Request["appid"];
                string out_trade_no  = context.Request["out_trade_no"];
                string out_refund_no = context.Request["out_refund_no"];
                string total_fee     = decimal.Parse(context.Request["total_fee"]).ToString();
                string refund_fee    = decimal.Parse(context.Request["refund_fee"]).ToString();;
                string refund_desc   = context.Request["refund_desc"];

                logger.Info(string.Format(@"支付宝退款的输入参数:appid={0},
                                                                        out_trade_no:{1},
                                                                        out_refund_no:{2},
                                                                        totalfee:{3}
                                                                        refundfee:{4}
                                                                        refund_desc:{5}", appid, out_trade_no, out_refund_no, total_fee, refund_fee, refund_desc));
                string sign = context.Request["sign"];
                //签名Key
                string sSignKey = TenPayHelp.MD5(appid).ToLower();
                string newSign  = GetSign(context.Request.Form, sSignKey);
                if (newSign == sign)
                {
                    //获取支付宝账户配置信息
                    var config = ApiHelper.QueryPayAccount(appid, 1, logger);
                    logger.Info(string.Format(@"Appid={0},Prikey={1},Pubkey={2}", config.Appid, config.Prikey, config.Pubkey));
                    IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do",
                                                             config.Appid,
                                                             config.Prikey,
                                                             "json",
                                                             "1.0",
                                                             "RSA2",
                                                             config.Pubkey,
                                                             "utf-8",
                                                             false);
                    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
                    AlipayTradeRefundModel   model   = new AlipayTradeRefundModel();
                    model.OutTradeNo   = out_trade_no;  //商户订单号  //"20170821141701640";
                    model.OutRequestNo = out_refund_no; //退款编号
                    model.RefundAmount = refund_fee;    //退款金额
                    model.RefundReason = refund_desc;   //退款原因
                    request.SetBizModel(model);
                    AlipayTradeRefundResponse response = client.Execute(request);
                    result.data = response.Body;
                }
                else
                {
                    result.data = "内部签名验证失败";
                }
            }
            catch (Exception e)
            {
                logger.Info("----------------支付宝退款异常---------------------");
                logger.Info("异常错误信息:" + e.Message, e);
                logger.Fatal("异常错误信息:" + e.Message, e);
                result.data = "Systyem Server Error";
            }
            context.Response.Clear();
            context.Response.ContentType = "text/plain";
            context.Response.Write(result.data);
        }
示例#28
0
        /// <summary>
        /// 分销系统订单申请退款
        /// </summary>
        /// <param name="alipayId"></param>
        /// <param name="sceneryDomain"></param>
        /// <returns>0 成功 1系统已经存在信息 2退款异常</returns>
        public string SceneryOrderRefund(int alipayId, UserDomain CurrentUser)
        {
            LogHelper.AlipayLog(string.Format("退款开始-》操作人:{0},退款ID:{1}", CurrentUser.Name, alipayId));

            var sceneryOrderRefund = new SceneryOrderRefundDao();

            var models = sceneryOrderRefund.GetAllDomain(QueryCondition.Instance.AddEqual("Id", alipayId.ToString()).AddEqual("ApprovalStatus", "0").AddEqual("RowState", "1"));

            var alipayDetailDao = new AlipayDetailDao();

            if (models.Count == 1)
            {
                //订单实体
                var sceneryOrder = models[0];
                //在交易表中查询是否已经退款过
                if (alipayDetailDao.IsExistsSceneryOrderRefund(sceneryOrder.BatchNumber, sceneryOrder.SerialId, -sceneryOrder.Total) == false)
                {
                    //查询交易表中支付时的记录
                    var list = alipayDetailDao.GetAllDomain(QueryCondition.Instance.AddEqual("SceneryName", sceneryOrder.SceneryName)
                                                            .AddEqual("BatchNumber", sceneryOrder.BatchNumber).AddEqualLarger("Total_amount", "0").AddEqual("SerialId", ""));
                    if (list.Count == 1)
                    {
                        //退款实体
                        var model = list[0];
                        // var tempTotal = -sceneryOrder.Total;


                        ////////////////////////////////////////////请求参数////////////////////////////////////////////

                        //支付宝交易号
                        string trade_no = model.Trade_no;
                        //退款金额
                        string refund_amount = sceneryOrder.Total.ToString();
                        //退款金额不能大于订单金额

                        //商户网站订单系统中唯一订单号,必填
                        StringBuilder request = new StringBuilder();
                        request.Append("{\"out_request_no\":\"" + sceneryOrder.SerialId + "\","); //本次退款请求流水号,部分退款时必传
                        request.Append("\"trade_no\":\"" + trade_no + "\",");                     //支付时返回的支付宝交易号,与out_trade_no必填一个
                        request.Append("\"refund_amount\":\"" + refund_amount + "\"}");

                        var query = QueryCondition.Instance.AddEqual("APP_ID", model.AppId).AddEqual("RowState", "1");


                        var alipay = new AlipayDao().GetAllDomain(query);
                        if (alipay.Count != 1)
                        {
                            return("没有找到支付宝配置信息");
                        }

                        LogHelper.AlipayLog(string.Format("退款JSON:{0},APP_ID:{1}", request.ToString(), alipay[0].APP_ID));
                        AlipayTradeRefundResponse refundResponse = DoRefund(request.ToString(), alipay[0]);

                        //请在这里加上商户的业务逻辑程序代码
                        //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                        string result = refundResponse.Body;

                        if (refundResponse.Code == "10000")//退款成功
                        {
                            Alipay_trade_refund_response alipayRefund = JsonConvert.DeserializeObject <Alipay_trade_refund_response>(refundResponse.Body);
                            model.Code           = alipayRefund.alipay_trade_refund_response.code;
                            model.Trade_no       = alipayRefund.alipay_trade_refund_response.trade_no;
                            model.Out_trade_no   = alipayRefund.alipay_trade_refund_response.out_trade_no;
                            model.Total_amount   = alipayRefund.alipay_trade_refund_response.refund_fee;
                            model.Send_pay_date  = alipayRefund.alipay_trade_refund_response.gmt_refund_pay;
                            model.Msg            = alipayRefund.alipay_trade_refund_response.msg;
                            model.SerialId       = sceneryOrder.SerialId;
                            model.Creater        = CurrentUser.Name;
                            model.Updater        = CurrentUser.Name;
                            model.CreateTime     = DateTime.Now;
                            model.UpdateTime     = DateTime.Now;
                            model.Total_amount   = -sceneryOrder.Total;
                            model.AlipayPlayDate = sceneryOrder.PlayDate;
                            if (alipayDetailDao.Add(model))
                            {
                                //更新订单申请表状态
                                sceneryOrderRefund.ComfirmRefund(sceneryOrder.Id, CurrentUser);
                            }

                            return("");
                        }
                        else
                        {
                            LogHelper.AlipayLog(string.Format("退款失败:{0},body:{1}", refundResponse.Code, result));
                            return("支付宝退款失败,网关返回码:" + refundResponse.Code + " ,业务返回码:" + refundResponse.SubCode + ",业务返回码描述:" + refundResponse.SubMsg);
                        }
                    }
                    return("交易信息中没有找到原始交易记录");
                }
                return("交易表中已经存在退款信息");
            }



            return("退款订单信息不存在");
        }
示例#29
0
        /// <summary>
        /// 交易信息全部退款
        /// </summary>
        /// <param name="alipayId"></param>
        /// <param name="sceneryDomain"></param>
        /// <returns>0 成功 1系统已经存在信息 2退款异常</returns>
        public int Refund(int alipayId, UserDomain CurrentUser)
        {
            LogHelper.AlipayLog(string.Format("退款开始-》操作人:{0},退款ID:{1}", CurrentUser.Name, alipayId));
            var alipayDetailDao = new AlipayDetailDao();
            var list            = alipayDetailDao.GetAllDomain(QueryCondition.Instance.AddEqual("Id", alipayId.ToString()));

            if (list.Count == 1)
            {
                var model     = list[0];
                var tempTotal = -model.Total_amount;

                if (!alipayDetailDao.IsExistsOut_trade_no(model.Out_trade_no, tempTotal, model.AppId))
                {
                    ////////////////////////////////////////////请求参数////////////////////////////////////////////

                    //支付宝交易号
                    string trade_no = model.Trade_no;
                    //支付宝交易号与商户网站订单号不能同时为空
                    string out_request_no = model.Out_trade_no;
                    //退款金额
                    string refund_amount = model.Total_amount.ToString();
                    //退款金额不能大于订单金额

                    //商户网站订单系统中唯一订单号,必填
                    StringBuilder request = new StringBuilder();
                    request.Append("{\"out_request_no\":\"" + out_request_no + "\",");
                    request.Append("\"trade_no\":\"" + trade_no + "\",");
                    request.Append("\"refund_amount\":\"" + refund_amount + "\"}");

                    var query = QueryCondition.Instance.AddEqual("APP_ID", model.AppId).AddEqual("RowState", "1");

                    var alipay = new AlipayDao().GetAllDomain(query);
                    if (alipay.Count != 1)
                    {
                        return(2);
                    }
                    LogHelper.AlipayLog(string.Format("退款JSON:{0},APP_ID:{1}", request.ToString(), alipay[0].APP_ID));
                    AlipayTradeRefundResponse refundResponse = DoRefund(request.ToString(), alipay[0]);

                    //请在这里加上商户的业务逻辑程序代码
                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    string result = refundResponse.Body;

                    if (refundResponse.Code == "10000")//退款成功
                    {
                        Alipay_trade_refund_response alipayRefund = JsonConvert.DeserializeObject <Alipay_trade_refund_response>(refundResponse.Body);
                        model.Code          = alipayRefund.alipay_trade_refund_response.code;
                        model.Trade_no      = alipayRefund.alipay_trade_refund_response.trade_no;
                        model.Out_trade_no  = alipayRefund.alipay_trade_refund_response.out_trade_no;
                        model.Total_amount  = alipayRefund.alipay_trade_refund_response.refund_fee;
                        model.Send_pay_date = alipayRefund.alipay_trade_refund_response.gmt_refund_pay;
                        model.Msg           = alipayRefund.alipay_trade_refund_response.msg;

                        model.Creater    = CurrentUser.Name;
                        model.Updater    = CurrentUser.Name;
                        model.CreateTime = DateTime.Now;
                        model.UpdateTime = DateTime.Now;

                        model.Total_amount = -model.Total_amount;
                        //新增一个负数的支付单信息。
                        alipayDetailDao.Add(model);
                        //新增一个退款申请的信息。
                        //判断退款信息是否存在。
                    }
                    else
                    {
                        LogHelper.AlipayLog(string.Format("退款失败:{0},body:{1}", refundResponse.Code, result));
                        return(2);
                    }
                }
                else
                {
                    return(1);
                }
            }
            return(0);
        }
示例#30
0
        protected override void DoWork()
        {
            //将已经过期的团购订单设置为失败,并退款
            //_orderRepository.GetAll().Where(t=>t.Type==OrderType.Groupon && t.GrouponStatus==GrouponStatus.Grouponing)

            var groupOrdrs = _groupOrderRepository.GetAll()
                             .Where(t => t.GrouponStatus == GrouponStatus.GrouponFail)
                             .ToList();

            Logger.Info("GrouponCancelWorker 需要退款数量:" + groupOrdrs.Count);

            foreach (var grouponOrder in groupOrdrs)
            {
                //设置对应订单的状态
                var orderInfo = _orderRepository.FirstOrDefault(t => t.JoinGrouponId == grouponOrder.Id);
                if (orderInfo != null && orderInfo.Type == OrderType.Groupon &&
                    orderInfo.GrouponStatus == GrouponStatus.GrouponFail)
                {
                    var payinfo = _orderPayRepository.FirstOrDefault(t => t.OrderId == orderInfo.Id);
                    if (payinfo == null)
                    {
                        continue;
                    }

                    switch (payinfo.Channel)
                    {
                    case "微信支付":
                        string nonceStr    = TenPayV3Util.GetNoncestr();
                        string outTradeNo  = orderInfo.OrderNo;
                        string outRefundNo = "OutRefunNo-" + DateTime.Now.Ticks;
                        int    totalFee    = (int)(payinfo.Money * 100);
                        int    refundFee   = totalFee;
                        var    paykey      = SettingManager.GetSettingValue(AppSettings.Weixin.PayKey);
                        var    AppId       = SettingManager.GetSettingValue(AppSettings.Weixin.AppId);
                        var    MchId       = SettingManager.GetSettingValue(AppSettings.Weixin.MchId);

                        string opUserId = MchId;
                        var    dataInfo = new TenPayV3RefundRequestData(AppId, MchId, paykey,
                                                                        null, nonceStr, null, outTradeNo, outRefundNo, totalFee, refundFee, opUserId, null);
                        var cert     = Path.Combine(_appFolders.Root, "apiclient_cert.p12"); //  @"D:\cert\apiclient_cert_SenparcRobot.p12";//根据自己的证书位置修改
                        var password = MchId;                                                //默认为商户号,建议修改
                        var result   = TenPayV3.Refund(dataInfo, cert, password);
                        Logger.Warn("refundFee:" + refundFee);
                        Logger.Warn(result.ToJsonString());
                        if (result.IsResultCodeSuccess() && result.IsReturnCodeSuccess())
                        {
                            payinfo.RefundsTradeNo  = result.out_refund_no;
                            payinfo.RefundsPayTime  = DateTime.Now;
                            orderInfo.GrouponStatus = GrouponStatus.GrouponFailAndRefunds;
                            _orderRepository.Update(orderInfo);

                            grouponOrder.GrouponStatus = GrouponStatus.GrouponFailAndRefunds;
                            _groupOrderRepository.Update(grouponOrder);
                        }


                        break;

                    case "支付宝":

                        string APPID             = "2016081501749843";
                        string PID               = "2088421556051016";
                        string APP_PRIVATE_KEY   = @"MIIEowIBAAKCAQEArtd47la2jHyV5wbTkn/GtVPvTzTr0w6PxWYRY/dnscHVHyPd56Yc/NMJoavcMvJaH4lUzmTBcj3Nz8cv4gsVqYUqyojtukh9JBqW4njdC3IuggBH1Lmo/6cgaZjOzSEHcwyWNU0TcgfFj+y8Kd47YVdh9+xW9/M3nQn9MAaQgfHZbmLMzV5mg/IsB9JzCG963JSuMGq1CiEtYggllC+bhLtJTi+Mmlf0EcTI7CWd80ibMVgtaCyuEl9mdPo9qf0uUHQvZjPo24H24yhinspNlWYkRz9KeqU+agaIz5VKL7Nqwf5YZMauCzsDvM6wurfAHBClRh/UfAvxHN7+Oeqz8QIDAQABAoIBAF/Vd1Gccf7bIwc4tKsuImqtkRRnO4O6DY/zfEDBETNbvUeOT0lzwZvKyRK2ssGyGTgD/FoM3AOUYMUsttA9pyf9+BB/sV5T8VPixyVnfjGR6nATW0v8X+eRYbC/s0q4ee7TzVl139y26dETv6drSjz2upo8DwdlZuxK116Fmpu+XiMc3u0QCbrnbFamhMXQoaYrYcU+pYYLc7Zzoc9ZN4szULZDDF6wkrktZbAuKyiERYF8vLNS2Gm6A6hMpVPpviSA48hhk4k4Gjn2oihEsvuqDf5Y8yI+5xASBLyqylvpZTNjp6B4V49MjyrY5DEecdpTf1kzFR6clAxaOmoCgCkCgYEA4t/5Ikbvyn3WdZK8Oyqlw9MxQKrZHz//s1OE+QV5Aqf5R3U30HaOGdImvocQb+Shgz7nV9fKN1hVdKNK6ASgQ0clhQGb6FrdxdyvPGrDmjDBvKULNM7rFbzeUSC5wHEHbZ8xkMY+sdai0R/sEk8FvUa+hzU3yyv5SmxJ2ESLjUMCgYEAxUl6Qaa5BO8qsrj33Px3Ag8umzLP7Dco+cPjR+b2D1Eg2RYvvr/+68gXB27nde5GEo+i8mIi9C2vfAsfbHJqLFBWX95gePMnRFoeWylNPqSz1+cGZJTsBWvptj7nHle5MYn8fe4JBLBIOGAUwPwA5SN5pMRkhU1+xT3mcUjRLLsCgYBw7ifm5gSKeOT9lVLY6LumpEOJ+wEkywiOzO4NvqmjptUwuqpTvA+zzqW2hSiradTzraYeVa20quWur3Gj2Fml445LjKd8m251BQq9Oi+vWsG1EzpmyPC/20mWfIG5xwl5iZp0hBnFEB/vlMI/wtIKi2Jfjx/8pCDs6MZBPq1wXQKBgG0lHmbtttRdAJFJtY7jeW+BOLaR4Of9CEVNsxLXWu/UYUjYdmegTobg9qSdHZ5nyQqBvpM76byO/dOxT5wunECR3YdCPrsLQoEVHlAuxFZQxlI+tJG2tfC15+F0YWau/3zBqxd8Ni8K25mcxj6R7GjYPHcEU9xPqD+05CVuNJL7AoGBAM1Xi7gWKaV7bYQdmW2HFfmAaW1z5DUPPZoVQ/wsZwSbBPf3Hn7qE6DM+dRMK6RBL1GIuRdxfCPOT4ktei9dvghM42gU2me8U5B6T5s1Sf99m/iw6svyoU5OAcIPSZ38R4l00VA1w+jYSMdQukhBlgYZQgRxeXKOFiM9IpkVvH9U";
                        string ALIPAY_PUBLIC_KEY = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlhGDVAL2+yN9HYkxgLBTI4MswpHi9QLrN/8zkJDFWQOGJEuUic2wPEJ/Mi45wuNMpeE57gzGMEk9AODTb+dzN5uA9gd0GVBcDI+5pBxJASWCouDUQR4Lvuo52vPTJGc2oageP5Of2L7eUazIYKU6jxoJWFbjzRN36p0l3SCvyvkOFaiTyIUFqDe5pprEPRWdxJmbwDnPsF4b3W1NdivoxP9y/ztCGN7ImX/mPLRrwveZe4xqvDOJ0sZ9LgfzJL7POE8lkj7m5LWM/5cNDKB3rtElp6eDWI7blBCvBsqMuzaCjzuYswYttu/j5gVLUd1oQ8v0wdw8lmPskcYEtobF6wIDAQAB";
                        string CHARSET           = "UTF-8";


                        APPID             = SettingManager.GetSettingValue(AppSettings.Alipay.APPID);
                        PID               = SettingManager.GetSettingValue(AppSettings.Alipay.PID);
                        APP_PRIVATE_KEY   = SettingManager.GetSettingValue(AppSettings.Alipay.APP_PRIVATE_KEY);
                        ALIPAY_PUBLIC_KEY = SettingManager.GetSettingValue(AppSettings.Alipay.ALIPAY_PUBLIC_KEY);

                        var client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", APPID, APP_PRIVATE_KEY, "json", "1.0", "RSA2", ALIPAY_PUBLIC_KEY, CHARSET, false);
                        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
                        request.BizContent = "{" +
                                             "    \"out_trade_no\":\"" + orderInfo.OrderNo + "\"," +
                                             "    \"trade_no\":\"" + payinfo.TradeNo + "\"," +
                                             "    \"refund_amount\":" + payinfo.Money.ToString("F2") + "," +
                                             "    \"refund_reason\":\"拼团失败退款\"" +
                                             "  }";
                        AlipayTradeRefundResponse response = client.Execute(request);
                        Logger.Warn(response.Body);
                        if (!response.IsError)
                        {
                            payinfo.RefundsTradeNo  = response.TradeNo;
                            payinfo.RefundsPayTime  = DateTime.Now;
                            orderInfo.GrouponStatus = GrouponStatus.GrouponFailAndRefunds;
                            _orderRepository.Update(orderInfo);

                            grouponOrder.GrouponStatus = GrouponStatus.GrouponFailAndRefunds;
                            _groupOrderRepository.Update(grouponOrder);
                        }
                        break;
                    }
                }



                //if (orderInfo != null && orderInfo.Type==OrderType.Groupon && orderInfo.GrouponStatus==GrouponStatus.GrouponFail)
                //{
                //    orderInfo.Status = OrderStatus.Cancel;
                //    orderInfo.GrouponStatus = GrouponStatus.GrouponFail;
                //    _orderRepository.Update(orderInfo);
                //}

                ////修改团购状态
                //grouponOrder.GrouponStatus = GrouponStatus.GrouponFail;
                //_groupOrderRepository.Update(grouponOrder);
            }
        }