Esempio n. 1
0
        public static string GetImgFile(string fileName)
        {
            string str = null;
            IDictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "fileName", HttpUtility.UrlEncode(fileName) }
            };

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

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

            return(str);
        }
Esempio n. 2
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            // 查黄图
            if (routeMsg.Group == null || routeMsg.GroupId != "133605766")
            {
                return(null);
            }
            var imgList = CoolQCode.GetImageInfo(routeMsg.RawMessage);

            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 = WebRequest.CreatePostHttpResponse(
                    "http://service.image.myqcloud.com/detection/porn_detect", str, authorization: Signature.Get());
                var respStr = WebRequest.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:
                    CoolQHttpApiClient.SetGroupBan(routeMsg.GroupId, routeMsg.UserId, 24 * 60 * 60);
                    return(routeMsg.ToSource("..."));

                default:
                    break;
                }

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

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

                break;
            }

            return(null);

            //if (user != "2241521134") return null;
        }