AuthDeviceController.php
1.72 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
<?php
namespace app\api\controllers;
use Yii;
use common\helpers\Utils;
use stdClass;
use function sizeof;
use function date;
use function count;
use function time;
/**
* 设备授权-控制器
* Class AuthDeviceController
* @package app\api\controllers
* manufacture 厂商ID string 是个数字字符串,例如“001”代表 XX厂商
device_id 设备id string 设备的ID
project 项目ID string 项目ID
model 型号ID string 例如 001
timestamp 时间戳 int 例如 2019-10-10 01:01:01
sign 签名 string 用来认证请求是否合法 签名组合为 md5(manufacture + project+ model + production + timestamp + salt) salt 为客户端和服务器约定的key
production 生产日期ID string 日期 例如001
*
*/
class AuthDeviceController extends BaseController
{
const SIGN_SALT = '13456';
/**
* 设备授权接口
* @return stdClass
*/
public function actionIndex()
{
$req = Yii::$app->request;
$manufacture = $req->post('manufacture');
$device_id = $req->post('device_id');
$project = $req->post('project');
$model = $req->post('model');
$sign = $req->post('sign');
$production = $req->post('production');
$timestamp = $req->post('timestamp');
$e = new stdClass();
$e->status = 0;
$e->message = 'fail';
$e->serial_no = '';;
$e->mac = '';
$salt = self::SIGN_SALT;
$makeSign = md5($manufacture . $project. $model . $production . $timestamp . $salt);
if ($sign != $makeSign) {
$e->message = 'sign 有误';
return $e;
}
$e->status = 1;
$e->message = '授权成功';
$e->mac = Utils::macGenerate();
return $e;
}
}