Esempio n. 1
0
        //扫描二维码事件
        public override AbstractResponse OnEvent_ScanRequest(ScanEventRequest scanEventRequest)
        {
            Utils.LogWriter.SaveLog("产生扫码事件:" + scanEventRequest.EventKey);
            if (!string.IsNullOrEmpty(scanEventRequest.EventKey))
            {
                /*
                 * 打开分享图片
                 * 获取用户信息
                 *
                 * */

                string open_id        = scanEventRequest.FromUserName;
                int    ReferralUserId = int.Parse(scanEventRequest.EventKey);

                //判断是否会员
                if (MemberProcessor.IsExitOpenId(open_id))
                {
                    //Utils.LogWriter.SaveLog("已存在会员:" + open_id);
                    Hidistro.Entities.Members.MemberInfo m = MemberProcessor.GetMembers(open_id);
                    if (m.ReferralUserId == 0 && m.OpenId != open_id)
                    {
                        m.ReferralUserId = ReferralUserId;
                        MemberProcessor.UpdateMember(m);
                        Utils.LogWriter.SaveLog("扫码填补上级ID:" + ReferralUserId);
                        return(null);
                    }

                    //Utils.LogWriter.SaveLog("返回提示:" + open_id);
                    TextResponse response = new TextResponse
                    {
                        CreateTime   = DateTime.Now,
                        Content      = "您已经有上级了哦",
                        ToUserName   = scanEventRequest.FromUserName,
                        FromUserName = scanEventRequest.ToUserName
                    };
                    return(response);
                }

                SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);

                JObject wx_user_info = TokenApi.GetUserInfo(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, open_id);
                Utils.LogWriter.SaveLog("wx_user_info:" + wx_user_info["nickname"].ToString());

                string generateId = Globals.GetGenerateId();
                Hidistro.Entities.Members.MemberInfo member = new Hidistro.Entities.Members.MemberInfo
                {
                    GradeId        = MemberProcessor.GetDefaultMemberGrade(),
                    UserName       = Globals.UrlDecode(wx_user_info["nickname"].ToString()),
                    OpenId         = open_id,
                    CreateDate     = DateTime.Now,
                    SessionId      = generateId,
                    SessionEndTime = DateTime.Now.AddYears(10),
                    ReferralUserId = ReferralUserId
                };

                //Utils.LogWriter.SaveLog("创建客户资料");
                MemberProcessor.CreateMember(member);
            }

            return(null);
        }
