ios消息推送
程序员文章站
2022-05-21 17:27:47
...
<?php /* include this content define('DEV_APP_TOKEN','test token'); define('PRODUCT_APP_TOKEN','product token'); define('DEV_CERT_PASSPHRASE','DEV_CERT_PASSPHRASE'); define('PRODUCT_CERT_PASSPHRASE','PRODUCT_CERT_PASSPHRASE'); define('DEV_SSL_URL','ssl://gateway.sandbox.push.apple.com:2195'); define('PRODUCT_SSL_URL','ssl://gateway.push.apple.com:2195'); define('API_KEY','you key'); */ include 'config.php'; $token = empty($_POST['dev_token']) ? '' : $_POST['dev_token']; //要推送的设备序列号 $message = empty($_POST['message']) ? '' : $_POST['message'];//内容 $type = empty($_POST['type']) ? 0 : intval($_POST['type']);//消息类型 $url = empty($_POST['url']) ? '' : $_POST['url'];//url $badge = empty($_POST['badge']) ? 1 : intval($_POST['badge']); //未读消息数 if($token == '' || empty($token)){ echo '设备token不能为空'; die; } // Put your device token here (without spaces): $deviceToken = $token; // Put your private key's passphrase here: $passphrase = PRODUCT_CERT_PASSPHRASE; //////////////////////////////////////////////////////////////////////////////// $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // Open a connection to the APNS server $fp = stream_socket_client( PRODUCT_SSL_URL, $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 $body = array('aps' => array('alert' => $message, 'sound' => 'default', 'type' => $type, 'url' => $url, 'badge' => $badge ) ); // Encode the payload as JSON $payload = json_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'Message not delivered' . PHP_EOL; else echo 'Message successfully delivered' . PHP_EOL; // Close the connection to the server fclose($fp); ?>
推荐阅读
-
PHP版微信公共平台消息主动推送,突破订阅号一天只能发送一条信息限制
-
Socket模拟SOAP消息
-
[PHP]利用XAMPP搭建本地服务器, 然后利用iOS客户端上传数据到本地服务器中(三. PHP端代码实现) - M_Lee
-
钉钉中文消息怎么转换成英文? 钉钉翻译的技巧
-
Go语言使用钉钉机器人推送消息的实现示例
-
Win11 Build 22000.282正式版推送: 附更新修复内容汇总
-
微信app撤回的消息怎么重新编辑?
-
iOS 14.3/iPadOS 14.3开发者预览版 Beta 2(18C5054c)怎么升级?
-
iOS15.4支持戴口罩解锁了!网友实测:支付也能用、无需Apple Watch
-
Win10 Mobile预览版15027推送:修复崩溃重启问题