Relation.php
2.4 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Relation.php.
*
* @author allen05ren <allen05ren@outlook.com>
* @copyright 2016 overtrue <i@overtrue.me>
*
* @see https://github.com/overtrue
* @see http://overtrue.me
*/
namespace EasyWeChat\ShakeAround;
use EasyWeChat\Core\AbstractAPI;
/**
* Class Relation.
*/
class Relation extends AbstractAPI
{
const API_DEVICE_BINDPAGE = 'https://api.weixin.qq.com/shakearound/device/bindpage';
const API_RELATION_SEARCH = 'https://api.weixin.qq.com/shakearound/relation/search';
/**
* Bind pages for device.
*
* @param array $deviceIdentifier
* @param array $pageIds
*
* @return \EasyWeChat\Support\Collection
*/
public function bindPage(array $deviceIdentifier, array $pageIds)
{
$params = [
'device_identifier' => $deviceIdentifier,
'page_ids' => $pageIds,
];
return $this->parseJSON('json', [self::API_DEVICE_BINDPAGE, $params]);
}
/**
* Get pageIds by deviceId.
*
* @param array $deviceIdentifier
* @param bool $raw
*
* @return array|\EasyWeChat\Support\Collection
*/
public function getPageByDeviceId(array $deviceIdentifier, $raw = false)
{
$params = [
'type' => 1,
'device_identifier' => $deviceIdentifier,
];
$result = $this->parseJSON('json', [self::API_RELATION_SEARCH, $params]);
if (true === $raw) {
return $result;
}
$page_ids = [];
if (!empty($result->data['relations'])) {
foreach ($result->data['relations'] as $item) {
$page_ids[] = $item['page_id'];
}
}
return $page_ids;
}
/**
* Get devices by pageId.
*
* @param int $pageId
* @param int $begin
* @param int $count
*
* @return \EasyWeChat\Support\Collection
*/
public function getDeviceByPageId($pageId, $begin, $count)
{
$params = [
'type' => 2,
'page_id' => intval($pageId),
'begin' => intval($begin),
'count' => intval($count),
];
return $this->parseJSON('json', [self::API_RELATION_SEARCH, $params]);
}
}