|
|
|
@ -106,6 +106,26 @@ class OcrLicense |
|
|
|
|
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 |
|
|
|
@ -114,10 +134,7 @@ class OcrLicense |
|
|
|
|
private function getToken() |
|
|
|
|
{ |
|
|
|
|
$token = ''; |
|
|
|
|
$data['grant_type'] = 'client_credentials'; |
|
|
|
|
$data['client_id'] = $this->clientId; |
|
|
|
|
$data['client_secret'] = $this->clientSecret; |
|
|
|
|
$result = $this->post(self::TOKENURL, $data); |
|
|
|
|
$result = $this->curlToken(); |
|
|
|
|
if (!empty($result->access_token)) { |
|
|
|
|
$token = $result->access_token; |
|
|
|
|
} else { |
|
|
|
|