Permalink
Browse files

添加摇一摇周边模块 (#548)

* Add ShakeAround module.

* remove getDeviceByPageId method.

* Add a argument for getPageByDeviceId method

* Clear up.

* Clear up.

* Clear up.

* camelCase style.
1 parent 058da32 commit 8d02ae757e6cdb3ca00a40433c33ceaa2f0b70f1 @allen05ren allen05ren committed with Dec 19, 2016
@@ -20,7 +20,7 @@
* @author overtrue <i@overtrue.me>
* @copyright 2015
*
- * @see https://github.com/overtrue/wechat
+ * @see https://github.com/overtrue
* @see http://overtrue.me
*/
@@ -64,6 +64,7 @@
* @property \EasyWeChat\Broadcast\Broadcast $broadcast
* @property \EasyWeChat\Card\Card $card
* @property \EasyWeChat\Device\Device $device
+ * @property \EasyWeChat\ShakeAround\ShakeAround $shakearound
*/
class Application extends Container
{
@@ -91,6 +92,7 @@ class Application extends Container
ServiceProviders\BroadcastServiceProvider::class,
ServiceProviders\CardServiceProvider::class,
ServiceProviders\DeviceServiceProvider::class,
+ ServiceProviders\ShakeAroundServiceProvider::class,
];
/**
@@ -0,0 +1,52 @@
+<?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.
+ */
+
+/**
+ * UserServiceProvider.php.
+ *
+ * Part of Overtrue\WeChat.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @author allen05ren <allen05ren@outlook.com>
+ * @copyright 2016 overtrue <i@overtrue.me>
+ *
+ * @see https://github.com/overtrue/wechat
+ * @see http://overtrue.me
+ */
+
+namespace EasyWeChat\Foundation\ServiceProviders;
+
+use EasyWeChat\ShakeAround\ShakeAround;
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ShakeAroundServiceProvider.
+ */
+class ShakeAroundServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * Registers services on the given container.
+ *
+ * This method should only be used to configure services and parameters.
+ * It should not get services.
+ *
+ * @param Container $pimple A container instance
+ */
+ public function register(Container $pimple)
+ {
+ $pimple['shakearound'] = function ($pimple) {
+ return new ShakeAround($pimple['access_token']);
+ };
+ }
+}
@@ -0,0 +1,198 @@
+<?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.
+ */
+
+/**
+ * Device.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;
+use EasyWeChat\Core\Exceptions\InvalidArgumentException;
+
+/**
+ * Class Device.
+ */
+class Device extends AbstractAPI
+{
+ const API_DEVICE_APPLYID = 'https://api.weixin.qq.com/shakearound/device/applyid';
+ const API_DEVICE_APPLYSTATUS = 'https://api.weixin.qq.com/shakearound/device/applystatus';
+ const API_DEVICE_UPDATE = 'https://api.weixin.qq.com/shakearound/device/update';
+ const API_DEVICE_BINDLOCATION = 'https://api.weixin.qq.com/shakearound/device/bindlocation';
+ const API_DEVICE_SEARCH = 'https://api.weixin.qq.com/shakearound/device/search';
+
+ /**
+ * Apply device ids.
+ *
+ * @param int $quantity
+ * @param string $reason
+ * @param string $comment
+ * @param int $poiId
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ public function apply($quantity, $reason, $comment = '', $poiId = null)
+ {
+ $params = [
+ 'quantity' => intval($quantity),
+ 'apply_reason' => $reason,
+ ];
+
+ if (!empty($comment)) {
+ $params['comment'] = $comment;
+ }
+
+ if (!is_null($poiId)) {
+ $params['poi_id'] = intval($poiId);
+ }
+
+ return $this->parseJSON('json', [self::API_DEVICE_APPLYID, $params]);
+ }
+
+ /**
+ * Get audit status.
+ *
+ * @param int $applyId
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ public function getStatus($applyId)
+ {
+ $params = [
+ 'apply_id' => intval($applyId),
+ ];
+
+ return $this->parseJSON('json', [self::API_DEVICE_APPLYSTATUS, $params]);
+ }
+
+ /**
+ * Update a device comment.
+ *
+ * @param array $deviceIdentifier
+ * @param string $comment
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ public function update(array $deviceIdentifier, $comment)
+ {
+ $params = [
+ 'device_identifier' => $deviceIdentifier,
+ 'comment' => $comment,
+ ];
+
+ return $this->parseJSON('json', [self::API_DEVICE_UPDATE, $params]);
+ }
+
+ /**
+ * Bind location for device.
+ *
+ * @param array $deviceIdentifier
+ * @param int $poiId
+ * @param int $type
+ * @param string $poiAppid
+ *
+ * @return \EasyWeChat\Support\Collection
+ *
+ * @throws InvalidArgumentException
+ */
+ public function bindLocation(array $deviceIdentifier, $poiId, $type = 1, $poiAppid = null)
+ {
+ $params = [
+ 'device_identifier' => $deviceIdentifier,
+ 'poi_id' => intval($poiId),
+ ];
+
+ if ($type === 2) {
+ if (is_null($poiAppid)) {
+ throw new InvalidArgumentException('If value of argument #3 is 2, argument #4 is required.');
+ }
+ $params['type'] = 2;
+ $params['poi_appid'] = $poiAppid;
+ }
+
+ return $this->parseJSON('json', [self::API_DEVICE_BINDLOCATION, $params]);
+ }
+
+ /**
+ * Fetch batch of devices by deviceIds.
+ *
+ * @param array $deviceIdentifiers
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ public function fetchByIds(array $deviceIdentifiers)
+ {
+ $params = [
+ 'type' => 1,
+ 'device_identifiers' => $deviceIdentifiers,
+ ];
+
+ return $this->fetch($params);
+ }
+
+ /**
+ * Pagination to fetch batch of devices.
+ *
+ * @param int $lastSeen
+ * @param int $count
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ public function pagination($lastSeen, $count)
+ {
+ $params = [
+ 'type' => 2,
+ 'last_seen' => intval($lastSeen),
+ 'count' => intval($count),
+ ];
+
+ return $this->fetch($params);
+ }
+
+ /**
+ * Fetch batch of devices by applyId.
+ *
+ * @param int $applyId
+ * @param int $lastSeen
+ * @param int $count
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ public function fetchByApplyId($applyId, $lastSeen, $count)
+ {
+ $params = [
+ 'type' => 3,
+ 'apply_id' => intval($applyId),
+ 'last_seen' => intval($lastSeen),
+ 'count' => intval($count),
+ ];
+
+ return $this->fetch($params);
+ }
+
+ /**
+ * Fetch batch of devices.
+ *
+ * @param array $params
+ *
+ * @return \EasyWeChat\Support\Collection
+ */
+ private function fetch($params)
+ {
+ return $this->parseJSON('json', [self::API_DEVICE_SEARCH, $params]);
+ }
+}
Oops, something went wrong.

0 comments on commit 8d02ae7

Please sign in to comment.