forked from thenbsp/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.php
More file actions
64 lines (55 loc) · 1.42 KB
/
Button.php
File metadata and controls
64 lines (55 loc) · 1.42 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
<?php
namespace Thenbsp\Wechat\Menu;
class Button implements ButtonInterface
{
/**
* 菜单名称
*/
protected $name;
/**
* 菜单类型
*/
protected $type;
/**
* 菜单值(key/url/media_id => value)
*/
protected $value = array();
/**
* 菜单类型映射关系
*/
protected $mapping = array(
'view' => 'url',
'click' => 'key',
'scancode_push' => 'key',
'scancode_waitmsg' => 'key',
'pic_sysphoto' => 'key',
'pic_photo_or_album'=> 'key',
'pic_weixin' => 'key',
'location_select' => 'key',
'media_id' => 'media_id',
'view_limited' => 'media_id'
);
/**
* 构造方法
*/
public function __construct($name, $type, $value)
{
if( !array_key_exists($type, $this->mapping) ) {
throw new \InvalidArgumentException(sprintf('Invalid Type: %s', $type));
}
$this->name = $name;
$this->type = $type;
$this->value = array($this->mapping[$type] => $value);
}
/**
* 菜单数据
*/
public function getData()
{
$data = array(
'name' => $this->name,
'type' => $this->type
);
return array_merge($data, $this->value);
}
}