示例#1
0
        private Task <string> CreateRequestAsync(IModel model)
        {
            var dic = new Dictionary <string, object>();

            var baseModel = model as BaseModel <TBaseContent, TBaseHead>;

            var props = baseModel.content.GetType().GetProperties();

            foreach (var prop in props)
            {
                var name  = prop.Name;
                var value = prop.GetValue(model);
                dic[name] = value;
            }

            props = baseModel.head.GetType().GetProperties();
            foreach (var prop in props)
            {
                var name  = prop.Name;
                var value = prop.GetValue(model);
                dic[name] = value;
            }

            var postData = SignUtil.SetSign <TBaseContent, TBaseHead>(model, dic, MD5Key);

            Console.WriteLine($"请求报文:{postData}");

            var result = WebRequestUtil.PostJsonAsync(Url, postData);

            Console.WriteLine($"接收报文:{result}");

            return(result);
        }
        protected String processList(String url, AuthorizationEntity authorization)
        {
            WebRequestUtil wrUtil = new WebRequestUtil(authorization);
            Dictionary <string, string> post_data = new Dictionary <string, string>();
            String response = wrUtil.getRequest(url, post_data);

            return(response);
        }
示例#3
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            if (messageObj.MessageType == MessageType.Private)
            {
                return(null);
            }
            string groupId = messageObj.GroupId ?? messageObj.DiscussId;

            if (!GroupDic.ContainsKey(groupId))
            {
                GroupDic.GetOrAdd(groupId, new GroupSettings
                {
                    GroupId    = groupId,
                    MessageObj = messageObj
                });
            }
            //GroupDic[groupId].GroupType = messageObj.GroupId == null ? MessageType.Discuss : MessageType.Group;

            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }

            foreach (var item in imgList)
            {
                if (item.Extension.ToLower() == ".gif")
                {
                    continue;
                }
                if (item.FileInfo.Exists)
                {
                    GroupDic[groupId].PathQueue.Enqueue(item.FileInfo.FullName);
                }
                else
                {
                    WebRequestUtil.GetImageFromUrl(item.Url, item.Md5, item.Extension);
                    GroupDic[groupId].PathQueue.Enqueue(Path.Combine(Domain.CurrentDirectory, "images",
                                                                     item.Md5 + item.Extension));
                }

                _totalCount++;
            }

            if (GroupDic[groupId].Task == null || GroupDic[groupId].Task.IsCompleted ||
                GroupDic[groupId].Task.IsCanceled)
            {
                GroupDic[groupId].Task = Task.Run(() => RunDetector(GroupDic[groupId]));
                Logger.Info("[" + groupId + "] (熊猫) 共 " + _totalCount);
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// 执行调用接口
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="guid"></param>
        /// <param name="Jsonstring"></param>
        /// <returns></returns>
        public string Requests(string Url, string guid, string Jsonstring)
        {
            //string query = "SELECT * FROM tb_Signature";
            //List<Signature> DBSignature = conn.Query<Signature>(query).ToList();
            //var LastDBSignature = DBSignature.LastOrDefault();
            //var ClientId = LastDBSignature.ClientId;
            //var SecretKey = LastDBSignature.SecretKey;
            var ClientId  = "aa40ee8b-fb21";
            var SecretKey = "ebdd6350-524b-6d12";
            var ts        = WebRequestUtil.GetTimeStamp(DateTime.Now);
            var sign      = WebRequestUtil.SHA256(ClientId + "," + SecretKey + "," + ts);
            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Host", "14.17.22.55:8028" },
                { "Content-Type", "application/json; charset=UTF-8" },
                { "Cache-Control", "no-cache" },
            };
            Dictionary <string, string> dict = new Dictionary <string, string>();

            if (guid != "")
            {
                dict.Add("guid", guid);
            }
            if (Jsonstring != "")
            {
                dict.Add("", Jsonstring);
            }

            WebRequestUtil webClieng = new WebRequestUtil
            {
                url        = "http://14.17.22.55:8028/public-api/" + Url + "?clientId=" + ClientId + "&sign=" + sign + "&ts=" + ts,
                headers    = headers,
                parameters = dict,
                method     = "post",
                Timeout    = 6000,
                Encode     = "utf-8"
            };
            string returnJson = "";

            try
            {
                returnJson = webClieng.SendPost();
            }
            catch (Exception ex)
            {
                throw;
            }
            return(returnJson);
        }
    async void Start()
    {
        var cts = new CancellationTokenSource();
        var url = "https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";

        try
        {
            var tex = await WebRequestUtil.LoadTexture(url, cts.Token);

            rawImage.texture = tex;
        }
        catch (Exception e)
        {
            Debug.LogError("Catch " + e.Message);
        }
    }
