| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | 
							- <?php
 
- namespace App\Services\Common;
 
- use GuzzleHttp\Client;
 
- use Illuminate\Support\Facades\Cache;
 
- /**
 
-  * 百度智能云
 
-  * Class BaiduService
 
-  * @package App\Services\Common
 
-  */
 
- class BaiduService
 
- {
 
-     protected $url = "https://aip.baidubce.com/";
 
-     protected $appid;
 
-     protected $appkey;
 
-     protected $httpClient;
 
-     /**
 
-      * BaiduService constructor.
 
-      */
 
-     public function __construct()
 
-     {
 
-         $this->httpClient=new Client([
 
-             'http_errors' => false
 
-         ]);
 
-         $this->appid=config('aix.fangyi.fangyi_zhaokao.fangyi_zhaokao.client_id');
 
-         $this->appkey=config('aix.fangyi.fangyi_zhaokao.fangyi_zhaokao.client_secret');
 
-     }
 
-     public function getAccessToken()
 
-     {
 
-         $access_token = Cache::get('baidu_access_token');
 
-         if (empty($access_token)) {
 
-             $uri=$this->url."oauth/2.0/token?grant_type=client_credentials&client_id=$this->appid&client_secret=$this->appkey";
 
-             $curl = new CurlService();
 
-             $resopnse= $curl->get($uri);
 
-             $result = json_decode($resopnse, true);
 
-             Cache::put("wechat_access_token", $result['access_token'], 24*60*29);
 
-             return $result['access_token'];
 
-         }
 
-         return $access_token;
 
-     }
 
-     public function health_code($image, $options=array())
 
-     {
 
-         $data = array();
 
-         $data['image'] = base64_encode($image);
 
-         $data = array_merge($data, $options);
 
-         $curl = new CurlService();
 
-         $resopnse = $this->httpClient->post($this->url . "rest/2.0/ocr/v1/health_code",['form_params' => $data]);
 
-         dd($resopnse->getBody()->getContents());
 
-     }
 
- }
 
 
  |