APNS Tester 推送通知失败
Failed in APNS Tester Push notifications
02-20 07:10:53 +0000: Connected to server gateway.sandbox.push.apple.com
2017-02-20 07:10:53 +0000: Set SSL connection
2017-02-20 07:10:53 +0000: Set peer domain name gateway.sandbox.push.apple.com
2017-02-20 07:10:53 +0000: Keychain Opened
2017-02-20 07:10:53 +0000: Certificate data for Apple Development IOS Push Services: MyApp initialized successfully
2017-02-20 07:10:53 +0000: Failure creating sec identity, error code -25300
2017-02-20 07:10:53 +0000: Failure creating client certificate, error code -50
2017-02-20 07:10:53 +0000: Failed with sending data to gateway.sandbox.push.apple.com:2195 with ERROR: -9806, error code -9806
2017-02-20 07:10:53 +0000: Disconnected from server`gateway.sandbox.push.apple.com:2195
此错误出现在 APNS 测试器中。谁能告诉我这个问题?
根据您提供的信息难以准确诊断。
但是请检查一下。
- 检查APNS发送服务器代码。
如果您正在使用 PHP :
,则可以使用此示例
<?php
// My device token here (without spaces):
$deviceToken = 'Token ID';
// My private key's passphrase here:
$passphrase = 'Password';
// My alert message here:
$message = 'Hello!';
//badge
$badge = 1;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) {
exit("Failed to connect: $err $errstr" . PHP_EOL);
}
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'badge' => $badge,
'sound' => 'newMessage.wav'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result) {
echo 'Error, notification not sent' . PHP_EOL;
}else{
echo 'notification sent!' . PHP_EOL;
}
// Close the connection to the server
fclose($fp);
?>
如果您使用 JSP,请使用此示例:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="javapns.back.PushNotificationManager" %>
<%@ page import="javapns.back.SSLConnectionHelper" %>
<%@ page import="javapns.data.Device" %>
<%@ page import="javapns.data.PayLoad" %>
<%@ page import="java.lang.Object" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Push Notification</title>
</head>
<body>
<%
System.out.println("Start~!!!");
String deviceToken = "Token ID";
PayLoad payLoad = new PayLoad();
payLoad.addAlert("Hello!"); // Message
payLoad.addBadge(1);
payLoad.addSound("default");
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iPhone", deviceToken);
//Connect to APNs
//String host = "gateway.push.apple.com"; // To Appstore
String host = "gateway.sandbox.push.apple.com"; // To Development
int port = 2195;
String certificatePath = "/Users/nzeen.com/Documents/apns/apns.p12"; // Push Notification Certificate
String certificatePassword = "Password"; // Password
pushManager.initializeConnection(host, port, certificatePath, certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
//Send Push
Device client = pushManager.getDevice("iPhone");
pushManager.sendNotification(client, payLoad);
pushManager.stopConnection();
pushManager.removeDevice("iPhone");
%>
please wait…!
</body>
</html>
检查您使用的证书。
您应该为每个环境使用证书。
因为使用的证书根据APNS的服务器类型不同,
您应该为每个环境使用证书。
"gateway.push.apple.com:2195"
要么
"gateway.sandbox.push.apple.com:2195"
识别被测网络。
可以在控制台通过以下命令查看连接是否正常
"[主机名/]$ Telnet gateway.sandbox.push.apple.com 2195"
或
"[主机名/]$ Telnet gateway.sandbox.push.apple.com 2195"
02-20 07:10:53 +0000: Connected to server gateway.sandbox.push.apple.com
2017-02-20 07:10:53 +0000: Set SSL connection
2017-02-20 07:10:53 +0000: Set peer domain name gateway.sandbox.push.apple.com
2017-02-20 07:10:53 +0000: Keychain Opened
2017-02-20 07:10:53 +0000: Certificate data for Apple Development IOS Push Services: MyApp initialized successfully
2017-02-20 07:10:53 +0000: Failure creating sec identity, error code -25300
2017-02-20 07:10:53 +0000: Failure creating client certificate, error code -50
2017-02-20 07:10:53 +0000: Failed with sending data to gateway.sandbox.push.apple.com:2195 with ERROR: -9806, error code -9806
2017-02-20 07:10:53 +0000: Disconnected from server`gateway.sandbox.push.apple.com:2195
此错误出现在 APNS 测试器中。谁能告诉我这个问题?
根据您提供的信息难以准确诊断。 但是请检查一下。
- 检查APNS发送服务器代码。
如果您正在使用 PHP :
,则可以使用此示例<?php
// My device token here (without spaces):
$deviceToken = 'Token ID';
// My private key's passphrase here:
$passphrase = 'Password';
// My alert message here:
$message = 'Hello!';
//badge
$badge = 1;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) {
exit("Failed to connect: $err $errstr" . PHP_EOL);
}
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'badge' => $badge,
'sound' => 'newMessage.wav'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result) {
echo 'Error, notification not sent' . PHP_EOL;
}else{
echo 'notification sent!' . PHP_EOL;
}
// Close the connection to the server
fclose($fp);
?>
如果您使用 JSP,请使用此示例:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="javapns.back.PushNotificationManager" %>
<%@ page import="javapns.back.SSLConnectionHelper" %>
<%@ page import="javapns.data.Device" %>
<%@ page import="javapns.data.PayLoad" %>
<%@ page import="java.lang.Object" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Push Notification</title>
</head>
<body>
<%
System.out.println("Start~!!!");
String deviceToken = "Token ID";
PayLoad payLoad = new PayLoad();
payLoad.addAlert("Hello!"); // Message
payLoad.addBadge(1);
payLoad.addSound("default");
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iPhone", deviceToken);
//Connect to APNs
//String host = "gateway.push.apple.com"; // To Appstore
String host = "gateway.sandbox.push.apple.com"; // To Development
int port = 2195;
String certificatePath = "/Users/nzeen.com/Documents/apns/apns.p12"; // Push Notification Certificate
String certificatePassword = "Password"; // Password
pushManager.initializeConnection(host, port, certificatePath, certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
//Send Push
Device client = pushManager.getDevice("iPhone");
pushManager.sendNotification(client, payLoad);
pushManager.stopConnection();
pushManager.removeDevice("iPhone");
%>
please wait…!
</body>
</html>
检查您使用的证书。 您应该为每个环境使用证书。 因为使用的证书根据APNS的服务器类型不同, 您应该为每个环境使用证书。
"gateway.push.apple.com:2195" 要么 "gateway.sandbox.push.apple.com:2195"
识别被测网络。 可以在控制台通过以下命令查看连接是否正常
"[主机名/]$ Telnet gateway.sandbox.push.apple.com 2195"
或
"[主机名/]$ Telnet gateway.sandbox.push.apple.com 2195"