You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdd-order-api/app/libs/tool/class.BaiduAip.php

32 lines
1003 B
PHP

<?php
Zc::import('@.vendor.baidu-aip.AipOcr');
class BaiduAip {
private $client;
public function __construct(){
$appId = 11692379;
$apiKey = 'v299PNarO7aK5SmVxFoVSMEq';
$secretKey = 'ZWED3khD2u4vdfTderCyBdeH0Oa2xPkx';
$this->client = new AipOcr($appId, $apiKey, $secretKey);
}
public function posOCRByUrl($imgUrl){
// 如果有可选参数
$options = array();
$options["language_type"] = "CHN_ENG";
$options["detect_direction"] = "true";
$options["detect_language"] = "true";
$options["probability"] = "true";
// 带参数调用通用文字识别, 图片参数为远程url图片
$postResp = $this->client->basicGeneralUrl($imgUrl, $options);
if ($postResp['error_code'] > 0) {
return CommonTool::failCodeResult($postResp['error_code'], $postResp['error_msg']);
}
return CommonTool::successResult(array(
'direction' => $postResp['direction'],
'wordsResultNum' => $postResp['words_result_num'],
'wordsResult' => $postResp['words_result']
));
}
}