public async Task <IEnumerable <WxConfig> > SelectWxConfigsAsync()
        {
            try
            {
                using (var client = new Tuhu.Service.Push.WeiXinPushClient())
                {
                    var result = await client.SelectWxConfigsAsync();

                    if (result.Success)
                    {
                        return(result.Result?.Where(_ => _.platform > 1).ToList() ?? new List <WxConfig>());
                    }
                    else
                    {
                        return(new List <WxConfig>());
                    }
                }
            }
            catch (Exception ex)
            {
                var exception = new DownloadAppException(1, "SelectWxConfigsAsync", ex);
                Logger.Log(Level.Error, exception, "SelectWxConfigsAsync");
                return(new List <WxConfig>());
            }
        }
示例#2
0
 public static IEnumerable <WxConfig> SelectWxConfigs()
 {
     using (var client = new Tuhu.Service.Push.WeiXinPushClient())
     {
         var result = client.SelectWxConfigs();
         return(result.Result);
     }
 }
示例#3
0
 public static string GetWeiXinAccessToken(string channel)
 {
     using (var client = new Tuhu.Service.Push.WeiXinPushClient())
     {
         var result = client.SelectWxAccessToken(channel);
         result.ThrowIfException(true);
         return(result.Result);
     }
 }
        public static async Task <IEnumerable <WxTemplateInfo> > SelectAllWxAppTemplatesAsync(int platform)
        {
            using (var client = new Tuhu.Service.Push.WeiXinPushClient())
            {
                var result = await client.SelectAllWxAppTemplatesAsync(platform);

                result.ThrowIfException(true);
                var datas = result.Result;
                return(datas);
            }
        }
        public static async Task <IEnumerable <WxConfig> > SelectAllWxAppConfigAsync()
        {
            using (var client = new Tuhu.Service.Push.WeiXinPushClient())
            {
                var result = await client.SelectWxConfigsAsync();

                result.ThrowIfException(true);
                var datas = result.Result;
                return(datas?.ToList());
                //return datas?.Where(x => x.Type == "WX_APP");
            }
        }
示例#6
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("结束重建");
        }
示例#7
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);
            }
        }