Notification.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: Notification.php 34003 2013-09-18 04:31:14Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. Cloud::loadFile('Service_Client_Restful');
  12. class Cloud_Service_Client_Notification extends Cloud_Service_Client_Restful {
  13. protected static $_instance;
  14. public static function getInstance($debug = false) {
  15. if (!(self::$_instance instanceof self)) {
  16. self::$_instance = new self($debug);
  17. }
  18. return self::$_instance;
  19. }
  20. public function __construct($debug = false) {
  21. return parent::__construct($debug);
  22. }
  23. public function add($siteUid, $pkId, $type, $authorId, $author, $fromId, $fromIdType, $note, $fromNum, $dateline, $extra = array()) {
  24. $_params = array(
  25. 'openid' => $this->getUserOpenId($siteUid),
  26. 'sSiteUid' => $siteUid,
  27. 'pkId' => $pkId,
  28. 'type' => $type,
  29. 'authorId' => $authorId,
  30. 'author' => $author,
  31. 'fromId' => $fromId,
  32. 'fromIdType' => $fromIdType,
  33. 'fromNum' => $fromNum,
  34. 'content' => $note,
  35. 'dateline' => $dateline,
  36. 'deviceToken' => $this->getUserDeviceToken($siteUid),
  37. 'extra' => array(
  38. 'isAdminGroup' => getglobal('adminid'),
  39. 'groupId' => getglobal('groupid'),
  40. 'groupName' => getglobal('group/grouptitle')
  41. )
  42. );
  43. if($extra) {
  44. foreach($extra as $key => $value) {
  45. $_params['extra'][$key] = $value;
  46. }
  47. }
  48. return $this->_callMethod('connect.discuz.notification.add', $_params);
  49. }
  50. public function update($siteUid, $pkId, $fromNum, $dateline, $notekey) {
  51. $_params = array(
  52. 'openid' => $this->getUserOpenId($siteUid),
  53. 'sSiteUid' => $siteUid,
  54. 'pkId' => $pkId,
  55. 'fromNum' => $fromNum,
  56. 'dateline' => $dateline,
  57. 'notekey' => $notekey,
  58. );
  59. return $this->_callMethod('connect.discuz.notification.update', $_params);
  60. }
  61. public function setNoticeFlag($siteUid, $dateline) {
  62. $_params = array(
  63. 'openid' => $this->getUserOpenId($siteUid),
  64. 'sSiteUid' => $siteUid,
  65. 'dateline' => $dateline
  66. );
  67. return $this->_callMethod('connect.discuz.notification.read', $_params);
  68. }
  69. public function addSiteMasterUserNotify($siteUids, $subject, $content, $authorId, $author, $fromType, $dateline) {
  70. $toUids = array();
  71. if($siteUids) {
  72. $users = C::t('#qqconnect#common_member')->fetch_all((array)$siteUids);
  73. $connectUsers = C::t('#qqconnect#common_member_connect')->fetch_all((array)$siteUids);
  74. $i = 1;
  75. foreach ($users as $uid => $user) {
  76. $conopenid = $connectUsers[$uid]['conopenid'];
  77. if (!$conopenid) {
  78. $conopenid = 'n' . $i ++;
  79. }
  80. $toUids[$conopenid] = $user['uid'];
  81. }
  82. $_params = array(
  83. 'openidData' => $toUids,
  84. 'subject' => $subject,
  85. 'content' => $content,
  86. 'authorId' => $authorId,
  87. 'author' => $author,
  88. 'fromType' => $fromType == 1 ? 1 : 2,
  89. 'dateline' => $dateline,
  90. 'deviceToken' => $this->getUserDeviceToken($siteUids)
  91. );
  92. return parent::_callMethod('connect.discuz.notification.addSiteMasterUserNotify', $_params);
  93. }
  94. return false;
  95. }
  96. protected function _callMethod($method, $args) {
  97. try {
  98. return parent::_callMethod($method, $args);
  99. } catch (Exception $e) {
  100. }
  101. }
  102. }