diff --git a/app/common/library/baidu/OcrLicense.php b/app/common/library/baidu/OcrLicense.php index c67d1951..11d92a4f 100644 --- a/app/common/library/baidu/OcrLicense.php +++ b/app/common/library/baidu/OcrLicense.php @@ -105,27 +105,7 @@ class OcrLicense curl_close($curl); return json_decode($response); } - - public function curlToken() - { - $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_URL => "https://aip.baidubce.com/oauth/2.0/token?client_id=$this->clientId&client_secret=$this->clientSecret&grant_type=client_credentials", - CURLOPT_TIMEOUT => 30, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_SSL_VERIFYHOST => false, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_HTTPHEADER => array( - 'Content-Type: application/json', - 'Accept: application/json' - ), - )); - $response = curl_exec($curl); - curl_close($curl); - return $response; - } - + /** * @notes:获取token * @return mixed|string @@ -134,7 +114,10 @@ class OcrLicense private function getToken() { $token = ''; - $result = $this->curlToken(); + $data['grant_type'] = 'client_credentials'; + $data['client_id'] = $this->clientId; + $data['client_secret'] = $this->clientSecret; + $result = $this->post(self::TOKENURL, $data); if (!empty($result->access_token)) { $token = $result->access_token; } else {