Esempio n. 1
0
        /// <summary>
        /// 最后生成signature:
        /// </summary>
        /// <param name="nonceStr"></param>
        /// <param name="timespanstr"></param>
        /// <returns></returns>
        public static string Getsignature(string nonceStr, string timespanstr)
        {
            if (SessionTools.GetSession("access_tokenzj") == null)
            {
                Getaccesstoken();
            }
            if (SessionTools.GetSession("ticketzj") == null)
            {
                Getjsapi_ticket();
            }
            //string url = HttpContext.Current.Request.Url.ToString();
            //string url = PayConfig.WebSiteDomain() + HttpContext.Current.Request.ApplicationPath;
            string url = PayConfig.WebSiteDomain() + HttpContext.Current.Request.RawUrl;
            string str = "jsapi_ticket=" + (string)SessionTools.GetSession("ticketzj") + "&noncestr=" + nonceStr +
                         "&timestamp=" + timespanstr + "&url=" + url;// +"&wxref=mp.weixin.qq.com";
            string singature = SHA1Util.getSha1(str);

            return(singature.ToLower());
        }
Esempio n. 2
0
        private static string GetReturnPath(ActionExecutingContext filterContext, string returnURL)
        {
            try
            {
                // Session.UserID 为空,则拉取用户注册信息
                if (string.IsNullOrEmpty(SessionTools.UserID))
                {
                    var code = filterContext.HttpContext.Request.QueryString["code"];
                    if (string.IsNullOrEmpty(code))
                    {
                        // CODE 为空,则根据appid拉取网页授权
                        var    redirect_uri = HttpUtility.UrlEncode(PayConfig.WebSiteDomain() + "/Home/OAuth?ReturnUrl=" + returnURL);
                        string url          = string.Format(@"https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                                                            PayConfig.WxAppid(), redirect_uri);
                        filterContext.HttpContext.Response.Redirect(url);
                        filterContext.HttpContext.Response.End();
                        filterContext.Result = new EmptyResult();
                        return(string.Empty);
                    }

                    // CODE 不为空,则根据 code获取用户信息,并注册
                    var User = Registered(code);
                    if (User == null)
                    {
                        // 如果User为空,则注册失败,因此不应该继续执行Action内的逻辑
                        filterContext.HttpContext.Response.End();
                        filterContext.Result = new EmptyResult();
                        return(string.Empty);
                    }

                    //// 用户手机号不存在则跳转至完善注册信息界面
                    //if (User != null && string.IsNullOrEmpty(User.TelePhone))
                    //    return "/Regist/RegistView";
                    //return "/Regist/RegistView?jsonUser="******"拉取用户网页授权信息并且注册异常", ex.ToString());
            }
            return(string.Empty);
        }
Esempio n. 3
0
        /// <summary>
        /// 向管理员发送请求用户所需要的验证码
        /// </summary>
        /// <param name="toUser">请求的用户</param>
        /// <param name="MstType">消息类型:1 成绩录入,2 退款申请</param>
        private ResultModel SendCodeMsg(Sys_User toUser, string OrderID, int CodeType, string ReturnUrl = "")
        {
            try
            {
                var USVC = new UserService();
                var CSVC = new CodeService();

                var telephone = ConfigurationManager.AppSettings["ManagerPhone"].ToString();
                var codeStr   = CSVC.CreateCode(toUser.TelePhone, CodeType);
                var baseUser  = USVC.GetUserBaseByTelePhone(telephone);

                if (baseUser != null && !string.IsNullOrEmpty(codeStr))
                {
                    var first    = string.Empty;
                    var keyword1 = string.Empty;
                    var remark   = string.Empty;
                    if (CodeType == 1)
                    {
                        first    = string.Format(@"用户 {0} 正在进行成绩录入,向您请求验证码。", string.IsNullOrEmpty(toUser.TelePhone) ? toUser.UserName : toUser.TelePhone);
                        keyword1 = "成绩录入";
                        remark   = "验证码5分钟内有效!";

                        Common.WxPay.JsApiPay.SendMsg(baseUser.WeiXin_Openid, Common.WxPay.Lib.MsgConfig.Msg3, new
                        {
                            first = new Common.WxPay.Lib.MsgValue()
                            {
                                value = first
                            },
                            keyword1 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = keyword1
                            },
                            keyword2 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = codeStr
                            },
                            remark = new Common.WxPay.Lib.MsgValue()
                            {
                                value = remark
                            },
                        });
                    }
                    else
                    {
                        first    = string.Format(@"用户 {0} 提交了一条退款申请,请尽快处理。", string.IsNullOrEmpty(toUser.TelePhone) ? toUser.UserName : toUser.TelePhone);
                        keyword1 = "退款申请";
                        var recordEntity = new RecordService().SelectByID(OrderID);
                        remark = string.Format(@"订单编号 {0}", recordEntity.OrderNo);

                        ReturnUrl = string.Format(@"{0}/User/ValidateRefund?OrderID={1}&TelePhone={2}&CodeStr={3}",
                                                  PayConfig.WebSiteDomain(), OrderID, toUser.TelePhone, codeStr);

                        Common.WxPay.JsApiPay.SendMsg(baseUser.WeiXin_Openid, Common.WxPay.Lib.MsgConfig.Msg4, new
                        {
                            first = new Common.WxPay.Lib.MsgValue()
                            {
                                value = first
                            },
                            keyword1 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = string.IsNullOrEmpty(toUser.TelePhone) ? toUser.UserName : toUser.TelePhone
                            },
                            keyword2 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = keyword1
                            },
                            keyword3 = new Common.WxPay.Lib.MsgValue()
                            {
                                value = DateTime.Now.ToString("yyyy-MM-dd")
                            },
                            remark = new Common.WxPay.Lib.MsgValue()
                            {
                                value = remark
                            },
                        }, ReturnUrl);
                    }


                    // 验证码发送过一次之后,就设为失效,5分钟之内不再重复发送
                    CSVC.SetCodeInvalid(toUser.TelePhone, codeStr);
                    return(Common.MessageRes.OperateSuccess.SetResult("SUCCESS"));
                }

                return(Common.MessageRes.OperateFailed.SetResult(null));
            }
            catch (Exception ex)
            {
                return((Common.MessageRes.OperateException + ex.ToString()).SetResult(null));
            }
        }