示例#6
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            BllUserRole        bllUserRole = new BllUserRole();
            List <TblUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId));

            if (userInfo.Count == 0)
            {
                return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true));
            }

            var id = userInfo[0].UserId.ToString();

            List <Beatmapsets> totalList = new List <Beatmapsets>();

            Beatmapsets[] tmpArray;
            int           page  = 0;
            const int     count = 10;

            do
            {
                string json = WebRequestUtil.GetResponseString(
                    WebRequestUtil.CreateGetHttpResponse(
                        "https://osu.ppy.sh/users/" + id + "/beatmapsets/graveyard?offset=" + page + "&limit=" + count));
                Logger.Debug("GET JSON");

                tmpArray = JsonConvert.DeserializeObject <Beatmapsets[]>(json);
                totalList.AddRange(tmpArray);
                page += count;

                if (tmpArray.Length != count)
                {
                    break;
                }
            } while (tmpArray.Length != 0);

            if (totalList.Count == 0)
            {
                return(new CommonMessageResponse("惊了,你竟然会没坑!", messageObj, true));
            }

            Random      rnd     = new Random();
            Beatmapsets beatmap = totalList[rnd.Next(totalList.Count)];
            var         cqMusic = new CustomMusic("https://osu.ppy.sh/s/" + beatmap.Id, $"https://b.ppy.sh/preview/{beatmap.Id}.mp3", beatmap.Title,
                                                  $"{beatmap.Artist}\r\n({beatmap.FavouriteCount} fav)", $"https://b.ppy.sh/thumb/{beatmap.Id}l.jpg");

            return(new CommonMessageResponse(cqMusic.ToString(), messageObj));
        }
示例#7
0
文件: AssistApi.cs 项目: Gtsz/Daylily
        public static string GetImgFile(string fileName)
        {
            string str = null;
            IDictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "fileName", HttpUtility.UrlEncode(fileName) }
            };

            var response = WebRequestUtil.CreatePostHttpResponse(ApiUrl + "/api/imgfile", parameters);

            if (response != null)
            {
                str = WebRequestUtil.GetResponseString(response);
            }

            return(str);
        }
        public MarkResponse markDone(String alpha_id, String flag, String request_key)
        {
            String url = authorizationEntity.getBaseUrl();

            url += "/v1/alphago/list/" + alpha_id + "/mark";

            WebRequestUtil wrUtil = new WebRequestUtil(authorizationEntity);

            Dictionary <string, string> post_data = new Dictionary <string, string>();

            post_data.Add("flag", flag);
            post_data.Add("request_key", request_key);

            String       response    = wrUtil.postRequest(url, post_data);
            MarkResponse objResponse = JsonConvert.DeserializeObject <MarkResponse>(response);

            return(objResponse);
        }
示例#9
0
        public void RegisterNewCustomerByAPI(Customer customer)
        {
            ResponseBase <Customer> response = new ResponseBase <Customer>();

            string uri         = "https://localhost:44331/api/Customer/NewCustomer";
            string method      = "POST";
            string contentType = "application/json";

            string jsonCustomers = JsonConvert.SerializeObject(customer);

            try
            {
                string request = WebRequestUtil.RequestPost(uri, method, contentType, jsonCustomers);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#10
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            if (messageObj.Group == null)
            {
                return(null);
            }

            //if (user != "2241521134") return null;
            _user      = messageObj.UserId;
            _group     = messageObj.GroupId;
            _messageId = messageObj.MessageId;

            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }

            foreach (var item in imgList)
            {
                if (item.Extension.ToLower() == ".gif")
                {
                    continue;
                }
                if (item.FileInfo.Exists)
                {
                    _pathList.Add(item.FileInfo.FullName);
                }
                else
                {
                    WebRequestUtil.GetImageFromUrl(item.Url, item.Md5, item.Extension);
                    _pathList.Add(Path.Combine(Domain.CurrentDirectory, "images", item.Md5 + item.Extension));
                }

                _totalCount++;
            }

            _thread = new Thread(RunDetector);
            _thread.Start(_pathList);
            Logger.Warn("已经发送了请求,目前队列中共" + _totalCount);
            return(null);
        }
