php ios推送(代碼)_PHP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:file_get_contents("php://input", "r")實例介紹
      解釋不清,直接上例子 index.html 復制代碼 代碼如下: form action=action.php method=post input type=text name=userName id=userName /br/ input type=text name=userPass id=userPass /br/ input type=submit value=ok / /form action.php 復制代碼 代碼如下: ?php

      本篇文章是對php ios推送進行了詳細的分析介紹,需要的朋友參考下   復制代碼 代碼如下:


      <?php
      //php需要開啟ssl(OpenSSL)支持
      $apnsCert = "ck.pem";//連接到APNS時的證書許可文件,證書需格外按要求創建
      $pass = "123456";//證書口令
      $serverUrl = "ssl://gateway.sandbox.push.apple.com:2195";//push服務器,這里是開發測試服務器
      $deviceToken = "a8fcd4aa8943b223d4ebcd54fe168a8b99b3f24c63dbc0612db25a8c0a588675";//ios設備id,中間不能有空格,每個ios設備一個id
      $message = $_GET ['message'] or $message = "hello!";
      $badge = ( int ) $_GET ['badge'] or $badge = 2;
      $sound = $_GET ['sound'] or $sound = "default";
      $body = array('aps' => array('alert' => $message , 'badge' => $badge , 'sound' => $sound));
      $streamContext = stream_context_create();
      stream_context_set_option ( $streamContext, 'ssl', 'local_cert', $apnsCert );
      stream_context_set_option ( $streamContext, 'ssl', 'passphrase', $pass );
      $apns = stream_socket_client ( $serverUrl, $error, $errorString, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext);//連接服務器
      if ($apns) {
      echo "Connection OK <br/>";
      } else {
      echo "Failed to connect $errorString";
      return;
      }
      $payload = json_encode ( $body );
      $msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n', strlen($payload)) . $payload;
      $result = fwrite ( $apns, $msg);//發送消息
      fclose ( $apns );
      if ($result)
      echo "Sending message successfully: " . $payload;
      else
      echo 'Message not delivered';
      ?>

      分享:mongo Table類文件 獲取MongoCursor(游標)的實現方法分析
      MongoCursor Object 游標類 Mongo Config.php配置文件 Table.php(mongodb操作數據庫類文件) Config.php配置文件 復制代碼 代碼如下: ?php require_once 'Zend/Exception.php'; class Hrs_Mongo_Config { const VERSION = '1.7.0'; const DEFAULT_HOST = 'localhost';

      來源:模板無憂//所屬分類:PHP教程/更新時間:2013-07-03
      相關PHP教程