Beispiel #1
0
        /// <summary>
        /// 取消订单
        /// </summary>
        public ActionResult CancelOrder()
        {
            int oid          = WebHelper.GetFormInt("oid");
            int cancelReason = WebHelper.GetFormInt("cancelReason");

            OrderInfo orderInfo = Orders.GetOrderByOid(oid);

            if (orderInfo == null || orderInfo.Uid != WorkContext.Uid)
            {
                return(AjaxResult("noorder", "订单不存在"));
            }

            if (!(orderInfo.OrderState == (int)OrderState.WaitPaying || (orderInfo.OrderState == (int)OrderState.Confirming && orderInfo.PayMode == 0)))
            {
                return(AjaxResult("donotcancel", "订单当前不能取消"));
            }

            //取消订单
            Orders.CancelOrder(ref WorkContext.PartUserInfo, orderInfo, WorkContext.Uid, DateTime.Now);
            //创建订单处理
            OrderActions.CreateOrderAction(new OrderActionInfo()
            {
                Oid        = oid,
                Uid        = WorkContext.Uid,
                RealName   = "本人",
                ActionType = (int)OrderActionType.Cancel,
                ActionTime = DateTime.Now,
                ActionDes  = "您取消了订单"
            });
            return(AjaxResult("success", oid.ToString()));
        }
        /// <summary>
        /// 收货
        /// </summary>
        /// <returns></returns>
        public ActionResult ReceiveOrder()
        {
            int oid = WebHelper.GetQueryInt("oid");

            OrderInfo orderInfo = Orders.GetOrderByOid(oid);

            if (orderInfo == null || orderInfo.Uid != WorkContext.Uid)
            {
                return(AjaxResult("noorder", "订单不存在"));
            }

            if (orderInfo.OrderState != (int)OrderState.Sended)
            {
                return(AjaxResult("donotreceive", "订单当前不能收货"));
            }

            //收货
            Orders.ReceiveOrder(ref WorkContext.PartUserInfo, orderInfo, DateTime.Now, WorkContext.IP);
            //创建订单处理
            OrderActions.CreateOrderAction(new OrderActionInfo()
            {
                Oid         = oid,
                Uid         = WorkContext.Uid,
                RealName    = "本人",
                AdminGid    = 0,
                AdminGTitle = "非管理员",
                ActionType  = (int)OrderActionType.Receive,
                ActionTime  = DateTime.Now,
                ActionDes   = "您已经收货"
            });
            return(AjaxResult("success", oid.ToString()));
        }
Beispiel #3
0
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            PluginSetInfo pluginSetInfo = PluginUtils.GetPluginSet();

            // 如果您还没有设置MD5密钥请登陆我们为您提供商户后台,地址:https://merchant3.chinabank.com.cn/
            // 登陆后在上面的导航栏里可能找到“B2C”,在二级导航栏里有“MD5密钥设置”
            // 建议您设置一个16位以上的密钥或更高,密钥最多64位,但设置16位已经足够了
            string key = pluginSetInfo.Key;

            int     v_oid       = WebHelper.GetRequestInt("v_oid");
            string  v_pstatus   = WebHelper.GetRequestString("v_pstatus");
            string  v_pstring   = WebHelper.GetRequestString("v_pstring");
            string  v_pmode     = WebHelper.GetRequestString("v_pmode");
            string  v_md5str    = WebHelper.GetRequestString("v_md5str");
            decimal v_amount    = TypeHelper.StringToDecimal(WebHelper.GetRequestString("v_amount"));
            string  v_moneytype = WebHelper.GetRequestString("v_moneytype");
            string  remark1     = WebHelper.GetRequestString("remark1");
            string  remark2     = WebHelper.GetRequestString("remark2");

            string str = v_oid + v_pstatus + v_amount + v_moneytype + key;

            str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToUpper();

            if (str == v_md5str)
            {
                if (v_pstatus.Equals("20"))
                {
                    //支付成功
                    OrderInfo orderInfo = Orders.GetOrderByOid(v_oid);
                    if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= v_amount)
                    {
                        Orders.PayOrder(v_oid, OrderState.Confirming, "", DateTime.Now);
                        OrderActions.CreateOrderAction(new OrderActionInfo()
                        {
                            Oid         = v_oid,
                            Uid         = orderInfo.Uid,
                            RealName    = "本人",
                            AdminGid    = 1,
                            AdminGTitle = "非管理员",
                            ActionType  = (int)OrderActionType.Pay,
                            ActionTime  = DateTime.Now,
                            ActionDes   = "你使用网银在线支付订单成功,支付银行为:" + v_pmode
                        });
                    }

                    return(RedirectToAction("payresult", "order", new RouteValueDictionary {
                        { "oid", orderInfo.Oid }
                    }));
                }
                else
                {
                    return(Content("支付失败"));
                }
            }
            else
            {
                return(Content("校验失败,数据可疑"));
            }
        }