示例#11
0
        public ResponseBase <List <Customer> > ListCustomerByAPI()
        {
            ResponseBase <List <Customer> > response = new ResponseBase <List <Customer> >();
            List <Customer> customers = new List <Customer>();

            string uri         = "https://localhost:44331/api/Customer/ListCustomers";
            string method      = "GET";
            string contentType = "application/json";

            try
            {
                string request = WebRequestUtil.Request(uri, method, contentType);
                customers     = JsonConvert.DeserializeObject <List <Customer> >(request);
                response.Data = customers;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
示例#12
0
        public void Authenticate()
        {
            WebRequestUtil wrUtil = new WebRequestUtil(new AuthorizationEntity("", "", ""));

            Dictionary <string, string> post_data = new Dictionary <string, string>();

            post_data.Add("username", authEntity.getUsername());
            post_data.Add("key", authEntity.getPassword());

            String url = (authEntity.getBaseUrl() + "/v1/authenticate");

            webResponse = wrUtil.postRequest(url, post_data);

            /*String url = (authEntity.getBaseUrl() + "/v1/authenticate");
             * WebRequest request = WebRequest.Create(url);
             * request.Method = "POST";
             * request.ContentType = "application/x-www-form-urlencoded";
             *
             * // manual concat credentials
             * //String post_data = "username="******"&key=" + authEntity.getPassword();
             *
             * // using string builder
             * StringBuilder formData = new StringBuilder();
             * formData.AppendFormat("{0}={1}", "username", authEntity.getUsername());
             * formData.AppendFormat("&{0}={1}", "key", authEntity.getPassword());
             * String post_data = formData.ToString();
             *
             * Stream stream = request.GetRequestStream();
             * byte[] postArray = Encoding.ASCII.GetBytes(post_data);
             * stream.Write(postArray, 0, postArray.Length);
             * stream.Close();
             *
             * StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream());
             * string Result = sr.ReadToEnd();
             *
             * webResponse = Result.ToString();*/
        }
示例#13
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            // 查黄图
            if (messageObj.Group == null || messageObj.GroupId != "133605766")
            {
                return(null);
            }
            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }
            List <string>    urlList   = new List <string>();
            List <CosObject> cacheList = new List <CosObject>();

            foreach (var item in imgList)
            {
                if (Md5List.Keys.Contains(item.Md5))
                {
                    cacheList.Add(Md5List[item.Md5]);
                }
                else if (item.Size > 1000 * 60) //60KB
                {
                    urlList.Add(item.Url);
                }
            }

            if (urlList.Count == 0 && cacheList.Count == 0)
            {
                return(null);
            }

            Logger.Warn("发现了" + (urlList.Count + cacheList.Count) + "张图");

            CosAnalyzer model = new CosAnalyzer
            {
                result_list = new List <CosObject>()
            };

            if (urlList.Count != 0)
            {
                string str = Newtonsoft.Json.JsonConvert.SerializeObject(new
                {
                    appid    = "1252749411",
                    url_list = urlList.ToArray()
                });

                var abc = WebRequestUtil.CreatePostHttpResponse(
                    "http://service.image.myqcloud.com/detection/porn_detect", str, authorization: Signature.Get());
                var respStr = WebRequestUtil.GetResponseString(abc);

                model = Newtonsoft.Json.JsonConvert.DeserializeObject <CosAnalyzer>(respStr);
            }

            model.result_list.AddRange(cacheList);
            int i = 0;

            foreach (var item in model.result_list)
            {
                if (i < imgList.Length && !Md5List.Keys.Contains(imgList[i].Md5))
                {
                    Md5List.Add(imgList[i].Md5, item);
                }
                i++;

                switch (item.data.result)
                {
                case 0 when item.data.normal_score > item.data.hot_score &&
                    item.data.normal_score > item.data.porn_score && item.data.confidence > 40:
                    continue;

                case 1:
                case 2:
                    CqApi.SetGroupBan(messageObj.GroupId, messageObj.UserId, 24 * 60 * 60);
                    return(new CommonMessageResponse("...", messageObj));

                default:
                    break;
                }

                if (item.data.porn_score >= item.data.hot_score && item.data.porn_score > 65)
                {
                    return(AddCount(messageObj));
                }

                if (item.data.hot_score >= item.data.porn_score && item.data.hot_score > item.data.normal_score &&
                    item.data.hot_score > 80)
                {
                    return(AddCount(messageObj));
                }

                break;
            }

            return(null);

            //if (user != "2241521134") return null;
        }
示例#14
0
        public static Bitmap GetStrokeString(string str)
        {
            var response = WebRequestUtil.GetImageFromUrl(ApiUrl + "/api/strokestring?str=" + str, Guid.NewGuid().ToString(), "png");

            return(new Bitmap(response));
        }
示例#15
0
文件: RssUtility.cs 项目: sobne/Nkit
        /// <summary>
        /// 读取指定URL的RSS,并解析之
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static RssUtility GetRss(string url)
        {
            string xml = new WebRequestUtil().FetchPage(url);

            return(XMLHelper.LoadXmlString(xml, typeof(RssUtility)) as RssUtility);
        }
示例#16
0
 public HttpHelper()
 {
     webUtils = new WebRequestUtil();
 }