Recall.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Created by PhpStorm.
* User: HanSon
* Date: 2017/1/13
* Time: 15:48
*/
namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Message\MediaTrait;
use Hanson\Vbot\Message\MessageInterface;
class Recall extends Message implements MessageInterface
{
use MediaTrait;
/**
* @var Message 上一条撤回的消息
*/
public $origin;
/**
* @var string 撤回者昵称
*/
public $nickname;
public function __construct($msg)
{
parent::__construct($msg);
$this->make();
}
/**
* 解析message获取msgId
*
* @param $xml
* @return string msgId
*/
private function parseMsgId($xml)
{
preg_match('/<msgid>(\d+)<\/msgid>/', $xml, $matches);
return $matches[1];
}
public function make()
{
$msgId = $this->parseMsgId($this->msg['Content']);
/** @var Message $message */
$this->origin = message()->get($msgId, null);
if($this->origin){
$this->nickname = $this->origin->sender ? $message->sender['NickName'] : account()->getAccount($this->origin->msg['FromUserName'])['NickName'];
$this->setContent();
}
}
private function setContent()
{
$this->content = "{$this->nickname} 刚撤回了消息";
}
}