Roh*_*hah 8 java push-notification apple-push-notifications spring-boot
我有一个 Java Spring Boot Web 服务,我正在尝试向 iOS 设备发送推送通知。
我面临的问题是直接粘贴的表情符号文本,例如
String emoji = "";
Run Code Online (Sandbox Code Playgroud)
或者它的代码,比如
String emoji = "\uD83D\uDE0A";
Run Code Online (Sandbox Code Playgroud)
它显示为?(问号符号)
我尝试将其作为 UTF_8 字符的字节获取,如下所示:
byte[] emojis = user.getEmoji().getBytes(); //Here user.getEmoji() returns a collection of 2-3 emojis
String emojisAsString = new String(emojis, StandardCharsets.UTF_8);
Integer emojiCodePoint = emojisAsString.codePointAt(emojisAsString.offsetByCodePoints(0,0));
char emojiChars[] = {Character.highSurrogate(emojiCodePoint), Character.lowSurrogate(emojiCodePoint)};
Run Code Online (Sandbox Code Playgroud)
但它仍然显示为问号。
我也尝试过使用 UTF-8 代码,"\xE2\x9A\xA1"但这个代码刚刚在通知上打印出来。
此外,当我使用 FCM API 从邮递员那里调用通知 API 并粘贴表情符号时,它会在通知中显示表情符号,当通过 Java Web 服务完成时,它仅显示为问号。
这是推送通知服务代码
@RequestMapping(value = "/send", method = RequestMethod.GET, produces = "application/json")
public static ResponseEntity<String> send(String message, String deviceToken, Integer type, Object response, String userNameAsTitle) {
//response.setMessage(message);
//response.setNotificationType(type);
JSONObject body = new JSONObject();
body.put("to", deviceToken);
body.put("priority", "high");
Map<String, Object> map = new HashMap<>();
map.put("title", userNameAsTitle);
map.put("body", message);
//map.put("alert", descprtion);
map.put("type", type);
map.put("badge", 1);
map.put("sound", "default");
map.put("response", response);
JSONObject notification = new JSONObject(map);
//body.put("notification", notification);
body.put("notification", notification);
HttpEntity<String> request = new HttpEntity<>(body.toString());
CompletableFuture<String> pushNotification = androidPushNotificationsService.send(request);
CompletableFuture.allOf(pushNotification).join();
try {
String firebaseResponse = pushNotification.get();
System.out.println(firebaseResponse.toString());
return new ResponseEntity<>(firebaseResponse.toString(), HttpStatus.OK);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return new ResponseEntity<>("Push Notification ERROR!", HttpStatus.BAD_REQUEST);
}
Run Code Online (Sandbox Code Playgroud)