YYPOST群发软件 发表于 2025-2-6 06:31:42

AIWORK联合图鉴实现全流程点击验证码

<p></p><div><br></div><div><table cellspacing="0" cellpadding="0" style="table-layout: fixed; width: 979px; font-size: 12px;"><tbody><tr><td class="t_f" id="postmessage_304" style="line-height: 24px;"><p style="font-size: 14px; margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"><ignore_js_op></ignore_js_op></p><p style="font-size: 14px;"></p><p style="font-size: 14px; margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"></p><p style="font-size: 14px; margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;"></p><br><p style="font-size: 14px;"></p><p style="font-size: 14px; margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;">详细版:</p><pre style="font-size: 12px; overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 1.6; font-family: &quot;YaHei Consolas Hybrid&quot;, Consolas, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">sendImageToAPI</span>(<span class="hljs-params" style="box-sizing: border-box;">username, password, typeid</span>) </span>{
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> url = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"http://api.ttshitu.com/predict"</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// API地址</span>


    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 截取全屏图像并裁剪验证码区域</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull().cutImagePercent(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.17</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.412</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.83</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.57</span>).toBase64();


    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 准备POST请求的数据</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> postData = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">JSON</span>.stringify({
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">username</span>: username,
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">password</span>: password,
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">typeid</span>: typeid,
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">image</span>: img <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// Base64 编码的图像</span>
    });


    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用OKHttp发送JSON请求并返回响应</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> okHttp().json(url, postData);
}


<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用该函数的示例</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> response = sendImageToAPI(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"账号"</span>, <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"密码"</span>, ID这个是数字不要弄错了);
printl(response); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印返回的结果</span>


<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 解析JSON响应并提取"result"字段的值</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> parsedResponse = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">JSON</span>.parse(response);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> result = parsedResponse.data.result;


<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 假设result是一个数组,例如["123", "456"]</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 将字符串转换为数字</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> x = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">Number</span>(result[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>]);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> y = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">Number</span>(result[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]);


printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">`原始X: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${x}</span>, 原始Y: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${y}</span>`</span>);


<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 假设您有一个基准坐标或者偏移量,这里我用基准坐标baseX和baseY作为示例</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 请根据实际情况替换下面的基准坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> baseX = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例基准X坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> baseY = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">200</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例基准Y坐标</span>


<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 计算实际的X和Y坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> X坐标 = x + baseX;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> Y坐标 = y + baseY;


printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">`实际X: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${X坐标}</span>`</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">`实际Y: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${Y坐标}</span>`</span>);


