Esempio n. 1
0
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("开始重建");
            var runtimeResponse = CheckIsOpenWithDescription("RebuildUserWxAuthInfo");
            int maxpkid         = 0;
            int minpkid         = 0;

            if (runtimeResponse != null && runtimeResponse.Item1 && !string.IsNullOrEmpty(runtimeResponse.Item2) && runtimeResponse.Item2.Split(',').Count() >= 2)
            {
                var splitResult = runtimeResponse.Item2.Split(',');
                if (int.TryParse(splitResult[0], out minpkid) && int.TryParse(splitResult[1], out maxpkid))
                {
                    int pagesize    = 100;
                    var totalCounts = SelectOpenIdCountsByMaxPkid(minpkid, maxpkid);
                    Logger.Info($"开始刷新.共{totalCounts}个.");
                    if (totalCounts != 0)
                    {
                        int pageCounts = (totalCounts / pagesize) + 1;
                        for (int i = 0; i < pageCounts; i++)
                        {
                            Logger.Info($"开始刷新{i}批次.共{totalCounts}个.{pageCounts}批次.");
                            var openids = SelectOpenIdByMaxPkid(ref minpkid, maxpkid, pagesize);
                            if (openids != null && openids.Any())
                            {
                                foreach (var kvp in openids)
                                {
                                    using (var client = new Tuhu.Service.Push.WeiXinPushClient())
                                    {
                                        var result = client.LogWxUserOpenIDWithChannel(kvp.Key, true, kvp.Value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Logger.Info("结束重建");
        }
Esempio n. 2
0
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("开始记录微信openid");
            var platform     = 0;
            var tempplatform = GetSyncWxUserPlatform();

            if (!tempplatform.Item1)
            {
                Logger.Info($"开关已关");
                return;
            }
            if (!int.TryParse(tempplatform.Item2, out platform))
            {
                Logger.Warn($"{tempplatform}--platform非法");
                return;
            }
            try
            {
                var wxconfigs  = SelectWxConfigs();
                var syncconfig = wxconfigs.FirstOrDefault(x => x.platform == platform);
                if (syncconfig == null)
                {
                    Logger.Warn($"{tempplatform}--配置未找到");
                    return;
                }
                var maxwxopenid = GetMaxJobOpenId(syncconfig.platform);
                var openids     = GetWeiXinOpenID(syncconfig.channel, maxwxopenid);
                int count       = 0;
                if (openids != null && openids.Item2 != null && openids.Item2.Any())
                {
                    Logger.Info($"{syncconfig.channel}记录微信openid,获得{openids.Item2.Count()}个");
                    bool iserror = false;
                    foreach (var openid in openids.Item2)
                    {
                        try
                        {
                            count += 1;
                            if (count % 100 == 0)
                            {
                                tempplatform = GetSyncWxUserPlatform();
                                if (!tempplatform.Item1)
                                {
                                    Logger.Info($"开关已关");
                                    return;
                                }
                            }
                            using (var client = new Tuhu.Service.Push.WeiXinPushClient())
                            {
                                var result = client.LogWxUserOpenIDWithChannel(openid, true, syncconfig.channel);
                                result.ThrowIfException(true);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            iserror = true;
                            Logger.Warn($"同步微信用户ex:{ex}");
                        }
                    }
                    UpdateMaxJobOpenId(syncconfig.platform, openids.Item1);
                    if (!iserror)
                    {
                        Logger.Info($"成功结束同步{syncconfig.channel}.");
                    }
                    Logger.Info($"结束同步{syncconfig.channel}.");
                }
            }
            catch (System.Exception ex)
            {
                Logger.Warn(ex);
            }
        }