Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteSettings        masterSettings      = SettingsManager.GetMasterSettings();
            NameValueCollection nameValueCollection = new NameValueCollection
            {
                this.Page.Request.QueryString,
                this.Page.Request.Form
            };
            string parameter = this.GetParameter("HIGW");

            if (!string.IsNullOrEmpty(parameter))
            {
                parameter = parameter.ToLower().Replace("_", ".");
                if (parameter.ToLower().IndexOf("cmpay.d") > -1)
                {
                    parameter = parameter.ToLower().Replace("cmpay.d", "cmpay_d");
                }
                if (parameter.ToLower().IndexOf(".ws.wappay.") > -1)
                {
                    parameter = parameter.ToLower().Replace(".ws.wappay.", ".ws_wappay.");
                }
            }
            else
            {
                parameter = "";
            }
            string text = "";

            if (!string.IsNullOrEmpty(parameter))
            {
                text = ((parameter.ToLower().IndexOf("alipay") <= -1 && parameter.ToLower().IndexOf(".ws_wappay.") <= -1) ? parameter.ToLower().Replace(".payment.", ".refund.") : "hishop.plugins.refund.alipaydirect.directrequest");
            }
            else
            {
                Globals.AppendLog(nameValueCollection, "错误的网关信息" + parameter + "-" + parameter.ToLower().Replace(".payment.", ".refund."), "", "", "/log/refundNotify.txt");
                base.Response.Write("fail");
                base.Response.End();
            }
            this.Notify = Hishop.Plugins.RefundNotify.CreateInstance(text, nameValueCollection);
            parameter   = parameter.Replace(".refund.", ".payment.");
            PaymentModeInfo alipayRefundPaymentMode = TradeHelper.GetAlipayRefundPaymentMode();

            if (alipayRefundPaymentMode == null)
            {
                Globals.AppendLog(nameValueCollection, "错误的网关信息" + parameter + "-" + parameter.ToLower().Replace(".payment.", ".refund."), "", "", "/log/refundNotify.txt");
                base.Response.Write("fail");
                base.Response.End();
            }
            string text2 = HiCryptographer.Decrypt(alipayRefundPaymentMode.Settings);

            if (alipayRefundPaymentMode.Gateway.ToLower() == "hishop.plugins.payment.ws_wappay.wswappayrequest")
            {
                text2 = text2.Replace("Seller_account_name", "SellerEmail");
            }
            bool flag = false;

            try
            {
                flag = this.Notify.VerifyNotify(600, text2);
            }
            catch (Exception ex)
            {
                Globals.AppendLog(nameValueCollection, "通知网关失败" + ex.Message + "-" + text, "", "", "/log/refundNotify.txt");
                base.Response.Write("fail");
                base.Response.End();
            }
            if (flag)
            {
                string     text3 = nameValueCollection["batch_no"];
                RefundInfo refundInfoOfRefundOrderId = TradeHelper.GetRefundInfoOfRefundOrderId(text3);
                string     text4        = nameValueCollection["success_num"];
                string     text5        = nameValueCollection["result_details"];
                string[]   array        = text5.Split('#');
                string     text6        = "";
                decimal    refundAmount = default(decimal);
                string     text7        = "";
                int        num          = 0;
                string[]   array2       = array;
                foreach (string text8 in array2)
                {
                    string[] array3 = text8.Split('$');
                    array3 = array3[0].Split('^');
                    if (array3.Length == 3)
                    {
                        text6 = array3[0];
                        decimal.TryParse(array3[1], out refundAmount);
                        text7 = array3[2];
                        if (text7 == "SUCCESS")
                        {
                            RefundDao refundDao = new RefundDao();
                            OrderInfo orderInfoFromGatewayOrderId = OrderHelper.GetOrderInfoFromGatewayOrderId(text6);
                            if (orderInfoFromGatewayOrderId != null)
                            {
                                num++;
                                try
                                {
                                    if (!OrderHelper.FinishRefund(text3, refundAmount, masterSettings.PointsRate))
                                    {
                                        Globals.AppendLog(nameValueCollection, "完成退款错误", text6, text3, "/log/refundNotify.txt");
                                    }
                                }
                                catch (Exception ex2)
                                {
                                    Globals.AppendLog(nameValueCollection, "完成退款异常:" + ex2.Message, text6, text3, "/log/refundNotify.txt");
                                }
                            }
                            else
                            {
                                Globals.AppendLog(nameValueCollection, "错误的订单号:" + text3, text6, "", "/log/refundNotify.txt");
                            }
                        }
                        else
                        {
                            Globals.AppendLog(nameValueCollection, "状态错误" + text7, "", "", "/log/refundNotify.txt");
                        }
                    }
                }
                base.Response.Write("success");
            }
            else
            {
                Globals.AppendLog(nameValueCollection, "签名验证失败", "", "", "/log/refundNotify.txt");
                base.Response.Write("fail");
                base.Response.End();
            }
        }
