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

前端 未结 2 1967
鱼传尺愫
鱼传尺愫 2021-01-29 03:10

i\'ve done a apple-mdm-ota-server for IOS so far. The devices deliver me following things to the server (in form of a plist/xml):

-Push Magic Token -Device Token (in b64

相关标签:
2条回答
  • 2021-01-29 03:51

    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();
    }
    
    0 讨论(0)
  • 2021-01-29 04:00

    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);
    
    0 讨论(0)
提交回复
热议问题