android_list_schedule.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. require_once(APP_ROOT_PATH.'system/libs/schedule.php');
  3. class android_list_schedule implements schedule {
  4. /**
  5. * $data 格式
  6. * array("dest"=>device_tokens,"content"=>序列化的消息配置);
  7. */
  8. public function exec($data){
  9. require_once(APP_ROOT_PATH. 'system/umeng/notification/android/AndroidListcast.php');
  10. try {
  11. $appMasterSecret = $GLOBALS['db']->getOne("select val from ".DB_PREFIX."m_config where code = 'android_master_secret'");
  12. $appkey = $GLOBALS['db']->getOne("select val from ".DB_PREFIX."m_config where code = 'android_app_key'");
  13. $title = app_conf("SITE_NAME")?app_conf("SITE_NAME"):"直播";
  14. $listcast = new AndroidListcast();
  15. $listcast->setAppMasterSecret($appMasterSecret);
  16. $listcast->setPredefinedKeyValue("appkey", $appkey);
  17. $listcast->setPredefinedKeyValue("timestamp", strval(time()));// 必填 时间戳,10位或者13位均可,时间戳有效期为10分钟 NOW_TIME
  18. // Set your device tokens here
  19. $listcast->setPredefinedKeyValue("device_tokens", trim($data['dest']));
  20. $listcast->setPredefinedKeyValue("ticker", $data['content']);//必填 通知栏提示文字
  21. $listcast->setPredefinedKeyValue("title", $title);// 必填 通知标题
  22. $listcast->setPredefinedKeyValue("text", $data['content']);// 必填 通知文字描述
  23. $listcast->setPredefinedKeyValue("after_open", "go_app");//"go_app": 打开应用;"go_url": 跳转到URL;"go_activity": 打开特定的activity;"go_custom": 用户自定义内容。
  24. // Set 'production_mode' to 'false' if it's a test device.
  25. // For how to register a test device, please see the developer doc.
  26. $listcast->setPredefinedKeyValue("production_mode", "true");//可选 正式/测试模式。测试模式下,只会将消息发给测试设备。
  27. // Set extra fields
  28. $listcast->setExtraField("room_id", $data['room_id']);
  29. $listcast->setExtraField("type", $data['type']);
  30. if ($data['type']==5) {
  31. $listcast->setExtraField("url", $data['url']);
  32. }
  33. //print("Sending unicast notification, please wait...\r\n");
  34. //json_decode($data) {"ret":"SUCCESS","data":{"msg_id":"uu05362143574400482600"}}
  35. $result = $listcast->send();
  36. $res = json_decode($result,1);
  37. //print("Sent SUCCESS\r\n");
  38. if ($res['ret'] == 'SUCCESS'){
  39. $is_success = 1;
  40. }else{
  41. $is_success = 0;
  42. $message = addslashes(print_r($result,true));
  43. }
  44. } catch (Exception $e) {
  45. $is_success = 0;
  46. $message = addslashes($e->getMessage());
  47. }
  48. $result = array();
  49. $result['status'] = $is_success;
  50. $result['attemp'] = 0;
  51. $result['info'] = $message;
  52. $result['res'] = $res;
  53. return $result;
  54. }
  55. }
  56. ?>