智能客服
你问我答,随时在线为你解决问题
用户事件变更通知。
当用户取消授权、运动记录发生变化以及原子数据变化时,通知开发者应用用户数据发生变更。
无
承载协议 | HTTPS POST |
|---|---|
接口方向 | Health Service Kit云->三方开发者云 |
接口URL | https://www.example.com/healthkit/notifications |
数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
Request Header
参数 | 参数类型 | 是否必选 | 描述 |
|---|---|---|---|
Content-type | String | 是 | 取值为:application/json; charset=UTF-8 |
x-notification-signature | String | 是 | 事件通知内容签名。 签名方式:HMAC-SHA256 with subscriber Secret(openId_eventType _eventTime)。 说明
|
获取签名Java示例代码如下:
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
StringBuilder str = new StringBuilder();
str.append(openId).append("_").append(eventType).append("_").append(eventTime);
byte[] bytes = java.util.Base64.getDecoder().decode(secret);
try {
Mac hmacSHA256 = Mac.getInstance("HmacSHA256");
hmacSHA256.init(new SecretKeySpec(bytes,"HmacSHA256"));
byte[] sinData = hmacSHA256.doFinal(str.toString().getBytes("utf-8"));
return Base64.getEncoder().encodeToString(sinData); // 生成的验证签名内容
} catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) {
// 异常处理
} Request Body
POST
https://www.example.com/healthkit/notifications
Content-Type: application/json
x-notification-signature: ***
{
"eventTime":1607514090688,
"eventType":"ACTIVITY_RECORD_EVENT$UPDATE",
"type":"ACTIVITY_RECORD_EVENT",
"subType":"UPDATE",
"metaData":[
{
"metaKey":"startTime",
"metaValue":"1606856007879"
},
{
"metaKey":"endTime",
"metaValue":"1606916007879"
},
{
"metaKey":"activityType",
"metaValue":"1"
}
],
"subscriptionId": "9aef7543-e8f6-4faf-b4a9-10f1ac2d4ddc",
"openId":"MDFAMTAxNTI0MzcxQGQ0Y2M3N2UxZTVmNjcxNWFkMWQ5Y2JjYjlmZDZiaNTY3QDVhNmNkY2FiaMTFhYzc4NDk4NDI0MzJiaNjg0MzViaYmUyMGEzZjZkNzUzYWVjM2Q5ZTgwYWM5NTgzNmY"
} 状态码为204时:
Response Header
参数 | 参数类型 | 是否必选 | 描述 |
|---|---|---|---|
Content-Type | String | 是 | 取值为:application/json; charset=UTF-8 |
Response Body
无
HTTP/1.1 204 OK Content-type: application/json;charset=utf-8
请参见错误码。