| Total Complexity | 13 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class Event implements \HughCube\Laravel\WeChat\Contracts\Message\Event\Event |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | protected $message; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param array $message |
||
| 22 | */ |
||
| 23 | public function __construct(array $message = []) |
||
| 24 | { |
||
| 25 | $this->message = $message; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string|null $key |
||
| 30 | * @return array|mixed|null |
||
| 31 | */ |
||
| 32 | public function getMessage(?string $key = null) |
||
| 33 | { |
||
| 34 | if (null === $key) { |
||
| 35 | return $this->message; |
||
| 36 | } |
||
| 37 | |||
| 38 | return $this->message[$key] ?? null; |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getToUserName(): ?string |
||
| 42 | { |
||
| 43 | return $this->getMessage('ToUserName'); |
||
|
|
|||
| 44 | } |
||
| 45 | |||
| 46 | public function getFromUserName(): ?string |
||
| 47 | { |
||
| 48 | return $this->getMessage('FromUserName'); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function getMessageType(): ?string |
||
| 52 | { |
||
| 53 | return $this->getMessage('MsgType'); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function getCreatedAt(): ?Carbon |
||
| 57 | { |
||
| 58 | $timestamp = $this->getMessage('CreateTime'); |
||
| 59 | if (empty($timestamp)) { |
||
| 60 | return null; |
||
| 61 | } |
||
| 62 | return Carbon::createFromTimestamp($timestamp); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function getMessageId(): ?int |
||
| 66 | { |
||
| 67 | return $this->getMessage('MsgId') ?: $this->getMessage('MsgID'); |
||
| 68 | } |
||
| 69 | |||
| 70 | public function getEvent(): ?string |
||
| 73 | } |
||
| 74 | |||
| 75 | public function getEventKey() |
||
| 76 | { |
||
| 77 | return $this->getMessage('EventKey'); |
||
| 78 | } |
||
| 79 | |||
| 80 | public function getOpenID(): ?string |
||
| 83 | } |
||
| 84 | } |
||
| 85 |