Commit d5e57a77a984fce56ec7c3867039f91c4704da48

Authored by xu
1 parent 831c9f5b
Exists in master

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
... ... @@ -5,11 +5,13 @@ return [
5 5  
6 6  
7 7 'POST authDevice' => 'auth-device/index',
  8 + 'POST authDeviceT' => 'auth-device/indext',
8 9 'POST checkOtaVersion' => 'upgrade/check-version',
9 10 'POST reportOtaUpgradeEvent' => 'upgrade/report-upgrade-event',
10 11 'POST checkAppVersion' => 'upgrade/check-app-version',
11 12 'POST reportAppUpgradeEvent' => 'upgrade/report-app-upgrade-event',
12 13 'POST reportDeviceVersion' => 'upgrade/report-device-version',
  14 + 'POST CryptTxt' => 'auth-device/crypt-txt',
13 15 'GET errorPage' => 'site/error-page-info',
14 16 'GET minaQuery' => 'site/mina-query',
15 17 ];
16 18 \ No newline at end of file
... ...
app-api/controllers/AuthDeviceController.php
... ... @@ -2,14 +2,13 @@
2 2  
3 3 namespace app\api\controllers;
4 4  
5   -
6 5 use Yii;
7   -
  6 +use common\exts\RSACrypt;
  7 +use common\exts\Aes;
8 8 use common\helpers\Utils;
9 9 use common\helpers\Log as AppLog;
10   -use domain\device\DeviceRepository;
11 10 use domain\device\Device;
12   -use domain\device\DeviceStatus;
  11 +
13 12 use stdClass;
14 13  
15 14 use function date;
... ... @@ -37,66 +36,135 @@ class AuthDeviceController extends BaseController
37 36 {
38 37 AppLog::DEBUG($str);
39 38 }
  39 +
40 40 /**
41 41 * 设备授权接口
42 42 * @return stdClass
43 43 */
44   - public function actionIndex()
45   - {
46   - $e = new stdClass();
47   - $e->status = 1;
48   - $e->message = 'message';
49   - $e->serial_no = '';;
50   - $e->mac = '';
51   -
52   - $getPostData = file_get_contents('php://input', 'r');
53   - self::myLog('actionIndex postData:'.$getPostData);
54   - if (!$getPostData) {
55   - $e->status = 1;
56   - $e->message = '传入的数据为空';
57   - return $e;
58   - }
59   - $getPostData = json_decode($getPostData, true);
60   - $manufactureNo = isset($getPostData['manufacture'])?$getPostData['manufacture']:'';
61   - $deviceId = isset($getPostData['device_id'])?$getPostData['device_id']:'';
62   - $projectNo = isset($getPostData['project'])?$getPostData['project']:'';
63   - $modelNo = isset($getPostData['model'])?$getPostData['model']:'';
64   - $productionNo = isset($getPostData['production'])?$getPostData['production']:'';
65   - $timestamp = isset($getPostData['timestamp'])?$getPostData['timestamp']:'';
66   - $sign = isset($getPostData['sign'])?$getPostData['sign']:'';
67   - if (empty($deviceId) || empty($manufactureNo) || empty($projectNo) || empty($modelNo) || empty($productionNo)) {
68   - $e->message = '传入的数据部分为空';
69   - return $e;
70   - }
71   - $pattern = "/^[a-zA-Z0-9]+$/";
72   - $dexPattern = "/^[0-9a-fA-F]+$/";
73   - if (!preg_match($pattern, $deviceId) || !preg_match($dexPattern, $manufactureNo) || !preg_match($dexPattern, $modelNo) || !preg_match($dexPattern, $productionNo)) {
74   - $e->status = 9;
75   - $e->message = '传入的数据字段格式不对';
76   - return $e;
77   - }
78   - if (isset(Yii::$app->params['secretKey']) && !empty(Yii::$app->params['secretKey'])) {
79   - $salt = Yii::$app->params['secretKey'];
80   - } else {
81   - $salt = isset(Yii::$app->params['secretKey'])? Yii::$app->params['secretKey']: self::$SIGN_SALT;
82   - }
83   -
84   - $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt);
85   - if ($sign != $makeSign || empty($sign)) {
86   - $e->status = 2;
87   - $e->message = '签名出错';
88   - return $e;
89   - }
90   -
91   - $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo);
92   -
93   - $e->status = $authResult->status;
94   - $e->message = $authResult->message;
95   - if ($authResult->success) {
96   - $e->mac = $authResult->mac;
97   - $e->serial_no = $authResult->serial_no;
98   - }
99   -
100   - return $e;
101   - }
  44 + public function actionIndex()
  45 + {
  46 + $getPostData = file_get_contents('php://input', 'r');
  47 + self::myLog('actionIndex postData:'.$getPostData);
  48 +
  49 + return $this->authDevice($getPostData);
  50 + }
  51 +
  52 + /**
  53 + * @param $getPostData
  54 + * @return stdClass
  55 + */
  56 + private function authDevice($getPostData)
  57 + {
  58 + $e = new stdClass();
  59 + $e->status = 1;
  60 + $e->message = 'message';
  61 + $e->serial_no = '';;
  62 + $e->mac = '';
  63 +
  64 + $getPostData = json_decode($getPostData, true);
  65 + if (empty($getPostData)) {
  66 + $e->status = 1;
  67 + $e->message = '传入的数据为空';
  68 + return $e;
  69 + }
  70 + $manufactureNo = isset($getPostData['manufacture'])?$getPostData['manufacture']:'';
  71 + $deviceId = isset($getPostData['device_id'])?$getPostData['device_id']:'';
  72 + $projectNo = isset($getPostData['project'])?$getPostData['project']:'';
  73 + $modelNo = isset($getPostData['model'])?$getPostData['model']:'';
  74 + $productionNo = isset($getPostData['production'])?$getPostData['production']:'';
  75 + $timestamp = isset($getPostData['timestamp'])?$getPostData['timestamp']:'';
  76 + $sign = isset($getPostData['sign'])?$getPostData['sign']:'';
  77 + if (empty($deviceId) || empty($manufactureNo) || empty($projectNo) || empty($modelNo) || empty($productionNo)) {
  78 + $e->message = '传入的数据部分为空';
  79 + return $e;
  80 + }
  81 + $pattern = "/^[a-zA-Z0-9]+$/";
  82 + $dexPattern = "/^[0-9a-fA-F]+$/";
  83 + if (!preg_match($pattern, $deviceId) || !preg_match($dexPattern, $manufactureNo) || !preg_match($dexPattern, $modelNo) || !preg_match($dexPattern, $productionNo)) {
  84 + $e->status = 9;
  85 + $e->message = '传入的数据字段格式不对';
  86 + return $e;
  87 + }
  88 + if (isset(Yii::$app->params['secretKey']) && !empty(Yii::$app->params['secretKey'])) {
  89 + $salt = Yii::$app->params['secretKey'];
  90 + } else {
  91 + $salt = isset(Yii::$app->params['secretKey'])? Yii::$app->params['secretKey']: self::$SIGN_SALT;
  92 + }
  93 +
  94 + $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt);
  95 + if ($sign != $makeSign || empty($sign)) {
  96 + $e->status = 2;
  97 + $e->message = '签名出错';
  98 + return $e;
  99 + }
  100 +
  101 + $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo);
  102 +
  103 + $e->status = $authResult->status;
  104 + $e->message = $authResult->message;
  105 + if ($authResult->success) {
  106 + $e->mac = $authResult->mac;
  107 + $e->serial_no = $authResult->serial_no;
  108 + }
  109 +
  110 + return $e;
  111 + }
  112 +
  113 + /**
  114 + *
  115 + */
  116 + public function actionCryptTxt()
  117 + {
  118 + $e = new stdClass();
  119 +
  120 + $getPostDataTxt = file_get_contents('php://input', 'r');
  121 + $getPostData = json_decode($getPostDataTxt, true);
  122 + $randomKey = $getPostData['randomKey'];
  123 + $content = $getPostData['content'];
  124 + $rsa = new RSACrypt();
  125 + $randKey = $rsa->decrypt($randomKey);
  126 + $aes = new Aes($randKey);
  127 + $contentStr = $aes->decrypt($content);
  128 +
  129 + $returnContent = [
  130 + "mac" => Utils::macGenerate(),
  131 + "serial_no" => Utils::rand(16),
  132 + 'random_key' =>$randKey,
  133 + ];
  134 +
  135 + $e->content = $aes->encrypt(json_encode($returnContent));
  136 +
  137 + return $e;
  138 + }
  139 +
  140 + /**
  141 + * @return stdClass
  142 + */
  143 + public function actionIndext()
  144 + {
  145 + $e = new stdClass();
  146 + $e->content = '';
  147 +
  148 + $getPostData = file_get_contents('php://input', 'r');
  149 + self::myLog('actionIndext postData:'.$getPostData);
  150 + $getPostData = json_decode($getPostData, true);
  151 + $randomKey = $getPostData['randomKey'];
  152 + $content = $getPostData['content'];
  153 + $rsa = new RSACrypt();
  154 + $randKey = $rsa->decrypt($randomKey);
  155 + if (16 != strlen($randKey)) {
  156 + // 检查randKey,当前只是做长度判断
  157 + $randKey = null;
  158 + }
  159 + $aes = new Aes($randKey);
  160 + $contentStr = $aes->decrypt($content);
  161 + $authResult = $this->authDevice($contentStr);
  162 +
  163 + $returnStr = json_encode($authResult, JSON_UNESCAPED_UNICODE);
  164 +
  165 + $e->content = $aes->encrypt($returnStr);
  166 +
  167 + return $e;
  168 + }
  169 +
