使用Php的iOS MDM推送通知,无法正常工作 [英] iOS MDM push notification using Php, not working

查看:137
本文介绍了使用Php的iOS MDM推送通知,无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是重复的



可以签署证书部分原因有问题,设备没有收到通知?,一个截图是TestMDM供应商,第二个是我的,即MobiLock

解决方案

我'我自己在Windows上使用PHP来推送通知。我注意到的一个可能是错误的事情是你在推送有效载荷中包含了这个主题。这不是必需的。



这是我编写的一些PHP代码,用于使用我在TestMDM中注册的设备进行测试。我不是PHP开发人员,而是使用它( http:// codular。 com / sending-ios-push-notifications-with-php )作为基线并从我的TestMDM数据库中获取pushMagic和deviceToken字符串,我得到它成功发送推送。



当我在Windows上时,我也使用PFX证书进行推送。

  $ deviceToken ='<你的设备作为BASE64 STRING>'; #base64 encoded 
$ token = bin2hex(base64_decode($ deviceToken));

//在此处输入私钥的密码:
$ passphrase ='< YOUR PASSWORD>';

$ ctx = stream_context_create();
stream_context_set_option($ ctx,'ssl','local_cert','。/ .Push.pfx');
stream_context_set_option($ ctx,'ssl','passphrase',$ passphrase);

$ fp = stream_socket_client('gateway.push.apple.com:2195', $ err,$ errstr,60,STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,$ ctx);

if(!$ fp){
exit(连接失败:$ err $ errstr。PHP_EOL);
}

echo'连接到APNS'。 PHP_EOL。 < br />;

$ payload ='{\'mdm \'= \'<你为这个设备推的魔法> \'}';

$ inner = chr(1)。包('n',32)。 pack('H *',$ token)
。 chr(2)。 pack('n',strlen($ payload))。 $ payload
。 chr(3)。包('n',4)。 pack('N',1)
。 chr(4)。 pack('n',4)
。 pack('N',time()+ 86400)
。 chr(5)。打包('n',1)。 CHR(10);

$ notification = chr(2)。 pack('N',strlen($ inner))。 $内;

echo $ payload。 PHP_EOL;

$ result = fwrite($ fp,$ notification,strlen($ notification));

echo $ result;

运行脚本后,我可以在设备的日志中看到这一点,这表明它是工作:

  7月11日10:16:10 Toms-iPod mdmd [11218]<通知> :(注)MDM: mdmd开始... 
Jul 11​​ 10:16:10 Toms-iPod mdmd [11218]<通知> :(注意)MDM:网络可达性已更改。
Jul 11​​ 10:16:10 Toms-iPod mdmd [11218]<通知> :(注)MDM:网络可达性已更改。
Jul 11​​ 10:16:10 Toms-iPod mdmd [11218]<通知> :(注)MDM:接收推送令牌。
Jul 11​​ 10:16:10 Toms-iPod mdmd [11218]<通知> :(注)MDM:收到推送通知。
Jul 11​​ 10:16:10 Toms-iPod mdmd [11218]< Notice> :(注)MDM:轮询MDM服务器https://testmdm.azurewebsites.net/<redacted>下一个命令。

希望这会有所帮助。



T


i know it's duplicate of this, but this one is not working for me.

My Php code to send notification is

// Put your device token here (without spaces):
$deviceToken = '6hPQc2HvdA20XGlQkznJxlappCrzm3kJccljjOsgF2k=\n'; #base64 encoded
// Put your private key's passphrase here:
$passphrase = 'Temp1234';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', './Certificates_push_dev_new.pem');
stream_context_set_option($ctx, 'ssl', 'cafile', './entrust_2048_ca.cer');

stream_context_set_option($ctx, 'ssl', 'verify_peer', true);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.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

$payload = json_encode(array(
                             'mdm' => '3742A63A-5BB3-4D61-9D4B-E7968DADAF84',
                             'topic' => 'com.apple.mgmt.External.e5814e69-1c24-437f-bae9-562049fd3cd5'
                             ));

echo $payload . PHP_EOL;
// Build the binary notification
#$msg = chr(0).pack('n', 32).$deviceToken . pack('n', strlen($payload)).$payload;

// Build the binary notification
#$msg = chr(0) . pack('n', 32) . pack('J', $deviceToken) . pack('n', strlen($payload)) . $payload;

#$msg = chr(0).chr(0).chr(32).bin2hex(base64_decode($deviceToken)).chr(0).chr(strlen($payload)).$payload;
$msg = chr(0).chr(0).chr(32).bin2hex(base64_decode($deviceToken)).chr(0).chr(strlen($payload)).$payload;

// Send it to the server
# $result = fwrite($fp, $msg, strlen($msg));
$result = fwrite($fp, $msg);

if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);

