这是我的原代码:
/**
* Post请求
*
* @param string $url 地址
* @param array $headers Http Header
* @param string $body 内容
* @return string
*/
function post($url, $headers, $body) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
// 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id
// 示例代码中 x-ti-app-id 非真实数据
const APP_ID = '6d9d285d1c896';
// 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code
// 示例代码中 x-ti-secret-code 非真实数据
const SECRET_CODE = 'be2b7be1f6203f';
// 通用表格识别
const URL = 'https://api.textin.com/ai/service/v2/recognize/table';
$headers = [
'x-ti-app-id:' . APP_ID,
'x-ti-secret-code:' . SECRET_CODE
];
$fileData = file_get_contents('123.png', false, stream_context_create([
'http' => [
'header' => 'Content-Type: image/png\r\n'
]
]));
$response = post(URL, $headers, $fileData);
$ocrResult = json_decode($response, true);
var_dump($ocrResult);
$ocrResult多维数组函数,能正确获取到,但是按原来的格式,在屏幕上显示表格及内容,不行,
这是识别出来的部份表格内容:发的图片,CSDN不让发内容。