国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.1KB

  1. <?php
  2. namespace WeChat;
  3. if (!defined('DEDEINC')) exit('dedebiz');
  4. use WeChat\Contracts\BasicPushEvent;
  5. /**
  6. * 公众号推送管理
  7. * Class Receive
  8. * @package WeChat
  9. */
  10. class Receive extends BasicPushEvent
  11. {
  12. /**
  13. * 转发多客服消息
  14. * @param string $account
  15. * @return $this
  16. */
  17. public function transferCustomerService($account = '')
  18. {
  19. $this->message = [
  20. 'CreateTime' => time(),
  21. 'ToUserName' => $this->getOpenid(),
  22. 'FromUserName' => $this->getToOpenid(),
  23. 'MsgType' => 'transfer_customer_service',
  24. ];
  25. empty($account) || $this->message['TransInfo'] = ['KfAccount' => $account];
  26. return $this;
  27. }
  28. /**
  29. * 设置文本消息
  30. * @param string $content 文本内容
  31. * @return $this
  32. */
  33. public function text($content = '')
  34. {
  35. $this->message = [
  36. 'MsgType' => 'text',
  37. 'CreateTime' => time(),
  38. 'Content' => $content,
  39. 'ToUserName' => $this->getOpenid(),
  40. 'FromUserName' => $this->getToOpenid(),
  41. ];
  42. return $this;
  43. }
  44. /**
  45. * 设置回复图文
  46. * @param array $newsData
  47. * @return $this
  48. */
  49. public function news($newsData = [])
  50. {
  51. $this->message = [
  52. 'CreateTime' => time(),
  53. 'MsgType' => 'news',
  54. 'Articles' => $newsData,
  55. 'ToUserName' => $this->getOpenid(),
  56. 'FromUserName' => $this->getToOpenid(),
  57. 'ArticleCount' => count($newsData),
  58. ];
  59. return $this;
  60. }
  61. /**
  62. * 设置图片消息
  63. * @param string $mediaId 图片媒体ID
  64. * @return $this
  65. */
  66. public function image($mediaId = '')
  67. {
  68. $this->message = [
  69. 'MsgType' => 'image',
  70. 'CreateTime' => time(),
  71. 'ToUserName' => $this->getOpenid(),
  72. 'FromUserName' => $this->getToOpenid(),
  73. 'Image' => ['MediaId' => $mediaId],
  74. ];
  75. return $this;
  76. }
  77. /**
  78. * 设置语音回复消息
  79. * @param string $mediaid 语音媒体ID
  80. * @return $this
  81. */
  82. public function voice($mediaid = '')
  83. {
  84. $this->message = [
  85. 'CreateTime' => time(),
  86. 'MsgType' => 'voice',
  87. 'ToUserName' => $this->getOpenid(),
  88. 'FromUserName' => $this->getToOpenid(),
  89. 'Voice' => ['MediaId' => $mediaid],
  90. ];
  91. return $this;
  92. }
  93. /**
  94. * 设置视频回复消息
  95. * @param string $mediaid 视频媒体ID
  96. * @param string $title 视频标题
  97. * @param string $description 视频描述
  98. * @return $this
  99. */
  100. public function video($mediaid = '', $title = '', $description = '')
  101. {
  102. $this->message = [
  103. 'CreateTime' => time(),
  104. 'MsgType' => 'video',
  105. 'ToUserName' => $this->getOpenid(),
  106. 'FromUserName' => $this->getToOpenid(),
  107. 'Video' => [
  108. 'Title' => $title,
  109. 'MediaId' => $mediaid,
  110. 'Description' => $description,
  111. ],
  112. ];
  113. return $this;
  114. }
  115. /**
  116. * 设置音乐回复消息
  117. * @param string $title 音乐标题
  118. * @param string $desc 音乐描述
  119. * @param string $musicurl 音乐地址
  120. * @param string $hgmusicurl 高清音乐地址
  121. * @param string $thumbmediaid 音乐图片缩略图的媒体id(可选)
  122. * @return $this
  123. */
  124. public function music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')
  125. {
  126. $this->message = [
  127. 'CreateTime' => time(),
  128. 'MsgType' => 'music',
  129. 'ToUserName' => $this->getOpenid(),
  130. 'FromUserName' => $this->getToOpenid(),
  131. 'Music' => [
  132. 'Title' => $title,
  133. 'Description' => $desc,
  134. 'MusicUrl' => $musicurl,
  135. 'HQMusicUrl' => $hgmusicurl,
  136. ],
  137. ];
  138. if ($thumbmediaid) {
  139. $this->message['Music']['ThumbMediaId'] = $thumbmediaid;
  140. }
  141. return $this;
  142. }
  143. }
  144. ?>