Exemple #1
0
        /// <summary>
        /// 此方法可以避免死锁
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> NoDeadLockTest()
        {
            var result = await RequestUtility.HttpGetAsync("https://sdk.weixin.senparc.com",
                                                           cookieContainer : null);

            return(Content(result));
        }
Exemple #2
0
        /// <summary>
        /// 此方法会引发死锁,需要重启服务
        /// </summary>
        /// <returns></returns>
        public ActionResult DeadLockTest()
        {
            var result =
                RequestUtility.HttpGetAsync("https://sdk.weixin.senparc.com",
                                            cookieContainer: null).Result;

            return(Content(result));
        }
Exemple #3
0
        /// <summary>
        /// 【异步方法】使用GET请求测试URL和TOKEN是否可用
        /// </summary>
        /// <param name="serviceProvider">.NET Core 的 ServiceProvider(.NET Framework 可设为 null)</param>
        /// <param name="url"></param>
        /// <param name="token"></param>
        /// <param name="timeOut">代理请求超时时间(毫秒)</param>
        /// <returns></returns>
        public static async Task <bool> CheckUrlAndTokenAsync(IServiceProvider serviceProvider, string url, string token, int timeOut = 2000)
        {
            try
            {
                string timestamp = SystemTime.Now.Ticks.ToString();
                string nonce     = "GodBlessYou";
                string echostr   = Guid.NewGuid().ToString("n");
                string signature = CheckSignatureWeChat.GetSignature(timestamp, nonce, token);
                url += string.Format("{0}signature={1}&timestamp={2}&nonce={3}&echostr={4}",
                                     url.Contains("?") ? "&" : "?", signature.AsUrlData(), timestamp.AsUrlData(), nonce.AsUrlData(), echostr.AsUrlData());

                var responseStr = await RequestUtility.HttpGetAsync(serviceProvider, url, encoding : null, timeOut : timeOut);

                return(echostr == responseStr);
            }
            catch
            {
                return(false);
            }
        }
Exemple #4
0
        public async Task <IActionResult> Index()
        {
            //测试Get方法
            var html = await RequestUtility.HttpGetAsync("https://www.baidu.com", refererUrl : "https://sdk.weixin.senparc.com");


            #region 获取版本信息


            Func <string, FileVersionInfo> getFileVersionInfo = dllFileName =>
#if NET45
                                                                FileVersionInfo.GetVersionInfo(Server.MapPath("~/bin/" + dllFileName));
#elif NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_0 || NETCOREAPP2_1
            {
                var dllPath =
                    Senparc.Weixin.MP.Sample.CommonService.Utilities.Server.GetMapPath(
                        System.IO.Path.Combine(AppContext.BaseDirectory, dllFileName)); //dll所在目录
                return(FileVersionInfo.GetVersionInfo(dllPath));
            };
#else
            {
                var dllPath = Server.GetMapPath("~/bin/[YOUR DIR]/" + dllFileName);
                return(FileVersionInfo.GetVersionInfo(dllPath));
            };
#endif

            Func <FileVersionInfo, string> getDisplayVersion = fileVersionInfo =>
                                                               Regex.Match(fileVersionInfo.FileVersion, @"\d+\.\d+\.\d+").Value;

            TempData["WeixinVersion"]    = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.dll"));
            TempData["MpVersion"]        = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.MP.dll"));
            TempData["ExtensionVersion"] = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.MP.MvcExtension.dll"));
            TempData["OpenVersion"]      = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.Open.dll"));
            //TempData["QYVersion"] = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.QY.dll"));//已经停止更新
            TempData["WorkVersion"]           = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.Work.dll"));
            TempData["RedisCacheVersion"]     = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.Cache.Redis.dll"));
            TempData["MemcachedCacheVersion"] =
                getDisplayVersion(getFileVersionInfo("Senparc.Weixin.Cache.Memcached.dll"));
            TempData["WxOpenVersion"]    = getDisplayVersion(getFileVersionInfo("Senparc.Weixin.WxOpen.dll"));
            TempData["WebSocketVersion"] = getDisplayVersion(getFileVersionInfo("Senparc.WebSocket.dll"));


            //缓存
            //var containerCacheStrategy = CacheStrategyFactory.GetContainerCacheStrategyInstance();
            var containerCacheStrategy = CacheStrategyFactory.GetObjectCacheStrategyInstance().ContainerCacheStrategy;
            TempData["CacheStrategy"] = containerCacheStrategy.GetType().Name.Replace("ContainerCacheStrategy", "");

            //文档下载版本
            var configHelper = new ConfigHelper(this.HttpContext);
            var config       = configHelper.GetConfig();
            TempData["NewestDocumentVersion"] = config.Versions.First();

#if NET45
            Weixin.WeixinTrace.SendCustomLog("首页被访问", string.Format("Url:{0}\r\nIP:{1}", Request.Url, Request.UserHostName));
#else
            Weixin.WeixinTrace.SendCustomLog("首页被访问",
                                             string.Format("Url:{0}\r\nIP:{1}", Request.Host, HttpContext.Connection.RemoteIpAddress));
            //or use Header: REMOTE_ADDR
#endif

            #endregion

            if (html.Length == 0)
            {
                throw new Exception("RequestUtility.HttpGet()方法测试失败");
            }

            return(View());
        }