Esempio n. 2
0
        //关注事件
        public override AbstractResponse OnEvent_SubscribeRequest(SubscribeEventRequest subscribeEventRequest)
        {
            Utils.LogWriter.SaveLog("产生关注事件:" + subscribeEventRequest.EventKey);
            string event_key = subscribeEventRequest.EventKey;

            if (!string.IsNullOrEmpty(event_key) && event_key.IndexOf("qrscene_") != -1)
            {
                //关联上级

                /*
                 * 打开分享图片
                 * 获取用户信息
                 *
                 * */

                string open_id = subscribeEventRequest.FromUserName;
                Utils.LogWriter.SaveLog("产生关注事件step1:" + open_id);
                int ReferralUserId = int.Parse(subscribeEventRequest.EventKey.Replace("qrscene_", ""));
                Utils.LogWriter.SaveLog("产生关注事件step2:" + ReferralUserId);

                //判断是否会员
                if (MemberProcessor.IsExitOpenId(open_id))
                {
                    Utils.LogWriter.SaveLog("产生关注事件step3:已存在会员信息");
                    Hidistro.Entities.Members.MemberInfo m = MemberProcessor.GetMembers(open_id);
                    if (m.ReferralUserId == 0 && m.OpenId != open_id)
                    {
                        m.ReferralUserId = ReferralUserId;
                        MemberProcessor.UpdateMember(m);
                        //Utils.LogWriter.SaveLog("扫码填补上级ID:" + ReferralUserId);
                        return(null);
                    }
                }
                else
                {
                    Utils.LogWriter.SaveLog("产生关注事件step3:不存在会员信息");
                    //关联上级并增加客户资料
                    SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);

                    JObject wx_user_info = TokenApi.GetUserInfo(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, open_id);
                    Utils.LogWriter.SaveLog("产生关注事件step4:" + wx_user_info["nickname"].ToString());

                    string generateId = Globals.GetGenerateId();
                    Hidistro.Entities.Members.MemberInfo member = new Hidistro.Entities.Members.MemberInfo
                    {
                        GradeId        = MemberProcessor.GetDefaultMemberGrade(),
                        UserName       = Globals.UrlDecode(wx_user_info["nickname"].ToString()),
                        OpenId         = open_id,
                        CreateDate     = DateTime.Now,
                        SessionId      = generateId,
                        SessionEndTime = DateTime.Now.AddYears(10),
                        ReferralUserId = ReferralUserId
                    };

                    Utils.LogWriter.SaveLog("创建客户资料");
                    MemberProcessor.CreateMember(member);

                    //获取上级
                    Hidistro.Entities.Members.MemberInfo parentInfo = MemberProcessor.GetMember(ReferralUserId);

                    //获取第多少个会员
                    int count = MemberProcessor.GetMemberCount();

                    TextResponse r = new TextResponse
                    {
                        CreateTime = DateTime.Now,
                        Content    = "恭喜您!您已通过【" + parentInfo.UserName + "】的推荐成为本站会员,您是本站第" + (10000 + count)
                                     + "个会员,点击右下方【创业良机】~【组建团队】进入财富倍增快通道。",
                        ToUserName   = subscribeEventRequest.FromUserName,
                        FromUserName = subscribeEventRequest.ToUserName
                    };
                    return(r);
                }
            }

            ReplyInfo subscribeReply = ReplyHelper.GetSubscribeReply();

            if (subscribeReply == null)
            {
                return(null);
            }
            subscribeReply.Keys = "登录";
            AbstractResponse response = this.GetResponse(subscribeReply, subscribeEventRequest.FromUserName);

            if (response == null)
            {
                this.GotoManyCustomerService(subscribeEventRequest);
            }
            response.ToUserName   = subscribeEventRequest.FromUserName;
            response.FromUserName = subscribeEventRequest.ToUserName;
            return(response);
        }
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="openId"></param>
        /// <returns></returns>
        public static IUser RegisterUser(string openId, string access_token)
        {
            ErrorLog.Write("laile:" + access_token + "");
            if (string.IsNullOrEmpty(openId))
            {
                return(null);
            }
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);
            Userinfo     userinfo       = TokenApi.GetUserInfo(access_token, openId, masterSettings.WeixinAppId, masterSettings.WeixinAppSecret);
            string       realName       = "";
            string       headImg        = "";

            if (userinfo != null)
            {
                if (!string.IsNullOrEmpty(userinfo.nickname))
                {
                    realName = userinfo.nickname;
                }
                if (!string.IsNullOrEmpty(userinfo.headimgurl))
                {
                    headImg = userinfo.headimgurl;
                }
            }
            long ip         = 0;
            int  ProvinceId = 0;

            try
            {
                ip = Globals.IpToInt(Globals.IPAddress);
            }
            catch
            {
            }
            ErrorLog.Write("laileip:" + ip + "");
            if (ip != 0)
            {
                string provinceName = TradeHelper.GetProvinceName(ip);
                if (!string.IsNullOrEmpty(provinceName))
                {
                    ProvinceId = RegionHelper.GetProvinceId(provinceName);
                    ErrorLog.Write("新用户ip" + Globals.IPAddress);
                    ErrorLog.Write(string.Format("新用户省份名称{0},省份Id{1}", provinceName, ProvinceId));
                }
            }
            string PasswordSalt = GenerateSalt();
            IUser  user         = UserHelper.CreateUsersMemberUsersInRoles(openId, PasswordSalt, realName, headImg, ProvinceId);

            ErrorLog.Write("laileuser:"******"");
            if (user != null && user.UserId > 0)
            {
                System.Collections.Hashtable hashtable = Users.UserCache();
                if (hashtable.ContainsKey(Users.UserKey(openId)))
                {
                    hashtable[Users.UserKey(openId)] = user;
                }
                else
                {
                    hashtable.Add(Users.UserKey(openId), user);
                }
                string     name       = "Vshop-Member";
                HttpCookie httpCookie = new HttpCookie("Vshop-Member");
                httpCookie.Value   = Globals.UrlEncode(user.Username);
                httpCookie.Expires = System.DateTime.Now.AddDays(7);
                httpCookie.Domain  = HttpContext.Current.Request.Url.Host;
                if (HttpContext.Current.Response.Cookies[name] != null)
                {
                    HttpContext.Current.Response.Cookies.Remove(name);
                }
                HttpContext.Current.Response.Cookies.Add(httpCookie);
                ErrorLog.Write("lailecookie:" + httpCookie + "");
                return(user);
            }
            return(null);
        }