利用Google GCM發送push通知到Android用戶端

來源:互聯網
上載者:User

標籤:

// 這個可以需要在google帳號中申請,勾選gcm服務選項$apiKey      = ‘AIzaSyC6h3ysrn2HDCBqONTo2vKIVVuktIFoxxx‘;$headers = array(    "Content-Type:" . "application/json",    "Authorization:" . "key=" . $apiKey);$messageData = array(    ‘type‘    => 1,    ‘msg‘     => ‘news test‘,    ‘push_id‘ => 100);// device token,Android用戶端擷取到的,註冊的時候儲存到資料庫中// 串連一次可以推送到多個用戶端,這裡建議最大1000條$regid = array(    ‘APA91bEapIMawO4Kg5tLul__sKVtWItS6j7vdvpjEw1bv1dDCHSzYtucz0PCGdtdAASL1bQdVTgmVCIN4I8u9HZ8fnUqpM3jwwy4DwVXHpZmEr4NO18ORJlIox97BUun_fgZzYBWWoSxJY_H5PJHsi0WoWZcYDgSLQ‘,    ‘APA91bHY-F_U-ovEMRM_hRJegcD7QDxxffh4uNjiaBIIBTD1mVUc2BSqSdhvTPnhrMhN-E3msNganWaYN7s62UzqTrZYNGJl29lbTkHWWUzAywwK1V99LYK4ICn_TQfwciftuNwqlgJNOPrszYf5yLlKTzKpOUG3OQ‘,    ‘APA91bHHeGuCPz7WH6Kc9dPhiV67aSfQ1WOG7fK5N18msOW5EhATeqAFhyvHPxGC3ANKkgGFn0AbQi3r3KF6yKALGJqRPJXJ_HALhCCUPRiKXYjIkpiuMyP1pb6xZNaWETzHYDsWPRkgoeSnGcX19RVGWHs2JJOQWQ‘,    ‘APA91bE6HyQV19QOk6SgfQnmeIa2d47-i82dxtPRrGCe9MXjiFI-nYglgS_6hOaMb7TQRssQ9M0DHkHdUDYygDZe3tbt_zymRXDCFa6By1LcTZPNUDNCDvP3h-yqt3j1YZIMwvSOFTqNLJ9GgrjM54RNao5P2q6E2g‘,    ‘APA91bENGEtKY8rz9r3CcT82et62kvKEzzdMtww1PUKmf3VOK3bh_O4QaK9PSrUzTZwd15CHkEAbIMi_9mP3J0BnrJox1NqO25OoOZ5kkOlPpUKPvm7byfTGgQRsITkbS_TpP2Wg8A3bONEWR9CBjmOfyWZjImBFXA‘,    ‘APA91bFeBqgGqeMAbmab62xocPf1RejGJmQBEKjTFvEk7HurL5A7zVeQ-0-7v6ekQ6rYehgr8AZza5cEE1iZSJt47HvFgmAFqID7YeiAsO7wYW9en0xM4GLnJgGGSfy6VNbqogsP6ftIxVFuKeHzzcJb8u1IBCzZGw‘,);$data = array(    ‘data‘ => $messageData,    ‘registration_ids‘ => $regid);        $url = "https://android.googleapis.com/gcm/send";$ch = curl_init();curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));$response = curl_exec($ch);curl_close($ch);var_dump($response);

  

利用Google GCM發送push通知到Android用戶端

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.