Пример #1
0
        /// <summary>
        /// 同步处理,递归算法
        /// </summary>
        /// <param name="totCount"></param>
        /// <param name="wid"></param>
        /// <param name="accessToken"></param>
        /// <param name="nexOpenid"></param>
        /// <param name="updateTime"></param>
        public string  SysPersonFun(int totCount, int wid, string accessToken, string nexOpenid, DateTime updateTime)
        {
            string ret = "";

            OpenIdResultJson gJson = Senparc.Weixin.MP.AdvancedAPIs.User.Get(accessToken, nexOpenid);

            List <string> openidStr = gJson.data.openid;//此次拉取的openid字符串

            totCount += InsertUserInfo(wid, accessToken, openidStr, updateTime);


            if (gJson.next_openid != "" && gJson.count == 1000)
            {
                SysPersonFun(totCount, wid, accessToken, gJson.next_openid, updateTime);
            }
            else
            {
                int sjTtCount = gJson.total;
                if (sjTtCount == totCount)
                {
                    //将此次同步的日期更新到设置表里
                    BLL.wx_crm_setting setBll = new BLL.wx_crm_setting();
                    setBll.UpdatePersonSysDate(wid, totCount, updateTime);
                    ret = "粉丝同步成功!";
                }
                else
                {
                    ret = "粉丝同步失败!";
                }
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// 同步处理,递归算法
        /// </summary>
        /// <param name="totCount"></param>
        /// <param name="wid"></param>
        /// <param name="accessToken"></param>
        /// <param name="nexOpenid"></param>
        /// <param name="updateTime"></param>
        public string SysPersonFun(int totCount, string wxid, string accessToken, string nexOpenid, DateTime updateTime)
        {
            string           ret       = "";
            OpenIdResultJson gJson     = UserApi.Get(accessToken, nexOpenid);
            List <string>    openidStr = gJson.data.openid;//此次拉取的openid字符串

            totCount += InsertUserInfo(wxid, accessToken, openidStr, updateTime);
            if (gJson.next_openid != "" && gJson.count == 1000)
            {
                SysPersonFun(totCount, wxid, accessToken, gJson.next_openid, updateTime);
            }
            else
            {
                int sjTtCount = gJson.total;
                if (sjTtCount == totCount)
                {
                    //将此次同步的日期更新到设置表里
                    WxBaseConfigEntity weixin = config.GetDefaultConfig();
                    weixin.PersonSynDate = updateTime;
                    weixin.OpenidCount   = totCount;
                    config.SubmitForm(weixin);
                    ret = "粉丝同步成功!";
                }
                else
                {
                    ret = "粉丝同步失败!";
                }
            }
            return(ret);
        }
Пример #3
0
        /// <summary>
        /// 获取关注着OpenId信息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static OpenIdResultJson User_Get(string accessToken)
        {
            OpenIdResultJson data = User_Get(accessToken, null);

            //while (data.count > 0)
            //{
            //    var result = Get(accessToken, data.next_openid);
            //    data.data.openid.AddRange(result.data.openid);
            //    data.next_openid = result.next_openid;
            //    data.count = result.count;
            //}
            return(User_Get(accessToken, null));
        }
Пример #4
0
        protected void btnSendAll_Click(object sender, EventArgs e)
        {
            string tempStr = new WeixinHelpService().GetTemp(Server);

            var accessToken = AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["LongNameAppId"],
                                                               WebConfigurationManager.AppSettings["LongNameAppSecret"]);
            OpenIdResultJson json = UserApi.Get(accessToken, "");

            var imgResult = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);

            SendImg(accessToken, imgResult);
            imgResult = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);

            SendGroupMessage(tempStr, accessToken, imgResult, "服务号");
        }
Пример #5
0
        /// <summary>
        /// 获取所有关注者的OpenId信息
        /// </summary>
        /// <returns></returns>
        private static OpenIdResultJson GetAllOpenIds()
        {
            string           accessToken  = AccessTokenContainer.TryGetToken(ConfigurationManager.AppSettings["appID"], ConfigurationManager.AppSettings["appsecret"]);
            OpenIdResultJson openIdResult = User.List(accessToken, null);

            while (!string.IsNullOrWhiteSpace(openIdResult.next_openid))
            {
                OpenIdResultJson tempResult = User.List(accessToken, openIdResult.next_openid);
                openIdResult.next_openid = tempResult.next_openid;
                if (tempResult.data != null && tempResult.data.openid != null)
                {
                    openIdResult.data.openid.AddRange(tempResult.data.openid);
                }
            }
            return(openIdResult);
        }
