PHP code example of baidu-sdk / aip

1. Go to this page and download the library: Download baidu-sdk/aip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

baidu-sdk / aip example snippets


AipBase.php 基类
AipBCEUtil.php 工具类
AipHttpClient.php 请求类
---------------------
AipBodyAnalysis.php 人体关键点识别
AipContentCensor.php 内容识别
AipFace.php 人脸识别
AipImageCensor.php 黄反识别
AipImageClassify.php 图片识别类别
AipImageProcess.php 图片处理
AipImageSearch.php 图片搜索
AipKg.php	任务
AipNlp.php 语言处理
AipOcr.php OCR识别
AipSpeech.php 语音识别

以OCR为例

namespace App\Helpers;

use Baidu\Aip\AipOcr;//引入相应的模块

class OCR
{

    protected $appId='';//APP_ID
    protected $apiKey='';//API_KEY
    protected $secretKey='';//SECRET_KEY

    public function build(){
        $client = new AipOcr($this->appId, $this->apiKey, $this->secretKey);//不同的模块不同的类,具体请参考文档
        $image = file_get_contents('./wepay.jpg');
        $result=$client->basicGeneral($image);
        print_r($result);
        
    }
}