Device Token with base64 Encoded

$deviceToken = '6hPQc2HvdA20XGlQkznJxlappCrzm3kJccljjOsgF2k=\n'; #base64 encoded

I have tried device token without base64 encoded as well in that case my token was

$deviceToken = '\xEA\u0013\xD0sa\xEFt\r\xB4\\iP\x939\xC9\xC6V\xA9\xA4*\xF3\x9By\tq\xC9c\x8C\xEB \u0017i';

To Check certificate validation, below command is working fine.

openssl s_client -connect gateway.push.apple.com:2195 -cert apns-dev.pem -key key.pem -CAfile entrust_2048_ca.cer

i don't receive any error while executing above php code. But device never contact our MDM server to pull configuration changes.

when my

could "SIGNING CERTIFICATE" section cause be of issue, device not receiving notification ?, one screenshot is of TestMDM vendor and second is of my i.e MobiLock

解决方案

I've had a go at pushing notifications myself, using PHP on Windows. One of the things I've noticed that might be wrong is your inclusion of the topic in the push payload. This isn't required.

Here is some PHP code I've written to test using a device I registered in TestMDM. I'm not a PHP developer, but using this (http://codular.com/sending-ios-push-notifications-with-php) as a baseline and taking the pushMagic and deviceToken strings from my TestMDM database, I got it to successfully send a push.

As I'm on Windows, I also use a PFX certificate for push.

$deviceToken = '<YOUR DEVICE TOKEN AS BASE64 STRING>'; #base64 encoded
$token = bin2hex(base64_decode($deviceToken));

// Put your private key's passphrase here:
$passphrase = '<YOUR PASSWORD>';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', './Push.pfx');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$fp = stream_socket_client('gateway.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 . "<br />";

$payload = '{ \'mdm\' = \'<YOUR PUSH MAGIC FOR THIS DEVICE>\' }';

$inner = chr(1) . pack('n', 32) . pack('H*', $token)
        . chr(2) . pack('n', strlen($payload)). $payload
        . chr(3) . pack('n', 4) . pack('N', 1)
        . chr(4) . pack('n', 4)
        . pack('N', time() + 86400)
        . chr(5) . pack('n', 1) . chr(10);

$notification = chr(2) . pack('N', strlen($inner)) . $inner;

echo $payload . PHP_EOL;

$result = fwrite($fp, $notification, strlen($notification));

echo $result;

Once I run the script, I can see this in the logs of my device, which indicates it is working:

Jul 11 10:16:10 Toms-iPod mdmd[11218] <Notice>: (Note ) MDM: mdmd starting...
Jul 11 10:16:10 Toms-iPod mdmd[11218] <Notice>: (Note ) MDM: Network reachability has changed.
Jul 11 10:16:10 Toms-iPod mdmd[11218] <Notice>: (Note ) MDM: Network reachability has changed.
Jul 11 10:16:10 Toms-iPod mdmd[11218] <Notice>: (Note ) MDM: Push token received.
Jul 11 10:16:10 Toms-iPod mdmd[11218] <Notice>: (Note ) MDM: Received push notification.
Jul 11 10:16:10 Toms-iPod mdmd[11218] <Notice>: (Note ) MDM: Polling MDM server https://testmdm.azurewebsites.net/<redacted> for next command.

Hopefully this will help.

T

这篇关于使用Php的iOS MDM推送通知,无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