1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/wechat. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Relation.php. |
14
|
|
|
* |
15
|
|
|
* @author allen05ren <[email protected]> |
16
|
|
|
* @copyright 2016 overtrue <[email protected]> |
17
|
|
|
* |
18
|
|
|
* @link https://github.com/overtrue |
19
|
|
|
* @link http://overtrue.me |
20
|
|
|
*/ |
21
|
|
|
namespace EasyWeChat\ShakeAround; |
22
|
|
|
|
23
|
|
|
use EasyWeChat\Core\AbstractAPI; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Relation. |
27
|
|
|
*/ |
28
|
|
|
class Relation extends AbstractAPI |
29
|
|
|
{ |
30
|
|
|
const API_DEVICE_BINDPAGE = 'https://api.weixin.qq.com/shakearound/device/bindpage'; |
31
|
|
|
const API_RELATION_SEARCH = 'https://api.weixin.qq.com/shakearound/relation/search'; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Bind pages for device. |
36
|
|
|
* |
37
|
|
|
* @param array $device_identifier |
38
|
|
|
* @param array $page_ids |
39
|
|
|
* |
40
|
|
|
* @return \EasyWeChat\Support\Collection |
41
|
|
|
*/ |
42
|
|
|
public function bindPage(array $device_identifier, array $page_ids) |
43
|
|
|
{ |
44
|
|
|
$params = [ |
45
|
|
|
'device_identifier' => $device_identifier, |
46
|
|
|
'page_ids' => $page_ids, |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
return $this->parseJSON('json', [self::API_DEVICE_BINDPAGE, $params]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get page_ids by device_id. |
54
|
|
|
* |
55
|
|
|
* @param array $device_identifier |
56
|
|
|
* @param boolean $raw |
57
|
|
|
* |
58
|
|
|
* @return array|\EasyWeChat\Support\Collection |
59
|
|
|
*/ |
60
|
|
|
public function getPageByDeviceId(array $device_identifier, $raw = false) |
61
|
|
|
{ |
62
|
|
|
$params = [ |
63
|
|
|
'type' => 1, |
64
|
|
|
'device_identifier' => $device_identifier, |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
$result = $this->parseJSON('json', [self::API_RELATION_SEARCH, $params]); |
68
|
|
|
|
69
|
|
|
if ($raw === true) { |
70
|
|
|
return $result; |
71
|
|
|
} |
72
|
|
|
$page_ids = array(); |
73
|
|
|
if (!empty($result->data['relations'])) { |
|
|
|
|
74
|
|
|
foreach ($result->data['relations'] as $item) { |
|
|
|
|
75
|
|
|
$page_ids[] = $item['page_id']; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $page_ids; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get devices by page_id. |
84
|
|
|
* |
85
|
|
|
* @param int $page_id |
86
|
|
|
* @param int $begin |
87
|
|
|
* @param int $count |
88
|
|
|
* |
89
|
|
|
* @return \EasyWeChat\Support\Collection |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function getDeviceByPageId($page_id, $begin, $count) |
92
|
|
|
{ |
93
|
|
|
$params = [ |
94
|
|
|
'type' => 2, |
95
|
|
|
'page_id' => intval($page_id), |
96
|
|
|
'begin' => intval($begin), |
97
|
|
|
'count' => intval($count), |
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
return $this->parseJSON('json', [self::API_RELATION_SEARCH, $params]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.