我在我的php代码下方在ios移动设备上发送推送通知但是没有发送通知。我有一个设备令牌工作。
当我将iPhone连接到Mac并运行其安装的应用程序然后成功发送推送通知但是当我从应用程序商店下载应用程序时它无法正常工作。
//send notification code
function send_apns($deviceToken,$body){
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'passphrase', 'vision');
stream_context_set_option($ctx, 'ssl', 'local_cert', VIS_PATH_PLUGINS.'iphone/ckProd.pem');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
stream_set_blocking ($fp, 0);
if (!$fp) {
echo "Failed to connect (stream_socket_client): $err $errstrn";
} else {
$apple_expiry = time() + (90 * 24 * 60 * 60);
$apple_identifier = 1;
$payload = json_encode($body);
$msg = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
print_r($body);
fclose($fp);
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
}
}
答案 0 :(得分:0)
众所周知,您必须使用不同的 Pem Certificate and APNS Gateway
进行开发和生产构建。
由于App Store中的构建是生产版,因此您应该更改 SSL地址
gateway.sandbox.push.apple.com:2195
到
gateway.push.apple.com:2195
和VIS_PATH_PLUGINS.'iphone/ckProd.pem
如果您尚未对其进行更改,请附加到您的生产证书。
希望它有所帮助!
答案 1 :(得分:0)
如果您要向实时应用发送推送通知,则您的目标'ssl://gateway.sandbox.push.apple.com:2195'
不应包含sandbox
,因此请从目的地移除sandbox
,因为如果应用是sandbox
,则使用Pem Certificate and APNS Gateway
在开发模式中。您还需要使用$app->group(['middleware' => 'auth'], function ($app) {
$app->get('/', function () use ($app) {
return $app->version();
});
$app->get('users[/{userId}]', ['uses' => 'UserController@getUsers']);
$app->post('users[/{userId}]', ['uses' => 'UserController@saveUsers']);
$app->delete('users/{userId}[/]', ['uses' => 'UserController@deleteUsers']);
});
生产环境。