Пример #6
0
        protected void btnSendMessage_Click(object sender, EventArgs e)
        {
            //获取 accessToken
            var accessToken = AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["LongNameAppId"],
                                                               WebConfigurationManager.AppSettings["LongNameAppSecret"]);


            OpenIdResultJson json = UserApi.Get(accessToken, "");

            txtResult.Text += json.count;

            foreach (var item in json.data.openid)
            {
                var userinfo = UserApi.Info(accessToken, item);
                txtResult.Text += item + " : " + userinfo.nickname + " " + userinfo.sex.ToString() + "   ";
            }

            var result = GroupsApi.Get(accessToken);
            List <GroupsJson_Group> list = result.groups;
            string content = "文本内容<a href='http://www.baidu.com'>百度</a>";
            string groupId = "100";//分组Id


            var dataSevice = new DataAccessSerive();
            var jobList    = dataSevice.GetTopJobInfoList();

            if (jobList.Count > 0)
            {
                List <Article> articles = new List <Article>();
                int            i        = 0;
                foreach (var job in jobList)
                {
                    string imgUrl = string.Format("{0}/image/{1}.jpg", WebConfigurationManager.AppSettings["domain"], i);
                    var    art1   = new Article()
                    {
                        Title       = job.ComName + "诚聘" + job.JobName,
                        Url         = WebConfigurationManager.AppSettings["domain"] + "/html/detail.html?id=" + job.JobId,
                        PicUrl      = imgUrl,
                        Description = ""
                    };
                    articles.Add(art1);
                    i++;
                }
                var rest = Senparc.Weixin.MP.AdvancedAPIs.Custom.CustomApi.SendNews(accessToken, "oJvzIt8go_mNhCAVE-M0D5EexLpU", articles);
            }
        }
Пример #7
0
        /// <summary>
        /// 获取所有微信关注用户的OpenID
        /// </summary>
        /// <param name="strAccessToken"></param>
        /// <returns></returns>
        public List <String> GetWCUserOpenID(string strAccessToken)
        {
            //汇总结果结合
            List <string> pListAllResultOpenID = new List <string>();
            //调用SDK API
            OpenIdResultJson result = Senparc.Weixin.MP.AdvancedAPIs.User.UserApi.Get(strAccessToken, string.Empty);

            pListAllResultOpenID.AddRange(result.data.openid);

            while (!String.IsNullOrEmpty(result.next_openid))
            {
                result = Senparc.Weixin.MP.AdvancedAPIs.User.UserApi.Get(strAccessToken, result.next_openid);
                if (result.data != null)
                {
                    pListAllResultOpenID.AddRange(result.data.openid);
                }
            }
            return(pListAllResultOpenID);
        }
Пример #8
0
        /// <summary>
        /// (基础方法)获得所有关注用户的openid字符串
        /// 递归算法
        /// </summary>
        /// <param name="nexOpenid"></param>
        /// <param name="openidList"></param>
        private void getNextUserOpenid(int wid, string nexOpenid, IList <string> openidList)
        {
            string           err          = "";
            string           access_token = WeiXinCRMComm.getAccessToken(wid, out err);
            OpenIdResultJson openidJson   = UserApi.Get(access_token, nexOpenid);

            if (openidJson == null || openidJson.count <= 0)
            {
                //return openidJson.data.openid;
                return;
            }
            else
            {
                for (int i = 0; i < openidJson.data.openid.Count; i++)
                {
                    openidList.Add(openidJson.data.openid[i]);
                }
                getNextUserOpenid(wid, openidJson.next_openid, openidList);
            }
        }
