lk
2022-10-19 8f80bea45f7646ac6b110aa9b706981645da6a08
使用位置点击操作遇到拒绝访问的问题2022-10-19LK
4个文件已修改
340 ■■■■ 已修改文件
BankRobot/CrawRobotWX.csproj 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BankRobot/app.config 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BankRobot/frmCollectWX.cs 244 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BankRobot/packages.config 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BankRobot/CrawRobotWX.csproj
@@ -55,6 +55,12 @@
      <EmbedInteropTypes>False</EmbedInteropTypes>
      <HintPath>bin\Debug\Microsoft.Office.Interop.Word.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json.Bson, Version=1.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll</HintPath>
    </Reference>
    <Reference Include="NPOI, Version=2.0.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
      <HintPath>..\packages\NPOI.2.0.6\lib\net20\NPOI.dll</HintPath>
    </Reference>
@@ -70,6 +76,7 @@
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
@@ -83,9 +90,12 @@
    <Compile Include="BLL\WechatInfoBLL.cs" />
    <Compile Include="Class\CsvHelper.cs" />
    <Compile Include="Class\DESEncrypt.cs" />
    <Compile Include="Class\GetNumbers.cs" />
    <Compile Include="Class\HotKey.cs" />
    <Compile Include="Class\NistTime.cs" />
    <Compile Include="Class\NPOIHelper.cs" />
    <Compile Include="Class\GetTokenHelper.cs" />
    <Compile Include="Class\TTHttp.cs" />
    <Compile Include="Class\XmlHelper.cs" />
    <Compile Include="DAL\BaseDAL.cs" />
    <Compile Include="DAL\WechatInfoDAL.cs" />
@@ -94,6 +104,12 @@
    </Compile>
    <Compile Include="frmCollect.Designer.cs">
      <DependentUpon>frmCollect.cs</DependentUpon>
    </Compile>
    <Compile Include="frmCollectTI.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="frmCollectTI.Designer.cs">
      <DependentUpon>frmCollectTI.cs</DependentUpon>
    </Compile>
    <Compile Include="frmCollectWX.cs">
      <SubType>Form</SubType>
@@ -121,6 +137,9 @@
    <EmbeddedResource Include="frmCollect.resx">
      <DependentUpon>frmCollect.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="frmCollectTI.resx">
      <DependentUpon>frmCollectTI.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="frmCollectWX.resx">
      <DependentUpon>frmCollectWX.cs</DependentUpon>
    </EmbeddedResource>
