IOS推送之PHP代碼

來源:互聯網
上載者:User

標籤:span   app   push   div   修改   write   phone   encode   ace   

準備工作

1.擷取手機註冊應用的deviceToken(iphone手機註冊應用時返回唯一值deviceToken)

2.擷取ck.pem檔案(做手機端的給)

3.擷取pass phrase(做手機端的給)

push.php檔案:

 

<?php//手機註冊應用返回唯一的deviceToken$deviceToken = ‘6ad7b13f b05e6137 a46a60ea 421e5016 4b701671 cc176f70 33bb9ef4 38a8aef9‘;//ck.pem通關密碼$pass = ‘jetson‘; //訊息內容$message = ‘A test message!‘;//badge我也不知是什麼$badge = 4;//sound我也不知是什麼(或許是推送訊息到手機時的提示音)$sound = ‘Duck.wav‘;//建設的通知有效載荷(即通知包含的一些資訊)$body = array();$body[‘id‘] = "4f94d38e7d9704f15c000055";$body[‘aps‘] = array(‘alert‘ => $message);if ($badge)$body[‘aps‘][‘badge‘] = $badge;if ($sound)$body[‘aps‘][‘sound‘] = $sound;//把數組資料轉換為json資料$payload = json_encode($body);echo strlen($payload),"\r\n";//下邊的寫法就是死寫法了,一般不需要修改,//唯一要修改的就是:ssl://gateway.sandbox.push.apple.com:2195這個是沙箱測試地址,ssl://gateway.push.apple.com:2195正式發布地址$ctx = stream_context_create();stream_context_set_option($ctx, ‘ssl‘, ‘local_cert‘, ‘ck.pem‘); stream_context_set_option($ctx, ‘ssl‘, ‘passphrase‘, $pass);$fp = stream_socket_client(‘ssl://gateway.sandbox.push.apple.com:2195‘, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);if (!$fp) {print "Failed to connect $err $errstr\n";return;}else {print "Connection OK\n<br/>";}// send message$msg = chr(0) . pack("n",32) . pack(‘H*‘, str_replace(‘ ‘, ‘‘, $deviceToken)) . pack("n",strlen($payload)) . $payload;print "Sending message :" . $payload . "\n"; fwrite($fp, $msg);fclose($fp);?>

 

IOS推送之PHP代碼(轉)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.