Пример #9
0
        /// <summary>
        /// 获得所有关注用户的openid字符串(别的方法调用此方法)
        /// </summary>
        /// <returns></returns>
        private IList <string> baseUserOpenid(int wid, out string error)
        {
            IList <string> ret = new List <string>();

            string access_token = WeiXinCRMComm.getAccessToken(wid, out error);

            if (error != "")
            {
                return(null);
            }
            OpenIdResultJson openidJson = UserApi.Get(access_token, "");

            if (openidJson.count == openidJson.total)
            {
                ret = openidJson.data.openid;
            }
            else
            {
                getNextUserOpenid(wid, openidJson.next_openid, ret);
            }

            return(ret);
        }
Пример #10
0
        /// <summary>
        /// 获得所有关注用户的openid字符串(别的方法调用此方法)
        /// </summary>
        /// <returns></returns>
        private IList <string> baseUserOpenid(int wid, out string error)
        {
            IList <string> ret = new List <string>();

            string access_token = getAccessToken(wid, out error);

            if (error != "")
            {
                return(null);
            }
            OpenIdResultJson openidJson = Senparc.Weixin.MP.AdvancedAPIs.User.Get(access_token, "");

            if (openidJson.count == openidJson.total)
            {
                ret = openidJson.data.openid;
            }
            else
            {
                getNextUserOpenid(wid, openidJson.next_openid, ret);
            }

            return(ret);
        }
