apn message cert

master
yixian 5 years ago
parent d7cae44e8a
commit c0004b6f82

@ -3,14 +3,12 @@ package au.com.royalpay.payment.manage.pushMessage;
import com.alibaba.fastjson.JSONObject;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -21,28 +19,28 @@ import java.io.InputStream;
public class APNSMessageHelper {
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("classpath:apple_message_cert_dev.p12")
private org.springframework.core.io.Resource appleMessageFileDev;
@Value("${apple.message.apns.file}")
private String appleApnsFile;
@Value("${apple.message.apns.file:classpath:apple_message_cert_dev.p12}")
private Resource appleApnsFile;
@Value("${apple.message.apns.password}")
private String appleMessagePassword;
public void sendAppleMessage(String title, String body, String token, JSONObject data, JSONObject type) throws IOException {
/**设置参数,发送数据**/
InputStream keyIns = new FileInputStream(new File(appleApnsFile));
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
logger.debug("推送信息已发送!");
try (InputStream keyIns = appleApnsFile.getInputStream()) {
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
logger.debug("推送信息已发送!");
}
}
public void sendAppleMessageDetail(String title, String body, String token, JSONObject data, JSONObject type) throws IOException {
/**设置参数,发送数据**/
InputStream keyIns = new FileInputStream(new File(appleApnsFile));
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).category("myNotificationCategory").badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
logger.debug("推送信息已发送!");
try (InputStream keyIns = appleApnsFile.getInputStream()) {
ApnsService service = APNS.newService().withCert(keyIns, appleMessagePassword).withProductionDestination().build();
String payload = APNS.newPayload().alertTitle(title).alertBody(body).category("myNotificationCategory").badge(1).sound("default").customField("data", data).customField("type", type).build();
service.push(token, payload);
logger.debug("推送信息已发送!");
}
}
}

Loading…
Cancel
Save