<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印结果</span>
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">`X: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${X坐标}</span>, Y: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${Y坐标}</span>`</span>);
</code></pre><p style="font-size: 14px; margin-bottom: 1.5em; box-sizing: border-box; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif;">如果想简单点调用的可以这样:</p><pre style="font-size: 12px; overflow-wrap: normal; box-sizing: border-box; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 1.6; font-family: &quot;YaHei Consolas Hybrid&quot;, Consolas, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Helvetica, monospace, monospace; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">sendImageToAPI</span>(<span class="hljs-params" style="box-sizing: border-box;">username, password, typeid</span>) </span>{
    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义API的URL地址</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> url = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"http://api.ttshitu.com/predict"</span>;

    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 截取全屏图像并裁剪验证码区域,然后将其转换为Base64编码</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull().cutImagePercent(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.17</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.412</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.83</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.57</span>).toBase64();

    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 准备POST请求的数据,包括用户名、密码、验证码类型ID和Base64编码的图像</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> postData = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">JSON</span>.stringify({
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">username</span>: username,
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">password</span>: password,
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">typeid</span>: typeid,
      <span class="hljs-attr" style="box-sizing: border-box; color: rgb(209, 154, 102);">image</span>: img <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// Base64 编码的图像</span>
    });

    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用OKHttp发送JSON请求并返回响应</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">return</span> <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> okHttp().json(url, postData);
}

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 调用sendImageToAPI函数,传入用户名、密码和验证码类型ID</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> response = sendImageToAPI(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"账号"</span>, <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"密码"</span>, ID这个是数字不要弄错了);

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 解析API返回的JSON响应</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> parsedResponse = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">JSON</span>.parse(response);

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提取JSON响应中的"result"字段的值</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> result = parsedResponse.data.result;

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 将字符串转换为数字</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> x = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">Number</span>(result[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>]);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> y = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">Number</span>(result[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]);

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 定义基准坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> baseX = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例基准X坐标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> baseY = <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">200</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 示例基准Y坐标</span>

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 计算实际的X和Y坐标,通过将基准坐标与解析得到的验证码坐标相加</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> X坐标 = x + baseX;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> Y坐标 = y + baseY;

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 打印计算得到的实际X和Y坐标</span>
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">`X: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${X坐标}</span>, Y: <span class="hljs-subst" style="box-sizing: border-box; color: rgb(224, 108, 117);">${Y坐标}</span>`</span>);
</code></pre><ol style="padding-left: 2em; box-sizing: border-box;"><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">函数定义</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sendImageToAPI(username, password, typeid)</code>:定义了一个名为<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sendImageToAPI</code>的函数,该函数接受三个参数:用户名、密码和验证码类型ID。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">API URL</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var url = "http://api.ttshitu.com/predict";</code>:定义了API的URL地址,该地址用于发送验证码识别请求。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">截取和裁剪图像</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var img = screen.screenShotFull().cutImagePercent(0.17, 0.412, 0.83, 0.57).toBase64();</code>:这段代码执行了三个主要操作:<ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">screen.screenShotFull()</code>:截取整个屏幕的图像。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">cutImagePercent(0.17, 0.412, 0.83, 0.57)</code>:根据百分比裁剪图像,提取验证码区域。这里的参数表示裁剪区域的左上角和右下角的百分比坐标。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">toBase64()</code>:将裁剪后的图像转换为Base64编码格式,以便于通过POST请求发送。</li></ul></li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">准备POST数据</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var postData = JSON.stringify({ username: username, password: password, typeid: typeid, image: img });</code>:将用户名、密码、验证码类型ID和Base64编码的图像封装成一个JSON对象,并将其转换为字符串格式,以便于HTTP请求。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">发送POST请求</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">return new okHttp().json(url, postData);</code>:使用<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">okHttp</code>库发送一个POST请求,请求的URL地址和数据分别为<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">url</code>和<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">postData</code>。该函数返回API的响应。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">调用函数并处理响应</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var response = sendImageToAPI("gmgne", "As123456", 27);</code>:调用<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">sendImageToAPI</code>函数,传入具体的用户名、密码和验证码类型ID,并将API的响应存储在<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">response</code>变量中。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var parsedResponse = JSON.parse(response);</code>:将API返回的JSON字符串解析为JavaScript对象。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var result = parsedResponse.data.result;</code>:从解析后的对象中提取<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">data.result</code>字段的值,该字段通常包含验证码识别的结果。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">字符串转数字</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var x = Number(result);</code>:将<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">result</code>数组中的第一个元素(假设是一个字符串)转换为数字,并赋值给<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">x</code>。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var y = Number(result);</code>:将<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">result</code>数组中的第二个元素转换为数字,并赋值给<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">y</code>。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">定义基准坐标</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var baseX = 100;</code>:定义了一个基准X坐标,用于后续计算。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var baseY = 200;</code>:定义了一个基准Y坐标,用于后续计算。</li></ul></li><li style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">计算实际坐标</span>:</p></li><ul style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var X坐标 = x + baseX;</code>:将基准X坐标与解析得到的X坐标相加,计算出实际的X坐标。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">var Y坐标 = y + baseY;</code>:将基准Y坐标与解析得到的Y坐标相加,计算出实际的Y坐标。</li></ul><li style=""><font color="#333333" face="Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif"><span style="font-size: 14px;">http://bbs.aiwork24.com/thread-112-1-1.html</span></font></li></ol></td></tr></tbody></table></div>
页: [1]
查看完整版本: AIWORK联合图鉴实现全流程点击验证码