Esempio n. 2
0
        public static string SendAlipayRefundRequest(OrderInfo order, decimal refundMoney, string refundOrderId, bool isRefund = true)
        {
            string          result = "backnotify";
            PaymentModeInfo alipayRefundPaymentMode = TradeHelper.GetAlipayRefundPaymentMode();

            if (alipayRefundPaymentMode == null)
            {
                result = "ERROR";
                Globals.AppendLog("未找到可支持原路返回的支付宝支付方式", "", "", "AlipayRefundError");
                return(result);
            }
            refundMoney = ((refundMoney == decimal.Zero) ? order.GetTotal(false) : refundMoney);
            string text      = "hishop.plugins.refund.alipaydirect.directrequest";
            string arg       = text.Replace(".", "_");
            string returnUrl = $"http://{HttpContext.Current.Request.Url.Host}/pay/RefundReturn?HIGW={arg}";
            string notifyUrl = $"http://{HttpContext.Current.Request.Url.Host}/pay/RefundNotify?HIGW={arg}";

            string[] orderId = new string[1]
            {
                order.GatewayOrderId
            };
            decimal[] amount = new decimal[1]
            {
                order.GetTotal(false)
            };
            decimal[] refundaAmount = new decimal[1]
            {
                refundMoney
            };
            string[] body = new string[1]
            {
                order.RefundRemark
            };
            string value = DateTime.Now.ToString("yyyyMMdd");

            if (!refundOrderId.StartsWith(value))
            {
                string oldRefundOrderId = refundOrderId;
                refundOrderId = Globals.GetGenerateId();
                if (isRefund)
                {
                    TradeHelper.UpdateRefundOrderId(oldRefundOrderId, refundOrderId, order.OrderId);
                }
                else
                {
                    TradeHelper.UpdateRefundOrderId_Return(oldRefundOrderId, refundOrderId, order.OrderId);
                }
            }
            try
            {
                string text2 = HiCryptographer.Decrypt(alipayRefundPaymentMode.Settings);
                if (alipayRefundPaymentMode.Gateway.ToLower() == "hishop.plugins.payment.ws_wappay.wswappayrequest")
                {
                    text2 = text2.Replace("Seller_account_name", "SellerEmail");
                }
                RefundRequest  refundRequest  = RefundRequest.CreateInstance(text, text2, orderId, refundOrderId, amount, refundaAmount, body, order.EmailAddress, DateTime.Now, returnUrl, notifyUrl, "退款");
                ResponseResult responseResult = refundRequest.SendRequest_Ret();
                if (responseResult.Status == ResponseStatus.Success)
                {
                    result = "";
                }
                else
                {
                    IDictionary <string, string> dictionary = new Dictionary <string, string>();
                    dictionary.Add("Gateway", order.Gateway);
                    dictionary.Add("refundMoney", refundMoney.F2ToString("f2"));
                    dictionary.Add("RefundGateWay", text);
                    dictionary.Add("PaySettings", text2);
                    dictionary.Add("NotifyUrl", $"http://{HttpContext.Current.Request.Url.Host}/pay/RefundNotify?HIGW={arg}");
                    dictionary.Add("settings", HiCryptographer.Decrypt(alipayRefundPaymentMode.Settings));
                    dictionary.Add("GatewayOrderId", order.GatewayOrderId);
                    dictionary.Add("OrderTotal", order.GetTotal(false).F2ToString("f2"));
                    dictionary.Add("OrderId", order.OrderId);
                    dictionary.Add("out_refund_no", refundOrderId);
                    Globals.AppendLog(dictionary, JsonHelper.GetJson(responseResult), "", "", "SendAlipayRefundRequest");
                    result = responseResult.Msg;
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    IDictionary <string, string> dictionary2 = new Dictionary <string, string>();
                    dictionary2.Add("Gateway", order.Gateway);
                    dictionary2.Add("refundMoney", refundMoney.F2ToString("f2"));
                    dictionary2.Add("RefundGateWay", text);
                    dictionary2.Add("NotifyUrl", $"http://{HttpContext.Current.Request.Url.Host}/pay/RefundNotify?HIGW={arg}");
                    dictionary2.Add("settings", HiCryptographer.Decrypt(alipayRefundPaymentMode.Settings));
                    dictionary2.Add("GatewayOrderId", order.GatewayOrderId);
                    dictionary2.Add("OrderTotal", order.GetTotal(false).F2ToString("f2"));
                    dictionary2.Add("OrderId", order.OrderId);
                    dictionary2.Add("out_refund_no", refundOrderId);
                    Globals.WriteExceptionLog(ex, dictionary2, "alipayBackReturn");
                    result = "ERROR";
                }
            }
            return(result);
        }