標籤:
// 這個可以需要在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用戶端