Exemple #1
0
        private Task MakeAppointment4User(UserModel userInfo)
        {
            var shopInfo = maskDataBase.GetShop(userInfo.ShopID).ConfigureAwait(false).GetAwaiter().GetResult();
            var parm     = new RequestParm()
            {
                pharmacyName    = shopInfo.serviceName,
                pharmcayId      = shopInfo.id,
                pharmacyAddress = shopInfo.serviceAddress,
                realName        = userInfo.Name.RSAEncrypt(),
                idcard          = userInfo.IDCard.RSAEncrypt(),
                mobile          = userInfo.Tel.RSAEncrypt()
            };
            var cts = new CancellationTokenSource();

            return(Task.Run(() =>
            {
                while (DatetimeUtils.GetChinaDatetimeNow().TimeOfDay < endTime)
                {
                    Enumerable.Range(1, threadNum).Select(p => new Task(() =>
                    {
                        if (serviceProvider.GetService <MaskWebClient>().MakeAppointment(parm, out var result))
                        {
                            cts.Cancel();
                        }
                        else
                        {
                        }
                    }, cts.Token));
                    Thread.Sleep(sleepTime);
                }
            }, cts.Token));
        }
        /// <summary>
        /// 预约口罩
        /// </summary>
        /// <param name="parm"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool MakeAppointment(RequestParm parm, out string result)
        {
            var json = JsonConvert.SerializeObject(parm);

            try
            {
                this.timeout = 5000;
                result       = this.UploadString(APPOINTMENT, "POST", json);
                if (result.Contains("200") || result.Contains("成功") || result.Contains("5天"))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                result = string.Empty;
                return(false);
            }
        }