PHP-ci version: 3.1.8
Baidu text recognition PHP sdk version: 2.2.2
Baidu text recognition document address (the document has the address of OCR PHP SDK download) https://cloud.baidu.com/doc/OCR/OCR-PHP-SDK.html#.E6.96.B0.E5.BB. BAAipOcr
After the download is complete, unzip the file to the application/libraries of PHP CodeIgniter (I built a directory under the libraries directory for separate management)
figure 1
If you create folder management in libraries separately like me, you need to make simple changes in the file introduction in the program; as shown in Figure 2
figure 2
If all the files and directories of the OCR PHP SDK are directly placed in the libraries directory, the above file paths can be left unchanged.
Here comes the point:
To change the construction method of the lib/AipBase.php file of the OCR PHP SDK (approximately between lines 50 and 80)
public function __construct($dataarr){ $this->appId = trim($dataarr['appId']); $this->apiKey = trim($dataarr['apiKey']); $this->secretKey = trim($dataarr['secretKey']); /*//The original constructor with three parameters is now passed as an array, the code is as above $this->appId = trim($appId); $this->apiKey = trim($apiKey); $this->secretKey = trim($secretKey); */ $this->isCloudUser = null; $this->client = new AipHttpClient(); $this->version = '2_2_2'; $this->proxies = array(); }
$this->load->library()//When loading the class library, the second parameter carries an array, so we need to use the three parameters of the above construction method as one parameter
This is simply changed. ready to use. The point is to remember to change the AipBase.php file.
defined('BASEPATH') OR exit('No direct script access allowed'); class Baiduocr extends CI_Controller { public function index() { $params = array('appId'=>'fill in your own', 'apiKey'=>' fill in your own ', 'secreKey'=>' fill in your own '); $this->load->library('AipOcr',$params);//Here you can create a config file for processing according to the official PHPci documentation given above $url ='http://wwwww.s21i.faiusr.com/4/11111111.png';//图片URL $data = $this->aipocr->basicGeneralUrl($url);//Choose the method of the corresponding function you need here print_r($data); } }
, and you can further understand the creation class library of PHP ci. . .