MessageController.class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class MessageController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'message');
  22. /**
  23. * 检查登录状态
  24. */
  25. public function __construct()
  26. {
  27. // 身份验证
  28. $server = new GuestModule;
  29. if (!$server->checkLogin()) {
  30. $this->returnJson['statusCode'] = '120005';
  31. exitOutput($this->returnJson);
  32. }
  33. }
  34. /**
  35. * 获取消息列表
  36. */
  37. public function getMessageList()
  38. {
  39. $page = securelyInput('page', 1);
  40. $server = new MessageModule;
  41. $result = $server->getMessageList($page);
  42. if ($result) {
  43. $this->returnJson['statusCode'] = '000000';
  44. $this->returnJson = array_merge($this->returnJson, $result);
  45. } else {
  46. //消息列表为空
  47. $this->returnJson['statusCode'] = '260001';
  48. }
  49. exitOutput($this->returnJson);
  50. }
  51. /**
  52. * 已阅消息
  53. */
  54. public function readMessage()
  55. {
  56. $msgID = securelyInput('msgID');
  57. // 判断ID格式是否合法
  58. if (!preg_match('/^[0-9]{1,11}$/', $msgID)) {
  59. $this->returnJson['statusCode'] = '260004';
  60. } else {
  61. $server = new MessageModule;
  62. if ($server->readMessage($msgID)) {
  63. $this->returnJson['statusCode'] = '000000';
  64. } else {
  65. $this->returnJson['statusCode'] = '260002';
  66. }
  67. }
  68. exitOutput($this->returnJson);
  69. }
  70. /**
  71. * 删除消息
  72. */
  73. public function delMessage()
  74. {
  75. $msgID = securelyInput('msgID');
  76. // 判断ID格式是否合法
  77. if (!preg_match('/^[0-9]{1,11}$/', $msgID)) {
  78. $this->returnJson['statusCode'] = '260004';
  79. } else {
  80. $server = new MessageModule;
  81. if ($server->delMessage($msgID)) {
  82. $this->returnJson['statusCode'] = '000000';
  83. } else {
  84. $this->returnJson['statusCode'] = '260005';
  85. }
  86. }
  87. exitOutput($this->returnJson);
  88. }
  89. /**
  90. * 清空消息
  91. */
  92. public function cleanMessage()
  93. {
  94. $server = new MessageModule;
  95. $result = $server->cleanMessage();
  96. if ($result) {
  97. $this->returnJson['statusCode'] = '000000';
  98. } else {
  99. $this->returnJson['statusCode'] = '260001';
  100. }
  101. exitOutput($this->returnJson);
  102. }
  103. /**
  104. * 获取未读消息数量
  105. */
  106. public function getUnreadMessageNum()
  107. {
  108. $server = new MessageModule;
  109. $result = $server->getUnreadMessageNum();
  110. if ($result) {
  111. $this->returnJson['statusCode'] = '000000';
  112. $this->returnJson['unreadMsgNum'] = $result;
  113. } else {
  114. //消息列表为空
  115. $this->returnJson['statusCode'] = '260001';
  116. }
  117. exitOutput($this->returnJson);
  118. }
  119. }
  120. ?>