How to send an apple mdm push notification with plain php?

北战南征 提交于 2019-12-02 09:57:05

I did not see that you included your APNS key when setting up the stream. Here is (roughly) what we do:

$apns_certkey_path = '/path/to/cert/and/key/file' ;
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apns_certkey_path);

$apns = stream_socket_client(
  'ssl://' . $apns_url . ':' . $apns_port,
  $error,
  $errorString,
  2, // timeout
  STREAM_CLIENT_CONNECT,
  $streamContext
);

$payload = json_encode(array('mdm' => $PushMagic));
$apnsMessage = chr(0)  . chr(0)
             . chr(32) . base64_decode($ApnsTokenB64)
             . chr(0)  . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);

use this libray

function push_device($data) {
    $push = new ApnsPHP_Push(
        ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,
        '../MyPushCert.pem'
    );
    $push->connect();
    $message = new ApnsPHP_Message_Custom($data["Token"]);
    $message->setCustomProperty('mdm', $data["PushMagic"]);
    $push->add($message);
    $push->send();
    $push->disconnect();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!