Skip to content

Instantly share code, notes, and snippets.

@yangl
Last active July 3, 2016 03:30
Show Gist options
  • Save yangl/ebd6ebd496ad44a8b89714ecdaa3f884 to your computer and use it in GitHub Desktop.
Save yangl/ebd6ebd496ad44a8b89714ecdaa3f884 to your computer and use it in GitHub Desktop.
公司apns接口私有协议java实现。Base64算法apache下的commons-codec实现有少许问题,最好使用JDK8原生的实现!
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());
}
<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