图鉴,是基于人工智能的高可用图片识别平台,可以识别二维码、验证码、缺图验证码等。

图鉴函数方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

declare(strict_types=1);

class ImgCaptcha
{

/**
* 图鉴 http://www.ttshitu.com/
*
* @param string $image 图片地址
* @param string $typeid 识别类型
*
* @return string
*/
public static function ttShiTu(string $image = '', string $typeid = '3'): string
{
$api_url = 'http://api.ttshitu.com/predict';
$info = [
'username' => '',
'password' => '',
'typeid' => $typeid,
'image' => $image
];
$res = self::getHttpResponse($api_url, [], json_encode($info));
$data = json_decode($res, true);
$captcha = '';
if ($data['success'] === true) {
$captcha = $data['data']['result'];
}

return $captcha;
}

// 请求外部资源
private static function getHttpResponse($url, $header = [], $post = null, $timeout = 10)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if ($header) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} else {
$httpheader[] = "Accept: */*";
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.9";
$httpheader[] = "Connection: close";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
}
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($post) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$response = curl_exec($ch);
curl_close($ch);

return $response;
}
}

调用方法:

1
2
3
4
5
6
7
// 解析验证码
private function getCaptchaInfo(string $image = '', string $typeid = '3'): string
{
$captcha = \ImgCaptcha::ttShiTu($image, $typeid);

return $captcha;
}

使用方法:

1
$captcha      = $this->getCaptchaInfo($img_url, '33');