www1350 / javaweb

http://www1350.github.io/
31 stars 5 forks source link

apple apns-http2 java调用 #83

Open www1350 opened 7 years ago

www1350 commented 7 years ago

使用开源项目:https://github.com/CleverTap/apns-http2

  @Test
    public void sync_push_notification() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
        FileInputStream cert = new FileInputStream("/path/to/certificate.p12");
        final ApnsClient client = new ApnsClientBuilder()
                .withProductionGateway(false)
                .inSynchronousMode()
                .withCertificate(cert)
                .withPassword("1")
//                .withDefaultTopic("<your app's topic>")
                .build();

        Notification n = new Notification.Builder("<the device token>")
                .alertBody("jfkldsjfkls djf叫疯狂了点事叫克里夫精神科了到甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食甲方省考虑到叫罚款粮食甲方省考虑到叫罚款粮食甲方克里斯蒂京客隆福建省考虑到叫罚款粮食店街鉴定费克鲁斯积分了康佳电视").build();
        NotificationResponse result = client.push(n);
        System.out.println(result);

    }

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
    <properties>
        <alpn-boot-version>8.1.4.v20150727</alpn-boot-version>
    </properties>
  ...
        <dependency>
            <groupId>org.mortbay.jetty.alpn</groupId>
            <artifactId>alpn-boot</artifactId>
            <version>${alpn-boot-version}</version>
        </dependency>

  ...
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>
                        -Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/alpn/alpn-boot/${alpn-boot-version}/alpn-boot-${alpn-boot-version}.jar
                    </argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

 ...
</project>

Table 15.1. ALPN vs. OpenJDK versions

OpenJDK version ALPN version 1.7.0u40 7.1.0.v20141016

1.7.0u45 7.1.0.v20141016

1.7.0u51 7.1.0.v20141016

1.7.0u55 7.1.0.v20141016

1.7.0u60 7.1.0.v20141016

1.7.0u65 7.1.0.v20141016

1.7.0u67 7.1.0.v20141016

1.7.0u71 7.1.2.v20141202

1.7.0u72 7.1.2.v20141202

1.7.0u75 7.1.3.v20150130

1.7.0u76 7.1.3.v20150130

1.7.0u79 7.1.3.v20150130

1.7.0u80 7.1.3.v20150130

1.8.0 8.1.0.v20141016

1.8.0u05 8.1.0.v20141016

1.8.0u11 8.1.0.v20141016

1.8.0u20 8.1.0.v20141016

1.8.0u25 8.1.2.v20141202

1.8.0u31 8.1.3.v20150130

1.8.0u40 8.1.3.v20150130

1.8.0u45 8.1.3.v20150130

1.8.0u51 8.1.4.v20150727

1.8.0u60 8.1.5.v20150921

1.8.0u65 8.1.6.v20151105

1.8.0u66 8.1.6.v20151105

1.8.0u71 8.1.7.v20160121

1.8.0u72 8.1.7.v20160121

1.8.0u73 8.1.7.v20160121

1.8.0u74 8.1.7.v20160121

1.8.0u77 8.1.7.v20160121

1.8.0u91 8.1.7.v20160121

1.8.0u92 8.1.8.v20160420

1.8.0u101 8.1.9.v20160720

1.8.0u102 8.1.9.v20160720

1.8.0u111 8.1.9.v20160720

1.8.0u112 8.1.10.v20161026

1.8.0u121 8.1.11.v20170118