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

@ -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 {

Loading…
Cancel
Save