Beispiel #1
0
        /// <summary>
        /// 测试接口是否能用
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Test_Click(object sender, RoutedEventArgs e)
        {
            //获取按钮的父容器以获取URL元素
            var parent = VisualTreeHelper.GetParent((UIElement)sender);
            //URL元素在父容器中是[3]个
            var    textURL = (TextBox)VisualTreeHelper.GetChild(parent, 3);
            string url     = textURL.Text;

            try
            {
                HttpWebClient http = new HttpWebClient()
                {
                    TimeOut           = 10000,
                    Encoding          = Encoding.UTF8,
                    Proxy             = MainSave.Proxy,
                    AllowAutoRedirect = true,
                };
                //以后要用的路径,先生成一个
                string targetdir = Path.Combine(Environment.CurrentDirectory, "data", "image", "CustomAPIPic");
                if (!Directory.Exists(targetdir))
                {
                    Directory.CreateDirectory(targetdir);
                }
                //将字节数组转换为图片
                string fullpath = Path.Combine(targetdir, DateTime.Now.ToString("yyyyMMddHHss") + ".jpg");
                http.DownloadFile(url, fullpath);
                parentwindow.SnackbarMessage_Show($"接口测试通过,图片已成功保存", 1);
                Process.Start(fullpath);
            }
            catch
            {
                parentwindow.SnackbarMessage_Show($"接口测试失败,检查接口是否有误", 1);
            }
        }
Beispiel #2
0
        public static IntPtr CQ_getImage(int authCode, IntPtr file)
        {
            string filename = file.ToString(GB18030);
            string path     = $"data\\image\\{filename}.cqimg";

            if (File.Exists(path))
            {
                IniConfig ini = new IniConfig(path);
                ini.Load();
                if (ini.Object.ContainsKey("image") is false)
                {
                    return(Marshal.StringToHGlobalAnsi(string.Empty));
                }
                string        picurl = ini.Object["image"]["url"];
                HttpWebClient http   = new HttpWebClient {
                    TimeOut = 10000
                };
                http.DownloadFile(picurl, $"data\\image\\{filename}.jpg");
                FileInfo fileInfo = new FileInfo($"data\\image\\{filename}.jpg");
                return(Marshal.StringToHGlobalAnsi(fileInfo.FullName));
            }
            else
            {
                return(Marshal.StringToHGlobalAnsi(string.Empty));
            }
        }
Beispiel #3
0
        public static CQCode GetIllustPic(Pixiv_PID info)
        {
            string path       = Path.Combine(Environment.CurrentDirectory, "data", "image", "LoliconPic", $"{info.data.id}.jpg");
            string pathcqcode = Path.Combine("LoliConPic", $"{info.data.id}.jpg");

            using (HttpWebClient http = new HttpWebClient())
            {
                http.TimeOut = 5000;
                try
                {
                    if (!File.Exists(path))
                    {
                        string url = string.Empty;
                        url = info.data.imageUrls[0].original.Replace("pximg.net", "pixiv.cat");

                        http.DownloadFile(url, path);
                        CommonHelper.AntiHX(path);
                        MainSave.CQLog.Info("插画详情", "图片下载成功,正在尝试发送");
                    }
                }
                catch (Exception e)
                {
                    MainSave.CQLog.Info("插画详情", $"图片下载失败,错误信息:{e.Message}");
                    return(CQApi.CQCode_Image("Error.jpg"));
                }
            }
            return(CQApi.CQCode_Image(pathcqcode));
        }
