From 99f0a153a1145be9913af853581114f56a281c66 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Mon, 15 Jul 2024 13:45:54 +0800 Subject: [PATCH] 1 --- app/common/library/baidu/OcrLicense.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/common/library/baidu/OcrLicense.php b/app/common/library/baidu/OcrLicense.php index a5dfaa17..c67d1951 100644 --- a/app/common/library/baidu/OcrLicense.php +++ b/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 {