diff --git a/src/Wechat/Work/Message/MessageInterface.php b/src/Wechat/Work/Message/MessageInterface.php index 9869fbf..6806c02 100644 --- a/src/Wechat/Work/Message/MessageInterface.php +++ b/src/Wechat/Work/Message/MessageInterface.php @@ -12,12 +12,12 @@ abstract class MessageInterface const TYPE_TEXT_CARD = 'textcard'; const TYPE_NEWS = 'news'; const TYPE_MP_NEWS = 'mpnews'; + const TYPE_MINI_PROGRAM_NOTICE = 'miniprogram_notice'; protected $type; - protected $attr; - protected $safe; protected $params; + protected $attr; public function toUser($user) { @@ -41,10 +41,17 @@ abstract class MessageInterface { $params = array_merge([ 'msgtype' => $this->type, - 'safe' => $this->safe, + 'safe' => 0, ], $this->params); switch ($this->type) { + case self::TYPE_TEXT: + $params = array_merge($params, [ + $this->type => [ + 'content' => $this->attr['content'], + ], + ]); + break; case self::TYPE_TEXT_CARD: $params = array_merge($params, [ $this->type => [ @@ -55,10 +62,15 @@ abstract class MessageInterface ], ]); break; + case self::TYPE_MINI_PROGRAM_NOTICE: + $params = array_merge($params, [ + $this->type => $this->attr, + ]); + break; default: throw new \Exception('message type ' . $this->type . ' is not allow'); } - return $arr; + return $params; } } \ No newline at end of file diff --git a/src/Wechat/Work/Message/MiniProgramMessage.php b/src/Wechat/Work/Message/MiniProgramMessage.php new file mode 100644 index 0000000..11b90bd --- /dev/null +++ b/src/Wechat/Work/Message/MiniProgramMessage.php @@ -0,0 +1,52 @@ +type = self::TYPE_MINI_PROGRAM_NOTICE; + } + + public function appid($val) + { + $this->attr['appid'] = $val; + return $this; + } + + public function page($val) + { + $this->attr['page'] = $val; + return $this; + } + + public function title($id) + { + $this->attr['title'] = $id; + return $this; + } + + public function description($id) + { + $this->attr['description'] = $id; + return $this; + } + + public function emphasisFirstItem($id) + { + $this->attr['emphasis_first_item'] = $id; + return $this; + } + + public function contentItem($id) + { + $this->attr['content_item'] = $id; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Wechat/Work/Message/TextCardMessage.php b/src/Wechat/Work/Message/TextCardMessage.php index 3a03a39..6f94e15 100644 --- a/src/Wechat/Work/Message/TextCardMessage.php +++ b/src/Wechat/Work/Message/TextCardMessage.php @@ -6,11 +6,7 @@ use Wechat\Work\Message\MessageInterface; class TextCardMessage extends MessageInterface { - - - protected $type; - protected $attr; - + public function __construct() { $this->type = self::TYPE_TEXT_CARD; @@ -40,24 +36,4 @@ class TextCardMessage extends MessageInterface return $this; } - public function toArray() - { - $arr = [ - 'msgtype' => $this->type, - $this->type => [ - 'title' => $this->attr['title'], - 'description' => $this->attr['description'], - 'url' => $this->attr['url'], - 'btntxt' => $this->attr['btntxt'], - ], - 'safe' => $this->safe, - ]; - - if (!empty($this->params)) { - $arr = array_merge($this->params, $arr); - } - - return $arr; - } - } \ No newline at end of file diff --git a/src/Wechat/Work/Message/TextMessage.php b/src/Wechat/Work/Message/TextMessage.php index fe43b13..69bba3e 100644 --- a/src/Wechat/Work/Message/TextMessage.php +++ b/src/Wechat/Work/Message/TextMessage.php @@ -1,35 +1,16 @@ type = self::TYPE_TEXT; $this->attr['content'] = $content; } - public function toArray() - { - $arr = [ - 'msgtype' => $this->type, - $this->type => [ - 'content' => $this->attr['content'], - ], - 'safe' => $this->safe, - ]; - - if (!empty($this->params)) { - $arr = array_merge($this->params, $arr); - } - - return $arr; - } - } \ No newline at end of file