/**
* 获取图片base64数据
* @param ImageFile String 图片路径
* @return base64数据
*/
function Base64EncodeImage($ImageFile) {
if(file_exists($ImageFile) || is_file($ImageFile)){
$base64_image = '';
$image_data = fread(fopen($ImageFile, 'r'), filesize($ImageFile));
$base64_image = base64_encode($image_data);
return $base64_image;
} else {
return '';
}
}
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
function send_post($url, $post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 30
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
// 获取图片base64位数据
$picdata = Base64EncodeImage('getverifyimage.png'); // 请替换成目标图片路径
$post_data = array(
'username' => 'admin',
'password' => '123456',
'captchaType' => 1001,
'captchaData' => $picdata
);
$result = send_post('http://www.bingtop.com/ocr/upload/', $post_data);
// 返回值示例{"code":0, "message":"", "data":{"captchaId":"1001-158201918112812","recognition":"RESULT"}}
echo $result