我遇到的问题:
消息推送了出去,但是设置的消息回执没有被调用。之前都有被调用,但由于回执接口定义有问题,提示406错误,于是我修复了下,结果现在直接连调用都没有了。
这是我有问题的代码:
public Result sendMessage(String appSecretKey, String appPackageName, String regId, Message msg) throws Exception {
Constants.useOfficial();
Sender sender = new Sender(appSecretKey);
String messagePayload = "消息";
Message message = new Message.Builder().title(msg.getTitle()).description(msg.getContent()).payload(messagePayload).restrictedPackageName(appPackageName).notifyType(1)
// 使用默认提示音提示
.extra("callback", "http://xxxx/message/push/call_back").extra("callback.type", "246").extra("callback.param", "xiaomi").build();
Result result = sender.send(message, regId, 3);
String resultStr = "result: " + result.toString();
log.info("Server response: " + resultStr);
return result;
}
@ApiOperation("消息推送回执")
@RequestMapping(path = "/message/push/call_back", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = {MediaType.ALL_VALUE})
@ResponseBody
public void pushByRegId(@ApiParam(name = "data", value = "推送的回执消息") String data) {
Object parse = JSONObject.parse(data);
log.info("callbackMsg" + parse.toString());
}
小米的回复:
3就包含了1和2,请去掉3,type加起来是243,您重新订阅试下。
我的理解:
我出错的原因就是回执类型数值写错了 。 (3已经包含了1和2,因此全部加起来是243而不是246)
因此把callback.type改为243就好了:
.extra("callback.type", "243")
PS:小米技术支持挺及时的,赞一个