pull/5/head
wanghousheng 6 months ago
parent 99f0a153a1
commit 4574b264b8
  1. 25
      app/common/library/baidu/OcrLicense.php

@ -106,26 +106,6 @@ class OcrLicense
return json_decode($response); 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 * @notes:获取token
* @return mixed|string * @return mixed|string
@ -134,7 +114,10 @@ class OcrLicense
private function getToken() private function getToken()
{ {
$token = ''; $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)) { if (!empty($result->access_token)) {
$token = $result->access_token; $token = $result->access_token;
} else { } else {

Loading…
Cancel
Save