码迷,mamicode.com
首页 > 移动开发 > 详细

利用Google GCM发送push通知到Android客户端

时间:2015-07-23 15:22:58      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

// 这个可以需要在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客户端

标签:

原文地址:http://www.cnblogs.com/adtuu/p/4670497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!