/// <summary>
        /// 模拟并发请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="token"></param>
        /// <param name="requestMessaageDoc"></param>
        /// <param name="autoFillUrlParameters">是否自动填充Url中缺少的参数(signature、timestamp、nonce),默认为 true</param>
        /// <returns></returns>
        private async Task <string> TestAsyncTask(string url, string token, XDocument requestMessaageDoc, bool autoFillUrlParameters, int index, int sleepMillionSeconds = 0)
        {
            //修改MsgId,防止被去重
            var msgId = DateTimeHelper.GetUnixDateTime(SystemTime.Now.AddSeconds(_random.Next(0, 9999999))).ToString();

            if (requestMessaageDoc.Root.Element("MsgId") != null)
            {
                requestMessaageDoc.Root.Element("MsgId").Value = msgId;
            }

            //修改文字内容
            if (requestMessaageDoc.Root.Element("MsgType") != null && requestMessaageDoc.Root.Element("MsgType").Value.ToUpper() == "TEXT")
            {
                var values = requestMessaageDoc.Root.Element("Content").Value.Split('|').Select(z => z.Trim()).ToList();
                if (values.Count == 1)
                {
                    values.Add(msgId);
                    values.Add(index.ToString());
                }
                else
                {
                    values[1] = msgId;
                    values[2] = index.ToString();
                }
                requestMessaageDoc.Root.Element("Content").Value = string.Join(" | ", values);
            }

            var responseMessageXml = await MessageAgent.RequestXmlAsync(null, url, token, requestMessaageDoc.ToString(), autoFillUrlParameters, 1000 * 20);

            Thread.Sleep(sleepMillionSeconds); //模拟服务器响应时间

            _responseMessageXml = responseMessageXml;
            return(responseMessageXml);
        }
Esempio n. 2
0
        /// <summary>
        /// 模拟并发请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="token"></param>
        /// <param name="requestMessaageDoc"></param>
        /// <param name="autoFillUrlParameters">是否自动填充Url中缺少的参数(signature、timestamp、nonce),默认为 true</param>
        /// <returns></returns>
        private async Task <string> TestAsyncTask(string url, string token, XDocument requestMessaageDoc, bool autoFillUrlParameters, int sleepMillionSeconds = 0)
        {
            //修改MsgId,防止被去重
            if (requestMessaageDoc.Root.Element("MsgId") != null)
            {
                requestMessaageDoc.Root.Element("MsgId").Value =
                    DateTimeHelper.GetUnixDateTime(SystemTime.Now.AddSeconds(token.GetHashCode())).ToString();
            }

            var responseMessageXml = await MessageAgent.RequestXmlAsync(null, url, token, requestMessaageDoc.ToString(), autoFillUrlParameters, 1000 * 20);

            Thread.Sleep(sleepMillionSeconds); //模拟服务器响应时间
            return(responseMessageXml);
        }