wangning 7 years ago
parent 0327de0101
commit 835246c24a

@ -534,7 +534,8 @@ public class RetailAppServiceImp implements RetailAppService {
order, type); order, type);
} }
if("android".equals(devToken.getString("client_type"))) { if("android".equals(devToken.getString("client_type"))) {
sendAppleMessage jpushMessageHelper.sendAppleMessage("Refund JpushMessage", LocaleSupport.localeMessage("app.message.body.refund") + refundAmount,token,
order, type);
} }
log.put("status", 2); log.put("status", 2);
appMessageLogMapper.update(log); appMessageLogMapper.update(log);

@ -29,10 +29,10 @@ public class JpushMessageHelper {
Logger logger = LoggerFactory.getLogger(getClass()); Logger logger = LoggerFactory.getLogger(getClass());
// 推送文本最大长度 // 推送文本最大长度
private static final Integer NOTIFICATION_MAX_LENGTH = 54; private final Integer NOTIFICATION_MAX_LENGTH = 54;
private static JPushClient client = null; private static JPushClient client = null;
public static JPushClient getPush() { private JPushClient getPush() {
if (client == null) { if (client == null) {
client = new JPushClient("c235e93f6b91abd72ca5d74e", "c235e93f6b91abd72ca5d74e"); client = new JPushClient("c235e93f6b91abd72ca5d74e", "c235e93f6b91abd72ca5d74e");
} }
@ -40,7 +40,7 @@ public class JpushMessageHelper {
} }
public void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException, APIConnectionException, APIRequestException { public void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException, APIConnectionException, APIRequestException {
JPushClient jPushClient= JpushMessageHelper.getPush(); JPushClient jPushClient= getPush();
JpushMessage jpushMessage = new JpushMessage(); JpushMessage jpushMessage = new JpushMessage();
jpushMessage.setTitle(title); jpushMessage.setTitle(title);
jpushMessage.setText(body); jpushMessage.setText(body);
@ -48,24 +48,24 @@ public class JpushMessageHelper {
param.put("data",data); param.put("data",data);
param.put("type",type); param.put("type",type);
jpushMessage.setParams(param); jpushMessage.setParams(param);
PushPayload pushPayload =JpushMessageHelper.generateSinglePayload(token,jpushMessage); PushPayload pushPayload = generateSinglePayload(token,jpushMessage);
jPushClient.sendPush(pushPayload); jPushClient.sendPush(pushPayload);
} }
public static PushPayload generateSinglePayload(String alias, JpushMessage pushMessage) { private PushPayload generateSinglePayload(String alias, JpushMessage pushMessage) {
Notification notify = getNotify(pushMessage); Notification notify = getNotify(pushMessage);
return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.alias(alias)).setNotification(notify) return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.alias(alias)).setNotification(notify)
// 设置离线时长 // 设置离线时长
.setOptions(Options.newBuilder().setTimeToLive(60 * 60 * 4).build()).build(); .setOptions(Options.newBuilder().setTimeToLive(60 * 60 * 4).build()).build();
} }
private static Notification getNotify(JpushMessage pushMessage) { private Notification getNotify(JpushMessage pushMessage) {
String alert = getText(pushMessage); String alert = getText(pushMessage);
return Notification.newBuilder().addPlatformNotification( return Notification.newBuilder().addPlatformNotification(
AndroidNotification.newBuilder().setTitle(pushMessage.getTitle()).setAlert(alert).addExtras(getExtra(pushMessage)).build()).build(); AndroidNotification.newBuilder().setTitle(pushMessage.getTitle()).setAlert(alert).addExtras(getExtra(pushMessage)).build()).build();
} }
private static String getText(JpushMessage pushMessage) { private String getText(JpushMessage pushMessage) {
String text = pushMessage.getText(); String text = pushMessage.getText();
int length = text.length(); int length = text.length();
int trueLength = 0; int trueLength = 0;
@ -90,7 +90,7 @@ public class JpushMessageHelper {
return cutString; return cutString;
} }
private static Map<String, String> getExtra(JpushMessage message) { private Map<String, String> getExtra(JpushMessage message) {
Map map = message.getParams(); Map map = message.getParams();
return map; return map;
} }

Loading…
Cancel
Save