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

cost

... ... @@ -28,10 +28,10 @@ class AesController extends HomeBaseController{
dump("解密密2857153e26d8dda190834c3a1a3f8f3c:".$aes->decryption('2857153e26d8dda190834c3a1a3f8f3c'));
}
/**
* @title 开锁
* @title 开锁(加密)
* @description 获取加密后的“开锁”命令
* @author 董瑞恩
* @url /portal/Aes/lock
* @url /portal/Aes/secretLock
* @method GET
*
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
... ... @@ -39,7 +39,7 @@ class AesController extends HomeBaseController{
*
* @return lockKey:加密的开锁指令(数组)
*/
public function lock(){
public function secretLock(){
$MACAddress=$this->request->param('MACAddress');
$strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
if (!empty($strKey)){
... ... @@ -54,10 +54,37 @@ class AesController extends HomeBaseController{
}
/**
* @title 获取电压、开关状态
* @title 开锁(不加密)
* @description 获取“开锁”命令
* @author 董瑞恩
* @url /portal/Aes/lock
* @method GET
*
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
*
*
* @return lockKey:加密的开锁指令(数组)
*/
public function lock(){
$MACAddress=$this->request->param('MACAddress');
$strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
if (!empty($strKey)){
$key="ff0ca2".$MACAddress."5500ef";
$lockKey=$this->ToArray($key);
$this->apiResponse(200,'success',$lockKey);
}else{
$this->apiResponse(301,'MAC地址未认证');
}
}
/**
* @title 获取电压、开关状态(加密)
* @description 获得加密后“获取电压、开关状态”的命令
* @author 董瑞恩
* @url /portal/Aes/getState
* @url /portal/Aes/getSecretState
* @method GET
*
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
... ... @@ -66,7 +93,7 @@ class AesController extends HomeBaseController{
* @return lockKey:获取电压、开关状态的指令(数组)
*/
public function getState(){
public function getSecretState(){
$MACAddress=$this->request->param('MACAddress');
$strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
if (!empty($strKey)){
... ... @@ -80,6 +107,32 @@ class AesController extends HomeBaseController{
}
/**
* @title 获取电压、开关状态(不加密)
* @description 获得加密后“获取电压、开关状态”的命令
* @author 董瑞恩
* @url /portal/Aes/getState
* @method GET
*
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
*
*
* @return lockKey:获取电压、开关状态的指令(数组)
*/
public function getState(){
$MACAddress=$this->request->param('MACAddress');
$strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
if (!empty($strKey)){
$key="ff05a301ef";
$StateKey=$this->ToArray($key);
$this->apiResponse(200,'success',$StateKey);
}else{
$this->apiResponse(301,'MAC地址未认证');
}
}
/**
* @title 命令解密
* @description 将设备的十六进制码进行解码,获得设备的返回信息
* @author 董瑞恩
... ... @@ -88,45 +141,67 @@ class AesController extends HomeBaseController{
*
* @param name:decryKey type:String require:1 default:无 other: desc:加密命令
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
* @param name:type type:String require:1 default:无 other: desc:命令类型 (1 开锁返回指令 2 状态返回指令)
*
* @return key:解密后的指令(数组)
* @return :code:1为锁已开,0位锁已关,2为数据异常
*/
public function decryption(){
$MACAddress=$this->request->param('MACAddress');
$decryKey=$this->request->param('decryKey');
$type=$this->request->param('type');
$strKey=Db::name('equipment')->where('mac_address',$MACAddress)->find();
if (!empty($strKey)){
$aes=new AESUtil($strKey['key']);
$key=$aes->decryption($decryKey);
$this->apiResponse(200,'success',$key);
$this->state($key,$type);
}else{
$this->apiResponse(301,'MAC地址未认证');
}
}
/**
* @title 状态验证
* @description 开锁前判断是否有未支付订单与是否提交押金
* @title 设备状态判断
* @description 解析设备返回值,获取设备状态
* @author 董瑞恩
* @url /portal/Aes/lock_check
* @url /portal/Aes/decryption
* @method GET
*
* @param name:users_id type:String require:1 default:无 other: desc:用户id
* @param name:key type:String require:1 default:无 other: desc:设备返回状态(未加密)
* @param name:type type:String require:1 default:无 other: desc:命令类型 (1 开锁返回指令 2 状态返回指令)
*
* @return :code:1为锁已开,0位锁已关,2为数据异常
*/
public function lock_check(){
$users_id=$this->request->param('users_id');
//获取提交押金的状态
$users=Db::name('users')->where('id',$users_id)->find();
if ($users['is_deposit']===1){
$order=Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();
if (empty($order)){
$this->apiResponse(200,'验证通过');
public function state($key,$type){
if ($type==1){
if($key[0]=='0xff' && $key[4]=='0xef'){
if ($key[3]=='0x01'){
$this->apiResponse(1,'锁已开');
}else if($key[3]=='0x00'){
$this->apiResponse(0,'开锁失败');
}
}else{
$this->apiResponse(302,'有未支付订单');
$this->apiResponse(2,'返回指令错误');
}
}else if($type==2){
if($key[0]=='0xff' && $key[7]=='0xef'){
if ($key[6]=='0x01'){
$this->apiResponse(1,'状态为开锁');//开着
}else if($key[6]=='0x00'){
$this->apiResponse(0,'状态为关锁');//关了
}
}else{
$this->apiResponse(301,'未支付押金');
$this->apiResponse(2,'返回指令错误');
}
}
}
//转成数组
private function ToArray($data){
$array = array();
for ($i = 0; $i < strlen($data); $i += 2) {
$array[]='0x'.substr($data, $i, 2);
}
return $array;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: ruidiudiu
* Date: 2018/11/23
* Time: 18:26
*/
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\Db;
class UsersController extends HomeBaseController{
/**
* @title 状态验证
* @description 开锁前判断是否有未支付订单与是否提交押金
* @author 董瑞恩
* @url /portal/Aes/lock_check
* @method GET
*
* @param name:users_id type:String require:1 default:无 other: desc:用户id
*/
public function lock_check(){
$users_id=$this->request->param('users_id');
//获取提交押金的状态
$users=Db::name('users')->where('id',$users_id)->find();
if ($users['is_deposit']===1){
$order=Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();
if (empty($order)){
$this->apiResponse(200,'验证通过');
}else{
$this->apiResponse(302,'有未支付订单');
}
}else{
$this->apiResponse(301,'未支付押金');
}
}
}
\ No newline at end of file
... ...
... ... @@ -39,127 +39,60 @@
<div class="col-md-6">
<table class="table table-bordered">
<tr>
<th width="80">检测编号<span class="form-required">*</span></th>
<th width="80">设备锁编号<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="test_no"
id="test_no" required value="" placeholder="请输入检测编号"/>
<input class="form-control" type="text" name="serial_number"
id="serial_number" required value="" placeholder="请输入设备锁编号"/>
</td>
<th width="80">油品名称<span class="form-required">*</span></th>
<th width="80">设备MAC地址<span class="form-required">*</span></th>
<td><input class="form-control" type="text" name="test_oil_name" id="test_oil_name" value=""
placeholder="请输入检测类型" required></td>
placeholder="请输入设备MAC地址" required></td>
</tr>
<tr>
<th width="80">手机号1<span class="form-required">*</span></th>
<th width="80">设备锁名称<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="test_phone1" id="test_phone1" value=""
placeholder="请输入手机号1" required>
placeholder="请输入设备锁名称" required>
</td>
<th width="80">手机号2</th>
<th width="80">所属医院</th>
<td>
<input class="form-control" type="text" name="test_phone2" id="test_phone2" value=""
placeholder="请输入手机号2">
placeholder="请输入所属医院">
</td>
</tr>
<tr>
<th width="80">所属公司<span class="form-required">*</span></th>
<th width="80">备注<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="test_company" id="test_company"
placeholder="请填写所属公司" required>
placeholder="请填写备注" required>
</td>
<th width="80">送样人<span class="form-required">*</span></th>
<th width="80">导入时间<span class="form-required">*</span></th>
<td>
<input class="form-control" name="test_people" id="test_people"
placeholder="请填写送样人" required>
</td>
</tr>
<tr>
<th width="80">设备标识</th>
<td>
<input class="form-control" type="text" name="test_facility_identify" id="test_facility_identify"
placeholder="请填写所属公司">
</td>
<th width="80">样品标识</th>
<td>
<input class="form-control" type="text" name="test_sample_identify" id="test_sample_identify"
placeholder="请填写所属城市">
</td>
</tr>
<!--<tr>-->
<!--<th width="80">检测状态<span class="form-required">*</span></th>-->
<!--<td>-->
<!--<input class="form-control" name=""-->
<!--placeholder="请填写摘要">-->
<!--</td>-->
<!--<th width="80">添加时间<span class="form-required">*</span></th>-->
<!--<td>-->
<!--<input class="form-control" name="post[post_excerpt]"-->
<!--placeholder="请填写摘要">-->
<!--</td>-->
<!--</tr>-->
<!--<tr>-->
<!--<th width="80">检测报告</th>-->
<!--<td colspan="3">-->
<!--<ul id="photos" class="pic-list list-unstyled form-inline"></ul>-->
<!--<a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"-->
<!--class="btn btn-default btn-sm">选择图片</a>-->
<!--</td>-->
<!--</tr>-->
</table>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<!--js-ajax-submit-->
<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
<a class="btn btn-default" href="{:url('AdminTestInfo/index')}">{:lang('BACK')}</a>
</div>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
//编辑器路径定义
var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content');
try {
editorcontent.sync();
} catch (err) {
}
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
function confirm() {
var selectedCategoriesId = [];
var selectedCategoriesName = [];
var selectedCategories = [];
});
function doSelectCategory() {
var selectedCategoriesId = $('#js-categories-id-input').val();
openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
area: ['700px', '400px'],
btn: ['确定', '取消'],
yes: function (index, layero) {
//do something
var iframeWin = window[layero.find('iframe')[0]['name']];
var selectedCategories = iframeWin.confirm();
if (selectedCategories.selectedCategoriesId.length == 0) {
layer.msg('请选择分类');
return;
}
$('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
$('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
//console.log(layer.getFrameIndex(index));
layer.close(index); //如果设定了yes回调,需进行手工关闭
}
});
return {
selectedCategories: selectedCategories,
selectedCategoriesId: selectedCategoriesId,
selectedCategoriesName: selectedCategoriesName
};
}
</script>
</body>
... ...