Пример #11
0
        private async Task ReFreshFans(MpAccount model)
        {
            var mpId = model.Id;

            #region 初始化
            var sb = new StringBuilder();
            int stoptick = 0, stopcount = 100;
            var fanssavestr = @"
if not exists(select * from MpFans where MpID='{0}' and OpenID='{1}')
insert into MpFans ([MpID],[OpenID],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadImgUrl],[SubscribeTime],[UnionID],[WxGroupID],[IsFans],[UpdateTime],CreationTime,IsDeleted) values ({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{12}','{13}',getdate(),getdate(),0)
else
update MpFans SET [MpID]='{0}',[OpenID]='{1}',[NickName]='{2}',[Sex]='{3}',[Language]='{4}',[City]='{5}',[Province]='{6}',[Country]='{7}',[HeadImgUrl]='{8}',[SubscribeTime]='{9}',[UnionID]='{10}',[WxGroupID]='{12}',[IsFans]='{13}',[UpdateTime]=getdate(),IsDeleted=0 WHERE MpID='{0}' and OpenID='{1}'
";
            #endregion

            #region 更新用户
            #region 更新前10000个用户
            OpenIdResultJson fansopenids  = null;
            string           _accesstoken = "";
            try
            {
                _accesstoken = (await StaticObjects.GetAccessToken(model.TaskAccessToken)).access_token;
                fansopenids  = UserApi.Get(_accesstoken, "");
            }
            catch (Exception e)
            {
                _accesstoken = (await StaticObjects.GetAccessToken(model.TaskAccessToken, 1)).access_token;
                //LogWriter.Error(string.Format("获取MpID为{0}的openid报错,错误信息:{1}", mpId, ex));
                fansopenids = UserApi.Get(_accesstoken, "");
            }
            DateTime now = DateTime.Now;
            if (fansopenids.count > 0)
            {
                foreach (var id in fansopenids.data.openid)
                {
                    UserInfoJson wxinfo = null;
                    try
                    {
                        wxinfo = UserApi.Info((await StaticObjects.GetAccessToken(model.TaskAccessToken)).access_token, id);
                    }
                    catch
                    {
                        //LogWriter.Error(string.Format("获取MpID为{0},openid为{1}的用户信息报错,错误信息:{2}", mpId.ToString(), id, ex));
                        wxinfo = UserApi.Info((await StaticObjects.GetAccessToken(model.TaskAccessToken, 1)).access_token, id);
                    }

                    sb.AppendFormat(fanssavestr, mpId, id,
                                    DbTool.ToSqlParamString(wxinfo.nickname), wxinfo.sex, DbTool.ToSqlParamString(wxinfo.language),
                                    DbTool.ToSqlParamString(wxinfo.city), DbTool.ToSqlParamString(wxinfo.province),
                                    DbTool.ToSqlParamString(wxinfo.country), DbTool.ToSqlParamString(wxinfo.headimgurl),
                                    DateTimeHelper.GetDateTimeFromXml(wxinfo.subscribe_time), DbTool.ToSqlParamString(wxinfo.unionid),
                                    DbTool.ToSqlParamString(wxinfo.remark), wxinfo.groupid, wxinfo.subscribe);
                    stoptick++;
                    if (stoptick % stopcount == 0 || stoptick == fansopenids.count)
                    {
                        if (sb.Length > 0)
                        {
                            StaticObjects.db.ExcuteNonQuery(sb.ToString(), null, false);
                        }
                        sb.Clear();
                    }
                }
            }
            #endregion

            #region while循环更新后续所有用户
            while (!string.IsNullOrEmpty(fansopenids.next_openid))
            {
                try
                {
                    fansopenids = UserApi.Get((await StaticObjects.GetAccessToken(model.TaskAccessToken)).access_token, fansopenids.next_openid);
                }
                catch
                {
                    //LogWriter.Error(string.Format("获取MpID为{0}的openid报错,nextopenid为{1},错误信息:{2}", mpId, fansopenids.next_openid, ex));
                    fansopenids = UserApi.Get((await StaticObjects.GetAccessToken(model.TaskAccessToken, 1)).access_token, fansopenids.next_openid);
                }
                if (fansopenids.count > 0)
                {
                    foreach (var id in fansopenids.data.openid)
                    {
                        UserInfoJson wxinfo = null;
                        try
                        {
                            wxinfo = UserApi.Info((await StaticObjects.GetAccessToken(model.TaskAccessToken)).access_token, id);
                        }
                        catch
                        {
                            //LogWriter.Error(string.Format("获取MpID为{0},openid为{1}的用户信息报错,错误信息:{2}", mpId, id, ex));
                            wxinfo = UserApi.Info((await StaticObjects.GetAccessToken(model.TaskAccessToken, 1)).access_token, id);
                        }

                        sb.AppendFormat(fanssavestr, mpId, id,
                                        DbTool.ToSqlParamString(wxinfo.nickname), wxinfo.sex, DbTool.ToSqlParamString(wxinfo.language),
                                        DbTool.ToSqlParamString(wxinfo.city), DbTool.ToSqlParamString(wxinfo.province),
                                        DbTool.ToSqlParamString(wxinfo.country), DbTool.ToSqlParamString(wxinfo.headimgurl),
                                        DateTimeHelper.GetDateTimeFromXml(wxinfo.subscribe_time), DbTool.ToSqlParamString(wxinfo.unionid),
                                        DbTool.ToSqlParamString(wxinfo.remark), wxinfo.groupid, wxinfo.subscribe);
                        stoptick++;
                        if (stoptick % stopcount == 0 || stoptick == fansopenids.count)
                        {
                            if (sb.Length > 0)
                            {
                                StaticObjects.db.ExcuteNonQuery(sb.ToString(), null, false);
                            }
                            sb.Clear();
                        }
                    }
                }
            }
            #endregion


            //没更新到的用户设为取消关注
            sb.AppendFormat("update MpFans set IsFans='0' where MpID='{0}' and UpdateTime<'{1}'", mpId, now.AddDays(-1));
            #endregion

            if (sb.Length > 0)
            {
                StaticObjects.db.ExcuteNonQuery(sb.ToString(), null, false);
            }
            //LogWriter.Info(string.Format("更新数量{0},更新完毕", stoptick));
        }
Пример #12
0
        /// <summary>
        /// 更新微信用户
        /// </summary>
        /// <param name="MpID"></param>
        private void ReFreshFans(string MpID)
        {
            #region 初始化
            var sb = new StringBuilder();
            int stoptick = 0, stopcount = 100; ;
            var groupdt = StaticObjects.wechatdh.ExecuteTable(string.Format("select ID,WxGroupID,Length from MpGroup where MpID='{0}'", MpID)).AsEnumerable()
                .Select(c => new
                {
                    ID = DbTool.ToString(c["ID"]),
                    WxGroupID = DbTool.ToNullInt(c["WxGroupID"]),
                    Length = DbTool.ToInt(c["Length"]),
                });
            var fanssavestr = @"
if not exists(select * from MpFans where MpID='{1}' and OpenID='{2}')
insert into MpFans ([ID],[MpID],[OpenID],[NickName],[Sex],[Language],[City],[Province],[Country],[HeadImgUrl],[SubscribeTime],[UniionID],[Remark],[WxGroupID],[GroupID],[IsFans],[UpdateTime]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate())
else
update MpFans SET [MpID]='{1}',[OpenID]='{2}',[NickName]='{3}',[Sex]='{4}',[Language]='{5}',[City]='{6}',[Province]='{7}',[Country]='{8}',[HeadImgUrl]='{9}',[SubscribeTime]='{10}',[UniionID]='{11}',[Remark]='{12}',[WxGroupID]='{13}',[GroupID]='{14}',[IsFans]='{15}',[UpdateTime]=getdate() WHERE MpID='{1}' and OpenID='{2}'";
            #endregion

            #region 更新用户
            #region 更新前10000个用户
            OpenIdResultJson fansopenids = null;
            try
            {
                fansopenids = UserApi.Get(WxApi.GetAccessToken(MpID), "");
            }
            catch (Exception ex)
            {
                LogWriter.Error(ex, string.Format("获取MpID为{0}的openid报错", MpID));
                fansopenids = UserApi.Get(WxApi.GetAccessToken(MpID, true), "");
            }
            DateTime now = DateTime.Now;
            if (fansopenids.count > 0)
            {
                foreach (var id in fansopenids.data.openid)
                {
                    UserInfoJson wxinfo = null;
                    try
                    {
                        wxinfo = UserApi.Info(WxApi.GetAccessToken(MpID), id);
                    }
                    catch (Exception ex)
                    {
                        LogWriter.Error(ex, string.Format("获取MpID为{0},openid为{1}的用户信息报错", MpID, id));
                        wxinfo = UserApi.Info(WxApi.GetAccessToken(MpID, true), id);
                    }
                    var group = groupdt.Where(c => c.WxGroupID == wxinfo.groupid).FirstOrDefault();
                    if (group == null)
                        continue;
                    sb.AppendFormat(fanssavestr, DbTool.CreateGuid(), MpID, id,
                        DbTool.ToSqlParamString(wxinfo.nickname), wxinfo.sex, DbTool.ToSqlParamString(wxinfo.language),
                        DbTool.ToSqlParamString(wxinfo.city), DbTool.ToSqlParamString(wxinfo.province),
                        DbTool.ToSqlParamString(wxinfo.country), DbTool.ToSqlParamString(wxinfo.headimgurl),
                        DateTimeHelper.GetDateTimeFromXml(wxinfo.subscribe_time), DbTool.ToSqlParamString(wxinfo.unionid),
                        DbTool.ToSqlParamString(wxinfo.remark), wxinfo.groupid, group.ID, 1);
                    stoptick++;
                    if (stoptick % stopcount == 0)
                    {
                        StaticObjects.wechatdh.ExecuteNonQuery(sb.ToString(), 36000);
                        sb.Clear();
                    }
                }
            }
            #endregion

            #region while循环更新后续所有用户
            while (!string.IsNullOrEmpty(fansopenids.next_openid))
            {
                try
                {
                    fansopenids = UserApi.Get(WxApi.GetAccessToken(MpID), fansopenids.next_openid);
                }
                catch (Exception ex)
                {
                    LogWriter.Error(ex, string.Format("获取MpID为{0}的openid报错,nextopenid为{1}", MpID, fansopenids.next_openid));
                    fansopenids = UserApi.Get(WxApi.GetAccessToken(MpID, true), fansopenids.next_openid);
                }
                if (fansopenids.count > 0)
                {
                    foreach (var id in fansopenids.data.openid)
                    {
                        UserInfoJson wxinfo = null;
                        try
                        {
                            wxinfo = UserApi.Info(WxApi.GetAccessToken(MpID), id);
                        }
                        catch (Exception ex)
                        {
                            LogWriter.Error(ex, string.Format("获取MpID为{0},openid为{1}的用户信息报错", MpID, id));
                            wxinfo = UserApi.Info(WxApi.GetAccessToken(MpID, true), id);
                        }
                        var group = groupdt.Where(c => c.WxGroupID == wxinfo.groupid).FirstOrDefault();
                        if (group == null)
                            continue;
                        sb.AppendFormat(fanssavestr, DbTool.CreateGuid(), MpID, id,
                            DbTool.ToSqlParamString(wxinfo.nickname), wxinfo.sex, DbTool.ToSqlParamString(wxinfo.language),
                            DbTool.ToSqlParamString(wxinfo.city), DbTool.ToSqlParamString(wxinfo.province),
                            DbTool.ToSqlParamString(wxinfo.country), DbTool.ToSqlParamString(wxinfo.headimgurl),
                            DateTimeHelper.GetDateTimeFromXml(wxinfo.subscribe_time), DbTool.ToSqlParamString(wxinfo.unionid),
                            DbTool.ToSqlParamString(wxinfo.remark), wxinfo.groupid, group.ID, 1);
                        stoptick++;
                        if (stoptick % stopcount == 0)
                        {
                            StaticObjects.wechatdh.ExecuteNonQuery(sb.ToString(), 36000);
                            sb.Clear();
                        }
                    }
                }
            }
            #endregion

            //没更新到的用户设为取消关注
            sb.AppendFormat("update MpFans set IsFans='0' where MpID='{0}' and UpdateTime<'{1}'", MpID, now.AddDays(-1));
            #endregion

            StaticObjects.wechatdh.ExecuteNonQuery(sb.ToString(), 36000);
            LogWriter.Info(string.Format("更新数量{0},更新完毕", stoptick));
        }
Пример #13
0
        public void PushNews(string accessToken, string webPath, string tempStr)
        {
            OpenIdResultJson json = UserApi.Get(accessToken, "");
            var imgResult         = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);
            var DircetPath        = Environment.CurrentDirectory + "/image/";

            if (!Directory.Exists(DircetPath))
            {
                Directory.CreateDirectory(DircetPath);
            }

            for (int i = 0; i < 6; i++)
            {
                string imgName = string.Format("send{0}.jpg", i);
                if (imgResult.item.Find(p => p.name == imgName) == null)
                {
                    var imgPath  = webPath + "/image/" + imgName;
                    var filePath = DircetPath + "/image/" + imgName;
                    CommonUtility.HttpUtility.DownloadFile(imgPath, filePath);
                    var mediaId = MediaApi.UploadForeverMedia(accessToken, filePath).media_id;
                }
            }
            imgResult = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);


            string sendCountTxtUrl = webPath + "/" + "sendcount.txt";
            var    sendCountTxt    = CommonUtility.HttpUtility.Get(sendCountTxtUrl);
            var    sendCount       = int.Parse(sendCountTxt);

            NewsModel[] newsList = new NewsModel[sendCount];

            var dataSevice = new DataAccessSerive();
            var jobList    = dataSevice.GetTopJobInfoList();

            if (jobList.Count > 0)
            {
                List <Article> articles = new List <Article>();
                int            i        = 0;
                string         imgName;
                foreach (var job in jobList)
                {
                    if (i == sendCount)
                    {
                        break;
                    }
                    string domain  = ConfigurationManager.AppSettings.Get("domain");
                    string website = ConfigurationManager.AppSettings.Get("website");
                    imgName = "send" + i.ToString() + ".jpg";
                    string imgUrl    = string.Format("{0}/image/{1}", domain, imgName);
                    var    jobDetail = dataSevice.GetJobDetail(job.JobId);
                    var    news      = new NewsModel()
                    {
                        author  = "",
                        content = tempStr.Replace("[ComName]", job.ComName)
                                  .Replace("[ComBrief]", jobDetail.ComBrief)
                                  .Replace("[DetailPalce]", jobDetail.DetailPalce)
                                  .Replace("[LinkMan]", jobDetail.LinkMan)
                                  .Replace("[Phone]", jobDetail.Phone)
                                  .Replace("[JobName]", jobDetail.JobName)
                                  .Replace("[JobType]", jobDetail.JobType)
                                  .Replace("[LowMoney]", jobDetail.LowMoney)
                                  .Replace("[HrNum]", jobDetail.HrNum)
                                  .Replace("[Edu]", jobDetail.Edu)
                                  .Replace("[RegisterDate]", jobDetail.RegisterDate)
                                  .Replace("[EffectDate]", jobDetail.EffectDate)
                                  .Replace("[Other]", jobDetail.Other)
                                  .Replace("[Sex]", jobDetail.Sex)
                        ,
                        //content_source_url = domain + "/html/detail.html?id=" + job.JobId,
                        content_source_url = website,
                        digest             = job.ComName + "诚聘" + job.JobName,
                        show_cover_pic     = "0",
                        thumb_media_id     = imgResult.item.Find(p => p.name == imgName).media_id,
                        title = job.ComName + "诚聘" + job.JobName
                    };
                    newsList[i] = news;
                    i++;
                }
                UploadForeverMediaResult mediaResult = MediaApi.UploadNews(accessToken, 100000, newsList);
                try
                {
                    if (isDebug != "1")
                    {
                        GroupMessageApi.SendGroupMessageByGroupId(accessToken, "-1", mediaResult.media_id, GroupMessageType.mpnews, true);
                    }
                    Console.WriteLine("素材提交推送  推送成功");
                    logger.Info(DateTime.Now.ToString() + " 素材提交推送  推送成功");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("素材提交推送  推送失败 " + ex.Message);
                    var MailService = new MailSendFunc();
                    MailService.SendMail("*****@*****.**", ex.Message, "素材提交推送异常", mailCfg);
                    logger.ErrorException(DateTime.Now.ToString() + "素材提交推送失败 " + ex.Message, ex);
                }
            }
        }
