cqpCow il y a 1 an
Parent
commit
f31009f1d2

+ 10 - 0
app/Http/Controllers/Api/JRFIDController.php

@@ -35,4 +35,14 @@ class JRFIDController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function getPrintData(Request $request){
+        list($bool, $data) = (new JRFIDServerService())->getPrintData($request->all());
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 0 - 46
app/Http/Controllers/Api/JobController.php

@@ -2,55 +2,9 @@
 
 namespace App\Http\Controllers\Api;
 
-
-use App\Jobs\DesktopDeviceJob;
-use App\Jobs\LabelDealJob;
-use App\Jobs\ManDeviceJob;
-use App\Jobs\ProcessDataJob;
-use App\Model\BigKingCbj;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Redis;
 
-
 class JobController extends BaseController
 {
-    //温度压力传感器设备
-    public function processDataJobAdd(Request $request)
-    {
-        dispatch(new ProcessDataJob($request->all()))->onQueue('cloud_device');
-        echo 'ok';
-    }
-
-    //桌面设备
-    public function processDataJobAddDevice(Request $request){
-        dispatch(new DesktopDeviceJob($request->all()))->onQueue('desktop_device');
-        echo 'ok';
-    }
-
-    //有人云
-    public function processDataJobAddDeviceMan(Request $request){
-        dispatch(new ManDeviceJob($request->all()))->onQueue('man_device');
-
-        echo $request->get('verify');die;
-    }
-
-    public function delKey(Request $request){return;
-        $token_key = 'big_king_login_token';
-//        $token = Redis::get($token_key);
-        Redis::del($token_key);
-    }
-
-    public function labelDeal(Request $request){
-        //记录数据
-        $model = new BigKingCbj();
-        $model->data = json_encode($request->all());
-        $model->crt_time = time();
-        $model->save();
-        $id = $model->id;
-
-        $header = $request->header('Authorization');
-        dispatch(new LabelDealJob($request->all(), $header, $id))->onQueue('label_deal');
-
-        return ['status'=>200,'msg'=>'success'];
-    }
 }

+ 22 - 0
app/Service/JRFIDServerService.php

@@ -95,6 +95,28 @@ class JRFIDServerService extends Service
         return [true, $result];
     }
 
+    public function getPrintData($data){
+        if(empty($data['id'])) return [false, '数据ID不能为空'];
+        if(empty($data['type'])) return [false, '打印数据类型不能为空'];
+
+        $rsaService = new RsaEncryptionService();
+        $dataToEncrypt = $data['id'];
+        $encryptedData = $rsaService->encrypt($dataToEncrypt);
+
+        $url = config("j_rfid.get_print_data");
+        $post = [
+            'encrypted_data' => $encryptedData,
+            'type' => $data['type'],
+        ];
+
+        list($status,$result) = $this->post_helper($url,json_encode($post),['Content-Type:application/json']);
+        if(! $status) return [false, $result];
+
+        if(! empty($result['status']) && $result['status'] == 'error') return [false, $result['msg']];
+
+        return [true, $result];
+    }
+
     public function post_helper($url, $data, $header = [], $timeout = 20){
         file_put_contents('jrfid_record.txt',date('Y-m-d H:i:s') . "请求参数:" . $data . PHP_EOL . "请求头部:" . json_encode($header) . PHP_EOL,8);
         $ch = curl_init();

+ 16 - 0
app/Service/RsaEncryptionService.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Service;
+
+class RsaEncryptionService extends Service
+{
+    public function encrypt($data)
+    {
+        //公钥文件位于 storage/app/public/rsa/public.pem
+        $publicKeyPath = storage_path('app/public/rsa/public.pem');
+        $publicKey = openssl_pkey_get_public(file_get_contents($publicKeyPath));
+
+        openssl_public_encrypt($data, $encrypted, $publicKey);
+        return base64_encode($encrypted);
+    }
+}

+ 2 - 0
config/j_rfid.php

@@ -13,4 +13,6 @@ return [
     'get_flow_by_produce' => 'https://gzy.qingyaokeji.com/api/module-data/process_flow/process_flow/diy/get_flow_by_produce',
     //生产订单查询接口
     'get_produce_by_contract' => 'https://gzy.qingyaokeji.com/api/module-data/produce_order/produce_order/diy/get_produce_by_contract',
+    //打印数据获取接口
+    'get_print_data' => 'https://gzy.qingyaokeji.com/api/module-data/produce_order/produce_order/diy/get_produce_by_contract',
 ];

+ 1 - 0
routes/api.php

@@ -18,6 +18,7 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
 });
 
 Route::any('login', 'Api\LoginController@login');
+Route::any('getPrintData', 'Api\JRFIDController@getPrintData');
 
 Route::group(['middleware'=> ['CheckJRFIDLogin']],function ($route){
     //站点获取