@@ -140,7 +159,9 @@
      <DependentUpon>Resources.resx</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <None Include="app.config" />
    <None Include="app.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="packages.config" />
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
BankRobot/app.config
@@ -6,4 +6,75 @@
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
  </startup>
  <appSettings>
    <!--公众号的验证码位置-->
    <add key="VerificationCodeLeft" value="85" />
    <add key="VerificationCodeTop" value="52" />
    <!--公众号的验证码输入位置-->
    <add key="inputLeft" value="85" />
    <add key="inputTop" value="52" />
    <!--公众号的验证码确认按钮位置-->
    <add key="determineLeft" value="85" />
    <add key="determineTop" value="52" />
    <!--界面刷新-->
    <add key="refreshLeft" value="85" />
    <add key="refreshTop" value="52" />
    <!--输入产品位置-->
    <add key="productLeft" value="600" />
    <add key="productTop" value="160" />
    <!--搜索产品位置-->
    <add key="searchproductLeft" value="780" />
    <add key="searchproductTop" value="154" />
    <!--输入购买数量位置-->
    <add key="purchasequantityLeft" value="1100" />
    <add key="purchasequantityTop" value="550" />
    <!--点击加入购物车位置-->
    <add key="shoppingcartLeft" value="1150" />
    <add key="shoppingcartTop" value="600" />
    <!--点击结算位置-->
    <add key="settlementLeft" value="550" />
    <add key="settlementTop" value="600" />
    <!--点击购物车里的结算位置-->
    <add key="settlementtwoLeft" value="1465" />
    <add key="settlementtwoTop" value="480" />
    <!--点击浏览器下滑-->
    <add key="slidedownwardLeft" value="1525" />
    <add key="slidedownwardTop" value="790" />
    <!--点击下一步-->
    <add key="nextstepLeft" value="340" />
    <add key="nextstepTop" value="600" />
    <!--点击必选框-->
    <add key="mandatoryLeft" value="209" />
    <add key="mandatoryTop" value="513" />
    <!--第二次点击下一步-->
    <add key="nextsteptwoLeft" value="345" />
    <add key="nextsteptwoTop" value="565" />
    <!--点击确认并继续-->
    <add key="determineLeft" value="550" />
    <add key="determineTop" value="460" />
    <!--第三次点击下一步-->
    <add key="nextstepthreeLeft" value="360" />
    <add key="nextstepthreeTop" value="550" />
    <!--点击服务条款阅读-->
    <add key="serviceLeft" value="730"/>
    <add key="serviceTop" value="690" />
    <!--点击接受-->
    <add key="acceptLeft" value="215" />
    <add key="acceptTop" value="770" />
    <!--第四次点击下一步-->
    <add key="nextstepfourLeft" value="320" />
    <add key="nextstepfourTop" value="640" />
    <!--选择支付宝-->
    <add key="alipayLeft" value="250" />
    <add key="alipayTop" value="620" />
    <!--选择微信-->
    <add key="weChatLeft" value="250" />
    <add key="weChatTop" value="400" />
    <!--点击支付-->
    <add key="paymentLeft" value="595" />
    <add key="paymentTop" value="230" />
    <!--支付截图位置-->
    <add key="iLeft" value="670" />
    <add key="iTop" value="235" />
  </appSettings>
