Last active
July 3, 2016 03:30
-
-
Save yangl/ebd6ebd496ad44a8b89714ecdaa3f884 to your computer and use it in GitHub Desktop.
公司apns接口私有协议java实现。Base64算法apache下的commons-codec实现有少许问题,最好使用JDK8原生的实现!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String apns(long uid, int type, String alert, long sn) { | |
String playload = APNS.newPayload().alertBody(alert).customField("type", type).build(); | |
int length = 13 + 9 + playload.getBytes(CharsetUtil.UTF_8).length; | |
ByteBuf bf = Unpooled.buffer(length); | |
bf.writeInt(length) | |
.writeByte(1) | |
.writeLong(sn) | |
.writeLong(uid) | |
.writeByte(1) | |
.writeBytes(playload.getBytes(CharsetUtil.UTF_8)); | |
return Base64.getUrlEncoder().encodeToString(bf.array()); | |
// return Base64Utils.encodeToUrlSafeString(bf.array()); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.notnoop.apns</groupId> | |
<artifactId>apns</artifactId> | |
<version>1.0.0.Beta6</version> | |
</dependency> | |
<dependency> | |
<groupId>io.netty</groupId> | |
<artifactId>netty-all</artifactId> | |
<version>4.1.2.Final</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment