AesController.php
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Created by PhpStorm.
* User: ruidiudiu
* Date: 2018/11/12
* Time: 11:02
*/
namespace app\portal\controller;
use aesutil\AESUtil;
use cmf\controller\HomeBaseController;
use think\Db;
/**
* @title 蓝牙锁相关接口
* @description 蓝牙锁相关接口
* @group 蓝牙锁相关接口
*/
class AesController extends HomeBaseController{
public function index(){
$strKey='2222222222222222';
$message='ff0ca23403de4f4aaf5500ef';
$aes=new AESUtil($strKey);
dump("加密".$message.":".$aes->encryption($message));
dump("解密密2857153e26d8dda190834c3a1a3f8f3c:".$aes->decryption('2857153e26d8dda190834c3a1a3f8f3c'));
}
/**
* @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";
$aes=new AESUtil($strKey['key']);
$lockKey=$aes->encryption($key);
$this->apiResponse(200,'success',$lockKey);
}else{
$this->apiResponse(301,'MAC地址未认证');
}
}
/**
* @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";
$aes=new AESUtil($strKey['key']);
$StateKey=$aes->encryption($key);
$this->apiResponse(200,'success',$StateKey);
}else{
$this->apiResponse(301,'MAC地址未认证');
}
}
/**
* @title 命令解密
* @description 将设备的十六进制码进行解码,获得设备的返回信息
* @author 董瑞恩
* @url /portal/Aes/decryption
* @method GET
*
* @param name:decryKey type:String require:1 default:无 other: desc:加密命令
* @param name:MACAddress type:String require:1 default:无 other: desc:设备MAC地址
*
* @return key:解密后的指令(数组)
*/
public function decryption(){
$MACAddress=$this->request->param('MACAddress');
$decryKey=$this->request->param('decryKey');
$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);
}else{
$this->apiResponse(301,'MAC地址未认证');
}
}
/**
* @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,'未支付押金');
}
}
}