Beispiel #4
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            SortedDictionary <string, string> paras = AlipayCore.GetRequestPost();

            if (paras.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.Verify(paras, Request.Form["notify_id"], Request.Form["sign"], AlipayConfig.SignType, AlipayConfig.Key, AlipayConfig.Code, AlipayConfig.VeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.Form["out_trade_no"];                                                                  //商户订单号
                    string   tradeSN      = Request.Form["trade_no"];                                                                      //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.Form["total_fee"]);                                         //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.Form["gmt_payment"]);                                      //交易时间

                    List <OrderInfo> orderList = new List <OrderInfo>();
                    foreach (string oid in StringHelper.SplitString(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10)))
                    {
                        OrderInfo orderInfo = Orders.GetOrderByOid(TypeHelper.StringToInt(oid));
                        orderList.Add(orderInfo);
                    }
                    decimal allSurplusMoney = 0M;
                    foreach (OrderInfo orderInfo in orderList)
                    {
                        allSurplusMoney += orderInfo.SurplusMoney;
                    }

                    if (orderList.Count > 0 && allSurplusMoney <= tradeMoney)
                    {
                        foreach (OrderInfo orderInfo in orderList)
                        {
                            if (orderInfo.SurplusMoney > 0 && orderInfo.OrderState == (int)OrderState.WaitPaying)
                            {
                                Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, tradeSN, DateTime.Now);
                                OrderActions.CreateOrderAction(new OrderActionInfo()
                                {
                                    Oid        = orderInfo.Oid,
                                    Uid        = orderInfo.Uid,
                                    RealName   = "本人",
                                    ActionType = (int)OrderActionType.Pay,
                                    ActionTime = tradeTime,
                                    ActionDes  = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                                });
                            }
                        }
                    }

                    return(Content("success"));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
Beispiel #5
0
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            System.Web.HttpContext Context = System.Web.HttpContext.Current;

            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(TenpayUtil.tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                //支付结果
                string trade_state = resHandler.getParameter("trade_state");
                //交易模式,1即时到账,2中介担保
                string trade_mode = resHandler.getParameter("trade_mode");

                if ("1".Equals(trade_mode) && "0".Equals(trade_state))
                {
                    int      oid        = TypeHelper.StringToInt(resHandler.getParameter("out_trade_no"));        //商户订单号
                    string   tradeSN    = resHandler.getParameter("transaction_id");                              //财付通订单号
                    decimal  tradeMoney = TypeHelper.StringToDecimal(resHandler.getParameter("total_fee")) / 100; //金额,以分为单位
                    DateTime tradeTime  = DateTime.Now;                                                           //交易时间

                    OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                    if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                    {
                        Orders.PayOrder(oid, OrderState.Confirming, tradeSN, DateTime.Now);
                        OrderActions.CreateOrderAction(new OrderActionInfo()
                        {
                            Oid         = oid,
                            Uid         = orderInfo.Uid,
                            RealName    = "本人",
                            AdminGid    = 1,
                            AdminGTitle = "非管理员",
                            ActionType  = (int)OrderActionType.Pay,
                            ActionTime  = tradeTime,
                            ActionDes   = "你使用财付通支付订单成功,财付通交易号为:" + tradeSN
                        });
                    }

                    return(RedirectToAction("payresult", "order", new RouteValueDictionary {
                        { "oid", orderInfo.Oid }
                    }));
                }
                else
                {
                    return(Content("财付通支付失败"));
                }
            }
            else
            {
                return(Content("认证签名失败"));
            }
        }