Пример #14
0
        /// <summary>
        /// 微信用户信息同步方法
        /// </summary>
        /// <returns></returns>
        private static void SynchronizeWeixinUser()
        {
            OpenIdResultJson weixinOpenIds = GetAllOpenIds();

            //获取已同步到数据库中的微信用户的OpenId
            List <string> dataOpenList     = new WeixinUserInfoDll().LoadEntities(p => p.ID > 0).Select(e => e.OpenId).ToList();
            List <string> insertOpenIdList = new List <string>();
            List <string> updateOpenIdList = new List <string>();
            List <string> deleteOpenIdList = new List <string>();

            //判断每个微信用户需要执行的操作
            for (int index = 0; index < weixinOpenIds.data.openid.Count; index++)
            {
                var weixinOpenId = weixinOpenIds.data.openid[index];
                var user         = dataOpenList.Find(e => e == weixinOpenId);
                if (user == null)
                {
                    //不存在数据库中的,插入
                    insertOpenIdList.Add(weixinOpenId);
                }
                else
                {
                    //已存在数据库中的,修改
                    updateOpenIdList.Add(weixinOpenId);
                }
            }
            //已取消关注该微信公众号的,删除
            insertOpenIdList.ForEach(e => dataOpenList.Remove(e));
            updateOpenIdList.ForEach(e => dataOpenList.Remove(e));
            deleteOpenIdList.AddRange(dataOpenList);

            //插入失败的openId列表,用于失败重试
            List <string> failedInsert = new List <string>();
            //修改失败的openId列表,用于失败重试
            List <string> failedUpdate = new List <string>();

            //插入新的微信用户
            foreach (var openId in insertOpenIdList)
            {
                ExecuteWeixinUser(openId, new WeixinUserInfoDll().Insert, failedInsert);
            }
            //更新已有微信用户
            foreach (var openId in updateOpenIdList)
            {
                ExecuteWeixinUser(openId, new WeixinUserInfoDll().Update, failedUpdate);
            }
            if (deleteOpenIdList.Count > 0)
            {
                //删除已取消关注该微信公众号的微信用户
                foreach (var openId in deleteOpenIdList)
                {
                    new WeixinUserInfoDll().DeleteByOpenId(openId);
                }
            }
            //插入失败,重试一次
            if (failedInsert.Count > 0)
            {
                List <string> fail = new List <string>();
                foreach (var openId in failedInsert)
                {
                    ExecuteWeixinUser(openId, new WeixinUserInfoDll().Insert, fail);
                }
            }
            //更新失败,重试一次
            if (failedUpdate.Count > 0)
            {
                List <string> fail = new List <string>();
                foreach (var openId in failedInsert)
                {
                    ExecuteWeixinUser(openId, new WeixinUserInfoDll().Update, fail);
                }
            }
        }