102 170 }
103 171 \ No newline at end of file
... ...
app-api/helpers/Aes.php
... ... @@ -1,73 +0,0 @@
1   -<?php
2   -
3   -namespace app\api\helpers;
4   -
5   -class Aes
6   -{
7   - /**
8   - * var string $method 加解密方法,可通过openssl_get_cipher_methods()获得
9   - */
10   - protected $method;
11   -
12   - /**
13   - * var string $secret_key 加解密的密钥
14   - */
15   - protected $secret_key;
16   -
17   - /**
18   - * var string $iv 加解密的向量,有些方法需要设置比如CBC
19   - */
20   - protected $iv;
21   -
22   - /**
23   - * var string $options (不知道怎么解释,目前设置为0没什么问题)
24   - */
25   - protected $options;
26   -
27   - /**
28   - * 构造函数
29   - *
30   - * @param string $key 密钥
31   - * @param string $method 加密方式
32   - * @param string $iv iv向量
33   - * @param mixed $options 还不是很清楚
34   - *
35   - */
36   - public function __construct($key, $method = 'AES-128-ECB', $iv = '', $options = 0)
37   - {
38   - // key是必须要设置的
39   - $this->secret_key = isset($key) ? $key : 'king_board_key_01';
40   -
41   - $this->method = $method;
42   -
43   - $this->iv = $iv;
44   -
45   - $this->options = $options;
46   - }
47   -
48   - /**
49   - * 加密方法,对数据进行加密,返回加密后的数据
50   - *
51   - * @param string $data 要加密的数据
52   - *
53   - * @return string
54   - *
55   - */
56   - public function encrypt($data)
57   - {
58   - return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
59   - }
60   -
61   - /**
62   - * 解密方法,对数据进行解密,返回解密后的数据
63   - *
64   - * @param string $data 要解密的数据
65   - *
66   - * @return string
67   - *
68   - */
69   - public function decrypt($data)
70   - {
71   - return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
72   - }
73   -}
74 0 \ No newline at end of file
app-ht/modules/device/controllers/DeviceController.php
... ... @@ -32,7 +32,7 @@ class DeviceController extends BaseController
32 32 return $this->render('index', $params);
33 33 }
34 34  
35   - private function dataList($type)
  35 + private function dataList($type, $delete = 0)
