如何发送与普通的PHP苹果MDM推送通知? [英] How to send an apple mdm push notification with plain php?
问题描述
我到目前为止已经做了苹果的MDM-OTA服务器的IOS。这些器件可提供以下我的东西服务器(在plist中/ XML的形式):
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魔令牌
-Device令牌(在B64格式OO)
-PN-主题(com.apple.mgmt.xxx)
-udid(十六进制code)
-UnlockToken(一个很长的B64连接codeD东西)
-Push Magic Token -Device Token (in b64 format oO) -PN-Topic (com.apple.mgmt.xxx) -UDID (in hexcode) -UnlockToken (a very long b64 encoded thing)
我需要以下内容的推送通知的事情,从苹果发送:
I need to send the following content to the push notification thing from apple:
{MDM:pushMagic}
{"mdm":"pushMagic"}
Pushmagic =推送魔令牌
Pushmagic = the Push Magic Token
我需要如何撰写我需要编写到APNS插座的数据?我想,对于其他推送通知的工作之一,但这个事实并非如此。目前正在发生的事情只是没有: - (
How I need to compose the data I need to write into the apns socket? I tried the one that works for other push notifications, but for this it doesn't. There is happening just nothing :-(.
$apns_url = 'gateway.push.apple.com';
[...]
$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port,
$error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);
fwrite($apns, chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ',
'', $wellWrittenToken)) . chr(0) . chr(strlen($mdmInitialPush)) .
$mdmInitialPush);
[...]
$误差为0。
$ wellwrittentoken =设备令牌在将十六进制code
$ apns_xx - 在SSL的事情似乎工作,因为它给了错误信息,因为它没有
$ mdminitialpush - 我的消息,我想送
$error is 0. $wellwrittentoken = the device-token in hex-code $apns_xx - The ssl thing seems to work, because it gave error message as it didn't $mdminitialpush - my message I want to send
推荐答案
我没有看到你设置的流时,包括你的APNS键。这里是(大约)我们做什么:
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);
这篇关于如何发送与普通的PHP苹果MDM推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!