Beispiel #6
0
 /// <summary>
 /// 创建订单行为
 /// </summary>
 private void CreateOrderAction(int oid, OrderActionType orderActionType, string actionDes)
 {
     OrderActions.CreateOrderAction(new OrderActionInfo()
     {
         Oid        = oid,
         Uid        = WorkContext.Uid,
         RealName   = AdminUsers.GetUserDetailById(WorkContext.Uid).RealName,
         ActionType = (int)orderActionType,
         ActionTime = DateTime.Now,
         ActionDes  = actionDes
     });
 }
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            SortedDictionary <string, string> paras = AlipayCore.GetRequestGet();

            if (paras.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.Verify(paras, Request.QueryString["notify_id"], Request.QueryString["sign"], AlipayConfig.SignType, AlipayConfig.Key, AlipayConfig.Code, AlipayConfig.VeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.QueryString["out_trade_no"];                                                                         //商户订单号
                    string   tradeSN      = Request.QueryString["trade_no"];                                                                             //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.QueryString["total_fee"]);                                                //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.QueryString["notify_time"]);                                             //交易时间

                    int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                    OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                    if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                    {
                        Orders.PayOrder(oid, OrderState.Confirming, tradeSN, "alipay", "支付宝", DateTime.Now);
                        OrderActions.CreateOrderAction(new OrderActionInfo()
                        {
                            Oid         = oid,
                            Uid         = orderInfo.Uid,
                            RealName    = "本人",
                            AdminGid    = 1,
                            AdminGTitle = "非管理员",
                            ActionType  = (int)OrderActionType.Pay,
                            ActionTime  = tradeTime,
                            ActionDes   = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                        });

                        //邮件通知客户
                        if (!string.IsNullOrWhiteSpace(orderInfo.Email))
                        {
                            Emails.SendOrderPayEmail(orderInfo.Email, "支付宝", tradeMoney.ToString(), orderInfo.OSN);
                        }
                    }

                    return(RedirectToAction("payresult", "order", new RouteValueDictionary {
                        { "oid", oid }
                    }));
                }
                else//验证失败
                {
                    return(Content("支付失败"));
                }
            }
            else
            {
                return(Content("支付失败"));
            }
        }
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

                if (verifyResult)                                                                                                              //验证成功
                {
                    if (verifyResult && (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")) //验证成功
                    {
                        string   out_trade_no = Request.Form["out_trade_no"];                                                                  //商户订单号
                        string   tradeSN      = Request.Form["trade_no"];                                                                      //支付宝交易号
                        decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.Form["total_fee"]);                                         //交易金额
                        DateTime tradeTime    = TypeHelper.StringToDateTime(Request.Form["gmt_payment"]);                                      //交易时间

                        int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                        OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                        if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                        {
                            Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, tradeSN, "alipay", "支付宝", DateTime.Now);
                            OrderActions.CreateOrderAction(new OrderActionInfo()
                            {
                                Oid        = orderInfo.Oid,
                                Uid        = orderInfo.Uid,
                                RealName   = "本人",
                                ActionType = (int)OrderActionType.Pay,
                                ActionTime = tradeTime,
                                ActionDes  = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                            });
                        }

                        return(Content("success"));
                    }
                    else//验证失败
                    {
                        return(Content("fail"));
                    }
                }
                else
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            SortedDictionary <string, string> sPara = AlipayCore.GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.AppVerify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"], AlipayConfig.AppSignType, AlipayConfig.PublicKey, AlipayConfig.AppInputCharset, AlipayConfig.AppVeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.QueryString["out_trade_no"];                                                                         //商户订单号
                    string   tradeSN      = Request.QueryString["trade_no"];                                                                             //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.QueryString["total_fee"]);                                                //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.QueryString["gmt_payment"]);                                             //交易时间

                    int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                    OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                    if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                    {
                        Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, tradeSN, "alipay", "支付宝", DateTime.Now);
                        OrderActions.CreateOrderAction(new OrderActionInfo()
                        {
                            Oid        = orderInfo.Oid,
                            Uid        = orderInfo.Uid,
                            RealName   = "本人",
                            ActionType = (int)OrderActionType.Pay,
                            ActionTime = tradeTime,
                            ActionDes  = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                        });
                    }

                    return(Content("{" + "\"state\":\"success\"" + "}"));
                }
                else//验证失败
                {
                    return(Content("{" + "\"state\":\"fail\"" + "}"));
                }
            }
            else
            {
                return(Content("{" + "\"state\":\"fail\"" + "}"));
            }
        }
