作者 董瑞恩
1 个管道 的构建 通过 耗费 1 秒

cost

@@ -28,10 +28,10 @@ class AesController extends HomeBaseController{ @@ -28,10 +28,10 @@ class AesController extends HomeBaseController{
28 dump("解密密2857153e26d8dda190834c3a1a3f8f3c:".$aes->decryption('2857153e26d8dda190834c3a1a3f8f3c')); 28 dump("解密密2857153e26d8dda190834c3a1a3f8f3c:".$aes->decryption('2857153e26d8dda190834c3a1a3f8f3c'));
29 } 29 }
30 /** 30 /**
31 - * @title 开锁 31 + * @title 开锁(加密)
32 * @description 获取加密后的“开锁”命令 32 * @description 获取加密后的“开锁”命令
33 * @author 董瑞恩 33 * @author 董瑞恩
34 - * @url /portal/Aes/lock 34 + * @url /portal/Aes/secretLock
35 * @method GET 35 * @method GET
36 * 36 *
37 * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址 37 * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
@@ -39,7 +39,7 @@ class AesController extends HomeBaseController{ @@ -39,7 +39,7 @@ class AesController extends HomeBaseController{
39 * 39 *
40 * @return lockKey:加密的开锁指令(数组) 40 * @return lockKey:加密的开锁指令(数组)
41 */ 41 */
42 - public function lock(){ 42 + public function secretLock(){
43 $MACAddress=$this->request->param('MACAddress'); 43 $MACAddress=$this->request->param('MACAddress');
44 $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find(); 44 $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
45 if (!empty($strKey)){ 45 if (!empty($strKey)){
@@ -54,10 +54,37 @@ class AesController extends HomeBaseController{ @@ -54,10 +54,37 @@ class AesController extends HomeBaseController{
54 } 54 }
55 55
56 /** 56 /**
57 - * @title 获取电压、开关状态 57 + * @title 开锁(不加密)
  58 + * @description 获取“开锁”命令
  59 + * @author 董瑞恩
  60 + * @url /portal/Aes/lock
  61 + * @method GET
  62 + *
  63 + * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
  64 + *
  65 + *
  66 + * @return lockKey:加密的开锁指令(数组)
  67 + */
  68 + public function lock(){
  69 + $MACAddress=$this->request->param('MACAddress');
  70 + $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
  71 + if (!empty($strKey)){
  72 + $key="ff0ca2".$MACAddress."5500ef";
  73 + $lockKey=$this->ToArray($key);
  74 + $this->apiResponse(200,'success',$lockKey);
  75 + }else{
  76 + $this->apiResponse(301,'MAC地址未认证');
  77 + }
  78 +
  79 + }
  80 +
  81 +
  82 +
  83 + /**
  84 + * @title 获取电压、开关状态(加密)
58 * @description 获得加密后“获取电压、开关状态”的命令 85 * @description 获得加密后“获取电压、开关状态”的命令
59 * @author 董瑞恩 86 * @author 董瑞恩
60 - * @url /portal/Aes/getState 87 + * @url /portal/Aes/getSecretState
61 * @method GET 88 * @method GET
62 * 89 *
63 * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址 90 * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
@@ -66,7 +93,7 @@ class AesController extends HomeBaseController{ @@ -66,7 +93,7 @@ class AesController extends HomeBaseController{
66 * @return lockKey:获取电压、开关状态的指令(数组) 93 * @return lockKey:获取电压、开关状态的指令(数组)
67 */ 94 */
68 95
69 - public function getState(){ 96 + public function getSecretState(){
70 $MACAddress=$this->request->param('MACAddress'); 97 $MACAddress=$this->request->param('MACAddress');
71 $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find(); 98 $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
72 if (!empty($strKey)){ 99 if (!empty($strKey)){
@@ -80,6 +107,32 @@ class AesController extends HomeBaseController{ @@ -80,6 +107,32 @@ class AesController extends HomeBaseController{
80 } 107 }
81 108
82 /** 109 /**
  110 + * @title 获取电压、开关状态(不加密)
  111 + * @description 获得加密后“获取电压、开关状态”的命令
  112 + * @author 董瑞恩
  113 + * @url /portal/Aes/getState
  114 + * @method GET
  115 + *
  116 + * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
  117 + *
  118 + *
  119 + * @return lockKey:获取电压、开关状态的指令(数组)
  120 + */
  121 +
  122 + public function getState(){
  123 + $MACAddress=$this->request->param('MACAddress');
  124 + $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
  125 + if (!empty($strKey)){
  126 + $key="ff05a301ef";
  127 + $StateKey=$this->ToArray($key);
  128 + $this->apiResponse(200,'success',$StateKey);
  129 + }else{
  130 + $this->apiResponse(301,'MAC地址未认证');
  131 + }
  132 + }
  133 +
  134 +
  135 + /**
83 * @title 命令解密 136 * @title 命令解密
84 * @description 将设备的十六进制码进行解码,获得设备的返回信息 137 * @description 将设备的十六进制码进行解码,获得设备的返回信息
85 * @author 董瑞恩 138 * @author 董瑞恩
@@ -88,45 +141,67 @@ class AesController extends HomeBaseController{ @@ -88,45 +141,67 @@ class AesController extends HomeBaseController{
88 * 141 *
89 * @param name:decryKey type:String require:1 default:无 other: desc:加密命令 142 * @param name:decryKey type:String require:1 default:无 other: desc:加密命令
90 * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址 143 * @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
  144 + * @param name:type type:String require:1 default:无 other: desc:命令类型 (1 开锁返回指令 2 状态返回指令)
91 * 145 *
92 - * @return key:解密后的指令(数组) 146 + * @return :code:1为锁已开,0位锁已关,2为数据异常
93 */ 147 */
94 public function decryption(){ 148 public function decryption(){
95 $MACAddress=$this->request->param('MACAddress'); 149 $MACAddress=$this->request->param('MACAddress');
96 $decryKey=$this->request->param('decryKey'); 150 $decryKey=$this->request->param('decryKey');
  151 + $type=$this->request->param('type');
97 $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find(); 152 $strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
98 if (!empty($strKey)){ 153 if (!empty($strKey)){
99 $aes=new AESUtil($strKey['key']); 154 $aes=new AESUtil($strKey['key']);
100 $key=$aes->decryption($decryKey); 155 $key=$aes->decryption($decryKey);
101 - $this->apiResponse(200,'success',$key); 156 + $this->state($key,$type);
102 }else{ 157 }else{
103 $this->apiResponse(301,'MAC地址未认证'); 158 $this->apiResponse(301,'MAC地址未认证');
104 } 159 }
105 } 160 }
106 161
107 /** 162 /**
108 - * @title 状态验证  
109 - * @description 开锁前判断是否有未支付订单与是否提交押金 163 + * @title 设备状态判断
  164 + * @description 解析设备返回值,获取设备状态
110 * @author 董瑞恩 165 * @author 董瑞恩
111 - * @url /portal/Aes/lock_check 166 + * @url /portal/Aes/decryption
112 * @method GET 167 * @method GET
113 * 168 *
114 - * @param name:users_id type:String require:1 default:无 other: desc:用户id 169 + * @param name:key type:String require:1 default:无 other: desc:设备返回状态(未加密)
  170 + * @param name:type type:String require:1 default:无 other: desc:命令类型 (1 开锁返回指令 2 状态返回指令)
  171 + *
  172 + * @return :code:1为锁已开,0位锁已关,2为数据异常
115 */ 173 */
116 - public function lock_check(){  
117 - $users_id=$this->request->param('users_id');  
118 - //获取提交押金的状态  
119 - $users=Db::name('users')->where('id',$users_id)->find();  
120 - if ($users['is_deposit']===1){  
121 - $order=Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();  
122 - if (empty($order)){  
123 - $this->apiResponse(200,'验证通过'); 174 + public function state($key,$type){
  175 + if ($type==1){
  176 + if($key[0]=='0xff' && $key[4]=='0xef'){
  177 + if ($key[3]=='0x01'){
  178 + $this->apiResponse(1,'锁已开');
  179 + }else if($key[3]=='0x00'){
  180 + $this->apiResponse(0,'开锁失败');
  181 + }
124 }else{ 182 }else{
125 - $this->apiResponse(302,'有未支付订单'); 183 + $this->apiResponse(2,'返回指令错误');
  184 + }
  185 + }else if($type==2){
  186 + if($key[0]=='0xff' && $key[7]=='0xef'){
  187 + if ($key[6]=='0x01'){
  188 + $this->apiResponse(1,'状态为开锁');//开着
  189 + }else if($key[6]=='0x00'){
  190 + $this->apiResponse(0,'状态为关锁');//关了
126 } 191 }
127 }else{ 192 }else{
128 - $this->apiResponse(301,'未支付押金'); 193 + $this->apiResponse(2,'返回指令错误');
  194 + }
  195 + }
  196 + }
  197 +
  198 + //转成数组
  199 + private function ToArray($data){
  200 + $array = array();
  201 + for ($i = 0; $i < strlen($data); $i += 2) {
  202 + $array[]='0x'.substr($data, $i, 2);
129 } 203 }
  204 + return $array;
130 } 205 }
131 206
132 } 207 }
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: ruidiudiu
  5 + * Date: 2018/11/23
  6 + * Time: 18:26
  7 + */
  8 +
  9 +namespace app\portal\controller;
  10 +
  11 +
  12 +use cmf\controller\HomeBaseController;
  13 +use think\Db;
  14 +
  15 +class UsersController extends HomeBaseController{
  16 +
  17 + /**
  18 + * @title 状态验证
  19 + * @description 开锁前判断是否有未支付订单与是否提交押金
  20 + * @author 董瑞恩
  21 + * @url /portal/Aes/lock_check
  22 + * @method GET
  23 + *
  24 + * @param name:users_id type:String require:1 default:无 other: desc:用户id
  25 + */
  26 + public function lock_check(){
  27 + $users_id=$this->request->param('users_id');
  28 + //获取提交押金的状态
  29 + $users=Db::name('users')->where('id',$users_id)->find();
  30 + if ($users['is_deposit']===1){
  31 + $order=Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();
  32 + if (empty($order)){
  33 + $this->apiResponse(200,'验证通过');
  34 + }else{
  35 + $this->apiResponse(302,'有未支付订单');
  36 + }
  37 + }else{
  38 + $this->apiResponse(301,'未支付押金');
  39 + }
  40 + }
  41 +}
@@ -39,127 +39,60 @@ @@ -39,127 +39,60 @@
39 <div class="col-md-6"> 39 <div class="col-md-6">
40 <table class="table table-bordered"> 40 <table class="table table-bordered">
41 <tr> 41 <tr>
42 - <th width="80">检测编号<span class="form-required">*</span></th> 42 + <th width="80">设备锁编号<span class="form-required">*</span></th>
43 <td> 43 <td>
44 - <input class="form-control" type="text" name="test_no"  
45 - id="test_no" required value="" placeholder="请输入检测编号"/> 44 + <input class="form-control" type="text" name="serial_number"
  45 + id="serial_number" required value="" placeholder="请输入设备锁编号"/>
46 </td> 46 </td>
47 - <th width="80">油品名称<span class="form-required">*</span></th> 47 + <th width="80">设备MAC地址<span class="form-required">*</span></th>
48 <td><input class="form-control" type="text" name="test_oil_name" id="test_oil_name" value="" 48 <td><input class="form-control" type="text" name="test_oil_name" id="test_oil_name" value=""
49 - placeholder="请输入检测类型" required></td> 49 + placeholder="请输入设备MAC地址" required></td>
50 </tr> 50 </tr>
51 <tr> 51 <tr>
52 - <th width="80">手机号1<span class="form-required">*</span></th> 52 + <th width="80">设备锁名称<span class="form-required">*</span></th>
53 <td> 53 <td>
54 <input class="form-control" type="text" name="test_phone1" id="test_phone1" value="" 54 <input class="form-control" type="text" name="test_phone1" id="test_phone1" value=""
55 - placeholder="请输入手机号1" required> 55 + placeholder="请输入设备锁名称" required>
56 </td> 56 </td>
57 - <th width="80">手机号2</th> 57 + <th width="80">所属医院</th>
58 <td> 58 <td>
59 <input class="form-control" type="text" name="test_phone2" id="test_phone2" value="" 59 <input class="form-control" type="text" name="test_phone2" id="test_phone2" value=""
60 - placeholder="请输入手机号2"> 60 + placeholder="请输入所属医院">
61 </td> 61 </td>
62 </tr> 62 </tr>
63 <tr> 63 <tr>
64 - <th width="80">所属公司<span class="form-required">*</span></th> 64 + <th width="80">备注<span class="form-required">*</span></th>
65 <td> 65 <td>
66 <input class="form-control" type="text" name="test_company" id="test_company" 66 <input class="form-control" type="text" name="test_company" id="test_company"
67 - placeholder="请填写所属公司" required> 67 + placeholder="请填写备注" required>
68 </td> 68 </td>
69 - <th width="80">送样人<span class="form-required">*</span></th> 69 + <th width="80">导入时间<span class="form-required">*</span></th>
70 <td> 70 <td>
71 <input class="form-control" name="test_people" id="test_people" 71 <input class="form-control" name="test_people" id="test_people"
72 placeholder="请填写送样人" required> 72 placeholder="请填写送样人" required>
73 </td> 73 </td>
74 </tr> 74 </tr>
75 - <tr>  
76 - <th width="80">设备标识</th>  
77 - <td>  
78 - <input class="form-control" type="text" name="test_facility_identify" id="test_facility_identify"  
79 - placeholder="请填写所属公司">  
80 - </td>  
81 - <th width="80">样品标识</th>  
82 - <td>  
83 - <input class="form-control" type="text" name="test_sample_identify" id="test_sample_identify"  
84 - placeholder="请填写所属城市">  
85 - </td>  
86 - </tr>  
87 - <!--<tr>-->  
88 - <!--<th width="80">检测状态<span class="form-required">*</span></th>-->  
89 - <!--<td>-->  
90 - <!--<input class="form-control" name=""-->  
91 - <!--placeholder="请填写摘要">-->  
92 - <!--</td>-->  
93 - <!--<th width="80">添加时间<span class="form-required">*</span></th>-->  
94 - <!--<td>-->  
95 - <!--<input class="form-control" name="post[post_excerpt]"-->  
96 - <!--placeholder="请填写摘要">-->  
97 - <!--</td>-->  
98 - <!--</tr>-->  
99 - <!--<tr>-->  
100 - <!--<th width="80">检测报告</th>-->  
101 - <!--<td colspan="3">-->  
102 - <!--<ul id="photos" class="pic-list list-unstyled form-inline"></ul>-->  
103 - <!--<a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"-->  
104 - <!--class="btn btn-default btn-sm">选择图片</a>-->  
105 - <!--</td>-->  
106 - <!--</tr>--> 75 +
107 </table> 76 </table>
108 - <div class="form-group">  
109 - <div class="col-sm-offset-2 col-sm-10">  
110 - <!--js-ajax-submit-->  
111 - <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>  
112 - <a class="btn btn-default" href="{:url('AdminTestInfo/index')}">{:lang('BACK')}</a>  
113 - </div>  
114 - </div>  
115 </div> 77 </div>
116 </div> 78 </div>
117 </form> 79 </form>
118 </div> 80 </div>
119 <script type="text/javascript" src="__STATIC__/js/admin.js"></script> 81 <script type="text/javascript" src="__STATIC__/js/admin.js"></script>
120 -<script type="text/javascript">  
121 - //编辑器路径定义  
122 - var editorURL = GV.WEB_ROOT;  
123 -</script> 82 +
124 <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script> 83 <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
125 <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script> 84 <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
126 <script type="text/javascript"> 85 <script type="text/javascript">
127 - $(function () {  
128 -  
129 - editorcontent = new baidu.editor.ui.Editor();  
130 - editorcontent.render('content');  
131 - try {  
132 - editorcontent.sync();  
133 - } catch (err) {  
134 - }  
135 -  
136 - $('.btn-cancel-thumbnail').click(function () {  
137 - $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');  
138 - $('#thumbnail').val('');  
139 - }); 86 + function confirm() {
  87 + var selectedCategoriesId = [];
  88 + var selectedCategoriesName = [];
  89 + var selectedCategories = [];
140 90
141 - });  
142 -  
143 - function doSelectCategory() {  
144 - var selectedCategoriesId = $('#js-categories-id-input').val();  
145 - openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {  
146 - area: ['700px', '400px'],  
147 - btn: ['确定', '取消'],  
148 - yes: function (index, layero) {  
149 - //do something  
150 -  
151 - var iframeWin = window[layero.find('iframe')[0]['name']];  
152 - var selectedCategories = iframeWin.confirm();  
153 - if (selectedCategories.selectedCategoriesId.length == 0) {  
154 - layer.msg('请选择分类');  
155 - return;  
156 - }  
157 - $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));  
158 - $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));  
159 - //console.log(layer.getFrameIndex(index));  
160 - layer.close(index); //如果设定了yes回调,需进行手工关闭  
161 - }  
162 - }); 91 + return {
  92 + selectedCategories: selectedCategories,
  93 + selectedCategoriesId: selectedCategoriesId,
  94 + selectedCategoriesName: selectedCategoriesName
  95 + };
163 } 96 }
164 </script> 97 </script>
165 </body> 98 </body>