我尝试使用mirror api通过我的应用程序中的菜单发送通知。对于开发环境我正在使用代理服务器,但在生产中我只使用SSl因为它是公共域。这两节的回调网址如下:
//开发 callbackUrl =“https://3a4660af.ngrok.com/notify”;
// production
if (callbackUrl.equals("https://www.mydomain.com:8080/notify")) {
callbackUrl = "https://www.mydomain.com:8443/notify";
} else {
callbackUrl = "https://www.mydomain.com:8443/notify";
}
LOG.info("\ncallbackUrl : " + callbackUrl);
Subscription subscription = new Subscription();
subscription.setCollection(collection);
subscription.setVerifyToken(userId);
subscription.setCallbackUrl(callbackUrl);
subscription.setUserToken(userId);
getMirror(credential).subscriptions().insert(subscription)
.execute();
但是当我尝试从通知类中读取通知时,我得到了不匹配,因此通知操作无效。下面的通知日志
//development
got raw notification : { "collection": "timeline",
"itemId": "6fa2445e-b14f-46b2-9cff-f0d44d63ecab",
"operation": "UPDATE", "verifyToken": "103560737611562800385",
"userToken": "103560737611562800385",
"userActions": [ { "type": "CUSTOM", "payload": "dealMenu" } ]}
//production
got raw notification : "collection": "timeline",
"operation": "UPDATE",
"userToken": "103560737611562800385", { "payload": "dealMenu" ]null
在通知类
中BufferedReader notificationReader = new BufferedReader(
new InputStreamReader(request.getInputStream()));
String notificationString = "";
// Count the lines as a very basic way to prevent Denial of Service
// attacks
int lines = 0;
while (notificationReader.ready()) {
notificationString += notificationReader.readLine();
lines++;
LOG.info("\ngot raw notification during read : "
+ notificationString);
// No notification would ever be this long. Something is very wrong.
if (lines > 1000) {
throw new IOException(
"Attempted to parse notification payload that was unexpectedly long.");
}
}
LOG.info("\ngot raw notification : " + notificationString);
JsonFactory jsonFactory = new JacksonFactory();
LOG.info("\ngot jsonFactory : " + jsonFactory);
// If logging the payload is not as important, use
// jacksonFactory.fromInputStream instead.
Notification notification = jsonFactory.fromString(notificationString,
Notification.class);
LOG.info("\n got notification " + notification);
在制作中,我无法获得所需的所有周界。为什么会发生这种不匹配?