21,887
社区成员
发帖
与我相关
我的任务
分享
准备工作
- 先向机智云申请得到enterprise_id和enterprise_key,并需要把客户端的因特网IP告知机智
- 云(因为使用了IP白名单调用安全机制)
- 把需要接收其信息的product_key关联到enterprise_id。一个enterprise_id可以关联多个
- product_key。
过程描述 事件通过SSL接口推送。通讯过程如下:
- 客户端以Client的身份与本接口(Gizwits Platform)建立SSL连接。客户端无需提供证书 ,只需要信任服务器证书即可;
- 客户端发送登陆指令完成身份验证;
- 客户端实时接受事件消息,并向服务器ack事件消息;
- 当客户端在一定时间范围内没有向服务器发送任何消息,需要发ping心跳请求,服务器回
- 复pong心跳响应。
服务地址
域名:noti.gizwitsapi.com 端口:2015
SSL的接口协议 请留意每个消息后都必须添加“ \n ”作为消息结尾符。
1. 连接与登陆
客户端和Gizwits Platform建立SSL连接后,客户端发送以下字符串内容作身份验证(登陆
Gizwits Platform): {
“cmd”: “enterprise_login_req”, “data”: {
“enterprise_id”: <enterprise_id string>,
“enterprise_secret”: <enterprise_secret string>,
“prefetch_count”: <uint> (0 < prefetch_count <= 3 2767 , 表示推送没有ACK 的消息的最大个数,建议值为5)
} }\n
Gizwits Platform回复: {
“cmd”: “enterprise_login_res”, “data”: {
“result”: true | false,
“msg”: “ok” | <error msg> }
}\n
如result为false表示登陆失败,该连接会被关闭。验证该登陆信息时,需要以参数 enterprise_id, enterprise_secret及ip调用内部API进行验证。
function ssl()
{
$header=array(
'Content-Type:application/json'
);
$params=array(
"cmd"=> "enterprise_login_req",
"data"=> array(
"enterprise_id"=>"9b05faa62e74b7da507d2b85e9fd21b",
"enterprise_secret"=>"a4c3727c934cf88d60f83dbb5c98e3",
"prefetch_count"=>5)
);
$data="{\"cmd\": \"enterprise_login_req\",\"data\": {\"enterprise_id\": \"9b05faaf62e74da507d2b85e9fd21b\",\"enterprise_secret\": \"a4c3737c934cf88d60f83dbb5c98e3\",\"prefetch_count\": 50}}\n";
$params_query=json_encode($params)."\n";
$result=curl_post_https("https://noti.gizwitsapi.com:2015",$data,30,$header);
echo '<pre>';
print_r($result);
return $result;
}