|
@@ -2,8 +2,7 @@
|
|
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-use App\Model\DeviceData;
|
|
|
|
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
|
|
class ClearDataService extends Service
|
|
class ClearDataService extends Service
|
|
@@ -36,13 +35,13 @@ class ClearDataService extends Service
|
|
|
// 获取错误信息
|
|
// 获取错误信息
|
|
|
$errorMessage = curl_error($curl);
|
|
$errorMessage = curl_error($curl);
|
|
|
$message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
$message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
|
- file_put_contents('lf_device_error.txt',date('Y-m-d H:i:s'). PHP_EOL . $message .PHP_EOL,8);
|
|
|
|
|
|
|
+ Log::channel('apiLog')->info('lf获取token curl', ["param" => $message]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
curl_close($curl);
|
|
curl_close($curl);
|
|
|
$result = json_decode($response,true);
|
|
$result = json_decode($response,true);
|
|
|
if(empty($result['token'])) {
|
|
if(empty($result['token'])) {
|
|
|
- file_put_contents('lf_device_error.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL,8);
|
|
|
|
|
|
|
+ Log::channel('apiLog')->info('lf获取token curl', ["param" => $response]);
|
|
|
return [false,''];
|
|
return [false,''];
|
|
|
}else{
|
|
}else{
|
|
|
$token = $result['token'];
|
|
$token = $result['token'];
|
|
@@ -55,4 +54,100 @@ class ClearDataService extends Service
|
|
|
|
|
|
|
|
return [true,$token];
|
|
return [true,$token];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static function getTokenHc(){
|
|
|
|
|
+ $token_key = 'hc_device_token';
|
|
|
|
|
+ $token = Redis::get($token_key);
|
|
|
|
|
+ if(! $token){
|
|
|
|
|
+ $url = config('ip.zslf');
|
|
|
|
|
+ $post = array("name" => "hcltdemo","password"=>"12345678","rememberMe"=>true);
|
|
|
|
|
+ $header = ['Content-Type:application/json'];
|
|
|
|
|
+ $curl = curl_init();
|
|
|
|
|
+ curl_setopt_array($curl, array(
|
|
|
|
|
+ CURLOPT_URL => $url . 'jbl/api/mes/login',
|
|
|
|
|
+ CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
+ CURLOPT_ENCODING => '',
|
|
|
|
|
+ CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
+ CURLOPT_TIMEOUT => 0,
|
|
|
|
|
+ CURLOPT_FOLLOWLOCATION => true,
|
|
|
|
|
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
+ CURLOPT_CUSTOMREQUEST => 'POST',
|
|
|
|
|
+ CURLOPT_SSL_VERIFYPEER => false,
|
|
|
|
|
+ CURLOPT_POSTFIELDS => json_encode($post),
|
|
|
|
|
+ CURLOPT_HTTPHEADER => $header,
|
|
|
|
|
+ ));
|
|
|
|
|
+ $response = curl_exec($curl);
|
|
|
|
|
+ if ($response === false) {
|
|
|
|
|
+ // 获取错误号
|
|
|
|
|
+ $errorNumber = curl_errno($curl);
|
|
|
|
|
+ // 获取错误信息
|
|
|
|
|
+ $errorMessage = curl_error($curl);
|
|
|
|
|
+ $message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
|
|
|
+ Log::channel('apiLog')->info('hc获取token curl', ["param" => $message]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ curl_close($curl);
|
|
|
|
|
+ $result = json_decode($response,true);
|
|
|
|
|
+ if(empty($result['token'])) {
|
|
|
|
|
+ Log::channel('apiLog')->info('hc获取token', ["param" => $response]);
|
|
|
|
|
+ return [false, ''];
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $token = $result['token'];
|
|
|
|
|
+ $expire_time = 1728000; //20天
|
|
|
|
|
+ Redis::set($token_key,$token);
|
|
|
|
|
+ Redis::expire($token_key, $expire_time);
|
|
|
|
|
+ return [true,$token];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true,$token];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function getTokenJLWM(){
|
|
|
|
|
+ $token_key = 'jlwm_device_token';
|
|
|
|
|
+ $token = Redis::get($token_key);
|
|
|
|
|
+ if(! $token){
|
|
|
|
|
+ $url = config('ip.zslf');
|
|
|
|
|
+ $post = array("name" => "jlwmdemo","password"=>"12345678","rememberMe"=>true);
|
|
|
|
|
+ $header = ['Content-Type:application/json'];
|
|
|
|
|
+ $curl = curl_init();
|
|
|
|
|
+ curl_setopt_array($curl, array(
|
|
|
|
|
+ CURLOPT_URL => $url . 'jbl/api/mes/login',
|
|
|
|
|
+ CURLOPT_RETURNTRANSFER => true,
|
|
|
|
|
+ CURLOPT_ENCODING => '',
|
|
|
|
|
+ CURLOPT_MAXREDIRS => 10,
|
|
|
|
|
+ CURLOPT_TIMEOUT => 0,
|
|
|
|
|
+ CURLOPT_FOLLOWLOCATION => true,
|
|
|
|
|
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
|
|
|
+ CURLOPT_CUSTOMREQUEST => 'POST',
|
|
|
|
|
+ CURLOPT_SSL_VERIFYPEER => false,
|
|
|
|
|
+ CURLOPT_POSTFIELDS => json_encode($post),
|
|
|
|
|
+ CURLOPT_HTTPHEADER => $header,
|
|
|
|
|
+ ));
|
|
|
|
|
+ $response = curl_exec($curl);
|
|
|
|
|
+ if ($response === false) {
|
|
|
|
|
+ // 获取错误号
|
|
|
|
|
+ $errorNumber = curl_errno($curl);
|
|
|
|
|
+ // 获取错误信息
|
|
|
|
|
+ $errorMessage = curl_error($curl);
|
|
|
|
|
+ $message = "cURL Error #{$errorNumber}: {$errorMessage}";
|
|
|
|
|
+ Log::channel('apiLog')->info('jlwm获取token curl', ["param" => $message]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ curl_close($curl);
|
|
|
|
|
+ $result = json_decode($response,true);
|
|
|
|
|
+ if(empty($result['token'])) {
|
|
|
|
|
+ Log::channel('apiLog')->info('jlwm获取token', ["param" => $response]);
|
|
|
|
|
+ return [false, ''];
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $token = $result['token'];
|
|
|
|
|
+ $expire_time = 1728000; //20天
|
|
|
|
|
+ Redis::set($token_key,$token);
|
|
|
|
|
+ Redis::expire($token_key, $expire_time);
|
|
|
|
|
+ return [true,$token];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true,$token];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|