Commit 9fc29de5 by HanSon Committed by GitHub

Merge pull request #29 from HanSon/dev

增加公众号推送消息类型,Official
2 parents 529287a0 abe5edb4
...@@ -21,6 +21,7 @@ use Hanson\Vbot\Message\Entity\RedPacket; ...@@ -21,6 +21,7 @@ use Hanson\Vbot\Message\Entity\RedPacket;
use Hanson\Vbot\Message\Entity\Transfer; use Hanson\Vbot\Message\Entity\Transfer;
use Hanson\Vbot\Message\Entity\Recommend; use Hanson\Vbot\Message\Entity\Recommend;
use Hanson\Vbot\Message\Entity\Share; use Hanson\Vbot\Message\Entity\Share;
use Hanson\Vbot\Message\Entity\Official;
use Hanson\Vbot\Message\Entity\Touch; use Hanson\Vbot\Message\Entity\Touch;
use Hanson\Vbot\Message\Entity\RequestFriend; use Hanson\Vbot\Message\Entity\RequestFriend;
...@@ -150,6 +151,16 @@ $robot->server->setMessageHandler(function ($message) use ($path) { ...@@ -150,6 +151,16 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
return $reply; return $reply;
} }
// 公众号推送信息
if($message instanceof Official){
/** @var $message Official */
$reply = "收到公众号推送\n标题:{$message->title}\n描述:{$message->description}\n链接:{$message->url}";
if($message->app){
$reply .= "\n来源公众号名称:{$message->app}";
}
return $reply;
}
// 手机点击聊天事件 // 手机点击聊天事件
if($message instanceof Touch){ if($message instanceof Touch){
Text::send($message->msg['ToUserName'], "我点击了此聊天"); Text::send($message->msg['ToUserName'], "我点击了此聊天");
......
...@@ -43,6 +43,8 @@ class Account ...@@ -43,6 +43,8 @@ class Account
$account = $account ?: contact()->get($username, null); $account = $account ?: contact()->get($username, null);
$account = $account ?: official()->get($username, null);
return $account ?: member()->get($username, []); return $account ?: member()->get($username, []);
} }
......
...@@ -83,7 +83,7 @@ class Message ...@@ -83,7 +83,7 @@ class Message
$this->fromType = 'Group'; $this->fromType = 'Group';
} elseif (contact()->get($this->msg['FromUserName'])) { } elseif (contact()->get($this->msg['FromUserName'])) {
$this->fromType = 'Contact'; $this->fromType = 'Contact';
} elseif (Official::getInstance()->get($this->msg['FromUserName'])) { } elseif (official()->get($this->msg['FromUserName'])) {
$this->fromType = 'Official'; $this->fromType = 'Official';
} elseif (Special::getInstance()->get($this->msg['FromUserName'], false)) { } elseif (Special::getInstance()->get($this->msg['FromUserName'], false)) {
$this->fromType = 'Special'; $this->fromType = 'Special';
......
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/1/15
* Time: 12:29
*/
namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Message\MessageInterface;
class Official extends Message implements MessageInterface
{
public $title;
public $description;
public $url;
public $app;
public function __construct($msg)
{
parent::__construct($msg);
$this->make();
}
public function make()
{
$array = (array)simplexml_load_string($this->msg['Content'], 'SimpleXMLElement', LIBXML_NOCDATA);
$info = (array)$array['appmsg'];
$this->title = $info['title'];
$this->description = $info['des'];
$appInfo = (array)$array['appinfo'];
$this->app = $appInfo['appname'];
$this->url = $this->msg['Url'];
}
}
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
namespace Hanson\Vbot\Message\Entity; namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Message\MessageInterface;
use Hanson\Vbot\Support\Content; use Hanson\Vbot\Support\Content;
class ShareFactory class ShareFactory
...@@ -26,6 +25,8 @@ class ShareFactory ...@@ -26,6 +25,8 @@ class ShareFactory
if($this->type == 6){ if($this->type == 6){
return new File($msg); return new File($msg);
}else if(official()->get($msg['FromUserName'])){
return new Official($msg);
}else{ }else{
return new Share($msg); return new Share($msg);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!