如何在没有 ssl 证书的情况下发送 android 推送通知

How to send android push notification without ssl certificate

我只使用 http 服务,不想支付 SSL 证书费用,也不使用自签名证书。还有其他方法可以在我的应用程序客户端中获取发送推送通知。提前致谢。

参见Link。我希望它能帮助你。您应该禁用您的服务器 ssl 然后发送推送通知。使用下面 link 作为参考。 1)客户端代码 2)为服务器添加此代码。

1) http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/ 2) http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/

public static void main(String[] args) throws Exception {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }
    };

    // Install the all-trusting trust manager
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    // Create all-trusting host name verifier
    HostnameVerifier allHostsValid = new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };

    // Install the all-trusting host verifier
    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

    URL url = new URL("https://www.nakov.com:2083/");
    URLConnection con = url.openConnection();
    Reader reader = new InputStreamReader(con.getInputStream());
    while (true) {
        int ch = reader.read();
        if (ch==-1) {
            break;
        }
        System.out.print((char)ch);
    }
}