Beispiel #10
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(System.Web.HttpContext.Current);

            resHandler.setKey(PayConfig.AppKey);

            //判断签名
            try
            {
                string error = "";
                if (resHandler.isWXsign(out error))
                {
                    #region 协议参数=====================================
                    //--------------协议参数--------------------------------------------------------
                    //SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查
                    string return_code = resHandler.getParameter("return_code");
                    //返回信息,如非空,为错误原因签名失败参数格式校验错误
                    string return_msg = resHandler.getParameter("return_msg");
                    //微信分配的公众账号 ID
                    string appid = resHandler.getParameter("appid");

                    //以下字段在 return_code 为 SUCCESS 的时候有返回--------------------------------
                    //微信支付分配的商户号
                    string mch_id = resHandler.getParameter("mch_id");
                    //微信支付分配的终端设备号
                    string device_info = resHandler.getParameter("device_info");
                    //微信分配的公众账号 ID
                    string nonce_str = resHandler.getParameter("nonce_str");
                    //业务结果 SUCCESS/FAIL
                    string result_code = resHandler.getParameter("result_code");
                    //错误代码
                    string err_code = resHandler.getParameter("err_code");
                    //结果信息描述
                    string err_code_des = resHandler.getParameter("err_code_des");

                    //以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回---------------
                    //-------------业务参数---------------------------------------------------------
                    //用户在商户 appid 下的唯一标识
                    string openid = resHandler.getParameter("openid");
                    //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
                    string is_subscribe = resHandler.getParameter("is_subscribe");
                    //JSAPI、NATIVE、MICROPAY、APP
                    string trade_type = resHandler.getParameter("trade_type");
                    //银行类型,采用字符串类型的银行标识
                    string bank_type = resHandler.getParameter("bank_type");
                    //订单总金额,单位为分
                    string total_fee = resHandler.getParameter("total_fee");
                    //货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
                    string fee_type = resHandler.getParameter("fee_type");
                    //微信支付订单号
                    string transaction_id = resHandler.getParameter("transaction_id");
                    //商户系统的订单号,与请求一致。
                    string out_trade_no = resHandler.getParameter("out_trade_no");
                    //商家数据包,原样返回
                    string attach = resHandler.getParameter("attach");
                    //支 付 完 成 时 间 , 格 式 为yyyyMMddhhmmss,如 2009 年12 月27日 9点 10分 10 秒表示为 20091227091010。时区为 GMT+8 beijing。该时间取自微信支付服务器
                    string time_end = resHandler.getParameter("time_end");

                    #endregion
                    //支付成功
                    if (!out_trade_no.Equals("") && return_code.Equals("SUCCESS") && result_code.Equals("SUCCESS"))
                    {
                        LogUtil.WriteLog("Notify 页面  支付成功,支付信息:商家订单号:" + out_trade_no + "、支付金额(分):" + total_fee + "、自定义参数:" + attach);

                        /**
                         *  这里输入用户逻辑操作,比如更新订单的支付状态
                         *
                         * **/

                        int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                        OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                        if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= TypeHelper.StringToDecimal(total_fee))
                        {
                            Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, transaction_id, "wechatpay", "微信支付", DateTime.Now);
                            OrderActions.CreateOrderAction(new OrderActionInfo()
                            {
                                Oid        = orderInfo.Oid,
                                Uid        = orderInfo.Uid,
                                RealName   = "本人",
                                ActionType = (int)OrderActionType.Pay,
                                ActionTime = TypeHelper.StringToDateTime(time_end),
                                ActionDes  = "你使用微信支付订单成功,微信交易号为:" + transaction_id
                            });
                        }

                        LogUtil.WriteLog("============ 单次支付结束 ===============");
                        return(Content("success"));
                    }
                    else
                    {
                        LogUtil.WriteLog("Notify 页面  支付失败,支付信息   total_fee= " + total_fee + "、err_code_des=" + err_code_des + "、result_code=" + result_code);
                        return(new EmptyResult());
                    }
                }
                else
                {
                    LogUtil.WriteLog("Notify 页面  isWXsign= false ,错误信息:" + error);
                    return(new EmptyResult());
                }
            }
            catch (Exception ee)
            {
                LogUtil.WriteLog("Notify 页面  发送异常错误:" + ee.Message);
                return(new EmptyResult());
            }
        }
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            SortedDictionary <string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表

                    //商户订单号

                    string out_trade_no = Request.QueryString["out_trade_no"];

                    //支付宝交易号

                    string tradeSN = Request.QueryString["trade_no"];

                    //交易状态
                    string trade_status = Request.QueryString["trade_status"];


                    if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        decimal  tradeMoney = TypeHelper.StringToDecimal(Request.QueryString["total_fee"]);    //交易金额
                        DateTime tradeTime  = TypeHelper.StringToDateTime(Request.QueryString["notify_time"]); //交易时间

                        int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                        OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                        if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                        {
                            Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, tradeSN, "alipay", "支付宝", DateTime.Now);
                            OrderActions.CreateOrderAction(new OrderActionInfo()
                            {
                                Oid        = orderInfo.Oid,
                                Uid        = orderInfo.Uid,
                                RealName   = "本人",
                                ActionType = (int)OrderActionType.Pay,
                                ActionTime = tradeTime,
                                ActionDes  = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                            });
                        }

                        return(RedirectToAction("payresult", "order", new RouteValueDictionary {
                            { "oid", oid }
                        }));
                    }
                    else//验证失败
                    {
                        return(Content("支付失败"));
                    }
                }
                else
                {
                    return(Content("支付失败"));
                }
            }
            else
            {
                return(Content("支付失败"));
            }
        }