</configuration>
BankRobot/frmCollectWX.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
@@ -16,6 +17,8 @@
using CrawRobot.BLL;
using CrawRobot.Model;
using ImgRec;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace CrawRobot
{
@@ -33,7 +36,7 @@
        public const int MOUSEEVENTF_ABSOLUTE = 0x8000;
        public static bool bStop = false;
        public static bool bExiting = false;     //正在退出
        public List<string> listWXGZH=new List<string>();//微信公众号
        public List<string> listWXGZH = new List<string>();//微信公众号
        public WebBrowser webBrowser = null;
        public int iFileId = 0;
        public int iStoreNum = 0;
@@ -169,7 +172,7 @@
        /// 导入选中数据
        /// </summary>
        /// <param name="openfile"></param>
        private void ImportandGenerate(OpenFileDialog openfile,string strFilePath="")
        private void ImportandGenerate(OpenFileDialog openfile, string strFilePath = "")
        {
            try
            {
@@ -188,13 +191,13 @@
                    {
                        if (srcTable.Rows[i][3].ToString().Contains("迁移") == false)
                        {
                             listWXGZH.Add(srcTable.Rows[i][3].ToString());
                            listWXGZH.Add(srcTable.Rows[i][3].ToString());
                        }
                    }
                    //bLoadExcelFile = true;
                    lblStatus.Text = "导入最新清单数据成功!总计"+listWXGZH.Count+"条";
                    lblStatus.Text = "导入最新清单数据成功!总计" + listWXGZH.Count + "条";
                }
                else
                {
@@ -305,10 +308,10 @@
                        break;
                    }
                    if (j % 15 == 0&& j>0)
                    if (j % 15 == 0 && j > 0)
                    {
                        richTextLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 延迟40分钟:" + j + "\r\n";
                        DelayTime(40*60000);
                        DelayTime(40 * 60000);
                    }
                    richTextLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Debug Index:" + j + "\r\n";
@@ -318,7 +321,7 @@
                    string strURL = HttpUtility.UrlEncode(txtURL.Text, Encoding.UTF8);
                    try
                    {
                        strURLSearch =
                            $"https://weixin.sogou.com/weixin?type=1&s_from=input&query={strURL}&ie=utf8&_sug_=n&_sug_type_=";
                        webBrowser1.Navigate(strURLSearch);
@@ -326,7 +329,7 @@
                        strResult = webBrowser1.Document.Body.InnerHtml;
                        //strResult = HttpApi(strURLSearch, "", "post");
                    }
                    catch
                    catch
                    {
                        try
                        {
@@ -376,11 +379,28 @@
                    }
                    else if (strResult.Contains("我们的系统检测到您网络中存在异常访问请求"))
                    {
                        richTextLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 未能获取到最新文章:" +
                                            listWXGZH[j] + ",系统检测到您网络中存在异常访问请求,我们将等待1s\r\n";
                        DelayTime(1000);
                        webBrowser1.Navigate(strURLSearch);
                        richTextLog.Text += "系统重新访问URL并等待3s:" + strURLSearch+"\r\n";
                        //截取验证码
                        int VerificationCodeLeft = Convert.ToInt32(ConfigurationManager.AppSettings["VerificationCodeLeft"]);
                        int VerificationCodeTop = Convert.ToInt32(ConfigurationManager.AppSettings["VerificationCodeTop"]);
                        string Base64Pic = ScreenVerifyCode(VerificationCodeLeft, VerificationCodeTop);
                        string VerifyCode = ValidateVerifyCode(Base64Pic);
                        if (VerifyCode != null)
                        {
                            //输入验证码
                            int inputLeft = Convert.ToInt32(ConfigurationManager.AppSettings["inputLeft"]);
                            int inputTop = Convert.ToInt32(ConfigurationManager.AppSettings["inputTop"]);
                            InputTextInfo(VerifyCode, inputLeft, inputTop);
                            //点击提交
                            int determineLeft = Convert.ToInt32(ConfigurationManager.AppSettings["determineLeft"]);
                            int determineTop = Convert.ToInt32(ConfigurationManager.AppSettings["determineTop"]);
                            ClickButtonBy(determineLeft, determineTop);
                        }
                        richTextLog.Text += "系统重新访问URL并等待3s:" + strURLSearch + "\r\n";
                        DelayTime(6000);
                        strResult = webBrowser1.Document.Body.InnerHtml;
                        if (strResult.Contains("最近文章:"))
@@ -418,7 +438,7 @@
                        else if (strResult.Contains("我们的系统检测到您网络中存在异常访问请求"))
                        {
                            richTextLog.Text += "系统等待30分钟解锁\r\n";
                            DelayTime(30*60000);
                            DelayTime(30 * 60000);
                        }
                        else
                        {
@@ -493,7 +513,7 @@
            {
                if (e.Url.ToString() != webBrowser1.Url.ToString())
                    return;
                if (e.Url.ToString().IndexOf("weixin.sogou.com")>=0)
                if (e.Url.ToString().IndexOf("weixin.sogou.com") >= 0)
                    return;
                if (bStop)
                    return;
@@ -509,7 +529,7 @@
                DelayTime(30);
                string strResult = Clipboard.GetData("Text").ToString().Replace("\r\n\r\n", "\r\n");//Tel. #: [+]{0,}[(0-9)]{0,}[0-9\- ]{3,}
                //1.过滤冗余字段
                string[] strFilterWord = { "赞赏二维码", "点个在看你最好看" };
                for (int i = 0; i < strFilterWord.Length; i++)
@@ -558,7 +578,7 @@
                    string strTitleTmp = strResult.Substring(0, strResult.IndexOf(strContentTime));
                    string[] strTitleSplit = Regex.Split(strTitleTmp, @"\r\n", RegexOptions.IgnoreCase);
                    if(GetRedudentWordFlag(strTitleTmp))
                    if (GetRedudentWordFlag(strTitleTmp))
                    {
                        richTextLog.Text += "Store WebBrowser Text Info Skip! strTitleTmp:" + strTitleTmp + "\r\n";
                    }
@@ -574,24 +594,24 @@
                        wechatInfo.WechatName = txtURL.Text.Trim();
                        if (!wechatInfoBll.ExistWechatInfo(wechatInfo, false))
                        {
                           iStoreNum++;
                           iFileId = wechatInfoBll.AddWechatInfo(wechatInfo);
                           if (Clipboard.ContainsData(DataFormats.Html) && iFileId>0)
                           {
                               if(Clipboard.GetData(DataFormats.Html)==null) return;
                               //将剪切板中的内容先转为HTML,再转成图片
                               string html = Clipboard.GetData(DataFormats.Html).ToString();
                               //去除HTML文件中的文件源信息部分
                               html = html.Substring(html.IndexOf("<HTML"));
                               webBrowser = new WebBrowser();
                               //是否显式滚动条
                               webBrowser.ScrollBarsEnabled = false;
                               webBrowser.ScriptErrorsSuppressed = true;
                               //加载 html
                               webBrowser.DocumentText = html;
                               //页面加载完成执行事件
                               webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
                           }
                            iStoreNum++;
                            iFileId = wechatInfoBll.AddWechatInfo(wechatInfo);
                            if (Clipboard.ContainsData(DataFormats.Html) && iFileId > 0)
                            {
                                if (Clipboard.GetData(DataFormats.Html) == null) return;
                                //将剪切板中的内容先转为HTML,再转成图片
                                string html = Clipboard.GetData(DataFormats.Html).ToString();
                                //去除HTML文件中的文件源信息部分
                                html = html.Substring(html.IndexOf("<HTML"));
                                webBrowser = new WebBrowser();
                                //是否显式滚动条
                                webBrowser.ScrollBarsEnabled = false;
                                webBrowser.ScriptErrorsSuppressed = true;
                                //加载 html
                                webBrowser.DocumentText = html;
                                //页面加载完成执行事件
                                webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
                            }
                        }
                        //richTextLog.Text += "Done!";
@@ -640,7 +660,7 @@
        {
            //获取解析后HTML的大小
            System.Drawing.Rectangle rectangle = webBrowser.Document.Body.ScrollRectangle;
            int width = rectangle.Width<1000?1000:rectangle.Width;
            int width = rectangle.Width < 1000 ? 1000 : rectangle.Width;
            int height = rectangle.Height;
            //设置解析后HTML的可视区域
@@ -659,7 +679,7 @@
                    Directory.CreateDirectory(dir);
                }
                filePath = new StringBuilder(dir).Append("\\").Append(DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss_")).Append(txtURL.Text.Trim()+"FID"+iFileId).Append(".png").ToString();
                filePath = new StringBuilder(dir).Append("\\").Append(DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss_")).Append(txtURL.Text.Trim() + "FID" + iFileId).Append(".png").ToString();
                bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
            }
@@ -716,7 +736,7 @@
            }
            catch (Exception ex)
            {
                richTextLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 定时器异常错误\r\n"+ex.ToString();
                richTextLog.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 定时器异常错误\r\n" + ex.ToString();
                //ResetSystem("定时器异常提前退出!");
                //MessageBox.Show("定时器异常提前退出!"+ex.ToString());
            }
@@ -750,5 +770,159 @@
                MessageBox.Show("系统启动异常终止!确认后可以继续抓取!\r\n错误信息:" + exception.ToString());
            }
        }
        /// <summary>
        /// 指定位置截取验证码
        /// </summary>
        /// <param name="iLeft"></param>
        /// <param name="iTop"></param>
        /// <returns></returns>
        private string ScreenVerifyCode(int iLeft, int iTop)
        {
            SetCursorPos(iLeft, iTop);
            int iWidth = 120;//int iWidth = 92;
            int iHeight = 45;//int iHeight = 36;
            Bitmap myImage = new Bitmap(iWidth, iHeight);
            Graphics gla = Graphics.FromImage(myImage);
            gla.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            gla.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gla.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            gla.CopyFromScreen(iLeft, iTop, 0, 0, new Size(iWidth, iHeight));
            myImage.Save(System.AppDomain.CurrentDomain.BaseDirectory + "/yzm.png");
            //字面是对当前图片进行了二进制转换
            MemoryStream ms = new MemoryStream();
            myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] arr = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(arr, 0, (int)ms.Length);
            ms.Close();
            string Base64Pic = Convert.ToBase64String(arr);
            return Base64Pic;
        }
        // <summary>
        /// 指定位置点击按钮
        /// </summary>
        /// <param name="iLeft"></param>
        /// <param name="iTop"></param>
        private void ClickButtonBy(int iLeft, int iTop, int DelayMS = 1000)
        {
            DelayTime(200);
            SetCursorPos(iLeft, iTop);
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            DelayTime(DelayMS);
        }
        /// <summary>
        /// 指定位置输入内容
        /// </summary>
        /// <param name="TextInfo"></param>
        /// <param name="iLeft"></param>
        /// <param name="iTop"></param>
        private void InputTextInfo(string TextInfo, int iLeft, int iTop, int DelayMS = 600)
        {
            DelayTime(DelayMS);
            Clipboard.SetDataObject(TextInfo);
            SetCursorPos(iLeft, iTop);
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            DelayTime(50);
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            DelayTime(30);
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            SendKeys.SendWait("{BACKSPACE}");
            DelayTime(30);
            SendKeys.SendWait("^v");
            DelayTime(20);
        }
        /// <summary>
        /// 调用接口识别验证码
        /// </summary>
        /// <param name="Base64Pic"></param>
        /// <returns></returns>
        private string ValidateVerifyCode(string Base64Pic)
        {
            //网址信息 http://www.ttshitu.com/
            // 识别
            // 图鉴平台的账号
            string UserName = "xl";
            // 图鉴平台账号对应的密码
            string Password = "123456!";
            // 16:汉字
            // 14:图片旋转
            // 11:计算题
            // 7:无感学习
            // 4:闪动GIF
            // 3:数英混合
            // 2:纯英文
            // 1:纯数字.
            string TypeId = "1";
            // 超时等待,单位:秒
            string TimeOut = "60";
            //将base64强转图片
            string base64 = Base64Pic.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
            byte[] bytes = Convert.FromBase64String(base64);
            byte[] VImage = bytes;
            var param = new Dictionary<object, object>{
                {"username",UserName},
                {"password",Password},
                {"typeid",TypeId},
                {"timeout",TimeOut}
            };
            string PostResult = TTHttp.Post("http://api.ttshitu.com/create.json", param, VImage);
            //json
            string joSuccess = "";
            string joMessage = "";
            //
            string joId = "";
            string joResult = "";
            JObject jo = null;
            try
            {
                jo = (JObject)JsonConvert.DeserializeObject(PostResult);
                // 识别结果
                joSuccess = jo["success"].ToString().ToLower();
                // 关联提示
                joMessage = jo["message"].ToString();
            }
            catch { }
            //识别成功
            if (joSuccess == "true")
            {
                //平台返回的图片ID
                joId = jo["data"]["id"].ToString();
                // 平台返回的识别结果
                joResult = jo["data"]["result"].ToString();
                //MessageBox.Show(joResult);
                // 可以按需要继续写入您的业务逻辑
                if (joResult != null)
                {
                }
            }
            else
            {
                // 识别失败
                //MessageBox.Show("识别失败:" + joMessage);
            }
            return joResult;
        }
    }
}
BankRobot/packages.config
@@ -2,6 +2,8 @@
<packages>
  <package id="BouncyCastle" version="1.8.9" targetFramework="net46" />
  <package id="Dapper" version="1.50.5" targetFramework="net46" />
  <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net46" />
  <package id="Newtonsoft.Json.Bson" version="1.0.2" targetFramework="net46" />
  <package id="NPOI" version="2.0.6" targetFramework="net35" requireReinstallation="true" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net35" />
</packages>