36 36 {
37 37 $request = Yii::$app->request;
38 38 $serialNo = $request->get('serial_no');
... ... @@ -48,13 +48,15 @@ class DeviceController extends BaseController
48 48 $endApplyAt = $request->get('end_apply_at');
49 49 $startAuthAt = $request->get('start_auth_at');
50 50 $endAuthAt = $request->get('end_auth_at');
  51 + $startCreatedAt = $request->get('start_created_at');
  52 + $endCreatedAt = $request->get('end_created_at');
51 53  
52 54 $has_re_auth = $request->get('has_re_auth');
53 55  
54 56 $page = $request->get('page');
55 57 $where = [
56 58 'and',
57   - ['=','a.is_delete', 0]
  59 + ['=','a.is_delete', $delete]
58 60 ];
59 61 if (!empty($serialNo)) {
60 62 $where[] = ['like', 'a.serial_no', $serialNo];
... ... @@ -87,11 +89,17 @@ class DeviceController extends BaseController
87 89 $where[] = ['>=', 'a.auth_at', strtotime($startAuthAt)];
88 90 }
89 91 if ($endAuthAt) {
90   - $where[] = ['>=', 'a.auth_at', strtotime($endAuthAt) + 86400];
  92 + $where[] = ['<=', 'a.auth_at', strtotime($endAuthAt) + 86400];
91 93 }
92 94 if ($has_re_auth) {
93 95 $where[] = ['=', 'a.has_re_auth', $has_re_auth];
94 96 }
  97 + if ($startCreatedAt) {
  98 + $where[] = ['>=', 'a.created_at', strtotime($startCreatedAt)];
  99 + }
  100 + if ($endCreatedAt) {
  101 + $where[] = ['<=', 'a.created_at', strtotime($endCreatedAt) + 86400];
  102 + }
95 103 if (isset($_GET['status']) && -1 != $status) {
96 104 $where[] = ['=', 'a.status', $status];
97 105 } else {
... ... @@ -129,6 +137,8 @@ class DeviceController extends BaseController
129 137 'start_auth_at' => $startAuthAt,
130 138 'end_auth_at' => $endAuthAt,
131 139 'has_re_auth' => $has_re_auth,
  140 + 'start_created_at' => $startCreatedAt,
  141 + 'end_created_at' => $endCreatedAt,
132 142 'status' => $status
133 143 ];
134 144  
... ... @@ -140,92 +150,7 @@ class DeviceController extends BaseController
140 150 */
141 151 public function actionDeleteIndex()
142 152 {
143   - $request = Yii::$app->request;
144   - $serialNo = $request->get('serial_no');
145   - $mac = $request->get('mac');
146   - $project = $request->get('project');
147   - $model = $request->get('model');
148   - $production = $request->get('production');
149   - $manufacture = $request->get('manufacture');
150   - $deviceId = $request->get('device_id');
151   - $status = $request->get('status');
152   -
153   - $startApplyAt = $request->get('start_apply_at');
154   - $endApplyAt = $request->get('end_apply_at');
155   - $startAuthAt = $request->get('start_auth_at');
156   - $endAuthAt = $request->get('end_auth_at');
157   - $page = $request->get('page');
158   - $where = [
159   - 'and',
160   - ['=','a.is_delete', 1]
161   - ];
162   - if (!empty($serialNo)) {
163   - $where[] = ['like', 'a.serial_no', $serialNo];
164   - }
165   - if (!empty($project)) {
166   - $where[] = ['like', 'p.name', $project];
167   - }
168   - if (!empty($model)) {
169   - $where[] = ['like', 'mo.name', $model];
170   - }
171   - if (!empty($production)) {
172   - $where[] = ['like', 'pd.name', $production];
173   - }
174   - if (!empty($mac)) {
175   - $where[] = ['like', 'a.mac', $mac];
176   - }
177   - if (!empty($manufacture)) {
178   - $where[] = ['like', 'm.name', $manufacture];
179   - }
180   - if (!empty($deviceId)) {
181   - $where[] = ['like', 'a.device_id', $deviceId];
182   - }
183   -
184   - if ($startApplyAt) {
185   - $where[] = ['>=', 'a.apply_at', strtotime($startApplyAt)];
186   - }
187   - if ($endApplyAt) {
188   - $where[] = ['<=', 'a.apply_at', strtotime($endApplyAt) + 86400];
189   - }
190   - if ($startAuthAt) {
191   - $where[] = ['>=', 'a.auth_at', strtotime($startAuthAt)];
192   - }
193   - if ($endAuthAt) {
194   - $where[] = ['<=', 'a.auth_at', strtotime($endAuthAt) + 86400];
195   - }
196   - if (isset($_GET['status']) && -1 != $status) {
197   - $where[] = ['=', 'a.status', $status];
198   - } else {
199   - $status = -1;
200   - }
201   -
202   - if (0 >= $page) {
203   - $page = 1;
204   - }
205   - $pageSize = 20;
206   - $page = ($page -1) * $pageSize;
207   - // DeviceRepository::getList($where, $pageSize, $page);
208   - $deviceData = DeviceRepository::getList($where, $pageSize, $page);
209   - $pages = new Pagination(['totalCount' => DeviceRepository::getListCount($where), 'pageSize' => $pageSize]);
210   - $statusList = DeviceStatus::statusLabels(); //
211   -
212   - $params['statusList'] = $statusList;
213   - $params['deviceList'] = $deviceData;
214   - $params['pages'] = $pages;
215   - $params["gets"] = [
216   - 'serial_no' => $serialNo,
217   - 'mac' => $mac,
218   - 'project' => $project,
219   - 'model' => $model,
220   - 'device_id' => $deviceId,
221   - 'production' => $production,
222   - 'manufacture' => $manufacture,
223   - 'start_apply_at' => $startApplyAt,
224   - 'end_apply_at' => $endApplyAt,
225   - 'start_auth_at' => $startAuthAt,
226   - 'end_auth_at' => $endAuthAt,
227   - 'status' => $status
228   - ];
  153 + $params = $this->dataList(1, 1);
229 154  
230 155 return $this->render('delete-index', $params);
231 156 }
... ... @@ -245,16 +170,10 @@ class DeviceController extends BaseController
245 170 public function actionDoCreateDevice()
246 171 {
247 172 $req = Yii::$app->request;
248   - $manufactureId = $req->post('manufactureId');
249   - $projectId = $req->post('projectId');
250   - $modelId = $req->post('modelId');
251   - $productionId = $req->post('productionId');
252   -
253   - $manufactureNo = $req->post('manufactureNo');
254   - $projectNo = $req->post('projectNo');
255   - $modelNo = $req->post('modelNo');
256   - $productionNo = $req->post('productionNo');
257   -
  173 + $manufacture = $req->post('manufacture');
  174 + $project = $req->post('project');
  175 + $model = $req->post('model');
  176 + $production = $req->post('production');
258 177 $num = $req->post('num');
259 178 $e = new stdClass();
260 179 $e->success = false;
... ... @@ -271,6 +190,34 @@ class DeviceController extends BaseController
271 190 $e->message = '数量不能超过1万';
272 191 return $this->renderJson($e);
273 192 }
  193 + if (empty($manufacture) || empty($project) || empty($model) || empty($production)) {
  194 + $e->message = '厂商,项目,型号,生产日期必填';
  195 + return $this->renderJson($e);
  196 + }
  197 + $manufactureArr = explode('_', $manufacture);
  198 + $projectArr = explode('_', $project);
  199 + $modelArr = explode('_', $model);
  200 + $productionArr = explode('_', $production);
  201 +
  202 + $manufactureId = isset($manufactureArr[0])? $manufactureArr[0] :0;
  203 + $manufactureNo = isset($manufactureArr[1])? $manufactureArr[1] :'';
  204 +
  205 + $projectId = isset($projectArr[0])? $projectArr[0] :0;
  206 + $projectNo = isset($projectArr[1])? $projectArr[1] :'';
  207 +
  208 + $modelId = isset($modelArr[0])? $modelArr[0] :0;
  209 + $modelNo = isset($modelArr[1])? $modelArr[1] :'';
  210 +
  211 + $productionId = isset($productionArr[0])? $productionArr[0] :0;
  212 + $productionNo = isset($productionArr[1])? $productionArr[1] :0;
  213 + if (empty($manufactureId) || empty($projectId) || empty($modelId) || empty($productionId)) {
  214 + $e->message = '找不到对应的厂商,项目,型号,生产日期';
  215 + return $this->renderJson($e);
  216 + }
  217 + if (empty($manufactureNo) || empty($projectNo) || empty($modelNo) || empty($productionNo)) {
  218 + $e->message = '找不到对应的厂商,项目,型号,生产日期!';
  219 + return $this->renderJson($e);
  220 + }
274 221  
275 222 $batchNo = strtoupper(Device::getBatchNo($manufactureNo, $projectNo, $modelNo, $productionNo));
276 223 $batchModel = CreateBatchRepository::findOne(['batch_no' => $batchNo]);
... ... @@ -725,7 +672,7 @@ class DeviceController extends BaseController
725 672 if ($needGen) {
726 673 $trans = Yii::$app->getDb()->beginTransaction();
727 674 try {
728   - $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 1, DeviceStatus::HAS_AUTH);
  675 + Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 1, DeviceStatus::NO_AUTH);
729 676 $deviceFailModel->is_delete = 1;
730 677 $deviceFailModel->save();
731 678 $trans->commit();
... ... @@ -748,7 +695,7 @@ class DeviceController extends BaseController
748 695 $trans = Yii::$app->getDb()->beginTransaction();
749 696 try {
750 697 $newDeviceModel->device_id = $deviceId;
751   - $newDeviceModel->status = DeviceStatus::HAS_AUTH;
  698 + $newDeviceModel->status = DeviceStatus::NO_AUTH;
752 699 $newDeviceModel->apply_at = $tt ;
753 700 $newDeviceModel->auth_at = $tt;
754 701 $newDeviceModel->save();
... ...
app-ht/modules/device/views/device/createDevice.php
... ... @@ -201,28 +201,28 @@ $(function() {
201 201 alert('请选择厂商');
202 202 return false;
203 203 }
204   - manufacture = manufacture.split('_');
  204 + //manufacture = manufacture.split('_');
205 205  
206 206 var project = $('#project').val();
207 207 if ('' == project) {
208 208 alert('请选择项目');
209 209 return false;
210 210 }
211   - project = project.split('_');
  211 + //project = project.split('_');
212 212  
213 213 var model = $('#model').val();
214 214 if ('' == model) {
215 215 alert('请选择型号');
216 216 return false;
217 217 }
218   - model = model.split('_');
  218 + //model = model.split('_');
219 219  
220 220 var production = $('#production').val();
221 221 if ('' == production) {
222 222 alert('请选生产日期');
223 223 return false;
224 224 }
225   - production = production.split('_');
  225 + //production = production.split('_');
226 226 var num = $('#num').val();
227 227 var par = /^[0-9]+$/;
228 228 if (par.test(num) && (num > 0)) {
... ... @@ -233,17 +233,10 @@ $(function() {
233 233 }
234 234  
235 235 var params = {
236   - manufactureId: manufacture[0],
237   - manufactureNo: manufacture[1],
238   -
239   - projectId: project[0],
240   - projectNo: project[1],
241   -
242   - modelId: model[0],
243   - modelNo: model[1],
244   -
245   - productionId: production[0],
246   - productionNo: production[1],
  236 + manufacture: manufacture,
  237 + project: project,
  238 + model: model,
  239 + production: production,
247 240 num: num
248 241 }
249 242 $.post(saveUrl, params, function(res) {
... ... @@ -271,14 +264,13 @@ $(function() {
271 264 return false;
272 265 }
273 266  
274   - return false;
275 267 if (append_num*1 > 3000) {
276 268 alert('追加数量不要超过3000');
277 269 return false;
278 270 }
279 271 $.post(appendSerialUrl,{batch_id:batch_id, append_num:append_num}, function(ajaxRes){
280 272 if (ajaxRes.success) {
281   - alert('成功追加');
  273 + alert('成功追加'+append_num+'个序列号');
282 274 window.location.href = '<?=Url::toRoute('/datas/device/index')?>'
283 275 } else {
284 276 alert(ajaxRes.message);
... ...
app-ht/modules/device/views/device/delete-index.php
... ... @@ -48,13 +48,6 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
48 48 <div class="col-sm-2 form-inline">
49 49 <input type="text" class="form-control" id="manufacture" name="manufacture" value="<?php if (!empty($gets['manufacture'])){ echo $gets['manufacture'];} ?>" autocomplete="off">
50 50 </div>
51   - <label for="apply_at" class="col-sm-1 control-label text-right">申请时间:</label>
52   - <div class="col-sm-5 form-inline">
53   - <input type="date" class="form-control" id="start_apply_at" name="start_apply_at" value="<?php if (!empty($gets['start_apply_at'])){ echo $gets['start_apply_at'];} ?>" autocomplete="off"> - <input type="date" class="form-control" id="end_apply_at" name="end_apply_at" value="<?php if (!empty($gets['end_apply_at'])){ echo $gets['end_apply_at'];} ?>" autocomplete="off">
54   - </div>
55   - </div>
56   -
57   - <div class="form-group col-sm-12">
58 51 <label for="mac" class="col-sm-1 control-label text-right">MAC地址:</label>
59 52 <div class="col-sm-2 form-inline">
60 53 <input type="text" class="form-control" id="mac" name="mac" value="<?php if (!empty($gets['mac'])){ echo $gets['mac'];} ?>" autocomplete="off">
... ... @@ -63,12 +56,30 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
63 56 <div class="col-sm-2 form-inline">
64 57 <input type="text" class="form-control" id="device_id" name="device_id" value="<?php if (!empty($gets['device_id'])){ echo $gets['device_id'];} ?>" autocomplete="off">
65 58 </div>
  59 + </div>
  60 + <div class="form-group col-sm-12">
  61 + <label for="apply_at" class="col-sm-1 control-label text-right">申请时间:</label>
  62 + <div class="col-sm-2 form-inline">
  63 + <input type="date" class="form-control" id="start_apply_at" name="start_apply_at" value="<?php if (!empty($gets['start_apply_at'])){ echo $gets['start_apply_at'];} ?>" autocomplete="off"> <br>-<br> <input type="date" class="form-control" id="end_apply_at" name="end_apply_at" value="<?php if (!empty($gets['end_apply_at'])){ echo $gets['end_apply_at'];} ?>" autocomplete="off">
  64 + </div>
66 65 <label for="auth_at" class="col-sm-1 control-label text-right">授权时间:</label>
67   - <div class="col-sm-5 form-inline">
68   - <input type="date" class="form-control" id="start_auth_at" name="start_auth_at" value="<?php if (!empty($gets['start_auth_at'])){ echo $gets['start_auth_at'];} ?>" autocomplete="off"> - <input type="date" class="form-control" id="end_auth_at" name="end_auth_at" value="<?php if (!empty($gets['end_auth_at'])){ echo $gets['end_auth_at'];} ?>" autocomplete="off">
  66 + <div class="col-sm-2 form-inline">
  67 + <input type="date" class="form-control" id="start_auth_at" name="start_auth_at" value="<?php if (!empty($gets['start_auth_at'])){ echo $gets['start_auth_at'];} ?>" autocomplete="off"> <br>-<br> <input type="date" class="form-control" id="end_auth_at" name="end_auth_at" value="<?php if (!empty($gets['end_auth_at'])){ echo $gets['end_auth_at'];} ?>" autocomplete="off">
69 68 </div>
70   - </div>
71 69  
  70 + <label for="auth_at" class="col-sm-1 control-label text-right">生成时间:</label>
  71 + <div class="col-sm-2 form-inline">
  72 + <input type="date" class="form-control" id="start_auth_at" name="start_created_at" value="<?php if (!empty($gets['start_created_at'])){ echo $gets['start_created_at'];} ?>" autocomplete="off"> <br>-<br> <input type="date" class="form-control" id="end_created_at" name="end_created_at" value="<?php if (!empty($gets['end_created_at'])){ echo $gets['end_created_at'];} ?>" autocomplete="off">
  73 + </div>
  74 + <label for="auth_at" class="col-sm-1 control-label text-right">处理:</label>
  75 + <div class="col-sm-2 form-inline">
  76 + <select name="has_re_auth" class="form-control">
  77 + <option value="">全部</option>
  78 + <option value="1" <?php if(1 ==$gets['has_re_auth']) {echo "selected";}?>>已处理</option>
  79 + <option value="2" <?php if(2 ==$gets['has_re_auth']) {echo "selected";}?>>未处理</option>
  80 + </select>
  81 + </div>
  82 + </div>
72 83 <div class="form-group col-sm-12" style="text-align: center;">
73 84 <button type="submit" class="btn btn-primary font-1" id="submitFilterBtn">查询</button>
74 85 </div>
... ... @@ -88,15 +99,14 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
88 99 <tr>
89 100 <th >ID</th>
90 101 <th width="6%">ID</th>
91   - <th width="6%">序列号</th>
92   - <th width="8%">厂商</th>
93   - <th width="6%">项目</th>
94   - <th width="7%">设备型号</th>
95   - <th width="6%">生产日期</th>
  102 + <th width="8%">序列号</th>
  103 + <th width="10%">批次信息</th>
  104 +
96 105 <th>MAC地址</th>
97   - <th width="7%">设备ID</th>
98   - <th width="7%">申请时间</th>
99   - <th width="7%">授权时间</th>
  106 + <th width="8%">设备ID</th>
  107 + <th width="8%">申请时间</th>
  108 + <th width="8%">授权时间</th>
  109 + <th width="8%">状态</th>
100 110 <th width="7%">状态</th>
101 111 <th >操作</th>
102 112 </tr>
... ... @@ -114,16 +124,10 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
114 124 <div class="cell-cls"><?= $item['serial_no'] ?></div>
115 125 </td>
116 126 <td class="td-cls">
117   - <?= $item['manufacture'] ?>
118   - </td>
119   - <td class="td-cls">
120   - <?= $item['project'] ?>
121   - </td>
122   - <td class="td-cls">
123   - <?= $item['model'] ?>
124   - </td>
125   - <td class="td-cls">
126   - <?= $item['production'] ?>
  127 + 厂商: <?= $item['manufacture'] ?><br/>
  128 + 项目:<?= $item['project'] ?><br/>
  129 + 型号:<?= $item['model'] ?><br/>
  130 + 生产日期:<?= $item['production'] ?><br/>
127 131 </td>
128 132 <td class="td-cls">
129 133 <div class="cell-cls edit_mac edit_mac_<?=$item['id']?>" data-id="<?=$item['id']?>" data="<?= $item['mac'] ?>"><?= $item['mac'] ?></div>
... ... @@ -138,6 +142,9 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
138 142 <?= $item['auth_at']? date('Y-m-d H:i:s', $item['auth_at']):'暂无' ?>
139 143 </td>
140 144 <td class="td-cls">
  145 + <?= $item['created_at']? date('Y-m-d H:i:s', $item['created_at']):'暂无' ?>
  146 + </td>
  147 + <td class="td-cls">
141 148 <?= $statusList[$item['status']] ?>
142 149 </td>
143 150 <td class="td-cls">
... ...
app-ht/modules/device/views/device/index.php
... ... @@ -59,22 +59,25 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
59 59 </div>
60 60 <div class="form-group col-sm-12">
61 61 <label for="apply_at" class="col-sm-1 control-label text-right">申请时间:</label>
62   - <div class="col-sm-4 form-inline">
63   - <input type="date" class="form-control" id="start_apply_at" name="start_apply_at" value="<?php if (!empty($gets['start_apply_at'])){ echo $gets['start_apply_at'];} ?>" autocomplete="off"> - <input type="date" class="form-control" id="end_apply_at" name="end_apply_at" value="<?php if (!empty($gets['end_apply_at'])){ echo $gets['end_apply_at'];} ?>" autocomplete="off">
  62 + <div class="col-sm-2 form-inline">
  63 + <input type="date" class="form-control" id="start_apply_at" name="start_apply_at" value="<?php if (!empty($gets['start_apply_at'])){ echo $gets['start_apply_at'];} ?>" autocomplete="off"> <br>-<br> <input type="date" class="form-control" id="end_apply_at" name="end_apply_at" value="<?php if (!empty($gets['end_apply_at'])){ echo $gets['end_apply_at'];} ?>" autocomplete="off">
64 64 </div>
65   - <label for="auth_at" class="col-sm-1 control-label text-right">授权时间:</label>
66   - <div class="col-sm-4 form-inline">
67   - <input type="date" class="form-control" id="start_auth_at" name="start_auth_at" value="<?php if (!empty($gets['start_auth_at'])){ echo $gets['start_auth_at'];} ?>" autocomplete="off"> - <input type="date" class="form-control" id="end_auth_at" name="end_auth_at" value="<?php if (!empty($gets['end_auth_at'])){ echo $gets['end_auth_at'];} ?>" autocomplete="off">
  65 + <label class="col-sm-1 control-label text-right">授权时间:</label>
  66 + <div class="col-sm-2 form-inline">
  67 + <input type="date" class="form-control" id="start_auth_at" name="start_auth_at" value="<?php if (!empty($gets['start_auth_at'])){ echo $gets['start_auth_at'];} ?>" autocomplete="off"> <br>-<br> <input type="date" class="form-control" id="end_auth_at" name="end_auth_at" value="<?php if (!empty($gets['end_auth_at'])){ echo $gets['end_auth_at'];} ?>" autocomplete="off">
68 68 </div>
69 69  
70   -
71   - <label for="auth_at" class="col-sm-1 control-label text-right">处理:</label>
72   - <div class="col-sm-1 form-inline">
73   - <select name="has_re_auth" class="form-control">
74   - <option value="">全部</option>
75   - <option value="1" <?php if(1 ==$gets['has_re_auth']) {echo "selected";}?>>已处理</option>
76   - <option value="2" <?php if(2 ==$gets['has_re_auth']) {echo "selected";}?>>未处理</option>
77   - </select>
  70 + <label class="col-sm-1 control-label text-right">生成时间:</label>
  71 + <div class="col-sm-2 form-inline">
  72 + <input type="date" class="form-control" id="start_auth_at" name="start_created_at" value="<?php if (!empty($gets['start_created_at'])){ echo $gets['start_created_at'];} ?>" autocomplete="off"> <br>-<br> <input type="date" class="form-control" id="end_created_at" name="end_created_at" value="<?php if (!empty($gets['end_created_at'])){ echo $gets['end_created_at'];} ?>" autocomplete="off">
  73 + </div>
  74 + <label for="handle_status" class="col-sm-1 control-label text-right">处理:</label>
  75 + <div class="col-sm-2 form-inline">
  76 + <select id="handle_status" name="has_re_auth" class="form-control">
  77 + <option value="">全部</option>
  78 + <option value="1" <?php if(1 ==$gets['has_re_auth']) {echo "selected";}?>>已处理</option>
  79 + <option value="2" <?php if(2 ==$gets['has_re_auth']) {echo "selected";}?>>未处理</option>
  80 + </select>
78 81 </div>
79 82 </div>
80 83  
... ... @@ -98,15 +101,14 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
98 101 <tr>
99 102 <th></th>
100 103 <th width="6%">ID</th>
101   - <th width="5%">序列号</th>
102   - <th width="8%">厂商</th>
103   - <th width="6%">项目</th>
104   - <th width="8%">设备型号</th>
105   - <th width="6%">生产日期</th>
  104 + <th width="8%">序列号</th>
  105 + <th width="10%">批次信息</th>
  106 +
106 107 <th>MAC地址</th>
107   - <th width="7%">设备ID</th>
108   - <th width="7%">申请时间</th>
109   - <th width="7%">授权时间</th>
  108 + <th width="8%">设备ID</th>
  109 + <th width="8%">申请时间</th>
  110 + <th width="8%">授权时间</th>
  111 + <th width="8%">生成时间</th>
110 112 <th width="7%">状态</th>
111 113 <th >操作</th>
112 114 </tr>
... ... @@ -124,17 +126,12 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
124 126 <div class="cell-cls"><?= $item['serial_no'] ?></div>
125 127 </td>
126 128 <td class="td-cls">
127   - <?= $item['manufacture'] ?>
128   - </td>
129   - <td class="td-cls">
130   - <?= $item['project'] ?>
131   - </td>
132   - <td class="td-cls">
133   - <?= $item['model'] ?>
134   - </td>
135   - <td class="td-cls">
136   - <?= $item['production'] ?>
  129 + 厂商: <?= $item['manufacture'] ?><br/>
  130 + 项目:<?= $item['project'] ?><br/>
  131 + 型号:<?= $item['model'] ?><br/>
  132 + 生产日期:<?= $item['production'] ?><br/>
137 133 </td>
  134 +
138 135 <td class="td-cls">
139 136 <div class="cell-cls edit_mac edit_mac_<?=$item['id']?>" data-id="<?=$item['id']?>" data="<?= $item['mac'] ?>"><?= $item['mac'] ?></div>
140 137 </td>
... ... @@ -148,6 +145,9 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
148 145 <?= $item['auth_at']? date('Y-m-d H:i:s', $item['auth_at']):'暂无' ?>
149 146 </td>
150 147 <td class="td-cls">
  148 + <?= $item['created_at']? date('Y-m-d H:i:s', $item['created_at']):'暂无' ?>
  149 + </td>
  150 + <td class="td-cls">
151 151 <?= $statusList[$item['status']] ?>
152 152 </td>
153 153 <td class="td-cls">
... ...
app-ht/modules/system/views/account/index.php
... ... @@ -70,9 +70,9 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
70 70 <?= $user['is_enable_label'] ?>
71 71 </td>
72 72 <td style="padding:12px;">
73   - <a href="<?php echo Url::toRoute(['/system/account/set-role', 'id' => $user['id']]) ?>"><span class="btn btn-success" style="padding:8px;">设置角色</span></a> &nbsp;&nbsp;
  73 + <?php if('admin' != $user['username'] ) {?><a href="<?php echo Url::toRoute(['/system/account/set-role', 'id' => $user['id']]) ?>"><span class="btn btn-success" style="padding:8px;">设置角色</span></a> &nbsp;&nbsp; <?php }?>
74 74 <a href="<?php echo Url::toRoute(['/system/account/update', 'id' => $user['id']]) ?>"><span class="btn btn-primary" style="padding:8px;">编辑</span></a> &nbsp;&nbsp;
75   - <a href="<?php echo Url::toRoute(['/system/account/enable', 'id' => $user['id']]) ?>"><span class="btn btn-danger" style="padding:8px;"><?php echo $user['is_enable_opt'] ?></span></a>
  75 + <?php if('admin' != $user['username'] ) {?> <a href="<?php echo Url::toRoute(['/system/account/enable', 'id' => $user['id']]) ?>"><span class="btn btn-danger" style="padding:8px;"><?php echo $user['is_enable_opt'] ?></span></a><?php }?>
76 76 </td>
77 77 </tr>
78 78 <?php endforeach; ?>
... ...
app-ht/modules/upgrade/controllers/UpgradeController.php
... ... @@ -132,7 +132,7 @@ class UpgradeController extends BaseController
132 132 $user = Yii::$app->user->identity;
133 133 if (isset($user->is_manufacture) && $user->is_manufacture == 1) {
134 134 $manufacturer = ManufacturerRepository::findOne(["sys_user_id" => $user->id]);
135   - if (empty($manufacturer) || $manufacturer->id != $request->post("manufacturer_id")) {
  135 + if (empty($manufacturer) || $manufacturer->id != $request->post("manufacture_id")) {
136 136 Yii::$app->session->setFlash('error', '添加失败');
137 137 return $this->render('create');
138 138 }
... ... @@ -218,7 +218,7 @@ class UpgradeController extends BaseController
218 218 $user = Yii::$app->user->identity;
219 219 if (isset($user->is_manufacture) && $user->is_manufacture == 1) {
220 220 $manufacturer = ManufacturerRepository::findOne(["sys_user_id" => $user->id]);
221   - if (empty($manufacturer) || $manufacturer->id != $request->post("manufacturer_id")) {
  221 + if (empty($manufacturer) || $manufacturer->id != $request->post("manufacture_id")) {
222 222 Yii::$app->session->setFlash('error', '编辑失败');
223 223 $params = $this->dataList(1);
224 224 return $this->render('index', $params);
... ... @@ -277,8 +277,8 @@ class UpgradeController extends BaseController
277 277 $user = Yii::$app->user->identity;
278 278 if (isset($user->is_manufacture) && $user->is_manufacture == 1) {
279 279 $manufacturer = ManufacturerRepository::findOne(["sys_user_id" => $user->id]);
280   - $upgrade = UpgradeRepository::selectOne($itemId,true);
281   - if (empty($upgrade) || empty($manufacturer) || $manufacturer->id != $request->post("manufacturer_id")) {
  280 + $upgrade = UpgradeRepository::selectOne($itemId, true);
  281 + if (empty($upgrade) || empty($manufacturer) || $manufacturer->id != $upgrade['manufacture_id']) {
282 282 $msg['status'] = 0;
283 283 $msg['msg'] = "删除";
284 284 return $this->renderJson($msg);
... ... @@ -717,6 +717,7 @@ class UpgradeController extends BaseController
717 717 $manufactureId = $request->post("manufacture");
718 718 $projectId = $request->post("project");
719 719 $modelId = $request->post("model");
  720 + $type = $request->post("type");
720 721 $id = $request->post('id');
721 722 if (empty($manufactureId)) {
722 723 $e->message = '请先选择厂商';
... ... @@ -733,14 +734,14 @@ class UpgradeController extends BaseController
733 734 return $this->renderJson($e);
734 735 }
735 736  
736   - $upgradeModel = UpgradeRepository::findOne(['manufacture_id' => $manufactureId, 'project_id' => $projectId, 'model_id' => $modelId, 'is_delete' => 0, 'status' => UpgradeStatus::STATUS_ON]);
  737 + $upgradeModel = UpgradeRepository::findOne(['manufacture_id' => $manufactureId, 'project_id' => $projectId, 'model_id' => $modelId, 'is_delete' => 0, 'status' => UpgradeStatus::STATUS_ON, 'type' => $type]);
737 738 if ($upgradeModel && empty($id)) {
738   - $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传';
  739 + $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传'.$upgradeModel->id;
739 740 return $this->renderJson($e);
740 741 }
741 742  
742 743 if ($upgradeModel && !empty($id) && $id != $upgradeModel->id) {
743   - $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传';
  744 + $e->message = '该厂商该批次已经存在一个版本号为:'.$upgradeModel->version.'的发布版本,请先取消发布的版本再上传';
744 745 return $this->renderJson($e);
745 746 }
746 747  
... ...
app-ht/modules/upgrade/views/upgrade/create.php
... ... @@ -37,7 +37,13 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
37 37 <?php } ?>
38 38 </div>
39 39 <div class="form-group col-sm-12">
40   - <label for="skillName" class="col-sm-4 control-label text-right"><span style="color: #ff0000;">*</span>APP版本号:</label>
  40 + <label for="skillName" class="col-sm-4 control-label text-right"><span style="color: #ff0000;">*</span>
  41 + <?php if (isset($gets["type"]) && $gets["type"] == UpgradeStatus::TYPE_OTA) { ?>
  42 + OTA版本号
  43 + <?php } else { ?>
  44 + APP版本号
  45 + <?php } ?>
  46 + </label>
41 47 <div class="col-sm-4 text-left">
42 48 <input type="text" value="<?= (isset($gets["version"]) ? $gets["version"] : "") ?>" name="version" placeholder="请填写APP版本号" style="margin-top: -6px;" class="form-control"">
43 49 </div>
... ... @@ -261,7 +267,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
261 267 var manufacture = $('#manufacture').val();
262 268 var project = $('#project').val();
263 269 var model = $('#model').val();
264   - $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model}, function(res){
  270 + var type = $('#type').val();
  271 + $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model,type:type}, function(res){
265 272 if (res.success) {
266 273 if (that.hasClass('disabled')) {
267 274 return false;
... ...
app-ht/modules/upgrade/views/upgrade/edit.php
... ... @@ -36,7 +36,12 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
36 36 <?php } ?>
37 37 </div>
38 38 <div class="form-group col-sm-12">
39   - <label for="skillName" class="col-sm-4 control-label text-right"><span style="color: #ff0000;">*</span>APP版本号:</label>
  39 + <label for="skillName" class="col-sm-4 control-label text-right"><span style="color: #ff0000;">*</span>
  40 + <?php if (isset($info["type"]) && $info["type"] == UpgradeStatus::TYPE_OTA) { ?>
  41 + OTA版本号
  42 + <?php } else { ?>
  43 + APP版本号
  44 + <?php } ?>:</label>
40 45 <div class="col-sm-4 text-left">
41 46 <input type="text" value="<?= (isset($info["version"]) ? $info["version"] : "") ?>" name="version" placeholder="请填写APP版本号" style="margin-top: -6px;" class="form-control"">
42 47 </div>
... ... @@ -251,7 +256,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
251 256 var manufacture = $('#manufacture').val();
252 257 var project = $('#project').val();
253 258 var model = $('#model').val();
254   - $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model, id: $('#uid').val()}, function(res){
  259 + var type = $('#type').val();
  260 + $.post(checkUpgradeUrl, {manufacture:manufacture, project:project,model:model, id: $('#uid').val(), 'type':type}, function(res){
255 261 if (res.success) {
256 262 if (that.hasClass('disabled')) {
257 263 return false;
... ...
common/exts/Aes.php 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +<?php
  2 +
  3 +namespace common\exts;
  4 +
  5 +class Aes
  6 +{
  7 + /**
  8 + * var string $method 加解密方法,可通过openssl_get_cipher_methods()获得
  9 + */
  10 + protected $method;
  11 +
  12 + /**
  13 + * var string $secret_key 加解密的密钥
  14 + */
  15 + protected $secret_key;
  16 +
  17 + /**
  18 + * var string $iv 加解密的向量,有些方法需要设置比如CBC
  19 + */
  20 + protected $iv;
  21 +
  22 + /**
  23 + * var string $options (不知道怎么解释,目前设置为0没什么问题)
  24 + */
  25 + protected $options;
  26 +
  27 + /**
  28 + * 构造函数
  29 + *
  30 + * @param string $key 密钥
  31 + * @param string $method 加密方式
  32 + * @param string $iv iv向量
  33 + * @param mixed $options 还不是很清楚
  34 + *
  35 + */
  36 + public function __construct($key, $method = 'AES-128-ECB', $iv = '', $options = 0)
  37 + {
  38 + // key是必须要设置的
  39 + $this->secret_key = isset($key) ? $key : 'king_board_key_01';
  40 +
  41 + $this->method = $method;
  42 +
  43 + $this->iv = $iv;
  44 +
  45 + $this->options = $options;
  46 + }
  47 +
  48 + /**
  49 + * 加密方法,对数据进行加密,返回加密后的数据
  50 + *
  51 + * @param string $data 要加密的数据
  52 + *
  53 + * @return string
  54 + *
  55 + */
  56 + public function encrypt($data)
  57 + {
  58 + return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
  59 + }
  60 +
  61 + /**
  62 + * 解密方法,对数据进行解密,返回解密后的数据
  63 + *
  64 + * @param string $data 要解密的数据
  65 + *
  66 + * @return string
  67 + *
  68 + */
  69 + public function decrypt($data)
  70 + {
  71 + return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
  72 + }
  73 +}
0 74 \ No newline at end of file
... ...
common/exts/RSACrypt.php 0 → 100644
... ... @@ -0,0 +1,86 @@
  1 +<?php
  2 +
  3 +namespace common\exts;
  4 +
  5 +class RSACrypt
  6 +{
  7 +
  8 + public static $private_key = "-----BEGIN RSA PRIVATE KEY-----
  9 +MIICXQIBAAKBgQCpS7mxdU6svbDcs10qbq9f9t5D4yfqC1jLmZD3GDD4D/8TbNkf
  10 +vcYDvde6nyPRSxrnzl9YmZhJKlP2iCIwdwwmW6yulXZyvPurfN/1AJt4JYDxnN/q
  11 +u1bSG5DZMribLsR2dlfA5J0D6lQ7g40eSgp4D6UWy8ezLy6UWFQCrnUHEQIDAQAB
  12 +AoGAQCQeoKtvOWdNIPEb9T2mWFdx8oqXzsapx8nQ8K1LsFBvNe7hfHMsGLLOjzhI
  13 +G7223eiEm07mMaJF2XvOaEpSYX/qQ1LZRSdBrzCec1lcDbB95dcRg9NmgBuCpUxE
  14 +3SGYm3VB8rurfsrRUUYoIbjWz8qyuIGdMbaNkHG/CpnUYpkCQQDfWYDYtQ3DxCt+
  15 +JBoLfuCykk8+nIV12CIYb023naoR2s/aQQRk9BkGCkDrdOAgZAN3BGOHYseKAfTP
  16 +nARDzfiDAkEAwgtYfgCDTOfW5/kJK1lZO21CdCCZnePwGYmWDLPzNiJIn8k0U6Ig
  17 +9GmxG+0GKzY71XO8W3Nh18ilZbX9dYel2wJASQ+AJGNlc0pyZ7rrgiMo4YEWxwZw
  18 +adIfpRqTs6KxhVGseFqYU2W94cns3pjG0BGnSIF5BUp8t1pYeKkyg/OWfQJBAK1w
  19 +mq41IycQaoR5kfqPKDT32dgWc3gvDqKk2duM1KzkQ+meXAkM90u/VLDTURo6pYyK
  20 +oCdVoHTRQRUCcAQnNNUCQQCO/zDRaY+5ssjPqj77eJqWfAhtbSDRRw+NurmUSas1
  21 +FT1cD5nil+uT48bIRoC5nk/XWfvAvMg/Yw5bslGUNx7f
  22 +-----END RSA PRIVATE KEY-----";
  23 +
  24 + public static $public_key = "-----BEGIN PUBLIC KEY-----
  25 +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpS7mxdU6svbDcs10qbq9f9t5D
  26 +4yfqC1jLmZD3GDD4D/8TbNkfvcYDvde6nyPRSxrnzl9YmZhJKlP2iCIwdwwmW6yu
  27 +lXZyvPurfN/1AJt4JYDxnN/qu1bSG5DZMribLsR2dlfA5J0D6lQ7g40eSgp4D6UW
  28 +y8ezLy6UWFQCrnUHEQIDAQAB
  29 +-----END PUBLIC KEY-----";
  30 +
  31 + private $pubkey;
  32 + private $privkey;
  33 +
  34 + /**
  35 + * RSACrypt constructor.
  36 + * @param null $privateKey
  37 + * @param null $publicKey
  38 + */
  39 + function __construct($privateKey = null, $publicKey = null)
  40 + {
  41 + // 获得资源类型公钥和私钥,
  42 + if ($publicKey) {
  43 + $_publicKey = $publicKey;
  44 + } else {
  45 + $_publicKey = self::$public_key;
  46 + }
  47 +
  48 + if ($privateKey) {
  49 + $_privateKey = $privateKey;
  50 + } else {
  51 + $_privateKey = self::$private_key;
  52 + }
  53 + $this->privkey = openssl_pkey_get_private($_privateKey);
  54 + $this->pubkey = openssl_pkey_get_public($_publicKey);
  55 + }
  56 +
  57 + /**
  58 + * 加密
  59 + * @param $data
  60 + * @return string
  61 + */
  62 + public function encrypt($data)
  63 + {
  64 + if (openssl_public_encrypt($data, $encrypted, $this->pubkey)) {
  65 + $data = base64_encode($encrypted);
  66 + return $data;
  67 + } else {
  68 + return null;
  69 + }
  70 + }
  71 +
  72 + /**
  73 + * 解密
  74 + * @param $data
  75 + * @return mixed
  76 + */
  77 + public function decrypt($data)
  78 + {
  79 + if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey)) {
  80 + $data = $decrypted;
  81 + return $data;
  82 + } else {
  83 + return null;
  84 + }
  85 + }
  86 +}
0 87 \ No newline at end of file
... ...
common/helpers/Utils.php
... ... @@ -42,7 +42,7 @@ class Utils
42 42 * @param bool|false $onlyNumber 是否纯数字
43 43 * @return string
44 44 */
45   - public static function rand($len,$onlyNumber = false)
  45 + public static function rand($len, $onlyNumber = false)
46 46 {
47 47 $randString = '';
48 48 $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_";
... ...
console/controllers/TestController.php
... ... @@ -7,15 +7,15 @@ namespace console\controllers;
7 7 * Time: 11:32 AM
8 8 */
9 9  
10   -
11   -use app\api\helpers\Aes;
  10 +use common\exts\Aes;
  11 +use common\exts\RSACrypt;
12 12 use common\exts\Http;
  13 +use common\helpers\Utils;
13 14 use domain\device\Device;
14 15 use GuzzleHttp\Psr7;
15 16 use yii\console\Controller;
16 17 use GuzzleHttp\Psr7\Request;
17 18 use function chr;
18   -use yii\helpers\ArrayHelper;
19 19  
20 20 class TestController extends Controller
21 21 {
... ... @@ -43,7 +43,7 @@ class TestController extends Controller
43 43 $modelNo = '0001';
44 44 $productionNo = '0001';
45 45 $timestamp = time();
46   - $salt = 13456;
  46 + $salt = '13456';
47 47 $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt);
48 48 $params = [
49 49 'manufacture' => $manufactureNo,
... ... @@ -154,7 +154,6 @@ class TestController extends Controller
154 154 echo $postResult;
155 155 }
156 156  
157   -
158 157 public function actionReportAppEvent()
159 158 {
160 159 //actionCheckAppVersion
... ... @@ -177,5 +176,83 @@ class TestController extends Controller
177 176 $postResult = Http::POST($url, $params);
178 177 echo $postResult;
179 178 }
  179 +
  180 + public function actionEncodePost()
  181 + {
  182 + $url = 'http://kingb:8012/app-api/web/CryptTxt';
  183 + $randKey = '98765432';//Utils::rand(32);
  184 + $rsa = new RSACrypt();
  185 + $aes = new Aes($randKey);
  186 + $deviceId = 'oelooeloeloeloe';
  187 + $manufactureNo = '0001';
  188 + $tt = time();
  189 + $sign = md5($deviceId . $tt . $randKey);
  190 + $dd = json_encode(['manufacture' => $manufactureNo, 'timestamp' => $tt, 'sign' => $sign, 'device_id' => $deviceId]);
  191 + $params = [
  192 + 'randomKey' => $rsa->encrypt($randKey),
  193 + 'content' => $aes->encrypt($dd)
  194 + ];
  195 + $params = json_encode($params);
  196 + $postResult = Http::POST($url, $params);
  197 + $postResult = json_decode($postResult, true);
  198 + $decodeJson = $aes->decrypt($postResult['content']);
  199 + print_r($decodeJson);
  200 + }
  201 +
  202 + /**
  203 + *
  204 + */
  205 + public function actionAuthDeviceT()
  206 + {
  207 + $url = 'http://kingb:8012/app-api/web/authDeviceT';
  208 + //$url = 'http://47.107.95.101/app-api/web/authDeviceT';
  209 + $manufactureNo = '0001';
  210 + $device_id = 'DEVICE00000A';
  211 + $projectNo = '0001';
  212 + $modelNo = '0001';
  213 + $productionNo = '0001';
  214 + $timestamp = time();
  215 +
  216 +
  217 + $randKey = Utils::rand(16).$timestamp;
  218 + $salt = "13456";
  219 + $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt);
  220 + $deviceParams = [
  221 + 'manufacture' => $manufactureNo,
  222 + 'device_id' => $device_id,
  223 + 'project' => $projectNo,
  224 + 'model' => $modelNo,
  225 + 'production' => $productionNo,
  226 + 'timestamp' => $timestamp,
  227 + 'sign' => $sign,
  228 + ];
  229 + $deviceParams = json_encode($deviceParams);
  230 + $rsa = new RSACrypt();
  231 + $randomKey = $rsa->encrypt($randKey);
  232 + $aes = new Aes($randKey);
  233 + $params = [
  234 + 'randomKey' => $randomKey,
  235 + 'content' => $aes->encrypt($deviceParams)
  236 + ];
  237 + $params = json_encode($params);
  238 + $postResult = Http::POST($url, $params);
  239 +
  240 + $postResult = json_decode($postResult, true);
  241 + $decodeJson = $aes->decrypt($postResult['content']);
  242 +
  243 + echo $decodeJson;
  244 + }
  245 +
  246 +
  247 + public function actionA()
  248 + {
  249 + $str = "87654321";
  250 + $rsa = new RSACrypt();
  251 + $deStr = "dFz10grDo8eO/+APJvPG4B4suilGLsFcHyMc/JIVUhIUWpILFhJD6g2z1TVusvzSxXsQJpNO44fFxzy8F4j/u/l61HAxS3owpgcmJ4e5mU3ugXftBqazOYErYssnoh03khaJUalwwlw/N5NpspRT6GXVwegEQnJKnGsIwZqXbsY=";
  252 +
  253 + //echo $deStr."\r\n";
  254 + echo $rsa->decrypt($deStr);
  255 + }
  256 +
180 257 }
181 258  
... ...