Beispiel #12
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            System.Web.HttpContext Context = System.Web.HttpContext.Current;

            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(TenpayUtil.tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(TenpayUtil.tenpay_key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", TenpayUtil.bargainor_id);
                queryReq.setParameter("notify_id", notify_id);

                //通信对象
                TenpayHttpClient httpClient = new TenpayHttpClient();
                httpClient.setTimeOut(5);
                //设置请求内容
                httpClient.setReqContent(queryReq.getRequestURL());
                //后台调用
                if (httpClient.call())
                {
                    //设置结果参数
                    ClientResponseHandler queryRes = new ClientResponseHandler();
                    queryRes.setContent(httpClient.getResContent());
                    queryRes.setKey(TenpayUtil.tenpay_key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //支付结果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");
                        #region
                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            if ("1".Equals(trade_mode) && "0".Equals(trade_state))
                            {
                                int      oid        = TypeHelper.StringToInt(queryRes.getParameter("out_trade_no"));  //商户订单号
                                string   tradeSN    = queryRes.getParameter("transaction_id");                        //财付通订单号
                                decimal  tradeMoney = TypeHelper.StringToDecimal(queryRes.getParameter("total_fee")); //金额,以分为单位
                                DateTime tradeTime  = DateTime.Now;                                                   //交易时间

                                OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                                if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                                {
                                    Orders.PayOrder(oid, OrderState.Confirming, tradeSN, DateTime.Now);
                                    OrderActions.CreateOrderAction(new OrderActionInfo()
                                    {
                                        Oid         = oid,
                                        Uid         = orderInfo.Uid,
                                        RealName    = "本人",
                                        AdminGid    = 1,
                                        AdminGTitle = "非管理员",
                                        ActionType  = (int)OrderActionType.Pay,
                                        ActionTime  = tradeTime,
                                        ActionDes   = "你使用财付通支付订单成功,财付通交易号为:" + tradeSN
                                    });
                                }

                                return(new EmptyResult());
                            }
                            else
                            {
                                return(Content("交易失败"));
                            }
                        }
                        else
                        {
                            return(Content("查询验证签名失败或id验证失败"));
                        }
                        #endregion
                    }
                    else
                    {
                        return(Content("通知ID查询签名验证失败"));
                    }
                }
                else
                {
                    return(Content("后台调用通信失败"));
                }
            }
            else
            {
                return(Content("签名验证失败"));
            }
        }
