From d5e57a77a984fce56ec7c3867039f91c4704da48 Mon Sep 17 00:00:00 2001 From: xu Date: Fri, 8 Nov 2019 16:37:10 +0800 Subject: [PATCH] app-api 1. A 设备授权接口加密计算 app-ht 1. F 添加序列号界面逻辑调整 2. F 删除序列号列表的筛选条件改为和列表一样 3. F admin 不能编辑自己的权限和禁用自己 4. F 厂商登录之后无法修改版本和提交版本 common 1. U 优化RSA 和AES的代码类 --- app-api/config/url-rules.php | 2 ++ app-api/controllers/AuthDeviceController.php | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------- app-api/helpers/Aes.php | 73 ------------------------------------------------------------------------- app-ht/modules/device/controllers/DeviceController.php | 149 ++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------- app-ht/modules/device/views/device/createDevice.php | 26 +++++++++----------------- app-ht/modules/device/views/device/delete-index.php | 63 +++++++++++++++++++++++++++++++++++---------------------------- app-ht/modules/device/views/device/index.php | 62 +++++++++++++++++++++++++++++++------------------------------- app-ht/modules/system/views/account/index.php | 4 ++-- app-ht/modules/upgrade/controllers/UpgradeController.php | 15 ++++++++------- app-ht/modules/upgrade/views/upgrade/create.php | 11 +++++++++-- app-ht/modules/upgrade/views/upgrade/edit.php | 10 ++++++++-- common/exts/Aes.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/exts/RSACrypt.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/helpers/Utils.php | 2 +- console/controllers/TestController.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 15 files changed, 524 insertions(+), 331 deletions(-) delete mode 100644 app-api/helpers/Aes.php create mode 100644 common/exts/Aes.php create mode 100644 common/exts/RSACrypt.php diff --git a/app-api/config/url-rules.php b/app-api/config/url-rules.php index 15e4259..adc98ed 100644 --- a/app-api/config/url-rules.php +++ b/app-api/config/url-rules.php @@ -5,11 +5,13 @@ return [ 'POST authDevice' => 'auth-device/index', + 'POST authDeviceT' => 'auth-device/indext', 'POST checkOtaVersion' => 'upgrade/check-version', 'POST reportOtaUpgradeEvent' => 'upgrade/report-upgrade-event', 'POST checkAppVersion' => 'upgrade/check-app-version', 'POST reportAppUpgradeEvent' => 'upgrade/report-app-upgrade-event', 'POST reportDeviceVersion' => 'upgrade/report-device-version', + 'POST CryptTxt' => 'auth-device/crypt-txt', 'GET errorPage' => 'site/error-page-info', 'GET minaQuery' => 'site/mina-query', ]; \ No newline at end of file diff --git a/app-api/controllers/AuthDeviceController.php b/app-api/controllers/AuthDeviceController.php index 95e3d02..49e0a99 100644 --- a/app-api/controllers/AuthDeviceController.php +++ b/app-api/controllers/AuthDeviceController.php @@ -2,14 +2,13 @@ namespace app\api\controllers; - use Yii; - +use common\exts\RSACrypt; +use common\exts\Aes; use common\helpers\Utils; use common\helpers\Log as AppLog; -use domain\device\DeviceRepository; use domain\device\Device; -use domain\device\DeviceStatus; + use stdClass; use function date; @@ -37,66 +36,135 @@ class AuthDeviceController extends BaseController { AppLog::DEBUG($str); } + /** * 设备授权接口 * @return stdClass */ - public function actionIndex() - { - $e = new stdClass(); - $e->status = 1; - $e->message = 'message'; - $e->serial_no = '';; - $e->mac = ''; - - $getPostData = file_get_contents('php://input', 'r'); - self::myLog('actionIndex postData:'.$getPostData); - if (!$getPostData) { - $e->status = 1; - $e->message = '传入的数据为空'; - return $e; - } - $getPostData = json_decode($getPostData, true); - $manufactureNo = isset($getPostData['manufacture'])?$getPostData['manufacture']:''; - $deviceId = isset($getPostData['device_id'])?$getPostData['device_id']:''; - $projectNo = isset($getPostData['project'])?$getPostData['project']:''; - $modelNo = isset($getPostData['model'])?$getPostData['model']:''; - $productionNo = isset($getPostData['production'])?$getPostData['production']:''; - $timestamp = isset($getPostData['timestamp'])?$getPostData['timestamp']:''; - $sign = isset($getPostData['sign'])?$getPostData['sign']:''; - if (empty($deviceId) || empty($manufactureNo) || empty($projectNo) || empty($modelNo) || empty($productionNo)) { - $e->message = '传入的数据部分为空'; - return $e; - } - $pattern = "/^[a-zA-Z0-9]+$/"; - $dexPattern = "/^[0-9a-fA-F]+$/"; - if (!preg_match($pattern, $deviceId) || !preg_match($dexPattern, $manufactureNo) || !preg_match($dexPattern, $modelNo) || !preg_match($dexPattern, $productionNo)) { - $e->status = 9; - $e->message = '传入的数据字段格式不对'; - return $e; - } - if (isset(Yii::$app->params['secretKey']) && !empty(Yii::$app->params['secretKey'])) { - $salt = Yii::$app->params['secretKey']; - } else { - $salt = isset(Yii::$app->params['secretKey'])? Yii::$app->params['secretKey']: self::$SIGN_SALT; - } - - $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt); - if ($sign != $makeSign || empty($sign)) { - $e->status = 2; - $e->message = '签名出错'; - return $e; - } - - $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo); - - $e->status = $authResult->status; - $e->message = $authResult->message; - if ($authResult->success) { - $e->mac = $authResult->mac; - $e->serial_no = $authResult->serial_no; - } - - return $e; - } + public function actionIndex() + { + $getPostData = file_get_contents('php://input', 'r'); + self::myLog('actionIndex postData:'.$getPostData); + + return $this->authDevice($getPostData); + } + + /** + * @param $getPostData + * @return stdClass + */ + private function authDevice($getPostData) + { + $e = new stdClass(); + $e->status = 1; + $e->message = 'message'; + $e->serial_no = '';; + $e->mac = ''; + + $getPostData = json_decode($getPostData, true); + if (empty($getPostData)) { + $e->status = 1; + $e->message = '传入的数据为空'; + return $e; + } + $manufactureNo = isset($getPostData['manufacture'])?$getPostData['manufacture']:''; + $deviceId = isset($getPostData['device_id'])?$getPostData['device_id']:''; + $projectNo = isset($getPostData['project'])?$getPostData['project']:''; + $modelNo = isset($getPostData['model'])?$getPostData['model']:''; + $productionNo = isset($getPostData['production'])?$getPostData['production']:''; + $timestamp = isset($getPostData['timestamp'])?$getPostData['timestamp']:''; + $sign = isset($getPostData['sign'])?$getPostData['sign']:''; + if (empty($deviceId) || empty($manufactureNo) || empty($projectNo) || empty($modelNo) || empty($productionNo)) { + $e->message = '传入的数据部分为空'; + return $e; + } + $pattern = "/^[a-zA-Z0-9]+$/"; + $dexPattern = "/^[0-9a-fA-F]+$/"; + if (!preg_match($pattern, $deviceId) || !preg_match($dexPattern, $manufactureNo) || !preg_match($dexPattern, $modelNo) || !preg_match($dexPattern, $productionNo)) { + $e->status = 9; + $e->message = '传入的数据字段格式不对'; + return $e; + } + if (isset(Yii::$app->params['secretKey']) && !empty(Yii::$app->params['secretKey'])) { + $salt = Yii::$app->params['secretKey']; + } else { + $salt = isset(Yii::$app->params['secretKey'])? Yii::$app->params['secretKey']: self::$SIGN_SALT; + } + + $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt); + if ($sign != $makeSign || empty($sign)) { + $e->status = 2; + $e->message = '签名出错'; + return $e; + } + + $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo); + + $e->status = $authResult->status; + $e->message = $authResult->message; + if ($authResult->success) { + $e->mac = $authResult->mac; + $e->serial_no = $authResult->serial_no; + } + + return $e; + } + + /** + * + */ + public function actionCryptTxt() + { + $e = new stdClass(); + + $getPostDataTxt = file_get_contents('php://input', 'r'); + $getPostData = json_decode($getPostDataTxt, true); + $randomKey = $getPostData['randomKey']; + $content = $getPostData['content']; + $rsa = new RSACrypt(); + $randKey = $rsa->decrypt($randomKey); + $aes = new Aes($randKey); + $contentStr = $aes->decrypt($content); + + $returnContent = [ + "mac" => Utils::macGenerate(), + "serial_no" => Utils::rand(16), + 'random_key' =>$randKey, + ]; + + $e->content = $aes->encrypt(json_encode($returnContent)); + + return $e; + } + + /** + * @return stdClass + */ + public function actionIndext() + { + $e = new stdClass(); + $e->content = ''; + + $getPostData = file_get_contents('php://input', 'r'); + self::myLog('actionIndext postData:'.$getPostData); + $getPostData = json_decode($getPostData, true); + $randomKey = $getPostData['randomKey']; + $content = $getPostData['content']; + $rsa = new RSACrypt(); + $randKey = $rsa->decrypt($randomKey); + if (16 != strlen($randKey)) { + // 检查randKey,当前只是做长度判断 + $randKey = null; + } + $aes = new Aes($randKey); + $contentStr = $aes->decrypt($content); + $authResult = $this->authDevice($contentStr); + + $returnStr = json_encode($authResult, JSON_UNESCAPED_UNICODE); + + $e->content = $aes->encrypt($returnStr); + + return $e; + } + } \ No newline at end of file diff --git a/app-api/helpers/Aes.php b/app-api/helpers/Aes.php deleted file mode 100644 index 557aeb8..0000000 --- a/app-api/helpers/Aes.php +++ /dev/null @@ -1,73 +0,0 @@ -secret_key = isset($key) ? $key : 'king_board_key_01'; - - $this->method = $method; - - $this->iv = $iv; - - $this->options = $options; - } - - /** - * 加密方法,对数据进行加密,返回加密后的数据 - * - * @param string $data 要加密的数据 - * - * @return string - * - */ - public function encrypt($data) - { - return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv); - } - - /** - * 解密方法,对数据进行解密,返回解密后的数据 - * - * @param string $data 要解密的数据 - * - * @return string - * - */ - public function decrypt($data) - { - return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv); - } -} \ No newline at end of file diff --git a/app-ht/modules/device/controllers/DeviceController.php b/app-ht/modules/device/controllers/DeviceController.php index 9c0ca66..5acc9b2 100644 --- a/app-ht/modules/device/controllers/DeviceController.php +++ b/app-ht/modules/device/controllers/DeviceController.php @@ -32,7 +32,7 @@ class DeviceController extends BaseController return $this->render('index', $params); } - private function dataList($type) + private function dataList($type, $delete = 0) { $request = Yii::$app->request; $serialNo = $request->get('serial_no'); @@ -48,13 +48,15 @@ class DeviceController extends BaseController $endApplyAt = $request->get('end_apply_at'); $startAuthAt = $request->get('start_auth_at'); $endAuthAt = $request->get('end_auth_at'); + $startCreatedAt = $request->get('start_created_at'); + $endCreatedAt = $request->get('end_created_at'); $has_re_auth = $request->get('has_re_auth'); $page = $request->get('page'); $where = [ 'and', - ['=','a.is_delete', 0] + ['=','a.is_delete', $delete] ]; if (!empty($serialNo)) { $where[] = ['like', 'a.serial_no', $serialNo]; @@ -87,11 +89,17 @@ class DeviceController extends BaseController $where[] = ['>=', 'a.auth_at', strtotime($startAuthAt)]; } if ($endAuthAt) { - $where[] = ['>=', 'a.auth_at', strtotime($endAuthAt) + 86400]; + $where[] = ['<=', 'a.auth_at', strtotime($endAuthAt) + 86400]; } if ($has_re_auth) { $where[] = ['=', 'a.has_re_auth', $has_re_auth]; } + if ($startCreatedAt) { + $where[] = ['>=', 'a.created_at', strtotime($startCreatedAt)]; + } + if ($endCreatedAt) { + $where[] = ['<=', 'a.created_at', strtotime($endCreatedAt) + 86400]; + } if (isset($_GET['status']) && -1 != $status) { $where[] = ['=', 'a.status', $status]; } else { @@ -129,6 +137,8 @@ class DeviceController extends BaseController 'start_auth_at' => $startAuthAt, 'end_auth_at' => $endAuthAt, 'has_re_auth' => $has_re_auth, + 'start_created_at' => $startCreatedAt, + 'end_created_at' => $endCreatedAt, 'status' => $status ]; @@ -140,92 +150,7 @@ class DeviceController extends BaseController */ public function actionDeleteIndex() { - $request = Yii::$app->request; - $serialNo = $request->get('serial_no'); - $mac = $request->get('mac'); - $project = $request->get('project'); - $model = $request->get('model'); - $production = $request->get('production'); - $manufacture = $request->get('manufacture'); - $deviceId = $request->get('device_id'); - $status = $request->get('status'); - - $startApplyAt = $request->get('start_apply_at'); - $endApplyAt = $request->get('end_apply_at'); - $startAuthAt = $request->get('start_auth_at'); - $endAuthAt = $request->get('end_auth_at'); - $page = $request->get('page'); - $where = [ - 'and', - ['=','a.is_delete', 1] - ]; - if (!empty($serialNo)) { - $where[] = ['like', 'a.serial_no', $serialNo]; - } - if (!empty($project)) { - $where[] = ['like', 'p.name', $project]; - } - if (!empty($model)) { - $where[] = ['like', 'mo.name', $model]; - } - if (!empty($production)) { - $where[] = ['like', 'pd.name', $production]; - } - if (!empty($mac)) { - $where[] = ['like', 'a.mac', $mac]; - } - if (!empty($manufacture)) { - $where[] = ['like', 'm.name', $manufacture]; - } - if (!empty($deviceId)) { - $where[] = ['like', 'a.device_id', $deviceId]; - } - - if ($startApplyAt) { - $where[] = ['>=', 'a.apply_at', strtotime($startApplyAt)]; - } - if ($endApplyAt) { - $where[] = ['<=', 'a.apply_at', strtotime($endApplyAt) + 86400]; - } - if ($startAuthAt) { - $where[] = ['>=', 'a.auth_at', strtotime($startAuthAt)]; - } - if ($endAuthAt) { - $where[] = ['<=', 'a.auth_at', strtotime($endAuthAt) + 86400]; - } - if (isset($_GET['status']) && -1 != $status) { - $where[] = ['=', 'a.status', $status]; - } else { - $status = -1; - } - - if (0 >= $page) { - $page = 1; - } - $pageSize = 20; - $page = ($page -1) * $pageSize; - // DeviceRepository::getList($where, $pageSize, $page); - $deviceData = DeviceRepository::getList($where, $pageSize, $page); - $pages = new Pagination(['totalCount' => DeviceRepository::getListCount($where), 'pageSize' => $pageSize]); - $statusList = DeviceStatus::statusLabels(); // - - $params['statusList'] = $statusList; - $params['deviceList'] = $deviceData; - $params['pages'] = $pages; - $params["gets"] = [ - 'serial_no' => $serialNo, - 'mac' => $mac, - 'project' => $project, - 'model' => $model, - 'device_id' => $deviceId, - 'production' => $production, - 'manufacture' => $manufacture, - 'start_apply_at' => $startApplyAt, - 'end_apply_at' => $endApplyAt, - 'start_auth_at' => $startAuthAt, - 'end_auth_at' => $endAuthAt, - 'status' => $status - ]; + $params = $this->dataList(1, 1); return $this->render('delete-index', $params); } @@ -245,16 +170,10 @@ class DeviceController extends BaseController public function actionDoCreateDevice() { $req = Yii::$app->request; - $manufactureId = $req->post('manufactureId'); - $projectId = $req->post('projectId'); - $modelId = $req->post('modelId'); - $productionId = $req->post('productionId'); - - $manufactureNo = $req->post('manufactureNo'); - $projectNo = $req->post('projectNo'); - $modelNo = $req->post('modelNo'); - $productionNo = $req->post('productionNo'); - + $manufacture = $req->post('manufacture'); + $project = $req->post('project'); + $model = $req->post('model'); + $production = $req->post('production'); $num = $req->post('num'); $e = new stdClass(); $e->success = false; @@ -271,6 +190,34 @@ class DeviceController extends BaseController $e->message = '数量不能超过1万'; return $this->renderJson($e); } + if (empty($manufacture) || empty($project) || empty($model) || empty($production)) { + $e->message = '厂商,项目,型号,生产日期必填'; + return $this->renderJson($e); + } + $manufactureArr = explode('_', $manufacture); + $projectArr = explode('_', $project); + $modelArr = explode('_', $model); + $productionArr = explode('_', $production); + + $manufactureId = isset($manufactureArr[0])? $manufactureArr[0] :0; + $manufactureNo = isset($manufactureArr[1])? $manufactureArr[1] :''; + + $projectId = isset($projectArr[0])? $projectArr[0] :0; + $projectNo = isset($projectArr[1])? $projectArr[1] :''; + + $modelId = isset($modelArr[0])? $modelArr[0] :0; + $modelNo = isset($modelArr[1])? $modelArr[1] :''; + + $productionId = isset($productionArr[0])? $productionArr[0] :0; + $productionNo = isset($productionArr[1])? $productionArr[1] :0; + if (empty($manufactureId) || empty($projectId) || empty($modelId) || empty($productionId)) { + $e->message = '找不到对应的厂商,项目,型号,生产日期'; + return $this->renderJson($e); + } + if (empty($manufactureNo) || empty($projectNo) || empty($modelNo) || empty($productionNo)) { + $e->message = '找不到对应的厂商,项目,型号,生产日期!'; + return $this->renderJson($e); + } $batchNo = strtoupper(Device::getBatchNo($manufactureNo, $projectNo, $modelNo, $productionNo)); $batchModel = CreateBatchRepository::findOne(['batch_no' => $batchNo]); @@ -725,7 +672,7 @@ class DeviceController extends BaseController if ($needGen) { $trans = Yii::$app->getDb()->beginTransaction(); try { - $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 1, DeviceStatus::HAS_AUTH); + Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 1, DeviceStatus::NO_AUTH); $deviceFailModel->is_delete = 1; $deviceFailModel->save(); $trans->commit(); @@ -748,7 +695,7 @@ class DeviceController extends BaseController $trans = Yii::$app->getDb()->beginTransaction(); try { $newDeviceModel->device_id = $deviceId; - $newDeviceModel->status = DeviceStatus::HAS_AUTH; + $newDeviceModel->status = DeviceStatus::NO_AUTH; $newDeviceModel->apply_at = $tt ; $newDeviceModel->auth_at = $tt; $newDeviceModel->save(); diff --git a/app-ht/modules/device/views/device/createDevice.php b/app-ht/modules/device/views/device/createDevice.php index 0c3fe46..7be6ef4 100644 --- a/app-ht/modules/device/views/device/createDevice.php +++ b/app-ht/modules/device/views/device/createDevice.php @@ -201,28 +201,28 @@ $(function() { alert('请选择厂商'); return false; } - manufacture = manufacture.split('_'); + //manufacture = manufacture.split('_'); var project = $('#project').val(); if ('' == project) { alert('请选择项目'); return false; } - project = project.split('_'); + //project = project.split('_'); var model = $('#model').val(); if ('' == model) { alert('请选择型号'); return false; } - model = model.split('_'); + //model = model.split('_'); var production = $('#production').val(); if ('' == production) { alert('请选生产日期'); return false; } - production = production.split('_'); + //production = production.split('_'); var num = $('#num').val(); var par = /^[0-9]+$/; if (par.test(num) && (num > 0)) { @@ -233,17 +233,10 @@ $(function() { } var params = { - manufactureId: manufacture[0], - manufactureNo: manufacture[1], - - projectId: project[0], - projectNo: project[1], - - modelId: model[0], - modelNo: model[1], - - productionId: production[0], - productionNo: production[1], + manufacture: manufacture, + project: project, + model: model, + production: production, num: num } $.post(saveUrl, params, function(res) { @@ -271,14 +264,13 @@ $(function() { return false; } - return false; if (append_num*1 > 3000) { alert('追加数量不要超过3000'); return false; } $.post(appendSerialUrl,{batch_id:batch_id, append_num:append_num}, function(ajaxRes){ if (ajaxRes.success) { - alert('成功追加'); + alert('成功追加'+append_num+'个序列号'); window.location.href = '' } else { alert(ajaxRes.message); diff --git a/app-ht/modules/device/views/device/delete-index.php b/app-ht/modules/device/views/device/delete-index.php index 4515de2..9f986a5 100644 --- a/app-ht/modules/device/views/device/delete-index.php +++ b/app-ht/modules/device/views/device/delete-index.php @@ -48,13 +48,6 @@ $this->params['breadcrumbs'][] = $this->title;
- -
- - -
- - -
@@ -63,12 +56,30 @@ $this->params['breadcrumbs'][] = $this->title;
+
+
+ +
+
-
+
-
- - +
+
-
-
+ +
+
-
+
+ +
+ +
+
@@ -88,15 +99,14 @@ $this->params['breadcrumbs'][] = $this->title; ID ID - 序列号 - 厂商 - 项目 - 设备型号 - 生产日期 + 序列号 + 批次信息 + MAC地址 - 设备ID - 申请时间 - 授权时间 + 设备ID + 申请时间 + 授权时间 + 状态 状态 操作 @@ -114,16 +124,10 @@ $this->params['breadcrumbs'][] = $this->title;
- - - - - - - - - - + 厂商:
+ 项目:
+ 型号:
+ 生产日期:
@@ -138,6 +142,9 @@ $this->params['breadcrumbs'][] = $this->title; + + + diff --git a/app-ht/modules/device/views/device/index.php b/app-ht/modules/device/views/device/index.php index ea68211..3e69a7c 100644 --- a/app-ht/modules/device/views/device/index.php +++ b/app-ht/modules/device/views/device/index.php @@ -59,22 +59,25 @@ $this->params['breadcrumbs'][] = $this->title;
-
- - +
+
-
- -
- - + +
+
-
- - -
- + +
+
-
+
+ +
+
@@ -98,15 +101,14 @@ $this->params['breadcrumbs'][] = $this->title; ID - 序列号 - 厂商 - 项目 - 设备型号 - 生产日期 + 序列号 + 批次信息 + MAC地址 - 设备ID - 申请时间 - 授权时间 + 设备ID + 申请时间 + 授权时间 + 生成时间 状态 操作 @@ -124,17 +126,12 @@ $this->params['breadcrumbs'][] = $this->title;
- - - - - - - - - - + 厂商:
+ 项目:
+ 型号:
+ 生产日期:
+
@@ -148,6 +145,9 @@ $this->params['breadcrumbs'][] = $this->title; + + + diff --git a/app-ht/modules/system/views/account/index.php b/app-ht/modules/system/views/account/index.php index 9c458be..e75f989 100644 --- a/app-ht/modules/system/views/account/index.php +++ b/app-ht/modules/system/views/account/index.php @@ -70,9 +70,9 @@ $this->params['breadcrumbs'][] = $this->title; - 设置角色    + 设置角色    编辑    - + diff --git a/app-ht/modules/upgrade/controllers/UpgradeController.php b/app-ht/modules/upgrade/controllers/UpgradeController.php index 06c218f..b523697 100644 --- a/app-ht/modules/upgrade/controllers/UpgradeController.php +++ b/app-ht/modules/upgrade/controllers/UpgradeController.php @@ -132,7 +132,7 @@ class UpgradeController extends BaseController $user = Yii::$app->user->identity; if (isset($user->is_manufacture) && $user->is_manufacture == 1) { $manufacturer = ManufacturerRepository::findOne(["sys_user_id" => $user->id]); - if (empty($manufacturer) || $manufacturer->id != $request->post("manufacturer_id")) { + if (empty($manufacturer) || $manufacturer->id != $request->post("manufacture_id")) { Yii::$app->session->setFlash('error', '添加失败'); return $this->render('create'); } @@ -218,7 +218,7 @@ class UpgradeController extends BaseController $user = Yii::$app->user->identity; if (isset($user->is_manufacture) && $user->is_manufacture == 1) { $manufacturer = ManufacturerRepository::findOne(["sys_user_id" => $user->id]); - if (empty($manufacturer) || $manufacturer->id != $request->post("manufacturer_id")) { + if (empty($manufacturer) || $manufacturer->id != $request->post("manufacture_id")) { Yii::$app->session->setFlash('error', '编辑失败'); $params = $this->dataList(1); return $this->render('index', $params); @@ -277,8 +277,8 @@ class UpgradeController extends BaseController $user = Yii::$app->user->identity; if (isset($user->is_manufacture) && $user->is_manufacture == 1) { $manufacturer = ManufacturerRepository::findOne(["sys_user_id" => $user->id]); - $upgrade = UpgradeRepository::selectOne($itemId,true); - if (empty($upgrade) || empty($manufacturer) || $manufacturer->id != $request->post("manufacturer_id")) { + $upgrade = UpgradeRepository::selectOne($itemId, true); + if (empty($upgrade) || empty($manufacturer) || $manufacturer->id != $upgrade['manufacture_id']) { $msg['status'] = 0; $msg['msg'] = "删除"; return $this->renderJson($msg); @@ -717,6 +717,7 @@ class UpgradeController extends BaseController $manufactureId = $request->post("manufacture"); $projectId = $request->post("project"); $modelId = $request->post("model"); + $type = $request->post("type"); $id = $request->post('id'); if (empty($manufactureId)) { $e->message = '请先选择厂商'; @@ -733,14 +734,14 @@ class UpgradeController extends BaseController return $this->renderJson($e); } - $upgradeModel = UpgradeRepository::findOne(['manufacture_id' => $manufactureId, 'project_id' => $projectId, 'model_id' => $modelId, 'is_delete' => 0, 'status' => UpgradeStatus::STATUS_ON]); + $upgradeModel = UpgradeRepository::findOne(['manufacture_id' => $manufactureId, 'project_id' => $projectId, 'model_id' => $modelId, 'is_delete' => 0, 'status' => UpgradeStatus::STATUS_ON, 'type' => $type]); if ($upgradeModel && empty($id)) { - $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传'; + $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传'.$upgradeModel->id; return $this->renderJson($e); } if ($upgradeModel && !empty($id) && $id != $upgradeModel->id) { - $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传'; + $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传!'; return $this->renderJson($e); } diff --git a/app-ht/modules/upgrade/views/upgrade/create.php b/app-ht/modules/upgrade/views/upgrade/create.php index f17ed0b..d1fe7d9 100644 --- a/app-ht/modules/upgrade/views/upgrade/create.php +++ b/app-ht/modules/upgrade/views/upgrade/create.php @@ -37,7 +37,13 @@ $this->params['breadcrumbs'][] = $this->title;
- +
" name="version" placeholder="请填写APP版本号" style="margin-top: -6px;" class="form-control"">
@@ -261,7 +267,8 @@ $this->params['breadcrumbs'][] = $this->title; var manufacture = $('#manufacture').val(); var project = $('#project').val(); var model = $('#model').val(); - $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model}, function(res){ + var type = $('#type').val(); + $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model,type:type}, function(res){ if (res.success) { if (that.hasClass('disabled')) { return false; diff --git a/app-ht/modules/upgrade/views/upgrade/edit.php b/app-ht/modules/upgrade/views/upgrade/edit.php index 9680bff..1558828 100644 --- a/app-ht/modules/upgrade/views/upgrade/edit.php +++ b/app-ht/modules/upgrade/views/upgrade/edit.php @@ -36,7 +36,12 @@ $this->params['breadcrumbs'][] = $this->title;
- +
" name="version" placeholder="请填写APP版本号" style="margin-top: -6px;" class="form-control"">
@@ -251,7 +256,8 @@ $this->params['breadcrumbs'][] = $this->title; var manufacture = $('#manufacture').val(); var project = $('#project').val(); var model = $('#model').val(); - $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model, id: $('#uid').val()}, function(res){ + var type = $('#type').val(); + $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model, id: $('#uid').val(), 'type':type}, function(res){ if (res.success) { if (that.hasClass('disabled')) { return false; diff --git a/common/exts/Aes.php b/common/exts/Aes.php new file mode 100644 index 0000000..5d2fc53 --- /dev/null +++ b/common/exts/Aes.php @@ -0,0 +1,73 @@ +secret_key = isset($key) ? $key : 'king_board_key_01'; + + $this->method = $method; + + $this->iv = $iv; + + $this->options = $options; + } + + /** + * 加密方法,对数据进行加密,返回加密后的数据 + * + * @param string $data 要加密的数据 + * + * @return string + * + */ + public function encrypt($data) + { + return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv); + } + + /** + * 解密方法,对数据进行解密,返回解密后的数据 + * + * @param string $data 要解密的数据 + * + * @return string + * + */ + public function decrypt($data) + { + return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv); + } +} \ No newline at end of file diff --git a/common/exts/RSACrypt.php b/common/exts/RSACrypt.php new file mode 100644 index 0000000..af85b92 --- /dev/null +++ b/common/exts/RSACrypt.php @@ -0,0 +1,86 @@ +privkey = openssl_pkey_get_private($_privateKey); + $this->pubkey = openssl_pkey_get_public($_publicKey); + } + + /** + * 加密 + * @param $data + * @return string + */ + public function encrypt($data) + { + if (openssl_public_encrypt($data, $encrypted, $this->pubkey)) { + $data = base64_encode($encrypted); + return $data; + } else { + return null; + } + } + + /** + * 解密 + * @param $data + * @return mixed + */ + public function decrypt($data) + { + if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey)) { + $data = $decrypted; + return $data; + } else { + return null; + } + } +} \ No newline at end of file diff --git a/common/helpers/Utils.php b/common/helpers/Utils.php index cb85ab7..7b45d4c 100644 --- a/common/helpers/Utils.php +++ b/common/helpers/Utils.php @@ -42,7 +42,7 @@ class Utils * @param bool|false $onlyNumber 是否纯数字 * @return string */ - public static function rand($len,$onlyNumber = false) + public static function rand($len, $onlyNumber = false) { $randString = ''; $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_"; diff --git a/console/controllers/TestController.php b/console/controllers/TestController.php index 67eeadc..2d31780 100644 --- a/console/controllers/TestController.php +++ b/console/controllers/TestController.php @@ -7,15 +7,15 @@ namespace console\controllers; * Time: 11:32 AM */ - -use app\api\helpers\Aes; +use common\exts\Aes; +use common\exts\RSACrypt; use common\exts\Http; +use common\helpers\Utils; use domain\device\Device; use GuzzleHttp\Psr7; use yii\console\Controller; use GuzzleHttp\Psr7\Request; use function chr; -use yii\helpers\ArrayHelper; class TestController extends Controller { @@ -43,7 +43,7 @@ class TestController extends Controller $modelNo = '0001'; $productionNo = '0001'; $timestamp = time(); - $salt = 13456; + $salt = '13456'; $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); $params = [ 'manufacture' => $manufactureNo, @@ -154,7 +154,6 @@ class TestController extends Controller echo $postResult; } - public function actionReportAppEvent() { //actionCheckAppVersion @@ -177,5 +176,83 @@ class TestController extends Controller $postResult = Http::POST($url, $params); echo $postResult; } + + public function actionEncodePost() + { + $url = 'http://kingb:8012/app-api/web/CryptTxt'; + $randKey = '98765432';//Utils::rand(32); + $rsa = new RSACrypt(); + $aes = new Aes($randKey); + $deviceId = 'oelooeloeloeloe'; + $manufactureNo = '0001'; + $tt = time(); + $sign = md5($deviceId . $tt . $randKey); + $dd = json_encode(['manufacture' => $manufactureNo, 'timestamp' => $tt, 'sign' => $sign, 'device_id' => $deviceId]); + $params = [ + 'randomKey' => $rsa->encrypt($randKey), + 'content' => $aes->encrypt($dd) + ]; + $params = json_encode($params); + $postResult = Http::POST($url, $params); + $postResult = json_decode($postResult, true); + $decodeJson = $aes->decrypt($postResult['content']); + print_r($decodeJson); + } + + /** + * + */ + public function actionAuthDeviceT() + { + $url = 'http://kingb:8012/app-api/web/authDeviceT'; + //$url = 'http://47.107.95.101/app-api/web/authDeviceT'; + $manufactureNo = '0001'; + $device_id = 'DEVICE00000A'; + $projectNo = '0001'; + $modelNo = '0001'; + $productionNo = '0001'; + $timestamp = time(); + + + $randKey = Utils::rand(16).$timestamp; + $salt = "13456"; + $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); + $deviceParams = [ + 'manufacture' => $manufactureNo, + 'device_id' => $device_id, + 'project' => $projectNo, + 'model' => $modelNo, + 'production' => $productionNo, + 'timestamp' => $timestamp, + 'sign' => $sign, + ]; + $deviceParams = json_encode($deviceParams); + $rsa = new RSACrypt(); + $randomKey = $rsa->encrypt($randKey); + $aes = new Aes($randKey); + $params = [ + 'randomKey' => $randomKey, + 'content' => $aes->encrypt($deviceParams) + ]; + $params = json_encode($params); + $postResult = Http::POST($url, $params); + + $postResult = json_decode($postResult, true); + $decodeJson = $aes->decrypt($postResult['content']); + + echo $decodeJson; + } + + + public function actionA() + { + $str = "87654321"; + $rsa = new RSACrypt(); + $deStr = "dFz10grDo8eO/+APJvPG4B4suilGLsFcHyMc/JIVUhIUWpILFhJD6g2z1TVusvzSxXsQJpNO44fFxzy8F4j/u/l61HAxS3owpgcmJ4e5mU3ugXftBqazOYErYssnoh03khaJUalwwlw/N5NpspRT6GXVwegEQnJKnGsIwZqXbsY="; + + //echo $deStr."\r\n"; + echo $rsa->decrypt($deStr); + } + } -- libgit2 0.21.0