| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace App\Service;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class ClearDataService extends Service
- {
- public static function getTokenLf(){
- $token_key = 'lf_device_token';
- $token = Redis::get($token_key);
- if(! $token){
- $url = config('ip.zslf');
- $post = array("name" => "LFMY001","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('lf获取token curl', ["param" => $message]);
- }
- curl_close($curl);
- $result = json_decode($response,true);
- if(empty($result['token'])) {
- Log::channel('apiLog')->info('lf获取token curl', ["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 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];
- }
- }
|