Ejemplo n.º 1
0
        public ActionResult Post(PostModel postModel)
        {
            Log4Helper.WriteInfoLog(String.Format("Post:{0}", DateTime.Now.ToString()), "api");

            if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token))
            {
                return(Content("参数错误!"));
            }

            postModel.Token          = Token;
            postModel.EncodingAESKey = EncodingAesKey; //根据自己后台的设置保持一致
            postModel.AppId          = AppId;          //根据自己后台的设置保持一致

            const int maxRecordCount = 10;
            var       messageHandler = new CustomMessageHandler(Request.InputStream, postModel, maxRecordCount);

            try
            {
                messageHandler.OmitRepeatedMessage = true;
                //执行微信处理过程
                messageHandler.Execute();

                return(new FixWeixinBugWeixinResult(messageHandler));//为了解决官方微信5.0软件换行bug暂时添加的方法,平时用下面一个方法即可
            }
            catch (Exception ex)
            {
                Log4Helper.WriteInfoLog(ex.Message, "wx");
            }
            return(Content(""));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 支付宝异步回调异常日志
        /// </summary>
        /// <param name="request">请求对象</param>
        /// <param name="ex">异常对象</param>
        /// <param name="folder">目录</param>
        /// <returns>void</returns>
        /// <remarks>2015-09-09 苟治国 创建</remarks>
        private void WriteAlipaySyncExceptionLog(HttpRequestBase request, Exception ex, string folder)
        {
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + Request["out_trade_no"] == "" ? Request["v_oid"] : Request["out_trade_no"]);
            sb.AppendLine("logtime:" + DateTime.Now);
            sb.AppendLine("message:" + ex.Message);
            Log4Helper.WriteInfoLog(sb.ToString(), folder);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 网银在线异步回调异常日志
        /// </summary>
        /// <param name="request">请求对象</param>
        /// <param name="ex">异常对象</param>
        /// <param name="folder">目录</param>
        /// <returns>void</returns>
        private void WriteChinaBankSyncExceptionLog(HttpRequestBase request, Exception ex, string folder)
        {
            var sb         = new StringBuilder("--------------------------------------------------------\r\n");
            var orderSysNo = Request["v_oid"].Split('-');

            sb.AppendLine("order:" + (orderSysNo.Length > 3 ? orderSysNo[2] : Request["v_oid"]));
            sb.AppendLine("logtime:" + DateTime.Now);
            sb.AppendLine("message:" + ex.Message);
            Log4Helper.WriteInfoLog(sb.ToString(), folder);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 微信回调异常日志
        /// </summary>
        /// <param name="ex">异常对象</param>
        /// <param name="param">微信支付回调请求对象</param>
        /// <returns>void</returns>
        private void WriteWeixinErrorLog(Exception ex, WeixinRequest param)
        {
            if (param == null)
            {
                param = new WeixinRequest();
            }
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + param.out_trade_no);
            sb.AppendLine("logtime:" + DateTime.Now);
            sb.AppendLine("message:" + ex.Message);
            Log4Helper.WriteInfoLog(sb.ToString(), "PayNotify");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 网银在线异步回调异常日志
        /// </summary>
        /// <param name="content">请求对象</param>
        /// <param name="folder">目录</param>
        /// <returns>void</returns>
        /// <remarks>2015-09-09 苟治国 创建</remarks>
        private void WriteLog(string content, string folder)
        {
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + Request["out_trade_no"] == "" ? Request["v_oid"] : Request["out_trade_no"]);
            sb.AppendLine("logtime:" + DateTime.Now);
            try
            {
                sb.AppendLine("content:" + content);
            }
            catch { }
            Log4Helper.WriteInfoLog(sb.ToString(), folder);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// OAuthScope.snsapi_userinfo方式回调
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns>视图</returns>
        public ActionResult Index(string code, string state)
        {
            Log4Helper.WriteInfoLog("账号:" + code, "Oauth2");

            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }
            if (string.IsNullOrEmpty(state))
            {
                return(Content("验证失败!请从正规途径进入!"));
            }
            var result = OAuthApi.GetAccessToken(appKey, appSecret, code);

            if (result.errcode != ReturnCode.请求成功)
            {
                return(Content("错误:" + result.errmsg));
            }

            try
            {
                //因为这里还不确定用户是否关注本微信,所以只能试探性地获取一下
                var userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                if (userInfo != null)
                {
                    //用户信息
                    var openId     = userInfo.openid;
                    var nickname   = userInfo.nickname;
                    var headimgurl = userInfo.headimgurl;
                    //保存用户信息
                    CookieUtil.SetCookie("OpenId", openId);
                    CookieUtil.SetCookie("HeadImgUrl", headimgurl);
                    CookieUtil.SetCookie("Nickname", nickname);

                    Log4Helper.WriteInfoLog(string.Format("OpenId:{0}", userInfo.ToJson2()), "Login");

                    var url = "http://app.1000n.com/me/vip";

                    return(Redirect(url));
                }
                else
                {
                    return(Content("用户已授权,获取UserInfo失败"));
                }
            }
            catch (ErrorJsonResultException ex)
            {
                return(Content("用户已授权,授权Token:" + result));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 微信回调普通日志
        /// </summary>
        /// <param name="content">日志内容</param>
        /// <param name="param">微信支付回调请求对象</param>
        /// <returns>void</returns>
        private void WriteWeixinLog(string content, WeixinRequest param)
        {
            if (param == null)
            {
                param = new WeixinRequest();
            }
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + param.out_trade_no);
            sb.AppendLine("logtime:" + DateTime.Now);
            try
            {
                sb.AppendLine("content:" + content);
                Log4Helper.WriteInfoLog(sb.ToString(), "PayNotify");
            }
            catch { }

            LogApp.Instance.Info(new LogRequest()
            {
                Source    = LogEnum.Source.前台,
                Message   = sb.ToString(),
                Exception = null
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 网银在线异步回调异常日志
        /// </summary>
        /// <param name="request">请求对象</param>
        /// <param name="folder">目录</param>
        /// <returns>void</returns>
        /// <remarks>2015-09-09 苟治国 创建</remarks>
        private void WriteRequestLog(HttpRequestBase request, string folder)
        {
            var sb = new StringBuilder("--------------------------------------------------------\r\n");

            sb.AppendLine("order:" + Request["out_trade_no"] == "" ? Request["v_oid"] : Request["out_trade_no"]);
            sb.AppendLine("logtime:" + DateTime.Now);
            try
            {
                foreach (var key in request.Form.AllKeys)
                {
                    sb.AppendLine(key + ":" + Request.Form[key]);
                }
                foreach (var key in request.QueryString.AllKeys)
                {
                    sb.AppendLine(key + ":" + Request.QueryString[key]);
                }
                sb.AppendLine("REMOTE_ADDR:" + request.ServerVariables["REMOTE_ADDR"]);
                sb.AppendLine("REMOTE_HOST:" + request.ServerVariables["REMOTE_HOST"]);
                sb.AppendLine("REMOTE_PORT:" + request.ServerVariables["REMOTE_PORT"]);
                sb.AppendLine("REQUEST_METHOD:" + request.ServerVariables["REQUEST_METHOD"]);
            }
            catch { }
            Log4Helper.WriteInfoLog(sb.ToString(), folder);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// OAuthScope.snsapi_userinfo方式回调
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns>视图</returns>
        public ActionResult Index(string code, string state)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }
            if (string.IsNullOrEmpty(state))
            {
                return(Content("验证失败!请从正规途径进入!"));
            }
            var result = OAuthApi.GetAccessToken(appKey, appSecret, code);

            if (result.errcode != ReturnCode.请求成功)
            {
                return(Content("错误:" + result.errmsg));
            }
            try
            {
                //因为这里还不确定用户是否关注本微信,所以只能试探性地获取一下
                var userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                if (userInfo != null)
                {
                    //用户信息
                    var openId     = userInfo.openid;
                    var nickname   = userInfo.nickname;
                    var headimgurl = userInfo.headimgurl;
                    //保存用户信息
                    CookieUtil.SetCookie("OpenId", openId);
                    CookieUtil.SetCookie("HeadImgUrl", headimgurl);
                    CookieUtil.SetCookie("Nickname", nickname);

                    var customerExt = CustomerApp.Instance.GetByOpenId(openId);

                    Log4Helper.WriteInfoLog(string.Format("OpenId:{0}", openId), "Login");
                    Log4Helper.WriteInfoLog(string.Format("会员对象:{0}", customerExt.ToJson2()), "Login");
                    if (customerExt == null)
                    {
                        return(RedirectToAction("Register", "Account"));
                    }
                    else
                    {
                        //登录成功
                        var response = CustomerApp.Instance.OpenIdLogin(new LoginRequest()
                        {
                            OpenId = openId
                        });

                        Log4Helper.WriteInfoLog(string.Format("登录成功:{0}", response.ToJson()), "Login");

                        if (response.Status)
                        {
                            return(RedirectToAction("Index", "Me"));
                        }
                        else
                        {
                            return(RedirectToAction("MemberBind", "Account"));
                        }
                    }
                }
                else
                {
                    return(Content("用户已授权,获取UserInfo失败"));
                }
            }
            catch (ErrorJsonResultException ex)
            {
                return(Content("用户已授权,授权Token:" + result));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 微信支付
        /// </summary>
        /// <param name="id">订单编号</param>
        /// <returns>视图</returns>
        public ActionResult GoPayWeiXin(string id)
        {
            Log4Helper.WriteInfoLog(id, "pay");

            //当前上下文
            var context = CustomerContext.Context;

            if (context == null)
            {
                return(View("Error", new JResult()
                {
                    Message = "用户已超时、请重新登录﹗"
                }));
            }

            var customerExt = CustomerApp.Instance.Get(context.SysNo);

            if (customerExt == null)
            {
                return(View("Error", new JResult()
                {
                    Message = "扩展会员不存在﹗"
                }));
            }

            //获取订单
            var recharge = RechargeApp.Instance.GetbyOrderNo(id);

            if (recharge == null)
            {
                return(View("Error", new JResult()
                {
                    Message = "订单号不存在﹗"
                }));
            }

            ViewBag.SourceUrl = WebUtil.GetSource();

            #region JsApi支付

            try
            {
                //创建支付应答对象
                var packageReqHandler = new RequestHandler(null);
                //初始化
                packageReqHandler.Init();

                var timeStamp = TenPayV3Util.GetTimestamp();
                var nonceStr  = TenPayV3Util.GetNoncestr();

                //设置package订单参数
                packageReqHandler.SetParameter("appid", TenPayV3Info.AppId);      //公众账号ID
                packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId);     //商户号
                packageReqHandler.SetParameter("nonce_str", nonceStr);            //随机字符串
                packageReqHandler.SetParameter("body", "千年教育充值订单");               //商品信息
                packageReqHandler.SetParameter("out_trade_no", recharge.OrderNo); //订单号
                packageReqHandler.SetParameter("total_fee", Convert.ToInt32(recharge.Amount * 100).ToString());
                //商品金额,以分为单位(money * 100).ToString()
                packageReqHandler.SetParameter("spbill_create_ip", Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
                packageReqHandler.SetParameter("notify_url", TenPayV3Info.TenPayV3Notify);   //接收财付通通知的URL
                packageReqHandler.SetParameter("trade_type", TenPayV3Type.JSAPI.ToString()); //交易类型
                packageReqHandler.SetParameter("openid", customerExt.OpenId);                //用户的openId

                var sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key);
                packageReqHandler.SetParameter("sign", sign); //签名

                var data = packageReqHandler.ParseXML();
                Log4Helper.WriteInfoLog("data:" + data, "pay");
                var result = TenPayV3.Unifiedorder(data);
                Log4Helper.WriteInfoLog("统一支付接口:" + result, "pay");

                var res = XDocument.Parse(result);

                var return_code = res.Element("xml").Element("return_code").Value;
                var result_code = res.Element("xml").Element("result_code").Value;
                if (return_code.ToUpper() != "SUCCESS")
                {
                    return(View("Error", new JResult {
                        Message = "通信故障,请稍后再试!"
                    }));
                }
                if (result_code.ToUpper() == "FAIL")
                {
                    var err_code_des = res.Element("xml").Element("err_code_des").Value;
                    if (err_code_des.Contains("订单号重复"))
                    {
                        return(View("Error", new JResult {
                            Message = "订单号重复"
                        }));
                    }
                    return(View("Error", new JResult {
                        Message = err_code_des
                    }));
                }

                var prepayId = res.Element("xml").Element("prepay_id").Value;

                //设置支付参数
                var paySignReqHandler = new RequestHandler(null);
                paySignReqHandler.SetParameter("appId", TenPayV3Info.AppId);
                paySignReqHandler.SetParameter("timeStamp", timeStamp);
                paySignReqHandler.SetParameter("nonceStr", nonceStr);
                paySignReqHandler.SetParameter("package", string.Format("prepay_id={0}", prepayId));
                paySignReqHandler.SetParameter("signType", "MD5");
                var paySign = paySignReqHandler.CreateMd5Sign("key", TenPayV3Info.Key);

                ViewData["appId"]     = TenPayV3Info.AppId;
                ViewData["timeStamp"] = timeStamp;
                ViewData["nonceStr"]  = nonceStr;
                ViewData["package"]   = string.Format("prepay_id={0}", prepayId);
                ViewData["paySign"]   = paySign;
            }
            catch (Exception ex)
            {
                Log4Helper.WriteInfoLog(ex.Message, "pay");
            }
            #endregion

            return(View(customerExt));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 提现申请
        /// </summary>
        /// <param name="request">参数</param>
        public JResult Cashout(CashoutRequest request)
        {
            var response = new JResult()
            {
                Status = false
            };

            using (var tran = new TransactionProvider())
            {
                try
                {
                    //更新会员钱包(钱包金额-提现金额)(升级金额+提现金额/(如果是普通、区域、全国才除)2)
                    if (Using <ICrCustomer>().UpdateWalletAmount(new UpdateWalletAmountRequest()
                    {
                        CustomerSysNo = request.CustomerSysNo,
                        WalletAmount = request.WalletAmount,
                        UpgradeFundAmount = request.UpgradeFundAmount
                    }) <= 0)
                    {
                        throw new Exception("更新会员钱包失败");
                    }
                    //添加提现记录
                    var amount = request.WalletAmount - request.UpgradeFundAmount;
                    var model  = new FnCashout()
                    {
                        CustomerSysNo = request.CustomerSysNo,
                        RealName      = request.Account,
                        CashoutType   = request.CashoutType,
                        Amount        = amount,
                        Remarks       = string.Format("提现金额:{0} 实际到账金额:{1} 升级基金:{2}", request.WalletAmount, request.WalletAmount - request.UpgradeFundAmount, request.UpgradeFundAmount),
                        Status        = amount < 200?FnEnum.CashoutStatus.完成.GetHashCode(): FnEnum.CashoutStatus.处理中.GetHashCode(),//FnEnum.CashoutStatus.处理中.GetHashCode()
                        CreatedDate   = DateTime.Now
                    };

                    var cashoutSysNo = Using <IFnCashout>().Insert(model);
                    if (cashoutSysNo <= 0)
                    {
                        throw new Exception("添加提现记录失败");
                    }

                    if (amount < 200)
                    {
                        var result = FnCashoutApp.Instance.H5CashoutWeiXin(cashoutSysNo, request.CertPath);

                        Log4Helper.WriteInfoLog("EC.H5 提现" + result.ToJson2(), "Cashout");

                        if (!result.Status)
                        {
                            throw new Exception(result.Message);
                        }
                    }

                    tran.Commit();
                    response.Status  = true;
                    response.Message = "提现申请成功、等待管理员审核!";
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    response.Message = ex.Message;
                }
                finally
                {
                    tran.Dispose();
                }
            }

            return(response);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 驳回
        /// </summary>
        /// <param name="sysNo">编码</param>
        /// <returns>影响行数</returns>
        public JResult H5CashoutWeiXin(int sysNo, string certPath)
        {
            var response = new JResult()
            {
                Status = false
            };

            var cashout = Using <IFnCashout>().Get(sysNo);

            if (cashout == null)
            {
                response.Message = "记录不存在!";
                return(response);
            }

            var customer = Using <ICrCustomer>().Get(cashout.CustomerSysNo);

            if (customer == null)
            {
                response.Message = "会员不存在!";
                return(response);
            }
            if (string.IsNullOrEmpty(customer.OpenId))
            {
                response.Message = "会员openId为空!";
                return(response);
            }

            WeiXinProvider wx = new WeiXinProvider();

            var result = wx.Transfers(new TransfersRequest()
            {
                mch_appid        = "wx9535283296d186c3",
                mchid            = "1491518502",
                nonce_str        = "1213546623546",
                partner_trade_no = cashout.SysNo.ToString(),
                openid           = customer.OpenId,
                check_name       = customer.RealName,
                amount           = cashout.Amount,
                desc             = "代理商佣金提现",
                spbill_create_ip = WebUtil.GetUserIp(),
                apiKey           = "0bad12ce2b775367347d0b3a4bacd698",
                isUseCert        = true,
                cert             = certPath,
                password         = "******"
            });

            Log4Helper.WriteInfoLog("EC.H5 提现" + result.ToJson2(), "Cashout");

            if (result.return_code.ToUpper() == "SUCCESS" && result.result_code.ToUpper() == "SUCCESS")
            {
                response.Message = "操作成功!";
                response.Status  = true;
            }
            else
            {
                response.Message = result.return_msg + result.err_code_des;
            }

            return(response);
        }
Ejemplo n.º 13
0
        public ActionResult Get(PostModel postModel, string echostr)
        {
            Log4Helper.WriteInfoLog(String.Format("Get:{0}", DateTime.Now.ToString()), "api");

            return(CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, Token) ? Content(echostr) : Content("failed:" + postModel.Signature + "," + CheckSignature.GetSignature(postModel.Timestamp, postModel.Nonce, Token) + "。" + "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。"));
        }
Ejemplo n.º 14
0
        public JsonResult Cashout(CashoutRequest request)
        {
            var response = new JResult()
            {
                Status = false
            };

            var result = VHelper.ValidatorRule(
                new Rule_Number(request.Amount.ToString(), "请输入提现金额!")
                );

            if (!result.IsPass)
            {
                response.Status  = false;
                response.Message = result.Message;
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            lock (_lock)
            {
                Log4Helper.WriteInfoLog("EC.H5 提现" + result.ToJson2(), "Cashout");
                //当前上下文
                var context = CustomerContext.Context;
                if (context == null)
                {
                    response.Message = "用户已超时、请重新登录﹗";
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                if (request.Amount <= 0)
                {
                    response.Message = "提现金额不能为零﹗";
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }

                var periodList = FnCashoutApp.Instance.GetPeriodTimes(new FnCashoutQueryRequest()
                {
                    CustomerSysNo = context.SysNo,
                    StartTime     = DateTime.Now.ToString("yyyy-MM-dd 00:00:00"),
                    EndTime       = DateTime.Now.ToString("yyyy-MM-dd 23:59:59")
                });
                if (periodList != null && periodList.Any())
                {
                    response.Message = "每天只能提现一次﹗";
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                //提现金额判断(100元的倍数)
                //var remainder = request.Amount % 100;
                //if (remainder != 0)
                //{
                //    response.Message = "提现金额必须为100的倍数﹗";
                //    return Json(response, JsonRequestBehavior.AllowGet);
                //}
                if (request.Amount < 10)
                {
                    response.Message = "提现金额必须为10元﹗";
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                //验证是否填写银行卡
                if (request.CashoutType.Equals(FnEnum.CashoutType.银联.GetHashCode()))
                {
                    if (context.Bank <= 0 && context.BankNumber == "")
                    {
                        response.Message = "请设置银行卡";
                        return(Json(response, JsonRequestBehavior.AllowGet));
                    }
                }
                if (context.WalletAmount >= request.Amount)
                {
                    WeiXinProvider wx = new WeiXinProvider();

                    var certPath = Server.MapPath(@"\cert\apiclient_cert.p12");

                    decimal upgradeFundAmount = 0;

                    if (!context.Grade.Equals(CustomerEnum.Grade.股东.GetHashCode()))
                    {
                        upgradeFundAmount = request.Amount / 2;
                    }

                    response = FnCashoutApp.Instance.Cashout(new CashoutRequest()
                    {
                        CustomerSysNo     = context.SysNo,
                        WalletAmount      = request.Amount,
                        UpgradeFundAmount = upgradeFundAmount,
                        Account           = context.Account,
                        CashoutType       = request.CashoutType,
                        CertPath          = certPath
                    });
                }
                else
                {
                    response.Message = "当前余额不足﹗";
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }