Esempio n. 1
0
        public ActionResult EditTag(WX_UserTag tag)
        {
            TagService ser    = new TagService(WXAPP.AppId, WXAPP.AppSecret);
            JObject    jo     = JObject.Parse(ser.Update(tag.TagId, tag.TagName));
            var        result = new
            {
                errcode = jo["errcode"],
                errmsg  = jo["errmsg"]
            };

            GetTagList();
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 编辑该标签名
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public ActionResult EditTag(WX_UserTag tag)
        {
            var        Ap     = new WX_AppManager().GetByPK(tag.AppId);
            TagService ser    = new TagService(Ap.AppId, Ap.AppSecret);
            JObject    jo     = JObject.Parse(ser.Update(tag.TagId, tag.TagName));
            var        result = new
            {
                errcode = jo["errcode"],
                errmsg  = jo["errmsg"]
            };

            GetTagList(Ap.AppId, Ap.AppSecret);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        /// <summary>
        /// 从服务器更新标签集合
        /// </summary>
        /// <returns></returns>
        public List <WX_UserTag> GetTagList()
        {
            WX_UserTagManager manager = new WX_UserTagManager();
            TagService        ser     = new TagService(WXAPP.AppId, WXAPP.AppSecret);
            List <WX_UserTag> list    = new List <WX_UserTag>();
            JToken            jo      = JObject.Parse(ser.GetList())["tags"];

            foreach (var i in jo.Children())
            {
                var tag = new WX_UserTag()
                {
                    TagId   = (int)i["id"],
                    TagName = i["name"].ToString(),
                    AppId   = WXAPP.AppId
                };
                var info = manager.GetAll().Where(t => t.TagId == Convert.ToInt32(i["id"]) && t.AppId.Equals(WXAPP.AppId));
                if (info.Count() > 0)
                {
                    //info.TagName = tag.TagName;
                    manager.Update(tag);
                }
                else
                {
                    manager.Add(tag);
                }
                list.Add(tag);
            }

            var idList = new List <int>();

            foreach (var i in manager.GetAll())
            {
                if (list.Where(t => t.TagId.Equals(i.TagId)).Count() == 0)
                {
                    idList.Add(i.TagId);
                }
            }
            foreach (var id in idList)
            {
                manager.Delete(id, WXAPP.AppId);
            }

            Controller_EX.BindSession(Session);
            return(list);
        }
        /// <summary>
        /// 新增标签到微信并在此标签下新增用户
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public ActionResult AddTagAndUse(string AppId, string tagName, string OpenId)
        {
            WX_App     app  = new WX_AppManager().GetByPK(AppId);
            TagService ser  = new TagService(app.AppId, app.AppSecret);
            string     json = ser.Create(tagName);
            JObject    jo   = (JObject)JsonConvert.DeserializeObject(json);
            WX_UserTag tag  = new WX_UserTag()
            {
                AppId   = AppId,
                TagId   = (int)jo["tag"]["id"],
                TagName = jo["tag"]["name"].ToString(),
            };
            ReturnResult result = new ReturnResult()
            {
                Result = true
            };

            if (!new WX_UserTagManager().Add(tag))
            {
                result.Result   = false;
                result.ErrorMsg = "新增失败!";
            }
            else
            {
                List <string> openIdList = JsonConvert.DeserializeObject <List <string> >(OpenId);
                JObject       job        = JObject.Parse(new UserService(app.AppId, app.AppSecret).AddTag(openIdList, tag.TagId));
                var           Adresult   = new
                {
                    errcode = job["errcode"].ToString(),
                    errmsg  = job["errmsg"].ToString()
                };
                if (Adresult.errcode.Equals("0"))
                {
                    WX_UserManager manager = new WX_UserManager();
                    foreach (var id in openIdList)
                    {
                        manager.AddTag(manager.GetByPK(id), tag.TagId);
                    }
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public ActionResult AddTag(string appId, string tagName)
        {
            WX_App     app  = new WX_AppManager().GetByPK(appId);
            TagService ser  = new TagService(app.AppId, app.AppSecret);
            string     json = ser.Create(tagName);
            JObject    jo   = (JObject)JsonConvert.DeserializeObject(json);
            WX_UserTag tag  = new WX_UserTag()
            {
                AppId   = appId,
                TagId   = (int)jo["tag"]["id"],
                TagName = jo["tag"]["name"].ToString(),
            };
            ReturnResult result = new ReturnResult()
            {
                Result = true
            };

            if (!new WX_UserTagManager().Add(tag))
            {
                result.Result   = false;
                result.ErrorMsg = "新增失败!";
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }