第三方接口对接——微光互联门禁系统

1.设备时长这个样子的

图片.png

图片.png

2.设备安装配置

图片.png

1、电源
POW:正极(12V)调测可以5V
GND:负极
(我这里使用的鼠标线,红线接正极,绿线接负极)
2、网线
TX-:橙
TX+:橙白
RX-:绿
RX+:绿白
3、成功标志
设备上面的蓝灯和白灯常亮

3.接口使用流程

编写接口公共参数(timestatmp使用UTC时间)->>注册用户(UserId)-->>注册设备(DeviceId)->>注册设备返回的设备配置码生成二维码并用设备扫码(绿灯成功,红灯失败)-->>增加时段(TimeRangeId;使用UTC时间)-->>增加规则(用前面的UserId、DeviceId、TimeRangeId)-->>获取用户认证信息->>用户认证返回的认证信息码生成二维码->>扫码即可(绿灯成功,红灯失败)
接口文档网址:https://www.dingdingkaimen.com/product/help/second.html

剩下的懒得说,直接上代码

<?php

class VideoInterface
{
    public $data;
    public $accessKeyId = "iuUgn1lJ36MYcWkP/aslklIKL";
    public $accessKeySecret = "6Z1yrc3cYKIJbLhHCm09SYHGM0x3xyPZ/LDKNils";
    public $url;

    public function __construct($actionArray, $url)
    {
        $this->url = $url;
        date_default_timezone_set("UTC");
        $this->data = array(
            // 公共参数
            'Format' => 'JSON',
            'Version' => '2017-11-27',
            'AccessKeyId' => $this->accessKeyId,
            'SignatureVersion' => '1.0',
            'SignatureMethod' => 'HMAC-SHA1',
            'SignatureNonce' => uniqid(),
            'Timestamp' => date('Y-m-d\TH:i:s\Z')
        );
        //判断输入的参数是否为数组
        if (is_array($actionArray)) {
            $this->data = array_merge($this->data, $actionArray);
        }
    }

    public function percentEncode($str)
    {
        // 使用urlencode编码后,将"+","*","%7E"做替换即满足ECS API规定的编码规范
        $res = urlencode($str);
        $res = preg_replace('/\+/', '%20', $res);
        $res = preg_replace('/\*/', '%2A', $res);
        $res = preg_replace('/%7E/', '~', $res);
        return $res;
    }

    public function computeSignature($parameters, $accessKeySecret)
    {
        // 将参数Key按字典顺序排序
        ksort($parameters);
        // 生成规范化请求字符串
        $canonicalizedQueryString = '';
        foreach ($parameters as $key => $value) {
            $canonicalizedQueryString .= '&' . $this->percentEncode($key)
                . '=' . $this->percentEncode($value);
        }
        // 生成用于计算签名的字符串 stringToSign
        $stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
        // 计算签名,注意accessKeySecret后面要加上字符'&'
        $signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret . '&', true));
        return $signature;
    }

    public function callInterface()
    {
        // 计算签名并把签名结果加入请求参数
        $this->data['Signature'] = $this->computeSignature($this->data, $this->accessKeySecret);
        // 发送请求
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->url . http_build_query($this->data));
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
}
//注册用户
/*  $arr = [
    "Action"=>"RegUser",
    "UserName"=>"刘春雷",
    "PhoneNum"=>"18710161616",
    "Email"=>"794123112@qq.com",
];*/
//修改用户
/* $arr = [
   "Action"=>"ModUser",
   "UserId"=>"109508",
   "UserName"=>"刘亮",
   "PhoneNum"=>"18710161622",
   "Email"=>"794123111@qq.com",
];*/
//查询用户
/* $arr = [
    "Action"=>"QueryUser",
    //"UserId"=>"109488",
    "PageSize"=>"100",
    "CurrentPage"=>"1",
];*/
 //删除用户
/*$arr = [
    "Action"=>"DelUser",
    "UserId"=>"109488"
];*/

//添加设备
/*$arr = [
    "Action"=>"RegDevice",
    "DeviceName"=>"A1001",
    "DeviceAddress"=>"eSSMw6vtpz4I",
    "DeviceType"=>1
];*/
//修改设备
/*$arr = [
    "Action"=>"ModDevice",
    "DeviceId"=>"747",
    "DeviceName"=>"A1001",
    "DeviceAddress"=>"eSSMw6vtpz4I-12389485",
    "DeviceType"=>1,
];*/
//查询设备
/*$arr = [
    "Action"=>"QueryDevice",
    "PageSize"=>100,
    "CurrentPage"=>1,
];*/
//注销设备
/*$arr = [
    "Action"=>"DelDevice",
    "DeviceId"=>"747"
];*/

//增加时段  必须使用UTC时区
/*date_default_timezone_set("UTC");
 $arr = [
    "Action"=>"AddTimeRange",
    "TimeRangeName"=>"T0001",
    "TimeRangeBeginTime"=>date('Y-m-d\TH:i:s\Z'),
    "TimeRangeEndTime"=>date('Y-m-d\TH:i:s\Z',strtotime("+5 minutes")),
    "TimeRangeRepeatFlag"=>0
];*/
//修改时段  必须使用UTC时区
/*date_default_timezone_set("UTC");
$arr = [
    "Action"=>"ModTimeRange",
    "TimeRangeId"=>"598",
    "TimeRangeName"=>"T0009",
    "TimeRangeBeginTime"=>date('Y-m-d\TH:i:s\Z'),
    "TimeRangeEndTime"=>date('Y-m-d\TH:i:s\Z',strtotime("+1 week")),
    "TimeRangeRepeatFlag"=>0
];*/
//查询时段
/*$arr = [
    "Action"=>"QueryTimeRange",
    //"TimeRangeId"=>"592",
    "PageSize"=>"100",
    "CurrentPage"=>"1",
];*/
//删除时段DelTimeRange
/*$arr = [
    "Action"=>"DelTimeRange",
    "TimeRangeId"=>"592"
];*/
//增加规则
/*$arr = [
    "Action"=>"AddRule",
    "UserId"=>"109511",
    "TimeRangeId"=>"599",
    "DeviceId"=>"747"
];*/
//修改规则
/*$arr = [
    "Action"=>"ModRule",
    "RuleId"=>"193882",
    "UserId"=>"109507",
    "TimeRangeId"=>"595",
    "DeviceId"=>"747"
];*/
//查询规则
/*$arr = [
    "Action"=>"QueryRule",
    //"UserId"=>"109509",
    "PageSize"=>"10",
    "CurrentPage"=>"1",
];*/

//删除规则
/*$arr = [
    "Action"=>"DelRule",
    "RuleId"=>"193880"
];*/

//用户认证信息(获取二维码)
/*    $arr = [
    "Action"=>"UserAuthByUserId",
    "UserId"=>"109511",
    "UserAuthBeginTime"=>date('Y-m-d\TH:i:s\Z'),
    "UserAuthEndTime"=>date('Y-m-d\TH:i:s\Z',strtotime("+1 minutes")),
];*/
//通过用户信息获取认证数据(二维码)
//这个接口会一次直接生成新用户,新设备,新时段,新规则,不建议使用该接口,因为有的字段ID可能需要保存在数据库
/*$arr = [
    "Action"=>"UserAuthByUserInfo",
    "UserName"=>"刘起",
    "PhoneNum"=>"13468157466",
    "Email"=>"838288824@qq.com",
    "DeviceId"=>"747",
    "DeviceBeginTime"=>date('Y-m-d\TH:i:s\Z',strtotime("-1 day")),
    "DeviceEndTime"=>date('Y-m-d\TH:i:s\Z',strtotime("+1 week")),
    "DeviceTimeRepeatFlag"=>0,
    "UserAuthBeginTime"=>date('Y-m-d\TH:i:s\Z'),
    "UserAuthEndTime"=>date('Y-m-d\TH:i:s\Z',strtotime("+2 minutes")),
];*/
//查询通行记录
$arr = [
    "Action" => "QueryAuthPassRecord",
    //"UserId" => "109509",
    "PageSize" => "100",
    "CurrentPage" => "1",
];
//查询用户通行记录
/*$arr = [
    "Action"=>"AuthPassRecordByUserId",
    "UserId"=>"109509",
    "BeginTime"=>date('Y-m-d\TH:i:s\Z',strtotime("-1 month")),
    "EndTime "=>date('Y-m-d\TH:i:s\Z')
];*/


$url = "https://www.dingdingkaimen.com/product/api/?";
$obj = new videoInterface($arr, $url);
var_dump($obj->callInterface());
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容