ClearDataService.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Service;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\Redis;
  5. class ClearDataService extends Service
  6. {
  7. public static function getTokenLf(){
  8. $token_key = 'lf_device_token';
  9. $token = Redis::get($token_key);
  10. if(! $token){
  11. $url = config('ip.zslf');
  12. $post = array("name" => "LFMY001","password"=>"12345678","rememberMe"=>true);
  13. $header = ['Content-Type:application/json'];
  14. $curl = curl_init();
  15. curl_setopt_array($curl, array(
  16. CURLOPT_URL => $url . 'jbl/api/mes/login',
  17. CURLOPT_RETURNTRANSFER => true,
  18. CURLOPT_ENCODING => '',
  19. CURLOPT_MAXREDIRS => 10,
  20. CURLOPT_TIMEOUT => 0,
  21. CURLOPT_FOLLOWLOCATION => true,
  22. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  23. CURLOPT_CUSTOMREQUEST => 'POST',
  24. CURLOPT_SSL_VERIFYPEER => false,
  25. CURLOPT_POSTFIELDS => json_encode($post),
  26. CURLOPT_HTTPHEADER => $header,
  27. ));
  28. $response = curl_exec($curl);
  29. if ($response === false) {
  30. // 获取错误号
  31. $errorNumber = curl_errno($curl);
  32. // 获取错误信息
  33. $errorMessage = curl_error($curl);
  34. $message = "cURL Error #{$errorNumber}: {$errorMessage}";
  35. Log::channel('apiLog')->info('lf获取token curl', ["param" => $message]);
  36. }
  37. curl_close($curl);
  38. $result = json_decode($response,true);
  39. if(empty($result['token'])) {
  40. Log::channel('apiLog')->info('lf获取token curl', ["param" => $response]);
  41. return [false,''];
  42. }else{
  43. $token = $result['token'];
  44. $expire_time = 1728000; //20天
  45. Redis::set($token_key,$token);
  46. Redis::expire($token_key, $expire_time);
  47. return [true,$token];
  48. }
  49. }
  50. return [true,$token];
  51. }
  52. public static function getTokenHc(){
  53. $token_key = 'hc_device_token';
  54. $token = Redis::get($token_key);
  55. if(! $token){
  56. $url = config('ip.zslf');
  57. $post = array("name" => "hcltdemo","password"=>"12345678","rememberMe"=>true);
  58. $header = ['Content-Type:application/json'];
  59. $curl = curl_init();
  60. curl_setopt_array($curl, array(
  61. CURLOPT_URL => $url . 'jbl/api/mes/login',
  62. CURLOPT_RETURNTRANSFER => true,
  63. CURLOPT_ENCODING => '',
  64. CURLOPT_MAXREDIRS => 10,
  65. CURLOPT_TIMEOUT => 0,
  66. CURLOPT_FOLLOWLOCATION => true,
  67. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  68. CURLOPT_CUSTOMREQUEST => 'POST',
  69. CURLOPT_SSL_VERIFYPEER => false,
  70. CURLOPT_POSTFIELDS => json_encode($post),
  71. CURLOPT_HTTPHEADER => $header,
  72. ));
  73. $response = curl_exec($curl);
  74. if ($response === false) {
  75. // 获取错误号
  76. $errorNumber = curl_errno($curl);
  77. // 获取错误信息
  78. $errorMessage = curl_error($curl);
  79. $message = "cURL Error #{$errorNumber}: {$errorMessage}";
  80. Log::channel('apiLog')->info('hc获取token curl', ["param" => $message]);
  81. }
  82. curl_close($curl);
  83. $result = json_decode($response,true);
  84. if(empty($result['token'])) {
  85. Log::channel('apiLog')->info('hc获取token', ["param" => $response]);
  86. return [false, ''];
  87. }else{
  88. $token = $result['token'];
  89. $expire_time = 1728000; //20天
  90. Redis::set($token_key,$token);
  91. Redis::expire($token_key, $expire_time);
  92. return [true,$token];
  93. }
  94. }
  95. return [true,$token];
  96. }
  97. public static function getTokenJLWM(){
  98. $token_key = 'jlwm_device_token';
  99. $token = Redis::get($token_key);
  100. if(! $token){
  101. $url = config('ip.zslf');
  102. $post = array("name" => "jlwmdemo","password"=>"12345678","rememberMe"=>true);
  103. $header = ['Content-Type:application/json'];
  104. $curl = curl_init();
  105. curl_setopt_array($curl, array(
  106. CURLOPT_URL => $url . 'jbl/api/mes/login',
  107. CURLOPT_RETURNTRANSFER => true,
  108. CURLOPT_ENCODING => '',
  109. CURLOPT_MAXREDIRS => 10,
  110. CURLOPT_TIMEOUT => 0,
  111. CURLOPT_FOLLOWLOCATION => true,
  112. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  113. CURLOPT_CUSTOMREQUEST => 'POST',
  114. CURLOPT_SSL_VERIFYPEER => false,
  115. CURLOPT_POSTFIELDS => json_encode($post),
  116. CURLOPT_HTTPHEADER => $header,
  117. ));
  118. $response = curl_exec($curl);
  119. if ($response === false) {
  120. // 获取错误号
  121. $errorNumber = curl_errno($curl);
  122. // 获取错误信息
  123. $errorMessage = curl_error($curl);
  124. $message = "cURL Error #{$errorNumber}: {$errorMessage}";
  125. Log::channel('apiLog')->info('jlwm获取token curl', ["param" => $message]);
  126. }
  127. curl_close($curl);
  128. $result = json_decode($response,true);
  129. if(empty($result['token'])) {
  130. Log::channel('apiLog')->info('jlwm获取token', ["param" => $response]);
  131. return [false, ''];
  132. }else{
  133. $token = $result['token'];
  134. $expire_time = 1728000; //20天
  135. Redis::set($token_key,$token);
  136. Redis::expire($token_key, $expire_time);
  137. return [true,$token];
  138. }
  139. }
  140. return [true,$token];
  141. }
  142. }