Esempio n. 1
0
 public void EGetEwm()
 {
     if (Context.Session["OpenIdE"] != null)
     {
         string     OpenId = Context.Session["OpenIdE"].ToString();
         WeChatUser wcu    = ve.WeChatUser.FirstOrDefault(x => x.OpenId == OpenId && x.State == true);
         TempBind   tb     = null;
         int        num    = 0;
         do
         {
             num = TextStr.RandomArray(1, 50000, 100000)[0];
             string str = num + "";
             tb = ve.TempBind.FirstOrDefault(q => q.SceneId == str);
         } while (tb != null);
         tb            = new TempBind();
         tb.Token      = wcu.Token;
         tb.SceneId    = num + "";
         tb.CreateDate = DateTime.Now;
         tb.DeviceId   = wcu.DeviceId;
         ve.TempBind.Add(tb);
         ve.SaveChanges();
         Context.Response.Clear();
         Context.Response.ContentType = "image/jpg";
         Context.Response.BinaryWrite(QrCodeManager.GenerateTemp(GetToken(), num));
         Context.Response.End();
     }
 }
Esempio n. 2
0
        private string BindWeChat(string OpenId, string SceneId)
        {
            StringBuilder str = new StringBuilder();
            TempBind      tb  = ve.TempBind.FirstOrDefault(q => q.SceneId == SceneId);

            if (tb != null)
            {
                WeChatUser tempwcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == OpenId && q.DeviceId == tb.DeviceId);
                if (tempwcu != null)
                {
                    if (tb.Token != tempwcu.Token)
                    {
                        tempwcu.Token = tb.Token;
                        ve.SaveChanges();
                    }
                    str.Append("你的帐号已绑定【" + tempwcu.DeviceName + "】该设备!");
                }
                else
                {
                    string     js  = "";
                    Message    ms  = null;
                    WeChatUser wcu = new WeChatUser();
                    wcu.OpenId     = OpenId;
                    wcu.Token      = tb.Token;
                    wcu.DeviceId   = tb.DeviceId;
                    wcu.DeviceName = tb.DeviceId;
                    wcu.State      = true;
                    wcu.UserPhone  = "";
                    wcu.HeadImg    = "../Img/ejq.jpg";
                    wcu.CreateDate = DateTime.Now;
                    ve.WeChatUser.Add(wcu);
                    ve.SaveChanges();
                    List <WeChatUser> list = ve.WeChatUser.Where(x => x.OpenId == OpenId).ToList();
                    foreach (var item in list)
                    {
                        if (item.DeviceId == wcu.DeviceId)
                        {
                            continue;
                        }
                        item.State = false;
                        ve.SaveChanges();
                    }
                    str.Append("\n请在下方回复“绑定设备+手机号”\n如:绑定设备13212345678\n即可激活设备!");
                    js = "{\"Title\":\"绑定推送\",\"Type\":6,\"OpenId\":\"" + OpenId + "\",\"Content\":\"\"}";
                    ms = new Message("e家亲", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                    string  returnStr = PushHelper.PushMsg(tb.Token, jsonSerializer.Serialize(ms));
                    JObject json      = JObject.Parse(returnStr);
                    returnStr = json["ret_code"].ToString();
                }
            }
            return(str.ToString());
        }
Esempio n. 3
0
        public void GetQrCodeImg(string Token, string deviceId)
        {
            TempBind tb  = null;
            int      num = 0;

            do
            {
                num = TextStr.RandomArray(1, 50000, 100000)[0];
                string str = num + "";
                tb = ve.TempBind.FirstOrDefault(q => q.SceneId == str);
            } while (tb != null);
            tb            = new TempBind();
            tb.Token      = Token;
            tb.SceneId    = num + "";
            tb.CreateDate = DateTime.Now;
            tb.DeviceId   = deviceId;
            ve.TempBind.Add(tb);
            ve.SaveChanges();
            WriteImg(QrCodeManager.GenerateTemp(GetToken(), num));
        }