Beispiel #13
0
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            System.Web.HttpContext Context = System.Web.HttpContext.Current;

            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.setKey(TenpayUtil.tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                //支付结果
                string trade_state = resHandler.getParameter("trade_state");
                //交易模式,1即时到账,2中介担保
                string trade_mode = resHandler.getParameter("trade_mode");

                if ("1".Equals(trade_mode) && "0".Equals(trade_state))
                {
                    string   out_trade_no = resHandler.getParameter("out_trade_no");                                //商户订单号
                    string   tradeSN      = resHandler.getParameter("transaction_id");                              //财付通订单号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(resHandler.getParameter("total_fee")) / 100; //金额,以分为单位
                    DateTime tradeTime    = DateTime.Now;                                                           //交易时间

                    List <OrderInfo> orderList = new List <OrderInfo>();
                    foreach (string oid in StringHelper.SplitString(out_trade_no))
                    {
                        OrderInfo orderInfo = Orders.GetOrderByOid(TypeHelper.StringToInt(oid));
                        orderList.Add(orderInfo);
                    }
                    decimal allSurplusMoney = 0M;
                    foreach (OrderInfo orderInfo in orderList)
                    {
                        allSurplusMoney += orderInfo.SurplusMoney;
                    }

                    if (orderList.Count > 0 && allSurplusMoney <= tradeMoney)
                    {
                        foreach (OrderInfo orderInfo in orderList)
                        {
                            if (orderInfo.SurplusMoney > 0 && orderInfo.OrderState == (int)OrderState.WaitPaying)
                            {
                                Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, tradeSN, DateTime.Now);
                                OrderActions.CreateOrderAction(new OrderActionInfo()
                                {
                                    Oid        = orderInfo.Oid,
                                    Uid        = orderInfo.Uid,
                                    RealName   = "本人",
                                    ActionType = (int)OrderActionType.Pay,
                                    ActionTime = tradeTime,
                                    ActionDes  = "你使用财付通支付订单成功,财付通交易号为:" + tradeSN
                                });
                            }
                        }
                    }

                    return(RedirectToAction("payresult", "order", new RouteValueDictionary {
                        { "oidList", out_trade_no }
                    }));
                }
                else
                {
                    return(Content("财付通支付失败"));
                }
            }
            else
            {
                return(Content("认证签名失败"));
            }
        }
Beispiel #14
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            PluginSetInfo pluginSetInfo = PluginUtils.GetPluginSet();

            // 如果您还没有设置MD5密钥请登陆我们为您提供商户后台,地址:https://merchant3.chinabank.com.cn/
            // 登陆后在上面的导航栏里可能找到“B2C”,在二级导航栏里有“MD5密钥设置”
            // 建议您设置一个16位以上的密钥或更高,密钥最多64位,但设置16位已经足够了
            string key = pluginSetInfo.Key;

            string  v_oid       = WebHelper.GetRequestString("v_oid");
            string  v_pstatus   = WebHelper.GetRequestString("v_pstatus");
            string  v_pstring   = WebHelper.GetRequestString("v_pstring");
            string  v_pmode     = WebHelper.GetRequestString("v_pmode");
            string  v_md5str    = WebHelper.GetRequestString("v_md5str");
            decimal v_amount    = TypeHelper.StringToDecimal(WebHelper.GetRequestString("v_amount"));
            string  v_moneytype = WebHelper.GetRequestString("v_moneytype");
            string  remark1     = WebHelper.GetRequestString("remark1");
            string  remark2     = WebHelper.GetRequestString("remark2");

            string str = v_oid + v_pstatus + v_amount + v_moneytype + key;

            str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5").ToUpper();

            if (str == v_md5str)
            {
                if (v_pstatus.Equals("20"))
                {
                    List <OrderInfo> orderList = new List <OrderInfo>();
                    foreach (string oid in StringHelper.SplitString(v_oid))
                    {
                        OrderInfo orderInfo = Orders.GetOrderByOid(TypeHelper.StringToInt(oid));
                        orderList.Add(orderInfo);
                    }
                    decimal allSurplusMoney = 0M;
                    foreach (OrderInfo orderInfo in orderList)
                    {
                        allSurplusMoney += orderInfo.SurplusMoney;
                    }

                    //支付成功
                    if (orderList.Count > 0 && allSurplusMoney <= v_amount)
                    {
                        foreach (OrderInfo orderInfo in orderList)
                        {
                            if (orderInfo.SurplusMoney > 0 && orderInfo.OrderState == (int)OrderState.WaitPaying)
                            {
                                Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, "", DateTime.Now);
                                OrderActions.CreateOrderAction(new OrderActionInfo()
                                {
                                    Oid        = orderInfo.Oid,
                                    Uid        = orderInfo.Uid,
                                    RealName   = "本人",
                                    ActionType = (int)OrderActionType.Pay,
                                    ActionTime = DateTime.Now,
                                    ActionDes  = "你使用网银在线支付订单成功,支付银行为:" + v_pmode
                                });
                            }
                        }
                    }
                }
                return(Content("ok"));
            }
            else
            {
                return(Content("error"));
            }
        }