Beispiel #4
0
        /// <summary>
        /// 获取魔法少女祈愿信息
        /// </summary>
        /// <returns></returns>
        public static bool GetMagic()
        {
            try
            {
                //创建获取公告连接
                string url = @"https://www.benghuai.com/news/getNotice";
                //创建对象
                HttpWebClient httpWebClient = new HttpWebClient();
                //将获获取的公告转换为新的对象
                NoticeRoot noticeRoot = JsonConvert.DeserializeObject <NoticeRoot>(Encoding.UTF8.GetString(httpWebClient.DownloadData(url)));
                //获取想要的公告id
                string princessid = "0";
                foreach (Gach item in noticeRoot.Data.Gach)
                {
                    //如果祈愿标题包含全神祈愿
                    if (item.title.Contains("魔法少女"))
                    {
                        //获取祈愿的id
                        princessid = item.id;
                        break;
                    }
                }
                //创建祈愿公告的id
                string WishUrl = @"https://www.benghuai.com/news/getNoticeByID?id=" + princessid;
                //将获取的信息转成对象
                QiyuanRoot qiyuanRoot = JsonConvert.DeserializeObject <QiyuanRoot>(Encoding.UTF8.GetString(httpWebClient.DownloadData(WishUrl)));
                //创建获取祈愿时间正则
                string WishTime = @"[0-9月日 :]+~[0-9月日 :]+";
                //获取祈愿时间
                string PrincessTime = Regex.Match(qiyuanRoot.data.text, WishTime).Value;
                //判断当前活动日期是否有效
                if (GetTi(PrincessTime))
                {
                    return(false);
                }

                //获取魔法少女祈愿图片
                string str = Regex.Match(qiyuanRoot.data.text, @"http://static-image.benghuai.com/hsod2_webview/images/broadcast_top/bannerv2.{3,25}(jpg|JPG|png)").Value;
                httpWebClient.DownloadFile(str, System.Environment.CurrentDirectory + "\\data\\image\\魔法少女祈愿.jpg");
                //写入魔法少女祈愿信息
                StringBuilder sb = new StringBuilder();
                sb.Append("【活动标题】" + "\n");
                sb.Append(qiyuanRoot.data.title + "\n");
                sb.Append("【活动时间】" + "\n");
                sb.Append(PrincessTime + "\n");
                sb.Append("活动期间,在魔法少女的祈愿中,每天都有不同的瞩目装备获得概率特别提升! 每日概率提升装备如下图:");
                sb.Append("[CQ:image,file=魔法少女祈愿.jpg]");

                //创建配置保存路径
                string PrincessPath = Common.CqApi.GetAppDirectory() + "魔法少女祈愿.txt";
                //保存内容
                SaveDate(PrincessPath, sb, false);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public FunctionResult Progress(CQGroupMessageEventArgs e)
        {
            FunctionResult result = new FunctionResult
            {
                Result   = true,
                SendFlag = true,
            };
            SendText sendText = new SendText
            {
                SendID = e.FromGroup,
            };

            //检查额度限制
            if (QuotaHelper.QuotaCheck(e.FromGroup, e.FromQQ) is false)
            {
                return(result);
            }
            try
            {
                string tagName      = e.Message.Text.Substring(GetOrderStr().Length).Trim();
                var    searchResult = TagSearch(tagName);
                if (searchResult.Count > 0 && searchResult[0] != 0)
                {
                    int id  = searchResult.OrderBy(x => Guid.NewGuid().ToString()).First();
                    var pic = YandeRePic.GetYandePic(id);
                    Directory.CreateDirectory(Path.Combine(MainSave.ImageDirectory, "YandeRePic"));
                    e.FromGroup.SendGroupMessage(pic.ToString());
                    using (HttpWebClient http = new HttpWebClient()
                    {
                        TimeOut = 10000,
                        Encoding = Encoding.UTF8,
                        Proxy = MainSave.Proxy,
                        AllowAutoRedirect = true,
                    })
                    {
                        string fileName = Path.Combine(MainSave.ImageDirectory, "YandeRePic", $"{pic.ID}.jpg");
                        if (File.Exists(fileName) is false)
                        {
                            http.DownloadFile(pic.PicLargeURL, fileName);
                        }
                    }
                    sendText.MsgToSend.Add(CQApi.CQCode_Image(Path.Combine("YandeRePic", $"{pic.ID}.jpg")).ToSendString());
                }
                else
                {
                    sendText.MsgToSend.Add("没有找到结果呢,请查看是否使用了正确的tag名称");
                }
            }
            catch (Exception exc)
            {
                e.CQLog.Info("YandeReTag解析出错", $"错误信息: {exc.Message} 错误位置: {exc.StackTrace}");
                sendText.MsgToSend.Add("解析出错,查看日志获取详细信息");
            }
            result.SendObject.Add(sendText);
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 测试接口是否能用
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Test_Click(object sender, RoutedEventArgs e)
        {
            //获取按钮的父容器以获取Path元素
            var    parent = VisualTreeHelper.GetParent((UIElement)sender);
            string url    = ((TextBox)VisualTreeHelper.GetChild(parent, 3)).Text;
            string path;
            //Path元素在父容器中是[4]个
            var c = JsonSaves.Find(x => x.url == url);

            if (c == null)
            {
                path = "";
            }
            else
            {
                path = c.picPath;
            }
            try
            {
                using (HttpWebClient http = new HttpWebClient()
                {
                    TimeOut = 10000,
                    Encoding = Encoding.UTF8,
                    Proxy = MainSave.Proxy,
                    AllowAutoRedirect = true,
                })
                {
                    string json = Encoding.UTF8.GetString(http.DownloadData(url)).Replace('', ' ');

                    string picpath = MainSave.ImageDirectory + "\\JsonDeserizePic\\" + Guid.NewGuid() + ".png";
                    if (!Directory.Exists(MainSave.ImageDirectory + "\\JsonDeserizePic"))
                    {
                        Directory.CreateDirectory(MainSave.ImageDirectory + "\\JsonDeserizePic");
                    }
                    JObject jObject = JObject.Parse(json);
                    url = jObject.SelectToken(path).ToString();

                    http.CookieCollection = new System.Net.CookieCollection();
                    http.DownloadFile(url, picpath);
                    parentwindow.SnackbarMessage_Show($"接口测试通过", 1);
                    Process.Start(picpath);
                }
            }
            catch (Exception exc)
            {
                MainSave.CQLog.Info("Json解析", exc.Message, exc.StackTrace);
                parentwindow.SnackbarMessage_Show($"接口测试失败,查看日志获取详细信息", 1);
            }
        }
        public FunctionResult Progress(CQGroupMessageEventArgs e)
        {
            FunctionResult result = new FunctionResult
            {
                Result   = true,
                SendFlag = true,
            };
            SendText sendText = new SendText
            {
                SendID = e.FromGroup,
            };

            //检查额度限制
            if (QuotaHelper.QuotaCheck(e.FromGroup, e.FromQQ) is false)
            {
                return(result);
            }
            try
            {
                int yandeID = Convert.ToInt32(e.Message.Text.Split(' ')[1]);
                var t       = GetYandePic(yandeID);
                Directory.CreateDirectory(Path.Combine(MainSave.ImageDirectory, "YandeRePic"));
                e.FromGroup.SendGroupMessage(t.ToString());
                using (HttpWebClient http = new HttpWebClient()
                {
                    TimeOut = 10000,
                    Encoding = Encoding.UTF8,
                    Proxy = MainSave.Proxy,
                    AllowAutoRedirect = true,
                })
                {
                    string fileName = Path.Combine(MainSave.ImageDirectory, "YandeRePic", $"{t.ID}.jpg");
                    if (File.Exists(fileName) is false)
                    {
                        http.DownloadFile(t.PicLargeURL, fileName);
                    }
                }
                sendText.MsgToSend.Add(CQApi.CQCode_Image(Path.Combine("YandeRePic", $"{t.ID}.jpg")).ToSendString());
            }
            catch (Exception exc)
            {
                e.CQLog.Info("YandeReID解析出错", $"错误信息: {exc.Message} 错误位置: {exc.StackTrace}");
                sendText.MsgToSend.Add("解析出错,查看日志获取详细信息");
            }
            result.SendObject.Add(sendText);
            return(result);
        }
Beispiel #8
0
        private SendText CustomAPI_Image(string orderText)
        {
            SendText sendText = new SendText();

            try
            {
                //尝试拉取图片,若有多个相同的接口则随机来一个
                CustomObject item = CustomAPIOrderList.Where(x => x.Order == orderText)
                                    .OrderBy(x => Guid.NewGuid().ToString()).FirstOrDefault();
                sendText.HandlingFlag = item.AutoRevoke;
                //以后要用的路径,先生成一个
                string targetdir = Path.Combine(Environment.CurrentDirectory, "data", "image", "CustomAPIPic", item.Order);
                if (!Directory.Exists(targetdir))
                {
                    Directory.CreateDirectory(targetdir);
                }
                string imagename = DateTime.Now.ToString("yyyyMMddHHss") + ".jpg";
                string fullpath  = Path.Combine(targetdir, imagename);
                using (HttpWebClient http = new HttpWebClient()
                {
                    TimeOut = 10000,
                    Encoding = Encoding.UTF8,
                    Proxy = MainSave.Proxy,
                    AllowAutoRedirect = true,
                })
                {
                    http.DownloadFile(item.URL, fullpath);
                }
                MainSave.CQLog.Info("自定义接口", $"图片下载成功,尝试发送");

                //GetSetu.AntiHX(fullpath);

                string imagepath = Path.Combine("CustomAPIPic", item.Order, imagename);
                sendText.MsgToSend.Add(CQApi.CQCode_Image(imagepath).ToSendString());
                return(sendText);
            }
            catch (Exception exc)
            {
                sendText.MsgToSend.Add("自定义接口调用失败");
                MainSave.CQLog.Info("自定义接口", $"调用失败,错误信息:{exc.Message}");
                return(sendText);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 通过OCR获取Up开始时间
        /// </summary>
        /// <param name="url">图片地址</param>
        /// <returns></returns>
        public List <string> GetUpDate(string url)
        {
            HttpWebClient http = new HttpWebClient();

            http.DownloadFile(url, $"{MainSave.ImageDirectory}\\ocrtemp.jpg");

            List <string> result = new List <string>();

            res = TXOCR();
            if (res.ret != 0)
            {
                Debug.WriteLine(res.ret);
            }
            foreach (var item in res.data.item_list)
            {
                if (Regex.IsMatch(item.itemstring, @"\(周.*\)"))
                {
                    result.Add(res.data.item_list[res.data.item_list.IndexOf(item)].itemstring.ToUpper().Replace("(", "(").Replace(")", ")").Replace("O", "0"));
                }
            }
            return(result);
        }
        public static CQCode GetSearchPic(Datum info)
        {
            string path = Path.Combine(Environment.CurrentDirectory, "data", "image", "LoliconPic", $"{info.id}.jpg");
            var    b    = Path.GetDirectoryName(path);

            if (!Directory.Exists(b))
            {
                Directory.CreateDirectory(b);
            }
            string pathcqcode = Path.Combine("LoliConPic", $"{info.id}.jpg");

            using (HttpWebClient http = new HttpWebClient()
            {
                TimeOut = 10000,
                Encoding = Encoding.UTF8,
                Proxy = MainSave.Proxy,
                AllowAutoRedirect = true,
            })
            {
                try
                {
                    if (!File.Exists(path))
                    {
                        string url = info.imageUrls[0].original.Replace("pximg.net", "pixiv.cat");
                        http.DownloadFile(url, path);
                        CommonHelper.AntiHX(path);
                        MainSave.CQLog.Info("搜索详情", "图片下载成功,正在尝试发送");
                    }
                }
                catch (Exception e)
                {
                    MainSave.CQLog.Info("搜索详情", $"图片下载失败,错误信息:{e.Message}\n{e.StackTrace}");
                    return(CQApi.CQCode_Image("Error.jpg"));
                }
            }
            return(CQApi.CQCode_Image(pathcqcode));
        }
        /// <summary>
        /// 获取图片
        /// </summary>
        /// <param name="ordertext">除指令外的控制文本</param>
        /// <returns></returns>
        public static SendText GetSetuPic(string ordertext, out string objectTostring)
        {
            SendText result = new SendText();

            objectTostring = String.Empty;
            using (HttpWebClient http = new HttpWebClient()
            {
                TimeOut = 10000,
                Encoding = Encoding.UTF8,
                Proxy = MainSave.Proxy,
                AllowAutoRedirect = true,
            })
            {
                try
                {
                    IniConfig ini = MainSave.ConfigMain;
                    string    url = api;
                    //拼接Url
                    if (PublicVariables.Lolicon_ApiSwitch)
                    {
                        url = api + $"apikey={PublicVariables.Lolicon_ApiKey}";
                    }
                    url += GetOrderText(ordertext);

                    if (url.Contains("r18=1") && ini.Object["R18"]["R18PicRevoke"] == "1")
                    {
                        GetLoliconPic.RevokeState = true;//用于后续撤回
                    }
                    string json = "";
                    try
                    {
                        json = http.DownloadString(url);
                    }
                    catch (Exception e)
                    {
                        MainSave.CQLog.Info("Error", e.Message);
                        result.MsgToSend.Add(e.Message);
                        result.HandlingFlag = false;
                        return(result);
                    }
                    //检查路径是否存在
                    if (!Directory.Exists(MainSave.ImageDirectory + @"\LoliconPic\"))
                    {
                        Directory.CreateDirectory(MainSave.ImageDirectory + @"\LoliconPic\");
                    }
                    //反序列化json
                    Setu deserialize = JsonConvert.DeserializeObject <Setu>(json);
                    objectTostring = deserialize.ToString();
                    if (deserialize.code != 0)//非成功调用
                    {
                        MainSave.CQLog.Info("非正常返回", json);
                        result.MsgToSend.Add("非正常返回");
                        result.HandlingFlag = false;
                        return(result);
                    }
                    //获取Data数组信息
                    var    pic  = deserialize.data[0];
                    string path = Path.Combine(MainSave.ImageDirectory, "LoliconPic", $"{pic.pid}.jpg");
                    if (!File.Exists(path))
                    {
                        http.CookieCollection = new CookieCollection();
                        http.DownloadFile(pic.url, path);
                        CommonHelper.AntiHX(path);
                    }
                    result.MsgToSend.Add(CQApi.CQCode_Image(@"\LoliconPic\" + pic.pid + ".jpg").ToSendString());
                    return(result);
                }
                catch (Exception e)
                {
                    MainSave.CQLog.Info("Error", $"发生错误的对象{e.Source} , 发送错误: {e.Message}\n{e.StackTrace}");
                    result.MsgToSend.Add(e.Message);
                    result.HandlingFlag = false;
                    return(result);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// SauceNao调用
        /// </summary>
        /// <param name="cqcode">图片CQ码</param>
        /// <param name="e"></param>
        public static void SauceNao_Call(CQCode cqcode, CQGroupMessageEventArgs e)
        {
            string url = "https://saucenao.com/search.php?output_type=2&api_key=56faa0cddf50860330a295e0c331be7c4b4c021f&db=999&numres=3&url=";

            url += CommonHelper.GetImageURL(cqcode.ToSendString());
            using (HttpWebClient http = new HttpWebClient()
            {
                TimeOut = 10000,
                Encoding = Encoding.UTF8,
                Proxy = MainSave.Proxy,
                AllowAutoRedirect = true,
            })
            {
                try
                {
                    Directory.CreateDirectory(MainSave.ImageDirectory + "SauceNaotemp");
                    var result = JsonConvert.DeserializeObject <SauceNao_Result.SauceNAO>(http.DownloadString(url));
                    if (result == null || result.results == null || result.results.Count == 0)
                    {
                        e.CQLog.Info("SauceNao识图", "拉取结果失败,建议重试");
                        e.FromGroup.SendGroupMessage("诶嘿,网络出了点小差~");
                        return;
                    }
                    e.CQLog.Info("SauceNao识图", "结果获取成功,正在拉取缩略图");
                    int count = 1;
                    result.results = result.results.Take(1).ToList();
                    string str = result.ToString();
                    foreach (var item in result.results)
                    {
                        try
                        {
                            string filename = Guid.NewGuid().ToString().ToString();
                            http.DownloadFile(item.header.thumbnail, $@"{MainSave.ImageDirectory}\SauceNaotemp\{filename}.jpg");
                            str = str.Replace($"{{{count}}}", CQApi.CQCode_Image($@"\SauceNaotemp\{filename}.jpg").ToSendString());
                        }
                        catch
                        {
                            str = str.Replace($"{{{count}}}", item.header.thumbnail);
                        }
                        finally { count++; }
                    }
                    e.FromGroup.SendGroupMessage(str);
                    List <int> ls = result.results.Where(x => x.data.pixiv_id.HasValue).Select(x => x.data.pixiv_id.Value).ToList();
                    if (ls.Count != 0)
                    {
                        e.FromGroup.SendGroupMessage("有Pixiv图片信息,尝试拉取原图...");
                        foreach (var item in ls)
                        {
                            try
                            {
                                http.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                                if (!File.Exists($@"{MainSave.ImageDirectory}\LoliconPic\${item}.jpg"))
                                {
                                    dynamic jObject   = JObject.Parse(http.UploadString("https://api.pixiv.cat/v1/generate", $"p={item}"));
                                    string  pixiv_url = string.Empty;
                                    try
                                    {
                                        var urllist = jObject.original_urls_proxy;
                                        pixiv_url = urllist[0];
                                        e.FromGroup.SendGroupMessage("此图为多P图片,选择第一P下载");
                                        MainSave.CQLog.Info("SauceNao识图", "此图为多P图片,选择第一P下载");
                                    }
                                    catch
                                    {
                                        pixiv_url = jObject.Value <string>("original_url_proxy");
                                    }
                                    if (!Directory.Exists($@"{MainSave.ImageDirectory}\LoliconPic"))
                                    {
                                        Directory.CreateDirectory($@"{MainSave.ImageDirectory}\LoliconPic");
                                    }
                                    http.DownloadFile(pixiv_url, $@"{MainSave.ImageDirectory}\LoliconPic\{item}.jpg");
                                    MainSave.CQLog.Info("SauceNao识图", $"pid={item}的图片下载成功,尝试发送");
                                }
                                QQMessage staues = e.FromGroup.SendGroupMessage(CQApi.CQCode_Image($@"\LoliconPic\{item}.jpg"));
                            }
                            catch (Exception exc)
                            {
                                e.FromGroup.SendGroupMessage($"pid={item}的图片拉取失败,错误信息:{exc.Message}");
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    e.CQLog.Info("SauceNao搜图", $"搜索失败,错误信息:{exc.Message}在{exc.StackTrace}");
                    e.FromGroup.SendGroupMessage($"拉取失败,错误信息:{exc.Message}");
                }
                try
                {
                    string path = $@"{MainSave.ImageDirectory}\SauceNaotemp";
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }
                }
                catch { }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Json解析拉取
        /// </summary>
        /// <param name="ls"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static SendText JsonDeserize_Image(string orderText, long GroupID, long QQID)
        {
            SendText result = new SendText();

            try
            {
                //尝试拉取图片,若有多个相同的接口则随机来一个
                JsonToDeserize item = JsonOrderList.Where(x => x.Order == orderText)
                                      .OrderBy(x => Guid.NewGuid().ToString()).FirstOrDefault();
                result.HandlingFlag = item.AutoRevoke;
                //以后要用的路径,先生成一个
                string targetdir = Path.Combine(Environment.CurrentDirectory, "data", "image", "JsonDeserizePic", item.Order);
                if (!Directory.Exists(targetdir))
                {
                    Directory.CreateDirectory(targetdir);
                }
                string imagename = DateTime.Now.ToString("yyyyMMddHHss") + ".jpg";
                string fullpath  = Path.Combine(targetdir, imagename);
                using (HttpWebClient http = new HttpWebClient()
                {
                    TimeOut = 10000,
                    Encoding = Encoding.UTF8,
                    Proxy = MainSave.Proxy,
                    AllowAutoRedirect = true,
                })
                {
                    string  url = item.url, jsonpath = item.picPath;
                    string  json    = Encoding.UTF8.GetString(http.DownloadData(url)).Replace('', ' ');
                    JObject jObject = JObject.Parse(json);
                    if (!string.IsNullOrEmpty(item.Text))
                    {
                        string str = item.Text;
                        var    c   = Regex.Matches(item.Text, "<.*?>");
                        foreach (var item2 in c)
                        {
                            string path = item2.ToString().Replace("<", "").Replace(">", "");
                            str = str.Replace(item2.ToString(), jObject.SelectToken(path).ToString());
                        }
                        MainSave.CQApi.SendGroupMessage(GroupID, str);
                    }
                    if (string.IsNullOrEmpty(jsonpath))
                    {
                        MainSave.CQLog.Warning("Json解析接口", $"jsonPath为空,发生在 {item.url} 接口中");
                        return(null);
                    }
                    url = jObject.SelectToken(jsonpath).ToString();
                    http.CookieCollection = new System.Net.CookieCollection();
                    http.DownloadFile(url, fullpath);
                }

                MainSave.CQLog.Info("Json解析接口", $"图片下载成功,尝试发送");
                //GetSetu.AntiHX(fullpath);
                string imagepath = Path.Combine("JsonDeserizePic", item.Order, imagename);
                result.MsgToSend.Add(CQApi.CQCode_Image(imagepath).ToSendString());
                return(result);
            }
            catch (Exception exc)
            {
                result.MsgToSend.Add("Json解析接口调用失败");
                MainSave.CQLog.Info("Json解析接口", $"调用失败,错误信息:{exc.Message}");
                return(result);
            }
        }
Beispiel #14
0
 /// <summary>
 /// 获取全神器祈愿信息
 /// </summary>
 public static bool GetGod()
 {
     try
     {
         //创建获取公告连接
         string url = @"https://www.benghuai.com/news/getNotice";
         //创建对象
         HttpWebClient httpWebClient = new HttpWebClient();
         //将获获取的公告转换为新的对象
         NoticeRoot noticeRoot = JsonConvert.DeserializeObject <NoticeRoot>(Encoding.UTF8.GetString(httpWebClient.DownloadData(url)));
         //获取想要的公告id
         string princessid = "0";
         foreach (Gach item in noticeRoot.Data.Gach)
         {
             //如果祈愿标题包含全神祈愿
             if (item.title.Contains("全神器"))
             {
                 //获取祈愿的id
                 princessid = item.id;
                 break;
             }
         }
         //创建祈愿公告的id
         string WishUrl = @"https://www.benghuai.com/news/getNoticeByID?id=" + princessid;
         //将获取的信息转成对象
         QiyuanRoot qiyuanRoot = JsonConvert.DeserializeObject <QiyuanRoot>(Encoding.UTF8.GetString(httpWebClient.DownloadData(WishUrl)));
         //创建获取祈愿时间正则
         string WishTime = @"[0-9月日 :]+~[0-9月日 :]+";
         //获取祈愿时间
         string PrincessTime = Regex.Match(qiyuanRoot.data.text, WishTime).Value;
         //判断当前活动日期是否有效
         if (GetTi(PrincessTime))
         {
             return(false);
         }
         //保存祈愿图片
         httpWebClient.DownloadFile(qiyuanRoot.data.banner_src_url, System.Environment.CurrentDirectory + "\\data\\image\\全神祈愿.jpg");
         //创建获取公主装备正则
         string PrincessZB = @"[\u4e00-\u9fa5a-zA-Z·-]+</td>";
         //创建公主装备数组
         List <string> PrincessZBstr = new List <string>();
         //往数组添加装备
         foreach (var item in Regex.Matches(qiyuanRoot.data.text, PrincessZB))
         {
             PrincessZBstr.Add(item.ToString().Replace("</td>", ""));
         }
         //创建配置保存路径
         string PrincessPath = Common.CqApi.GetAppDirectory() + "全神祈愿.txt";
         //创建保存的内容
         StringBuilder sb = new StringBuilder();
         //添加内容
         sb.Append("【活动标题】" + "\n");
         sb.Append(qiyuanRoot.data.title + "\n");
         sb.Append("【活动时间】" + "\n");
         sb.Append(PrincessTime);
         sb.Append("[CQ:image,file=全神祈愿.jpg]");
         sb.Append("【注目装备】" + "\n");
         for (int i = 0; i < PrincessZBstr.Count; i++)
         {
             if (i == PrincessZBstr.Count - 1)
             {
                 sb.Append(PrincessZBstr[i]);
             }
             else
             {
                 sb.Append(PrincessZBstr[i] + "\n");
             }
         }
         //保存内容
         SaveDate(PrincessPath, sb, false);
         return(true);
     }
     catch (Exception ex)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(DateTime.Now.ToString() + "获取全神祈愿信息失败:");
         sb.Append(ex.Message);
         //创建保存路径
         string FamiliarPath = Common.CqApi.GetAppDirectory() + "ErrorLog.txt";
         //保存数据
         SaveDate(FamiliarPath, sb, true);
         return(true);
     }
 }
Beispiel #15
0
 /// <summary>
 /// 获取当前魔女祈愿信息并保存
 /// </summary>
 /// <param name="ia"></param>
 public static void GetWitch()
 {
     try
     {
         //创建获取公告连接
         string url = @"https://www.benghuai.com/news/getNotice";
         //创建对象
         HttpWebClient httpWebClient = new HttpWebClient();
         //将获获取的公告转换为新的对象
         NoticeRoot noticeRoot = JsonConvert.DeserializeObject <NoticeRoot>(Encoding.UTF8.GetString(httpWebClient.DownloadData(url)));
         //获取想要的公告id
         string princessid = "0";
         foreach (Gach item in noticeRoot.Data.Gach)
         {
             //如果祈愿标题其中的
             if (item.title.Contains("魔女祈愿") || item.title.Contains("使魔祈愿"))
             {
                 //获取魔女祈愿的id
                 princessid = item.id;
                 break;
             }
         }
         //创建祈愿公告的id
         string WishUrl = @"https://www.benghuai.com/news/getNoticeByID?id=" + princessid;
         //将获取的信息转成对象
         QiyuanRoot qiyuanRoot = JsonConvert.DeserializeObject <QiyuanRoot>(Encoding.UTF8.GetString(httpWebClient.DownloadData(WishUrl)));
         //创建获取祈愿时间正则
         string WishTime = @"[0-9月日 :]+~[0-9月日 :]+";
         //获取祈愿时间
         string PrincessTime = Regex.Match(qiyuanRoot.data.text, WishTime).Value;
         //如果当前是使魔祈愿
         if (qiyuanRoot.data.title.Contains("使魔祈愿"))
         {
             //保存祈愿图片
             httpWebClient.DownloadFile(qiyuanRoot.data.banner_src_url, System.Environment.CurrentDirectory + "\\data\\image\\使魔祈愿.jpg");
             //创建获取使魔祈愿信息
             List <string> Str = new List <string>();
             foreach (var item in Regex.Matches(qiyuanRoot.data.text, @";[\u4e00-\u9fa5a-zA-Z::·-]+&"))
             {
                 Str.Add(item.ToString().Replace(";", "").Replace("&", ""));
             }
             //获取集齐(30|50)颗可合成
             List <string> Strke = new List <string>();
             foreach (var item in Regex.Matches(qiyuanRoot.data.text, @"集齐(30|50)颗可合成"))
             {
                 Strke.Add(item.ToString());
             }
             //保存信息
             StringBuilder sb = new StringBuilder();
             try
             {
                 sb.Append("【活动标题】" + "\n");
                 sb.Append(qiyuanRoot.data.title + "\n");
                 sb.Append("【活动时间】" + "\n");
                 sb.Append(PrincessTime);
                 sb.Append("[CQ:image,file=使魔祈愿.jpg]");
                 sb.Append("【第一注目素材:】" + "\n");
                 sb.Append(Str[0] + " >>>>" + Strke[0] + " >>>>" + Str[1] + "\n");
                 sb.Append("【第二注目素材:】" + "\n");
                 sb.Append(Str[2] + " >>>>" + Strke[1] + " >>>>" + Str[3] + "\n");
                 sb.Append("【其他可能获得】" + "\n");
                 sb.Append(Str[4] + "\n");
                 sb.Append(Str[5] + "\n");
                 sb.Append(Str[6] + "\n");
                 sb.Append(Str[7] + "\n");
                 sb.Append(Str[8] + "\n");
                 sb.Append(Str[9] + "\n");
                 sb.Append(Str[10] + "\n");
                 sb.Append(Str[11]);
             }
             catch (Exception)
             {
                 sb.Append("保存使魔祈愿信息失败");
             }
             //创建保存路径
             string FamiliarPath = Common.CqApi.GetAppDirectory() + "使魔祈愿.txt";
             //保存数据
             SaveDate(FamiliarPath, sb, false);
         }
         else
         {
             //保存祈愿图片
             httpWebClient.DownloadFile(qiyuanRoot.data.banner_src_url, System.Environment.CurrentDirectory + "\\data\\image\\魔女祈愿.jpg");
             //获取魔女祈愿装备
             List <string> Str = new List <string>();
             //foreach (var item in Regex.Matches(qiyuanRoot.data.text, @";[\u4e00-\u9fa5a-zA-Z::·-]{3,}(&|<)"))
             //{
             //    Str.Add(item.ToString().Replace(";", "").Replace("&", "").Replace("<", ""));
             //}
             foreach (var item in Regex.Matches(qiyuanRoot.data.text, @"&nbsp;[\u4e00-\u9fa5a-zA-Z::·-]+&nbsp;"))
             {
                 Str.Add(item.ToString().Replace("&nbsp;", ""));
             }
             //写入保存内容
             StringBuilder sb = new StringBuilder();
             try
             {
                 sb.Append("【活动标题】" + "\n");
                 sb.Append(qiyuanRoot.data.title + "\n");
                 sb.Append("【活动时间】" + "\n");
                 sb.Append(PrincessTime);
                 sb.Append("[CQ:image,file=魔女祈愿.jpg]");
                 sb.Append("【注目装备】" + "\n");
                 for (int i = 0; i < Str.Count; i++)
                 {
                     if (i == Str.Count - 1)
                     {
                         sb.Append(Str[i]);
                     }
                     else
                     {
                         sb.Append(Str[i] + "\n");
                     }
                 }
             }
             catch (Exception)
             {
                 sb.Append("写入魔女祈愿信息失败");
             }
             //创建保存路径
             string FamiliarPath = Common.CqApi.GetAppDirectory() + "魔女祈愿.txt";
             //保存数据
             SaveDate(FamiliarPath, sb, false);
         }
     }
     catch (Exception ex)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(DateTime.Now.ToString() + "获取魔女祈愿信息失败:");
         sb.Append(ex.Message);
         //创建保存路径
         string FamiliarPath = Common.CqApi.GetAppDirectory() + "ErrorLog.txt";
         //保存数据
         SaveDate(FamiliarPath, sb, true);
     }
 }