-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
添加摇一摇周边模块 #548
Merged
Merged
添加摇一摇周边模块 #548
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
14de14f
Add ShakeAround module.
allen05ren 6c6ef85
remove getDeviceByPageId method.
allen05ren a2b2fa1
Add a argument for getPageByDeviceId method
allen05ren 6a88f3f
Clear up.
allen05ren cb0d3e3
Clear up.
allen05ren 5eeca82
Clear up.
allen05ren b0b1780
camelCase style.
allen05ren 80688f0
Merge pull request #1 from overtrue/master
allen05ren 66680d8
Merge branch 'master' into shake-around
allen05ren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,10 @@ | |
* @author overtrue <[email protected]> | ||
* @copyright 2015 | ||
* | ||
* @link https://github.com/overtrue/wechat | ||
* @link http://overtrue.me | ||
* @see https://github.com/overtrue/wechat | ||
* @see http://overtrue.me | ||
*/ | ||
|
||
namespace EasyWeChat\Foundation; | ||
|
||
use Doctrine\Common\Cache\Cache as CacheInterface; | ||
|
@@ -63,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 | ||
{ | ||
|
@@ -90,6 +92,7 @@ class Application extends Container | |
ServiceProviders\BroadcastServiceProvider::class, | ||
ServiceProviders\CardServiceProvider::class, | ||
ServiceProviders\DeviceServiceProvider::class, | ||
ServiceProviders\ShakeAroundServiceProvider::class, | ||
]; | ||
|
||
/** | ||
|
52 changes: 52 additions & 0 deletions
52
src/Foundation/ServiceProviders/ShakeAroundServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
* @copyright 2016 overtrue <[email protected]> | ||
* | ||
* @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']); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/wechat. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* Device.php. | ||
* | ||
* @author allen05ren <[email protected]> | ||
* @copyright 2016 overtrue <[email protected]> | ||
* | ||
* @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 $poi_id | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function apply($quantity, $reason, $comment = '', $poi_id = null) | ||
{ | ||
$params = [ | ||
'quantity' => intval($quantity), | ||
'apply_reason' => $reason, | ||
]; | ||
|
||
if (!empty($comment)) { | ||
$params['comment'] = $comment; | ||
} | ||
|
||
if (!is_null($poi_id)) { | ||
$params['poi_id'] = intval($poi_id); | ||
} | ||
|
||
return $this->parseJSON('json', [self::API_DEVICE_APPLYID, $params]); | ||
} | ||
|
||
/** | ||
* Get audit status. | ||
* | ||
* @param int $apply_id | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function getStatus($apply_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 请使用驼峰命名法 |
||
{ | ||
$params = [ | ||
'apply_id' => intval($apply_id), | ||
]; | ||
|
||
return $this->parseJSON('json', [self::API_DEVICE_APPLYSTATUS, $params]); | ||
} | ||
|
||
/** | ||
* Update a device comment. | ||
* | ||
* @param array $device_identifier | ||
* @param string $comment | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function update(array $device_identifier, $comment) | ||
{ | ||
$params = [ | ||
'device_identifier' => $device_identifier, | ||
'comment' => $comment, | ||
]; | ||
|
||
return $this->parseJSON('json', [self::API_DEVICE_UPDATE, $params]); | ||
} | ||
|
||
/** | ||
* Bind location for device. | ||
* | ||
* @param array $device_identifier | ||
* @param int $poi_id | ||
* @param int $type | ||
* @param string $poi_appid | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function bindLocation(array $device_identifier, $poi_id, $type = 1, $poi_appid = null) | ||
{ | ||
$params = [ | ||
'device_identifier' => $device_identifier, | ||
'poi_id' => intval($poi_id), | ||
]; | ||
|
||
if ($type === 2) { | ||
if (is_null($poi_appid)) { | ||
throw new InvalidArgumentException('If value of argument #3 is 2, argument #4 is required.'); | ||
} | ||
$params['type'] = 2; | ||
$params['poi_appid'] = $poi_appid; | ||
} | ||
|
||
return $this->parseJSON('json', [self::API_DEVICE_BINDLOCATION, $params]); | ||
} | ||
|
||
/** | ||
* Fetch batch of devices by device_ids. | ||
* | ||
* @param array $device_identifiers | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function fetchByIds(array $device_identifiers) | ||
{ | ||
$params = [ | ||
'type' => 1, | ||
'device_identifiers' => $device_identifiers, | ||
]; | ||
|
||
return $this->fetch($params); | ||
} | ||
|
||
/** | ||
* Pagination to fetch batch of devices. | ||
* | ||
* @param int $last_seen | ||
* @param int $count | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function pagination($last_seen, $count) | ||
{ | ||
$params = [ | ||
'type' => 2, | ||
'last_seen' => intval($last_seen), | ||
'count' => intval($count), | ||
]; | ||
|
||
return $this->fetch($params); | ||
} | ||
|
||
/** | ||
* Fetch batch of devices by apply_id. | ||
* | ||
* @param int $apply_id | ||
* @param int $last_seen | ||
* @param int $count | ||
* | ||
* @return \EasyWeChat\Support\Collection | ||
*/ | ||
public function fetchByApplyId($apply_id, $last_seen, $count) | ||
{ | ||
$params = [ | ||
'type' => 3, | ||
'apply_id' => intval($apply_id), | ||
'last_seen' => intval($last_seen), | ||
'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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是干嘛?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
styleci检测提示把link改成see,强迫症
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦,好吧,请忽略它