1. 项目说明
第三方 API 项目
1.1 请求地址
http://api.slaaplekker.cn/
1.2 historyVI 传参数
{
"sn": "bb1000b600000000",
"date": "2018-11-19"
}
1.3 tokent 生产
没有凭证请联系对接负责人获取
1.4 websoc ket
url:ws://api.slaaplekker.cn/webSocket/msg
请求参数:
{
"accessToken": "xxxxxxxxxxxxxxxxxxxxxxx",
"sn": "xxxxxxxx,xxxxxxxxx,xxxxxxxx"
}
1.5 请求示例
1.6推送接口说明
接受推送需提供一个http协议的接口接收json格式的消息 消息格式如下
{"breathe":"","heart":"","message":"离床","sn":"BB1000E100000000","timestamp":1554886610483,"type":3}
异常消息type有: 1:心率异常, 2:呼吸异常, 3:离床 , 5:体动, 6:SOS主动报警 , 8:防褥翻身提醒 接口完成以后请给对接人员测试后完成使用
2. openapi接口示例
接口参数请参考:https://openapi.doc.slaaplekker.cn/#/guidelines/Guidelines
语言: Java
示例代码使用工具:okhttp,maven坐标:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.13.1</version>
</dependency>
也可直接下载相应的jar包导入到项目中。
2.1 获取数据相关
2.1.1 获取房颤统计
- url :
/get/atriaTrembleReportByDay
- 请求方式:'POST'
请求示例:
import com.alibaba.fastjson.JSON;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.util.HashMap;
import java.util.Map;
public class OpenApi_Get_AtriaTrembleReportByDay {
public static final String accessToken = "xxxxxxxxxxxxxxxxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/atriaTrembleReportByDay";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-05-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
说明:
accessToken
: 请用实际值替换。
2.1.2 获取呼吸统计
- url :
/get/breathReportByDay
- 请求方式:'POST'
请求示例:
import com.alibaba.fastjson.JSON;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.util.HashMap;
import java.util.Map;
public class OpenApi_Get_BreathReportByDay {
public static final String accessToken = "xxxxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/breathReportByDay";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
说明:
accessToken
: 请用实际值替换。
2.1.3 获取心率统计
- url :
/get/heartReportByDay
- 请求方式:'POST'
请求示例:
import com.alibaba.fastjson.JSON;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.util.HashMap;
import java.util.Map;
public class OpenApi_Get_HeartReportByDay {
public static final String accessToken = "xxxxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/heartReportByDay";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
说明:
accessToken
: 请用实际值替换。
2.1.4 查询设备联网状态
- url :
/get/isHardwareOnline/{sn}
- 请求方式:'GET'
请求示例:
public class OpenApi_Get_IsHardwareOnline {
public static final String accessToken = "xxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
String uri="/get/isHardwareOnline/xxxxxxxxx";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(urlRoot+uri)
.get()
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
注意:
/get/isHardwareOnline/xxxxxxxxx
中的xxxxxxxxx
用sn替换accessToken
: 请用实际值替换。
2.1.5 获取离床统计
- url :
/get/leaveBedReportByDay
- 请求方式:'POST'
请求示例:
public class OpenApi_Get_LeaveBedReportByDay {
public static final String accessToken = "xxxxxxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/leaveBedReportByDay";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
accessToken
: 请用实际值替换。
2.1.6 获取压力值
- url :
/get/pressure
- 请求方式:'POST'
请求示例:
public class OpenApi_Get_Pressure {
public static final String accessToken = "xxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/pressure";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
accessToken
: 请用实际值替换。
2.1.7 获取睡眠日报告
- url :
/get/sleepReport
- 请求方式:'POST'
请求示例:
ublic class OpenApi_Get_SleepReport {
public static final String accessToken = "xxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/sleepReport";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
accessToken
: 请用实际值替换。
2.2 获取周报和月报
2.2.1 获取月睡眠报告
- url :
/get/report/month
- 请求方式:'POST'
请求示例:
public class OpenApi_Get_Report_Month {
public static final String accessToken = "xxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/report/month";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
accessToken
: 请用实际值替换。map.put("date","2019-05-01");
日期是所查询月中的任何一天
2.2.2 获取周睡眠报告
- url :
/get/report/week
- 请求方式:'POST'
请求示例:
public class OpenApi_Get_Report_Week {
public static final String accessToken = "xxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,String> map = new HashMap<>();
String uri="/get/report/week";
map.put("sn","BB1201C001247BDA9");
map.put("date","2019-06-08");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
accessToken
: 请用实际值替换。map.put("date","2019-05-01");
日期是所查询周中的任何一天,一周的开始是星期一,星期日是一周的最后一天。
2.3 websocket相关
2.3.1 实时数据
- url :
/webSocket/msg
- 请求方式:
ws
引入jar包:
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.5</version>
</dependency>
WebsocketClient客户端工具类:
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
public class WebsocketClient {
public static WebSocketClient client;
private static String rsul;
private static String msg = "{\"sn\":\"BBxxxxxxxx\",\"accessToken\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}";
public static void main(String[] args) {
run();
}
public static void run() {
try {
client = new WebSocketClient(new URI("ws://api.slaaplekker.cn/webSocket/msg"), new Draft_6455()) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
System.out.println("打开链接");
}
@Override
public void onMessage(String s) {
rsul = s;
System.out.println(new Date() + rsul);
}
@Override
public void onClose(int i, String s, boolean b) {
System.out.println("断开链接!");
}
@Override
public void onError(Exception e) {
e.printStackTrace();
System.out.println("发生错误已关闭");
}
};
} catch (Exception e) {
e.printStackTrace();
}
client.connect();
System.out.println(client.getDraft());
while (!client.getReadyState().equals(WebSocket.READYSTATE.OPEN)) {
System.out.println("尝试连接");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("打开了");
try {
while (true) {
client.send(msg);
Thread.sleep(4000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2.4 异常消息推送相关
2.4.1 更改异常推送设置
- url :
/change/device/config
- 请求方式:'POST'
请求示例:
public class OpenApi_Change_Device_Config {
public static final String accessToken = "xxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String, Object> config = new HashMap<>();
config.put("breathlower",6);
config.put("breathupper",30);
config.put("endTime","12-30");
config.put("heartlower", 45);
config.put("heartupper",160);
config.put("leaveBed",true);
config.put("leaveBedTime",10);
config.put("move",true);
config.put("moveTime",5);
config.put("startTime","12-30");
Map<String,Object> map = new HashMap<>();
String uri="/change/device/config";
map.put("id",26);
map.put("config",config);
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
- 配置信息Id(可通过
get/device/config
查询)
2.4.2 删除异常推送
- url :
/delete/device/config
- 请求方式:'POST'
请求示例:
public class OpenApi_Delete_Device_Config {
public static final String accessToken = "xxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,Object> map = new HashMap<>();
String uri="/delete/device/config";
map.put("id",26);
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
2.4.3 新增异常推送
- url :
/device/config
- 请求方式:'POST'
请求示例:
public class OpenApi_Device_Config {
public static final String accessToken = "xxxxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String, Object> config = new HashMap<>();
config.put("breathlower",6);
config.put("breathupper",30);
config.put("endTime","07-00");
config.put("heartlower", 45);
config.put("heartupper",160);
config.put("leaveBed",true);
config.put("leaveBedTime",10);
config.put("move",true);
config.put("moveTime",5);
config.put("startTime","20-00");
Map<String,Object> map = new HashMap<>();
String uri="/device/config";
map.put("sn", "BB1201C001247BDA9");
map.put("config",config);
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
2.4.4 获取异常推送设置
- url :
/device/config
- 请求方式:'POST'
请求示例:
public class OpenApi_Device_Config {
public static final String accessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
public static final String urlRoot = "http://api.slaaplekker.cn";
public static void main(String[] args) throws Exception {
Map<String,Object> map = new HashMap<>();
String uri="/get/device/config";
map.put("sn", "BB1201C001247BDA9");
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Request request = new Request.Builder()
.url(urlRoot+uri)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("Cache-Control", "no-cache")
.addHeader("accessToken", accessToken)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}