Exemple #1
0
        private bool DoAdd()
        {
            bool   result = false;
            string name   = txtTitle.Text.Trim();

            Model.wx_userweixin weixin = GetWeiXinCode();
            WeiXinCRMComm       wcr    = new WeiXinCRMComm();
            string err         = "";
            string accessToken = wcr.getAccessToken(weixin.id, out err);

            if (err.Trim() != "")
            {
                JscriptMsg(err, "", "Error");
                return(false);
            }
            WxJsonResult wjr = Groups.Create(accessToken, name);

            if (wjr.errcode.ToString() == "请求成功")
            {
                result = true;
            }
            if (result)
            {
                BLL.wx_crm_group   gBll  = new BLL.wx_crm_group();
                Model.wx_crm_group group = new Model.wx_crm_group();
                group.wid   = weixin.id;
                group.id    = ((Senparc.Weixin.MP.AdvancedAPIs.CreateGroupResult)(wjr)).group.id;
                group.name  = name;
                group.count = 0;
                gBll.Add(group);
            }
            return(result);
        }
Exemple #2
0
        //同步
        protected void btnSyn_Click(object sender, EventArgs e)
        {
            string err = "";

            Model.wx_userweixin weixin = GetWeiXinCode();
            WeiXinCRMComm       wcr    = new WeiXinCRMComm();
            string accessToken         = wcr.getAccessToken(weixin.id, out err);

            if (err != "")
            {
                return;
            }
            GroupsJson gJson            = Groups.Get(accessToken);
            List <GroupsJson_Group> gjg = gJson.groups;

            #region   将数据插入到数据库里
            BLL.wx_crm_group   gBll  = new BLL.wx_crm_group();
            Model.wx_crm_group group = new Model.wx_crm_group();
            try
            {
                gBll.DeleteByWid(weixin.id);

                int ttCount     = gjg.Count;
                int insertCount = 0;
                for (int i = 0; i < gjg.Count; i++)
                {
                    group.id    = gjg[i].id;
                    group.name  = gjg[i].name;
                    group.count = gjg[i].count;
                    group.wid   = weixin.id;
                    bool succ = gBll.Add(group);
                    if (succ)
                    {
                        insertCount++;
                    }
                }
                if (ttCount == insertCount)
                {
                    //将此次同步的日期更新到设置表里
                    BLL.wx_crm_setting setBll = new BLL.wx_crm_setting();
                    setBll.UpdateGroupSysDate(weixin.id, ttCount, DateTime.Now);
                    JscriptMsg("分组同步成功!", "group_list.aspx", "Success");
                }
                else
                {
                    JscriptMsg("分组同步失败!", "", "Error");
                    return;
                }
            }
            catch (Exception ex)
            {
                JscriptMsg("分组同步失败!" + ex.Message, "", "Error");
                return;
            }
            #endregion
        }