129 changed files with 11244 additions and 0 deletions
@ -0,0 +1,85 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\ActivityMessage; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function createActivityId() |
|||
{ |
|||
return $this->httpGet('cgi-bin/message/wxopen/activityid/create'); |
|||
} |
|||
|
|||
/** |
|||
* @param string $activityId |
|||
* @param int $state |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateMessage(string $activityId, int $state = 0, array $params = []) |
|||
{ |
|||
if (!in_array($state, [0, 1], true)) { |
|||
throw new InvalidArgumentException('"state" should be "0" or "1".'); |
|||
} |
|||
|
|||
$params = $this->formatParameters($params); |
|||
|
|||
$params = [ |
|||
'activity_id' => $activityId, |
|||
'target_state' => $state, |
|||
'template_info' => ['parameter_list' => $params], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/message/wxopen/updatablemsg/send', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
protected function formatParameters(array $params) |
|||
{ |
|||
$formatted = []; |
|||
|
|||
foreach ($params as $name => $value) { |
|||
if (!in_array($name, ['member_count', 'room_limit', 'path', 'version_type'], true)) { |
|||
continue; |
|||
} |
|||
|
|||
if ('version_type' === $name && !in_array($value, ['develop', 'trial', 'release'], true)) { |
|||
throw new InvalidArgumentException('Invalid value of attribute "version_type".'); |
|||
} |
|||
|
|||
$formatted[] = [ |
|||
'name' => $name, |
|||
'value' => strval($value), |
|||
]; |
|||
} |
|||
|
|||
return $formatted; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\ActivityMessage; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['activity_message'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\AppCode; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Http\StreamResponse; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get AppCode. |
|||
* |
|||
* @param string $path |
|||
* @param array $optional |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
*/ |
|||
public function get(string $path, array $optional = []) |
|||
{ |
|||
$params = array_merge([ |
|||
'path' => $path, |
|||
], $optional); |
|||
|
|||
return $this->getStream('wxa/getwxacode', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get AppCode unlimit. |
|||
* |
|||
* @param string $scene |
|||
* @param array $optional |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
*/ |
|||
public function getUnlimit(string $scene, array $optional = []) |
|||
{ |
|||
$params = array_merge([ |
|||
'scene' => $scene, |
|||
], $optional); |
|||
|
|||
return $this->getStream('wxa/getwxacodeunlimit', $params); |
|||
} |
|||
|
|||
/** |
|||
* Create QrCode. |
|||
* |
|||
* @param string $path |
|||
* @param int|null $width |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
*/ |
|||
public function getQrCode(string $path, int $width = null) |
|||
{ |
|||
return $this->getStream('cgi-bin/wxaapp/createwxaqrcode', compact('path', 'width')); |
|||
} |
|||
|
|||
/** |
|||
* Get stream. |
|||
* |
|||
* @param string $endpoint |
|||
* @param array $params |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function getStream(string $endpoint, array $params) |
|||
{ |
|||
$response = $this->requestRaw($endpoint, 'POST', ['json' => $params]); |
|||
|
|||
if (false !== stripos($response->getHeaderLine('Content-disposition'), 'attachment')) { |
|||
return StreamResponse::buildFromPsrResponse($response); |
|||
} |
|||
|
|||
return $this->castResponseToType($response, $this->app['config']->get('response_type')); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\AppCode; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['app_code'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram; |
|||
|
|||
use EasyWeChat\BasicService; |
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
* |
|||
* @property \EasyWeChat\MiniProgram\Auth\AccessToken $access_token |
|||
* @property \EasyWeChat\MiniProgram\DataCube\Client $data_cube |
|||
* @property \EasyWeChat\MiniProgram\AppCode\Client $app_code |
|||
* @property \EasyWeChat\MiniProgram\Auth\Client $auth |
|||
* @property \EasyWeChat\OfficialAccount\Server\Guard $server |
|||
* @property \EasyWeChat\MiniProgram\Encryptor $encryptor |
|||
* @property \EasyWeChat\MiniProgram\TemplateMessage\Client $template_message |
|||
* @property \EasyWeChat\OfficialAccount\CustomerService\Client $customer_service |
|||
* @property \EasyWeChat\MiniProgram\Plugin\Client $plugin |
|||
* @property \EasyWeChat\MiniProgram\Plugin\DevClient $plugin_dev |
|||
* @property \EasyWeChat\MiniProgram\UniformMessage\Client $uniform_message |
|||
* @property \EasyWeChat\MiniProgram\ActivityMessage\Client $activity_message |
|||
* @property \EasyWeChat\MiniProgram\Express\Client $logistics |
|||
* @property \EasyWeChat\MiniProgram\NearbyPoi\Client $nearby_poi |
|||
* @property \EasyWeChat\MiniProgram\OCR\Client $ocr |
|||
* @property \EasyWeChat\MiniProgram\Soter\Client $soter |
|||
* @property \EasyWeChat\BasicService\Media\Client $media |
|||
* @property \EasyWeChat\BasicService\ContentSecurity\Client $content_security |
|||
* @property \EasyWeChat\MiniProgram\Mall\ForwardsMall $mall |
|||
* @property \EasyWeChat\MiniProgram\SubscribeMessage\Client $subscribe_message |
|||
*/ |
|||
class Application extends ServiceContainer |
|||
{ |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $providers = [ |
|||
Auth\ServiceProvider::class, |
|||
DataCube\ServiceProvider::class, |
|||
AppCode\ServiceProvider::class, |
|||
Server\ServiceProvider::class, |
|||
TemplateMessage\ServiceProvider::class, |
|||
CustomerService\ServiceProvider::class, |
|||
UniformMessage\ServiceProvider::class, |
|||
ActivityMessage\ServiceProvider::class, |
|||
OpenData\ServiceProvider::class, |
|||
Plugin\ServiceProvider::class, |
|||
Base\ServiceProvider::class, |
|||
Express\ServiceProvider::class, |
|||
NearbyPoi\ServiceProvider::class, |
|||
OCR\ServiceProvider::class, |
|||
Soter\ServiceProvider::class, |
|||
Mall\ServiceProvider::class, |
|||
SubscribeMessage\ServiceProvider::class, |
|||
// Base services |
|||
BasicService\Media\ServiceProvider::class, |
|||
BasicService\ContentSecurity\ServiceProvider::class, |
|||
]; |
|||
|
|||
/** |
|||
* Handle dynamic calls. |
|||
* |
|||
* @param string $method |
|||
* @param array $args |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __call($method, $args) |
|||
{ |
|||
return $this->base->$method(...$args); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Auth; |
|||
|
|||
use EasyWeChat\Kernel\AccessToken as BaseAccessToken; |
|||
|
|||
/** |
|||
* Class AccessToken. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class AccessToken extends BaseAccessToken |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $endpointToGetToken = 'https://api.weixin.qq.com/cgi-bin/token'; |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
protected function getCredentials(): array |
|||
{ |
|||
return [ |
|||
'grant_type' => 'client_credential', |
|||
'appid' => $this->app['config']['app_id'], |
|||
'secret' => $this->app['config']['secret'], |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Auth; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Auth. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get session info by code. |
|||
* |
|||
* @param string $code |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function session(string $code) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
'secret' => $this->app['config']['secret'], |
|||
'js_code' => $code, |
|||
'grant_type' => 'authorization_code', |
|||
]; |
|||
|
|||
return $this->httpGet('sns/jscode2session', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Auth; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
!isset($app['access_token']) && $app['access_token'] = function ($app) { |
|||
return new AccessToken($app); |
|||
}; |
|||
|
|||
!isset($app['auth']) && $app['auth'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Base; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get paid unionid. |
|||
* |
|||
* @param string $openid |
|||
* @param array $options |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getPaidUnionid($openid, $options = []) |
|||
{ |
|||
return $this->httpGet('wxa/getpaidunionid', compact('openid') + $options); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Base; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['base'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\CustomerService; |
|||
|
|||
use EasyWeChat\OfficialAccount\CustomerService\Client; |
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['customer_service'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,174 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\DataCube; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get summary trend. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function summaryTrend(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappiddailysummarytrend', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get daily visit trend. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function dailyVisitTrend(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappiddailyvisittrend', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get weekly visit trend. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function weeklyVisitTrend(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappidweeklyvisittrend', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get monthly visit trend. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function monthlyVisitTrend(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappidmonthlyvisittrend', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get visit distribution. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function visitDistribution(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappidvisitdistribution', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get daily retain info. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function dailyRetainInfo(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappiddailyretaininfo', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get weekly retain info. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function weeklyRetainInfo(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappidweeklyretaininfo', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get monthly retain info. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function monthlyRetainInfo(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappidmonthlyretaininfo', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get visit page. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function visitPage(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappidvisitpage', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Get user portrait. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function userPortrait(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getweanalysisappiduserportrait', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* Unify query. |
|||
* |
|||
* @param string $api |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function query(string $api, string $from, string $to) |
|||
{ |
|||
$params = [ |
|||
'begin_date' => $from, |
|||
'end_date' => $to, |
|||
]; |
|||
|
|||
return $this->httpPostJson($api, $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\DataCube; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['data_cube'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram; |
|||
|
|||
use EasyWeChat\Kernel\Encryptor as BaseEncryptor; |
|||
use EasyWeChat\Kernel\Exceptions\DecryptException; |
|||
use EasyWeChat\Kernel\Support\AES; |
|||
|
|||
/** |
|||
* Class Encryptor. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Encryptor extends BaseEncryptor |
|||
{ |
|||
/** |
|||
* Decrypt data. |
|||
* |
|||
* @param string $sessionKey |
|||
* @param string $iv |
|||
* @param string $encrypted |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\DecryptException |
|||
*/ |
|||
public function decryptData(string $sessionKey, string $iv, string $encrypted): array |
|||
{ |
|||
$decrypted = AES::decrypt( |
|||
base64_decode($encrypted, false), base64_decode($sessionKey, false), base64_decode($iv, false) |
|||
); |
|||
|
|||
$decrypted = json_decode($this->pkcs7Unpad($decrypted), true); |
|||
|
|||
if (!$decrypted) { |
|||
throw new DecryptException('The given payload is invalid.'); |
|||
} |
|||
|
|||
return $decrypted; |
|||
} |
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Express; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author kehuanhuan <1152018701@qq.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function listProviders() |
|||
{ |
|||
return $this->httpGet('cgi-bin/express/business/delivery/getall'); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function createWaybill(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/order/add', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deleteWaybill(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/order/cancel', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getWaybill(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/order/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getWaybillTrack(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/path/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $deliveryId |
|||
* @param string $bizId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getBalance(string $deliveryId, string $bizId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/quota/get', [ |
|||
'delivery_id' => $deliveryId, |
|||
'biz_id' => $bizId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bindPrinter(string $openid) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/printer/update', [ |
|||
'update_type' => 'bind', |
|||
'openid' => $openid, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unbindPrinter(string $openid) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/express/business/printer/update', [ |
|||
'update_type' => 'unbind', |
|||
'openid' => $openid, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Express; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author kehuanhuan <1152018701@qq.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['express'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Mall; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class CartClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 导入收藏. |
|||
* |
|||
* @param array $params |
|||
* @param bool $isTest |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function add($params, $isTest = false) |
|||
{ |
|||
return $this->httpPostJson('mall/addshoppinglist', $params, ['is_test' => (int) $isTest]); |
|||
} |
|||
|
|||
/** |
|||
* 查询用户收藏信息. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function query($params) |
|||
{ |
|||
return $this->httpPostJson('mall/queryshoppinglist', $params, ['type' => 'batchquery']); |
|||
} |
|||
|
|||
/** |
|||
* 查询用户收藏信息. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function queryByPage($params) |
|||
{ |
|||
return $this->httpPostJson('mall/queryshoppinglist', $params, ['type' => 'getbypage']); |
|||
} |
|||
|
|||
/** |
|||
* 删除收藏. |
|||
* |
|||
* @param string $openid |
|||
* @param array $products |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete($openid, array $products = []) |
|||
{ |
|||
if (empty($products)) { |
|||
return $this->httpPostJson('mall/deletebizallshoppinglist', ['user_open_id' => $openid]); |
|||
} |
|||
|
|||
return $this->httpPostJson('mall/deleteshoppinglist', ['user_open_id' => $openid, 'sku_product_list' => $products]); |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Mall; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
* |
|||
* @property \EasyWeChat\MiniProgram\Mall\OrderClient $order |
|||
* @property \EasyWeChat\MiniProgram\Mall\CartClient $cart |
|||
* @property \EasyWeChat\MiniProgram\Mall\ProductClient $product |
|||
* @property \EasyWeChat\MiniProgram\Mall\MediaClient $media |
|||
*/ |
|||
class ForwardsMall |
|||
{ |
|||
/** |
|||
* @var \EasyWeChat\Kernel\ServiceContainer |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* @param \EasyWeChat\Kernel\ServiceContainer $app |
|||
*/ |
|||
public function __construct($app) |
|||
{ |
|||
$this->app = $app; |
|||
} |
|||
|
|||
/** |
|||
* @param string $property |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __get($property) |
|||
{ |
|||
return $this->app["mall.{$property}"]; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Mall; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class MediaClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 更新或导入媒体信息. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function import($params) |
|||
{ |
|||
return $this->httpPostJson('mall/importmedia', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Mall; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class OrderClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 导入订单. |
|||
* |
|||
* @param array $params |
|||
* @param bool $isHistory |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function add($params, $isHistory = false) |
|||
{ |
|||
return $this->httpPostJson('mall/importorder', $params, ['action' => 'add-order', 'is_history' => (int) $isHistory]); |
|||
} |
|||
|
|||
/** |
|||
* 导入订单. |
|||
* |
|||
* @param array $params |
|||
* @param bool $isHistory |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update($params, $isHistory = false) |
|||
{ |
|||
return $this->httpPostJson('mall/importorder', $params, ['action' => 'update-order', 'is_history' => (int) $isHistory]); |
|||
} |
|||
|
|||
/** |
|||
* 删除订单. |
|||
* |
|||
* @param string $openid |
|||
* @param string $orderId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete($openid, $orderId) |
|||
{ |
|||
$params = [ |
|||
'user_open_id' => $openid, |
|||
'order_id' => $orderId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('mall/deleteorder', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Mall; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ProductClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 更新或导入物品信息. |
|||
* |
|||
* @param array $params |
|||
* @param bool $isTest |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function import($params, $isTest = false) |
|||
{ |
|||
return $this->httpPostJson('mall/importproduct', $params, ['is_test' => (int) $isTest]); |
|||
} |
|||
|
|||
/** |
|||
* 查询物品信息. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function query($params) |
|||
{ |
|||
return $this->httpPostJson('mall/queryproduct', $params, ['type' => 'batchquery']); |
|||
} |
|||
|
|||
/** |
|||
* 小程序的物品是否可被搜索. |
|||
* |
|||
* @param bool $value |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setSearchable($value) |
|||
{ |
|||
return $this->httpPostJson('mall/brandmanage', ['can_be_search' => $value], ['action' => 'set_biz_can_be_search']); |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Mall; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['mall'] = function ($app) { |
|||
return new ForwardsMall($app); |
|||
}; |
|||
|
|||
$app['mall.order'] = function ($app) { |
|||
return new OrderClient($app); |
|||
}; |
|||
|
|||
$app['mall.cart'] = function ($app) { |
|||
return new CartClient($app); |
|||
}; |
|||
|
|||
$app['mall.product'] = function ($app) { |
|||
return new ProductClient($app); |
|||
}; |
|||
|
|||
$app['mall.media'] = function ($app) { |
|||
return new MediaClient($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\NearbyPoi; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author joyeekk <xygao2420@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Add nearby poi. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function add(array $params) |
|||
{ |
|||
$params = array_merge([ |
|||
'is_comm_nearby' => '1', |
|||
'poi_id' => '', |
|||
], $params); |
|||
|
|||
return $this->httpPostJson('wxa/addnearbypoi', $params); |
|||
} |
|||
|
|||
/** |
|||
* Update nearby poi. |
|||
* |
|||
* @param string $poiId |
|||
* @param array $params |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(string $poiId, array $params) |
|||
{ |
|||
$params = array_merge([ |
|||
'is_comm_nearby' => '1', |
|||
'poi_id' => $poiId, |
|||
], $params); |
|||
|
|||
return $this->httpPostJson('wxa/addnearbypoi', $params); |
|||
} |
|||
|
|||
/** |
|||
* Delete nearby poi. |
|||
* |
|||
* @param string $poiId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $poiId) |
|||
{ |
|||
return $this->httpPostJson('wxa/delnearbypoi', [ |
|||
'poi_id' => $poiId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Get nearby poi list. |
|||
* |
|||
* @param int $page |
|||
* @param int $pageRows |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list(int $page, int $pageRows) |
|||
{ |
|||
return $this->httpGet('wxa/getnearbypoilist', [ |
|||
'page' => $page, |
|||
'page_rows' => $pageRows, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Set nearby poi show status. |
|||
* |
|||
* @param string $poiId |
|||
* @param int $status |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setVisibility(string $poiId, int $status) |
|||
{ |
|||
if (!in_array($status, [0, 1], true)) { |
|||
throw new InvalidArgumentException('status should be 0 or 1.'); |
|||
} |
|||
|
|||
return $this->httpPostJson('wxa/setnearbypoishowstatus', [ |
|||
'poi_id' => $poiId, |
|||
'status' => $status, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\NearbyPoi; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author joyeekk <xygao2420@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['nearby_poi'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\OCR; |
|||
|
|||
use EasyWeChat\OfficialAccount\OCR\Client; |
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author joyeekk <xygao2420@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['ocr'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,96 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\OpenData; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author tianyong90 <412039588@qq.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $baseUri = 'https://api.weixin.qq.com/wxa/'; |
|||
|
|||
/** |
|||
* removeUserStorage. |
|||
* |
|||
* @param string $openid |
|||
* @param string $sessionKey |
|||
* @param array $key |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function removeUserStorage(string $openid, string $sessionKey, array $key) |
|||
{ |
|||
$data = ['key' => $key]; |
|||
$query = [ |
|||
'openid' => $openid, |
|||
'sig_method' => 'hmac_sha256', |
|||
'signature' => hash_hmac('sha256', json_encode($data), $sessionKey), |
|||
]; |
|||
|
|||
return $this->httpPostJson('remove_user_storage', $data, $query); |
|||
} |
|||
|
|||
/** |
|||
* setUserStorage. |
|||
* |
|||
* @param string $openid |
|||
* @param string $sessionKey |
|||
* @param array $kvList |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setUserStorage(string $openid, string $sessionKey, array $kvList) |
|||
{ |
|||
$kvList = $this->formatKVLists($kvList); |
|||
|
|||
$data = ['kv_list' => $kvList]; |
|||
$query = [ |
|||
'openid' => $openid, |
|||
'sig_method' => 'hmac_sha256', |
|||
'signature' => hash_hmac('sha256', json_encode($data), $sessionKey), |
|||
]; |
|||
|
|||
return $this->httpPostJson('set_user_storage', $data, $query); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function formatKVLists(array $params) |
|||
{ |
|||
$formatted = []; |
|||
|
|||
foreach ($params as $name => $value) { |
|||
$formatted[] = [ |
|||
'key' => $name, |
|||
'value' => strval($value), |
|||
]; |
|||
} |
|||
|
|||
return $formatted; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\OpenData; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['open_data'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Plugin; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param string $appId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function apply($appId) |
|||
{ |
|||
return $this->httpPostJson('wxa/plugin', [ |
|||
'action' => 'apply', |
|||
'plugin_appid' => $appId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpPostJson('wxa/plugin', [ |
|||
'action' => 'list', |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param string $appId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unbind($appId) |
|||
{ |
|||
return $this->httpPostJson('wxa/plugin', [ |
|||
'action' => 'unbind', |
|||
'plugin_appid' => $appId, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Plugin; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class DevClient. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class DevClient extends BaseClient |
|||
{ |
|||
/** |
|||
* Get users. |
|||
* |
|||
* @param int $page |
|||
* @param int $size |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getUsers(int $page = 1, int $size = 10) |
|||
{ |
|||
return $this->httpPostJson('wxa/devplugin', [ |
|||
'action' => 'dev_apply_list', |
|||
'page' => $page, |
|||
'num' => $size, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Agree to use plugin. |
|||
* |
|||
* @param string $appId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function agree(string $appId) |
|||
{ |
|||
return $this->httpPostJson('wxa/devplugin', [ |
|||
'action' => 'dev_agree', |
|||
'appid' => $appId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Refuse to use plugin. |
|||
* |
|||
* @param string $reason |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function refuse(string $reason) |
|||
{ |
|||
return $this->httpPostJson('wxa/devplugin', [ |
|||
'action' => 'dev_refuse', |
|||
'reason' => $reason, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Delete rejected applications. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete() |
|||
{ |
|||
return $this->httpPostJson('wxa/devplugin', [ |
|||
'action' => 'dev_delete', |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Plugin; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider 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 \Pimple\Container $app |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['plugin'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
|
|||
$app['plugin_dev'] = function ($app) { |
|||
return new DevClient($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Server; |
|||
|
|||
use EasyWeChat\MiniProgram\Encryptor; |
|||
use EasyWeChat\OfficialAccount\Server\Guard; |
|||
use EasyWeChat\OfficialAccount\Server\Handlers\EchoStrHandler; |
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
!isset($app['encryptor']) && $app['encryptor'] = function ($app) { |
|||
return new Encryptor( |
|||
$app['config']['app_id'], |
|||
$app['config']['token'], |
|||
$app['config']['aes_key'] |
|||
); |
|||
}; |
|||
|
|||
!isset($app['server']) && $app['server'] = function ($app) { |
|||
$guard = new Guard($app); |
|||
$guard->push(new EchoStrHandler($app)); |
|||
|
|||
return $guard; |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Soter; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author her-cat <hxhsoft@foxmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param string $openid |
|||
* @param string $json |
|||
* @param string $signature |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function verifySignature(string $openid, string $json, string $signature) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/soter/verify_signature', [ |
|||
'openid' => $openid, |
|||
'json_string' => $json, |
|||
'json_signature' => $signature, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\Soter; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author her-cat <hxhsoft@foxmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['soter'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,208 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\SubscribeMessage; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
use ReflectionClass; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author hugo <rabbitzhang52@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected $message = [ |
|||
'touser' => '', |
|||
'template_id' => '', |
|||
'page' => '', |
|||
'data' => [], |
|||
]; |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected $required = ['touser', 'template_id', 'data']; |
|||
|
|||
/** |
|||
* Send a template message. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function send(array $data = []) |
|||
{ |
|||
$params = $this->formatMessage($data); |
|||
|
|||
$this->restoreMessage(); |
|||
|
|||
return $this->httpPostJson('cgi-bin/message/subscribe/send', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
protected function formatMessage(array $data = []) |
|||
{ |
|||
$params = array_merge($this->message, $data); |
|||
|
|||
foreach ($params as $key => $value) { |
|||
if (in_array($key, $this->required, true) && empty($value) && empty($this->message[$key])) { |
|||
throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key)); |
|||
} |
|||
|
|||
$params[$key] = empty($value) ? $this->message[$key] : $value; |
|||
} |
|||
|
|||
foreach ($params['data'] as $key => $value) { |
|||
if (is_array($value)) { |
|||
if (isset($value['value'])) { |
|||
$params['data'][$key] = ['value' => $value['value']]; |
|||
|
|||
continue; |
|||
} |
|||
|
|||
if (count($value) >= 1) { |
|||
$value = [ |
|||
'value' => $value[0], |
|||
// 'color' => $value[1],// color unsupported |
|||
]; |
|||
} |
|||
} else { |
|||
$value = [ |
|||
'value' => strval($value), |
|||
]; |
|||
} |
|||
|
|||
$params['data'][$key] = $value; |
|||
} |
|||
|
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* Restore message. |
|||
*/ |
|||
protected function restoreMessage() |
|||
{ |
|||
$this->message = (new ReflectionClass(static::class))->getDefaultProperties()['message']; |
|||
} |
|||
|
|||
/** |
|||
* Combine templates and add them to your personal template library under your account. |
|||
* |
|||
* @param string $tid |
|||
* @param array $kidList |
|||
* @param string|null $sceneDesc |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function addTemplate(string $tid, array $kidList, string $sceneDesc = null) |
|||
{ |
|||
$sceneDesc = $sceneDesc ?? ''; |
|||
$data = \compact('tid', 'kidList', 'sceneDesc'); |
|||
|
|||
return $this->httpPost('wxaapi/newtmpl/addtemplate', $data); |
|||
} |
|||
|
|||
/** |
|||
* Delete personal template under account. |
|||
* |
|||
* @param string $id |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deleteTemplate(string $id) |
|||
{ |
|||
return $this->httpPost('wxaapi/newtmpl/deltemplate', ['priTmplId' => $id]); |
|||
} |
|||
|
|||
/** |
|||
* Get keyword list under template title. |
|||
* |
|||
* @param string $tid |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getTemplateKeywords(string $tid) |
|||
{ |
|||
return $this->httpGet('wxaapi/newtmpl/getpubtemplatekeywords', compact('tid')); |
|||
} |
|||
|
|||
/** |
|||
* Get the title of the public template under the category to which the account belongs. |
|||
* |
|||
* @param array $ids |
|||
* @param int $start |
|||
* @param int $limit |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getTemplateTitles(array $ids, int $start = 0, int $limit = 30) |
|||
{ |
|||
$ids = \implode(',', $ids); |
|||
$query = \compact('ids', 'start', 'limit'); |
|||
|
|||
return $this->httpGet('wxaapi/newtmpl/getpubtemplatetitles', $query); |
|||
} |
|||
|
|||
/** |
|||
* Get list of personal templates under the current account. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getTemplates() |
|||
{ |
|||
return $this->httpGet('wxaapi/newtmpl/gettemplate'); |
|||
} |
|||
|
|||
/** |
|||
* Get the category of the applet account. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getCategory() |
|||
{ |
|||
return $this->httpGet('wxaapi/newtmpl/getcategory'); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\SubscribeMessage; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['subscribe_message'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,114 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\TemplateMessage; |
|||
|
|||
use EasyWeChat\OfficialAccount\TemplateMessage\Client as BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
const API_SEND = 'cgi-bin/message/wxopen/template/send'; |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected $message = [ |
|||
'touser' => '', |
|||
'template_id' => '', |
|||
'page' => '', |
|||
'form_id' => '', |
|||
'data' => [], |
|||
'emphasis_keyword' => '', |
|||
]; |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected $required = ['touser', 'template_id', 'form_id']; |
|||
|
|||
/** |
|||
* @param int $offset |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(int $offset, int $count) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/template/library/list', compact('offset', 'count')); |
|||
} |
|||
|
|||
/** |
|||
* @param string $id |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(string $id) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/template/library/get', compact('id')); |
|||
} |
|||
|
|||
/** |
|||
* @param string $id |
|||
* @param array $keyword |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function add(string $id, array $keyword) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/template/add', [ |
|||
'id' => $id, |
|||
'keyword_id_list' => $keyword, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param string $templateId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $templateId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/template/del', [ |
|||
'template_id' => $templateId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param int $offset |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getTemplates(int $offset, int $count) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/template/list', compact('offset', 'count')); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\TemplateMessage; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['template_message'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,146 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\UniformMessage; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
use EasyWeChat\OfficialAccount\TemplateMessage\Client as BaseClient; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
const API_SEND = 'cgi-bin/message/wxopen/template/uniform_send'; |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $message = [ |
|||
'touser' => '', |
|||
]; |
|||
|
|||
/** |
|||
* Weapp Attributes. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $weappMessage = [ |
|||
'template_id' => '', |
|||
'page' => '', |
|||
'form_id' => '', |
|||
'data' => [], |
|||
'emphasis_keyword' => '', |
|||
]; |
|||
|
|||
/** |
|||
* Official account attributes. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $mpMessage = [ |
|||
'appid' => '', |
|||
'template_id' => '', |
|||
'url' => '', |
|||
'miniprogram' => [], |
|||
'data' => [], |
|||
]; |
|||
|
|||
/** |
|||
* Required attributes. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $required = ['touser', 'template_id', 'form_id', 'miniprogram', 'appid']; |
|||
|
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws InvalidArgumentException |
|||
*/ |
|||
protected function formatMessage(array $data = []) |
|||
{ |
|||
$params = array_merge($this->message, $data); |
|||
|
|||
if (empty($params['touser'])) { |
|||
throw new InvalidArgumentException(sprintf('Attribute "touser" can not be empty!')); |
|||
} |
|||
|
|||
if (!empty($params['weapp_template_msg'])) { |
|||
$params['weapp_template_msg'] = $this->formatWeappMessage($params['weapp_template_msg']); |
|||
} |
|||
|
|||
if (!empty($params['mp_template_msg'])) { |
|||
$params['mp_template_msg'] = $this->formatMpMessage($params['mp_template_msg']); |
|||
} |
|||
|
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
protected function formatWeappMessage(array $data = []) |
|||
{ |
|||
$params = $this->baseFormat($data, $this->weappMessage); |
|||
|
|||
$params['data'] = $this->formatData($params['data'] ?? []); |
|||
|
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
protected function formatMpMessage(array $data = []) |
|||
{ |
|||
$params = $this->baseFormat($data, $this->mpMessage); |
|||
|
|||
if (empty($params['miniprogram']['appid'])) { |
|||
$params['miniprogram']['appid'] = $this->app['config']['app_id']; |
|||
} |
|||
|
|||
$params['data'] = $this->formatData($params['data'] ?? []); |
|||
|
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* @param array $default |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
protected function baseFormat($data = [], $default = []) |
|||
{ |
|||
$params = array_merge($default, $data); |
|||
foreach ($params as $key => $value) { |
|||
if (in_array($key, $this->required, true) && empty($value) && empty($default[$key])) { |
|||
throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key)); |
|||
} |
|||
|
|||
$params[$key] = empty($value) ? $default[$key] : $value; |
|||
} |
|||
|
|||
return $params; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\MiniProgram\UniformMessage; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['uniform_message'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount; |
|||
|
|||
use EasyWeChat\BasicService; |
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
* |
|||
* @property \EasyWeChat\BasicService\Media\Client $media |
|||
* @property \EasyWeChat\BasicService\Url\Client $url |
|||
* @property \EasyWeChat\BasicService\QrCode\Client $qrcode |
|||
* @property \EasyWeChat\BasicService\Jssdk\Client $jssdk |
|||
* @property \EasyWeChat\OfficialAccount\Auth\AccessToken $access_token |
|||
* @property \EasyWeChat\OfficialAccount\Server\Guard $server |
|||
* @property \EasyWeChat\OfficialAccount\User\UserClient $user |
|||
* @property \EasyWeChat\OfficialAccount\User\TagClient $user_tag |
|||
* @property \EasyWeChat\OfficialAccount\Menu\Client $menu |
|||
* @property \EasyWeChat\OfficialAccount\TemplateMessage\Client $template_message |
|||
* @property \EasyWeChat\OfficialAccount\Material\Client $material |
|||
* @property \EasyWeChat\OfficialAccount\CustomerService\Client $customer_service |
|||
* @property \EasyWeChat\OfficialAccount\CustomerService\SessionClient $customer_service_session |
|||
* @property \EasyWeChat\OfficialAccount\Semantic\Client $semantic |
|||
* @property \EasyWeChat\OfficialAccount\DataCube\Client $data_cube |
|||
* @property \EasyWeChat\OfficialAccount\AutoReply\Client $auto_reply |
|||
* @property \EasyWeChat\OfficialAccount\Broadcasting\Client $broadcasting |
|||
* @property \EasyWeChat\OfficialAccount\Card\Card $card |
|||
* @property \EasyWeChat\OfficialAccount\Device\Client $device |
|||
* @property \EasyWeChat\OfficialAccount\ShakeAround\ShakeAround $shake_around |
|||
* @property \EasyWeChat\OfficialAccount\POI\Client $poi |
|||
* @property \EasyWeChat\OfficialAccount\Store\Client $store |
|||
* @property \EasyWeChat\OfficialAccount\Base\Client $base |
|||
* @property \EasyWeChat\OfficialAccount\Comment\Client $comment |
|||
* @property \EasyWeChat\OfficialAccount\OCR\Client $ocr |
|||
* @property \EasyWeChat\OfficialAccount\Goods\Client $goods |
|||
* @property \Overtrue\Socialite\Providers\WeChatProvider $oauth |
|||
* @property \EasyWeChat\OfficialAccount\WiFi\Client $wifi |
|||
* @property \EasyWeChat\OfficialAccount\WiFi\CardClient $wifi_card |
|||
* @property \EasyWeChat\OfficialAccount\WiFi\DeviceClient $wifi_device |
|||
* @property \EasyWeChat\OfficialAccount\WiFi\ShopClient $wifi_shop |
|||
*/ |
|||
class Application extends ServiceContainer |
|||
{ |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $providers = [ |
|||
Auth\ServiceProvider::class, |
|||
Server\ServiceProvider::class, |
|||
User\ServiceProvider::class, |
|||
OAuth\ServiceProvider::class, |
|||
Menu\ServiceProvider::class, |
|||
TemplateMessage\ServiceProvider::class, |
|||
Material\ServiceProvider::class, |
|||
CustomerService\ServiceProvider::class, |
|||
Semantic\ServiceProvider::class, |
|||
DataCube\ServiceProvider::class, |
|||
POI\ServiceProvider::class, |
|||
AutoReply\ServiceProvider::class, |
|||
Broadcasting\ServiceProvider::class, |
|||
Card\ServiceProvider::class, |
|||
Device\ServiceProvider::class, |
|||
ShakeAround\ServiceProvider::class, |
|||
Store\ServiceProvider::class, |
|||
Comment\ServiceProvider::class, |
|||
Base\ServiceProvider::class, |
|||
OCR\ServiceProvider::class, |
|||
Goods\ServiceProvider::class, |
|||
WiFi\ServiceProvider::class, |
|||
// Base services |
|||
BasicService\QrCode\ServiceProvider::class, |
|||
BasicService\Media\ServiceProvider::class, |
|||
BasicService\Url\ServiceProvider::class, |
|||
BasicService\Jssdk\ServiceProvider::class, |
|||
]; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Auth; |
|||
|
|||
use EasyWeChat\Kernel\AccessToken as BaseAccessToken; |
|||
|
|||
/** |
|||
* Class AuthorizerAccessToken. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class AccessToken extends BaseAccessToken |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $endpointToGetToken = 'https://api.weixin.qq.com/cgi-bin/token'; |
|||
|
|||
/** |
|||
* @return array |
|||
*/ |
|||
protected function getCredentials(): array |
|||
{ |
|||
return [ |
|||
'grant_type' => 'client_credential', |
|||
'appid' => $this->app['config']['app_id'], |
|||
'secret' => $this->app['config']['secret'], |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Auth; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
!isset($app['access_token']) && $app['access_token'] = function ($app) { |
|||
return new AccessToken($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\AutoReply; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get current auto reply settings. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function current() |
|||
{ |
|||
return $this->httpGet('cgi-bin/get_current_autoreply_info'); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\AutoReply; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['auto_reply'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Base; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Clear quota. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function clearQuota() |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/clear_quota', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get wechat callback ip. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getValidIps() |
|||
{ |
|||
return $this->httpGet('cgi-bin/getcallbackip'); |
|||
} |
|||
|
|||
/** |
|||
* Check the callback address network. |
|||
* |
|||
* @param string $action |
|||
* @param string $operator |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function checkCallbackUrl(string $action = 'all', string $operator = 'DEFAULT') |
|||
{ |
|||
if (!in_array($action, ['dns', 'ping', 'all'], true)) { |
|||
throw new InvalidArgumentException('The action must be dns, ping, all.'); |
|||
} |
|||
|
|||
$operator = strtoupper($operator); |
|||
|
|||
if (!in_array($operator, ['CHINANET', 'UNICOM', 'CAP', 'DEFAULT'], true)) { |
|||
throw new InvalidArgumentException('The operator must be CHINANET, UNICOM, CAP, DEFAULT.'); |
|||
} |
|||
|
|||
$params = [ |
|||
'action' => $action, |
|||
'check_operator' => $operator, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/callback/check', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Base; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['base'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,383 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Broadcasting; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Contracts\MessageInterface; |
|||
use EasyWeChat\Kernel\Exceptions\RuntimeException; |
|||
use EasyWeChat\Kernel\Messages\Card; |
|||
use EasyWeChat\Kernel\Messages\Image; |
|||
use EasyWeChat\Kernel\Messages\Media; |
|||
use EasyWeChat\Kernel\Messages\Text; |
|||
use EasyWeChat\Kernel\Support\Arr; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @method \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string previewTextByName($text, $name); |
|||
* @method \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string previewNewsByName($mediaId, $name); |
|||
* @method \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string previewVoiceByName($mediaId, $name); |
|||
* @method \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string previewImageByName($mediaId, $name); |
|||
* @method \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string previewVideoByName($message, $name); |
|||
* @method \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string previewCardByName($cardId, $name); |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
const PREVIEW_BY_OPENID = 'touser'; |
|||
const PREVIEW_BY_NAME = 'towxname'; |
|||
|
|||
/** |
|||
* Send a message. |
|||
* |
|||
* @param array $message |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function send(array $message) |
|||
{ |
|||
if (empty($message['filter']) && empty($message['touser'])) { |
|||
throw new RuntimeException('The message reception object is not specified'); |
|||
} |
|||
|
|||
$api = Arr::get($message, 'touser') ? 'cgi-bin/message/mass/send' : 'cgi-bin/message/mass/sendall'; |
|||
|
|||
return $this->httpPostJson($api, $message); |
|||
} |
|||
|
|||
/** |
|||
* Preview a message. |
|||
* |
|||
* @param array $message |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function preview(array $message) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/message/mass/preview', $message); |
|||
} |
|||
|
|||
/** |
|||
* Delete a broadcast. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $msgId, int $index = 0) |
|||
{ |
|||
$options = [ |
|||
'msg_id' => $msgId, |
|||
'article_idx' => $index, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/message/mass/delete', $options); |
|||
} |
|||
|
|||
/** |
|||
* Get a broadcast status. |
|||
* |
|||
* @param string $msgId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function status(string $msgId) |
|||
{ |
|||
$options = [ |
|||
'msg_id' => $msgId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/message/mass/get', $options); |
|||
} |
|||
|
|||
/** |
|||
* Send a text message. |
|||
* |
|||
* @param string $message |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendText(string $message, $reception = null, array $attributes = []) |
|||
{ |
|||
return $this->sendMessage(new Text($message), $reception, $attributes); |
|||
} |
|||
|
|||
/** |
|||
* Send a news message. |
|||
* |
|||
* @param string $mediaId |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendNews(string $mediaId, $reception = null, array $attributes = []) |
|||
{ |
|||
return $this->sendMessage(new Media($mediaId, 'mpnews'), $reception, $attributes); |
|||
} |
|||
|
|||
/** |
|||
* Send a voice message. |
|||
* |
|||
* @param string $mediaId |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendVoice(string $mediaId, $reception = null, array $attributes = []) |
|||
{ |
|||
return $this->sendMessage(new Media($mediaId, 'voice'), $reception, $attributes); |
|||
} |
|||
|
|||
/** |
|||
* Send a image message. |
|||
* |
|||
* @param string $mediaId |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendImage(string $mediaId, $reception = null, array $attributes = []) |
|||
{ |
|||
return $this->sendMessage(new Image($mediaId), $reception, $attributes); |
|||
} |
|||
|
|||
/** |
|||
* Send a video message. |
|||
* |
|||
* @param string $mediaId |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendVideo(string $mediaId, $reception = null, array $attributes = []) |
|||
{ |
|||
return $this->sendMessage(new Media($mediaId, 'mpvideo'), $reception, $attributes); |
|||
} |
|||
|
|||
/** |
|||
* Send a card message. |
|||
* |
|||
* @param string $cardId |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendCard(string $cardId, $reception = null, array $attributes = []) |
|||
{ |
|||
return $this->sendMessage(new Card($cardId), $reception, $attributes); |
|||
} |
|||
|
|||
/** |
|||
* Preview a text message. |
|||
* |
|||
* @param string $message message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewText(string $message, $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
return $this->previewMessage(new Text($message), $reception, $method); |
|||
} |
|||
|
|||
/** |
|||
* Preview a news message. |
|||
* |
|||
* @param string $mediaId message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewNews(string $mediaId, $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
return $this->previewMessage(new Media($mediaId, 'mpnews'), $reception, $method); |
|||
} |
|||
|
|||
/** |
|||
* Preview a voice message. |
|||
* |
|||
* @param string $mediaId message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewVoice(string $mediaId, $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
return $this->previewMessage(new Media($mediaId, 'voice'), $reception, $method); |
|||
} |
|||
|
|||
/** |
|||
* Preview a image message. |
|||
* |
|||
* @param string $mediaId message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewImage(string $mediaId, $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
return $this->previewMessage(new Image($mediaId), $reception, $method); |
|||
} |
|||
|
|||
/** |
|||
* Preview a video message. |
|||
* |
|||
* @param string $mediaId message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewVideo(string $mediaId, $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
return $this->previewMessage(new Media($mediaId, 'mpvideo'), $reception, $method); |
|||
} |
|||
|
|||
/** |
|||
* Preview a card message. |
|||
* |
|||
* @param string $cardId message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewCard(string $cardId, $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
return $this->previewMessage(new Card($cardId), $reception, $method); |
|||
} |
|||
|
|||
/** |
|||
* @param \EasyWeChat\Kernel\Contracts\MessageInterface $message |
|||
* @param string $reception |
|||
* @param string $method |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function previewMessage(MessageInterface $message, string $reception, $method = self::PREVIEW_BY_OPENID) |
|||
{ |
|||
$message = (new MessageBuilder())->message($message)->buildForPreview($method, $reception); |
|||
|
|||
return $this->preview($message); |
|||
} |
|||
|
|||
/** |
|||
* @param \EasyWeChat\Kernel\Contracts\MessageInterface $message |
|||
* @param mixed $reception |
|||
* @param array $attributes |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function sendMessage(MessageInterface $message, $reception = null, $attributes = []) |
|||
{ |
|||
$message = (new MessageBuilder())->message($message)->with($attributes)->toAll(); |
|||
|
|||
if (\is_int($reception)) { |
|||
$message->toTag($reception); |
|||
} elseif (\is_array($reception)) { |
|||
$message->toUsers($reception); |
|||
} |
|||
|
|||
return $this->send($message->build()); |
|||
} |
|||
|
|||
/** |
|||
* @codeCoverageIgnore |
|||
* |
|||
* @param string $method |
|||
* @param array $args |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __call($method, $args) |
|||
{ |
|||
if (strpos($method, 'ByName') > 0) { |
|||
$method = strstr($method, 'ByName', true); |
|||
|
|||
if (method_exists($this, $method)) { |
|||
array_push($args, self::PREVIEW_BY_NAME); |
|||
|
|||
return $this->$method(...$args); |
|||
} |
|||
} |
|||
|
|||
throw new \BadMethodCallException(sprintf('Method %s not exists.', $method)); |
|||
} |
|||
} |
|||
@ -0,0 +1,162 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Broadcasting; |
|||
|
|||
use EasyWeChat\Kernel\Contracts\MessageInterface; |
|||
use EasyWeChat\Kernel\Exceptions\RuntimeException; |
|||
|
|||
/** |
|||
* Class MessageBuilder. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class MessageBuilder |
|||
{ |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $to = []; |
|||
|
|||
/** |
|||
* @var \EasyWeChat\Kernel\Contracts\MessageInterface |
|||
*/ |
|||
protected $message; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $attributes = []; |
|||
|
|||
/** |
|||
* Set message. |
|||
* |
|||
* @param \EasyWeChat\Kernel\Contracts\MessageInterface $message |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function message(MessageInterface $message) |
|||
{ |
|||
$this->message = $message; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Set target user or group. |
|||
* |
|||
* @param array $to |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function to(array $to) |
|||
{ |
|||
$this->to = $to; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @param int $tagId |
|||
* |
|||
* @return \EasyWeChat\OfficialAccount\Broadcasting\MessageBuilder |
|||
*/ |
|||
public function toTag(int $tagId) |
|||
{ |
|||
$this->to([ |
|||
'filter' => [ |
|||
'is_to_all' => false, |
|||
'tag_id' => $tagId, |
|||
], |
|||
]); |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @param array $openids |
|||
* |
|||
* @return \EasyWeChat\OfficialAccount\Broadcasting\MessageBuilder |
|||
*/ |
|||
public function toUsers(array $openids) |
|||
{ |
|||
$this->to([ |
|||
'touser' => $openids, |
|||
]); |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @return $this |
|||
*/ |
|||
public function toAll() |
|||
{ |
|||
$this->to([ |
|||
'filter' => ['is_to_all' => true], |
|||
]); |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @param array $attributes |
|||
* |
|||
* @return \EasyWeChat\OfficialAccount\Broadcasting\MessageBuilder |
|||
*/ |
|||
public function with(array $attributes) |
|||
{ |
|||
$this->attributes = $attributes; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Build message. |
|||
* |
|||
* @param array $prepends |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function build(array $prepends = []): array |
|||
{ |
|||
if (empty($this->message)) { |
|||
throw new RuntimeException('No message content to send.'); |
|||
} |
|||
|
|||
$content = $this->message->transformForJsonRequest(); |
|||
|
|||
if (empty($prepends)) { |
|||
$prepends = $this->to; |
|||
} |
|||
|
|||
$message = array_merge($prepends, $content, $this->attributes); |
|||
|
|||
return $message; |
|||
} |
|||
|
|||
/** |
|||
* Build preview message. |
|||
* |
|||
* @param string $by |
|||
* @param string $user |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function buildForPreview(string $by, string $user): array |
|||
{ |
|||
return $this->build([$by => $user]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Broadcasting; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['broadcasting'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
/** |
|||
* Class BoardingPassClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class BoardingPassClient extends Client |
|||
{ |
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function checkin(array $params) |
|||
{ |
|||
return $this->httpPostJson('card/boardingpass/checkin', $params); |
|||
} |
|||
} |
|||
@ -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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class Card. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
* |
|||
* @property \EasyWeChat\OfficialAccount\Card\CodeClient $code |
|||
* @property \EasyWeChat\OfficialAccount\Card\MeetingTicketClient $meeting_ticket |
|||
* @property \EasyWeChat\OfficialAccount\Card\MemberCardClient $member_card |
|||
* @property \EasyWeChat\OfficialAccount\Card\GeneralCardClient $general_card |
|||
* @property \EasyWeChat\OfficialAccount\Card\MovieTicketClient $movie_ticket |
|||
* @property \EasyWeChat\OfficialAccount\Card\CoinClient $coin |
|||
* @property \EasyWeChat\OfficialAccount\Card\SubMerchantClient $sub_merchant |
|||
* @property \EasyWeChat\OfficialAccount\Card\BoardingPassClient $boarding_pass |
|||
* @property \EasyWeChat\OfficialAccount\Card\JssdkClient $jssdk |
|||
* @property \EasyWeChat\OfficialAccount\Card\GiftCardClient $gift_card |
|||
* @property \EasyWeChat\OfficialAccount\Card\GiftCardOrderClient $gift_card_order |
|||
* @property \EasyWeChat\OfficialAccount\Card\GiftCardPageClient $gift_card_page |
|||
* @property \EasyWeChat\OfficialAccount\Card\InvoiceClient $invoice |
|||
*/ |
|||
class Card extends Client |
|||
{ |
|||
/** |
|||
* @param string $property |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public function __get($property) |
|||
{ |
|||
if (isset($this->app["card.{$property}"])) { |
|||
return $this->app["card.{$property}"]; |
|||
} |
|||
|
|||
throw new InvalidArgumentException(sprintf('No card service named "%s".', $property)); |
|||
} |
|||
} |
|||
@ -0,0 +1,428 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Traits\InteractsWithCache; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
use InteractsWithCache; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $url; |
|||
|
|||
/** |
|||
* Ticket cache key. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $ticketCacheKey; |
|||
|
|||
/** |
|||
* Ticket cache prefix. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $ticketCachePrefix = 'easywechat.official_account.card.api_ticket.'; |
|||
|
|||
/** |
|||
* 获取卡券颜色. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function colors() |
|||
{ |
|||
return $this->httpGet('card/getcolors'); |
|||
} |
|||
|
|||
/** |
|||
* 卡券开放类目查询接口. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function categories() |
|||
{ |
|||
return $this->httpGet('card/getapplyprotocol'); |
|||
} |
|||
|
|||
/** |
|||
* 创建卡券. |
|||
* |
|||
* @param string $cardType |
|||
* @param array $attributes |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create($cardType = 'member_card', array $attributes) |
|||
{ |
|||
$params = [ |
|||
'card' => [ |
|||
'card_type' => strtoupper($cardType), |
|||
strtolower($cardType) => $attributes, |
|||
], |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/create', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查看卡券详情. |
|||
* |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get($cardId) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* 批量查询卡列表. |
|||
* |
|||
* @param int $offset |
|||
* @param int $count |
|||
* @param string $statusList |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list($offset = 0, $count = 10, $statusList = 'CARD_STATUS_VERIFY_OK') |
|||
{ |
|||
$params = [ |
|||
'offset' => $offset, |
|||
'count' => $count, |
|||
'status_list' => $statusList, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/batchget', $params); |
|||
} |
|||
|
|||
/** |
|||
* 更改卡券信息接口 and 设置跟随推荐接口. |
|||
* |
|||
* @param string $cardId |
|||
* @param string $type |
|||
* @param array $attributes |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update($cardId, $type, array $attributes = []) |
|||
{ |
|||
$card = []; |
|||
$card['card_id'] = $cardId; |
|||
$card[strtolower($type)] = $attributes; |
|||
|
|||
return $this->httpPostJson('card/update', $card); |
|||
} |
|||
|
|||
/** |
|||
* 删除卡券接口. |
|||
* |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete($cardId) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/delete', $params); |
|||
} |
|||
|
|||
/** |
|||
* 创建二维码. |
|||
* |
|||
* @param array $cards |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function createQrCode(array $cards) |
|||
{ |
|||
return $this->httpPostJson('card/qrcode/create', $cards); |
|||
} |
|||
|
|||
/** |
|||
* ticket 换取二维码图片. |
|||
* |
|||
* @param string $ticket |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getQrCode($ticket) |
|||
{ |
|||
$baseUri = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'; |
|||
$params = [ |
|||
'ticket' => $ticket, |
|||
]; |
|||
|
|||
$response = $this->requestRaw($baseUri, 'GET', $params); |
|||
|
|||
return [ |
|||
'status' => $response->getStatusCode(), |
|||
'reason' => $response->getReasonPhrase(), |
|||
'headers' => $response->getHeaders(), |
|||
'body' => strval($response->getBody()), |
|||
'url' => $baseUri.'?'.http_build_query($params), |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* 通过ticket换取二维码 链接. |
|||
* |
|||
* @param string $ticket |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getQrCodeUrl($ticket) |
|||
{ |
|||
return sprintf('https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s', $ticket); |
|||
} |
|||
|
|||
/** |
|||
* 创建货架接口. |
|||
* |
|||
* @param string $banner |
|||
* @param string $pageTitle |
|||
* @param bool $canShare |
|||
* @param string $scene [SCENE_NEAR_BY 附近,SCENE_MENU 自定义菜单,SCENE_QRCODE 二维码,SCENE_ARTICLE 公众号文章, |
|||
* SCENE_H5 h5页面,SCENE_IVR 自动回复,SCENE_CARD_CUSTOM_CELL 卡券自定义cell] |
|||
* @param array $cardList |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function createLandingPage($banner, $pageTitle, $canShare, $scene, $cardList) |
|||
{ |
|||
$params = [ |
|||
'banner' => $banner, |
|||
'page_title' => $pageTitle, |
|||
'can_share' => $canShare, |
|||
'scene' => $scene, |
|||
'card_list' => $cardList, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/landingpage/create', $params); |
|||
} |
|||
|
|||
/** |
|||
* 图文消息群发卡券. |
|||
* |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getHtml($cardId) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/mpnews/gethtml', $params); |
|||
} |
|||
|
|||
/** |
|||
* 设置测试白名单. |
|||
* |
|||
* @param array $openids |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setTestWhitelist($openids) |
|||
{ |
|||
$params = [ |
|||
'openid' => $openids, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/testwhitelist/set', $params); |
|||
} |
|||
|
|||
/** |
|||
* 设置测试白名单(by username). |
|||
* |
|||
* @param array $usernames |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setTestWhitelistByName(array $usernames) |
|||
{ |
|||
$params = [ |
|||
'username' => $usernames, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/testwhitelist/set', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取用户已领取卡券接口. |
|||
* |
|||
* @param string $openid |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getUserCards($openid, $cardId = '') |
|||
{ |
|||
$params = [ |
|||
'openid' => $openid, |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/user/getcardlist', $params); |
|||
} |
|||
|
|||
/** |
|||
* 设置微信买单接口. |
|||
* 设置买单的 card_id 必须已经配置了门店,否则会报错. |
|||
* |
|||
* @param string $cardId |
|||
* @param bool $isOpen |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setPayCell($cardId, $isOpen = true) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
'is_open' => $isOpen, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/paycell/set', $params); |
|||
} |
|||
|
|||
/** |
|||
* 设置自助核销接口 |
|||
* 设置买单的 card_id 必须已经配置了门店,否则会报错. |
|||
* |
|||
* @param string $cardId |
|||
* @param bool $isOpen |
|||
* @param bool $verifyCod |
|||
* @param bool $remarkAmount |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function setPayConsumeCell($cardId, $isOpen = true, $verifyCod = false, $remarkAmount = false) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
'is_open' => $isOpen, |
|||
'need_verify_cod' => $verifyCod, |
|||
'need_remark_amount' => $remarkAmount, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/selfconsumecell/set', $params); |
|||
} |
|||
|
|||
/** |
|||
* 增加库存. |
|||
* |
|||
* @param string $cardId |
|||
* @param int $amount |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function increaseStock($cardId, $amount) |
|||
{ |
|||
return $this->updateStock($cardId, $amount, 'increase'); |
|||
} |
|||
|
|||
/** |
|||
* 减少库存. |
|||
* |
|||
* @param string $cardId |
|||
* @param int $amount |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function reduceStock($cardId, $amount) |
|||
{ |
|||
return $this->updateStock($cardId, $amount, 'reduce'); |
|||
} |
|||
|
|||
/** |
|||
* 修改库存接口. |
|||
* |
|||
* @param string $cardId |
|||
* @param int $amount |
|||
* @param string $action |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function updateStock($cardId, $amount, $action = 'increase') |
|||
{ |
|||
$key = 'increase' === $action ? 'increase_stock_value' : 'reduce_stock_value'; |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
$key => abs($amount), |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/modifystock', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,193 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class CodeClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class CodeClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 导入code接口. |
|||
* |
|||
* @param string $cardId |
|||
* @param array $codes |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deposit(string $cardId, array $codes) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
'code' => $codes, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/deposit', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询导入code数目. |
|||
* |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getDepositedCount(string $cardId) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/getdepositcount', $params); |
|||
} |
|||
|
|||
/** |
|||
* 核查code接口. |
|||
* |
|||
* @param string $cardId |
|||
* @param array $codes |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function check(string $cardId, array $codes) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
'code' => $codes, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/checkcode', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询 Code 接口. |
|||
* |
|||
* @param string $code |
|||
* @param string $cardId |
|||
* @param bool $checkConsume |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(string $code, string $cardId = '', bool $checkConsume = true) |
|||
{ |
|||
$params = [ |
|||
'code' => $code, |
|||
'check_consume' => $checkConsume, |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* 更改Code接口. |
|||
* |
|||
* @param string $code |
|||
* @param string $newCode |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(string $code, string $newCode, string $cardId = '') |
|||
{ |
|||
$params = [ |
|||
'code' => $code, |
|||
'new_code' => $newCode, |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/update', $params); |
|||
} |
|||
|
|||
/** |
|||
* 设置卡券失效. |
|||
* |
|||
* @param string $code |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function disable(string $code, string $cardId = '') |
|||
{ |
|||
$params = [ |
|||
'code' => $code, |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/unavailable', $params); |
|||
} |
|||
|
|||
/** |
|||
* 核销 Code 接口. |
|||
* |
|||
* @param string $code |
|||
* @param string|null $cardId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function consume(string $code, string $cardId = null) |
|||
{ |
|||
$params = [ |
|||
'code' => $code, |
|||
]; |
|||
|
|||
if (!is_null($cardId)) { |
|||
$params['card_id'] = $cardId; |
|||
} |
|||
|
|||
return $this->httpPostJson('card/code/consume', $params); |
|||
} |
|||
|
|||
/** |
|||
* Code解码接口. |
|||
* |
|||
* @param string $encryptedCode |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function decrypt(string $encryptedCode) |
|||
{ |
|||
$params = [ |
|||
'encrypt_code' => $encryptedCode, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/code/decrypt', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,119 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class CoinClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class CoinClient extends BaseClient |
|||
{ |
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function activate() |
|||
{ |
|||
return $this->httpGet('card/pay/activate'); |
|||
} |
|||
|
|||
/** |
|||
* @param string $cardId |
|||
* @param int $quantity |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getPrice(string $cardId, int $quantity) |
|||
{ |
|||
return $this->httpPostJson('card/pay/getpayprice', [ |
|||
'card_id' => $cardId, |
|||
'quantity' => $quantity, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function summary() |
|||
{ |
|||
return $this->httpGet('card/pay/getcoinsinfo'); |
|||
} |
|||
|
|||
/** |
|||
* @param int $count |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function recharge(int $count) |
|||
{ |
|||
return $this->httpPostJson('card/pay/recharge', [ |
|||
'coin_count' => $count, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param string $orderId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function order(string $orderId) |
|||
{ |
|||
return $this->httpPostJson('card/pay/getorder', ['order_id' => $orderId]); |
|||
} |
|||
|
|||
/** |
|||
* @param array $filters |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function orders(array $filters) |
|||
{ |
|||
return $this->httpPostJson('card/pay/getorderlist', $filters); |
|||
} |
|||
|
|||
/** |
|||
* @param string $cardId |
|||
* @param string $orderId |
|||
* @param int $quantity |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function confirm(string $cardId, string $orderId, int $quantity) |
|||
{ |
|||
return $this->httpPostJson('card/pay/confirm', [ |
|||
'card_id' => $cardId, |
|||
'order_id' => $orderId, |
|||
'quantity' => $quantity, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
/** |
|||
* Class GeneralCardClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class GeneralCardClient extends Client |
|||
{ |
|||
/** |
|||
* 通用卡接口激活. |
|||
* |
|||
* @param array $info |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function activate(array $info = []) |
|||
{ |
|||
return $this->httpPostJson('card/generalcard/activate', $info); |
|||
} |
|||
|
|||
/** |
|||
* 通用卡撤销激活. |
|||
* |
|||
* @param string $cardId |
|||
* @param string $code |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deactivate(string $cardId, string $code) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
'code' => $code, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/generalcard/unactivate', $params); |
|||
} |
|||
|
|||
/** |
|||
* 更新会员信息. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateUser(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('card/generalcard/updateuser', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class GiftCardClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class GiftCardClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 申请微信支付礼品卡权限接口. |
|||
* |
|||
* @param string $subMchId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function add(string $subMchId) |
|||
{ |
|||
$params = [ |
|||
'sub_mch_id' => $subMchId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/pay/whitelist/add', $params); |
|||
} |
|||
|
|||
/** |
|||
* 绑定商户号到礼品卡小程序接口(商户号必须为公众号申请的商户号,否则报错). |
|||
* |
|||
* @param string $subMchId |
|||
* @param string $wxaAppid |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function bind(string $subMchId, string $wxaAppid) |
|||
{ |
|||
$params = [ |
|||
'sub_mch_id' => $subMchId, |
|||
'wxa_appid' => $wxaAppid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/pay/submch/bind', $params); |
|||
} |
|||
|
|||
/** |
|||
* 上传小程序代码. |
|||
* |
|||
* @param string $wxaAppid |
|||
* @param string $pageId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function set(string $wxaAppid, string $pageId) |
|||
{ |
|||
$params = [ |
|||
'wxa_appid' => $wxaAppid, |
|||
'page_id' => $pageId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/wxa/set', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class GiftCardOrderClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class GiftCardOrderClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 查询-单个礼品卡订单信息接口. |
|||
* |
|||
* @param string $orderId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function get(string $orderId) |
|||
{ |
|||
$params = [ |
|||
'order_id' => $orderId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/order/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询-批量查询礼品卡订单信息接口. |
|||
* |
|||
* @param int $beginTime |
|||
* @param int $endTime |
|||
* @param int $offset |
|||
* @param int $count |
|||
* @param string $sortType |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function list(int $beginTime, int $endTime, int $offset = 0, int $count = 10, string $sortType = 'ASC') |
|||
{ |
|||
$params = [ |
|||
'begin_time' => $beginTime, |
|||
'end_time' => $endTime, |
|||
'sort_type' => $sortType, |
|||
'offset' => $offset, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/order/batchget', $params); |
|||
} |
|||
|
|||
/** |
|||
* 退款接口. |
|||
* |
|||
* @param string $orderId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function refund(string $orderId) |
|||
{ |
|||
$params = [ |
|||
'order_id' => $orderId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/order/refund', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class GiftCardPageClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class GiftCardPageClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 创建-礼品卡货架接口. |
|||
* |
|||
* @param array $attributes |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function add(array $attributes) |
|||
{ |
|||
$params = [ |
|||
'page' => $attributes, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/page/add', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询-礼品卡货架信息接口. |
|||
* |
|||
* @param string $pageId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function get(string $pageId) |
|||
{ |
|||
$params = [ |
|||
'page_id' => $pageId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/page/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* 修改-礼品卡货架信息接口. |
|||
* |
|||
* @param string $pageId |
|||
* @param string $bannerPicUrl |
|||
* @param array $themeList |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function update(string $pageId, string $bannerPicUrl, array $themeList) |
|||
{ |
|||
$params = [ |
|||
'page' => [ |
|||
'page_id' => $pageId, |
|||
'banner_pic_url' => $bannerPicUrl, |
|||
'theme_list' => $themeList, |
|||
], |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/page/update', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询-礼品卡货架列表接口. |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpPostJson('card/giftcard/page/batchget'); |
|||
} |
|||
|
|||
/** |
|||
* 下架-礼品卡货架接口(下架某一个货架或者全部货架). |
|||
* |
|||
* @param string $pageId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function setMaintain(string $pageId = '') |
|||
{ |
|||
$params = ($pageId ? ['page_id' => $pageId] : ['all' => true]) + [ |
|||
'maintain' => true, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/giftcard/maintain/set', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,113 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class InvoiceClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class InvoiceClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 设置支付后开票信息接口. |
|||
* |
|||
* @param string $mchid |
|||
* @param string $sPappid |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function set(string $mchid, string $sPappid) |
|||
{ |
|||
$params = [ |
|||
'paymch_info' => [ |
|||
'mchid' => $mchid, |
|||
's_pappid' => $sPappid, |
|||
], |
|||
]; |
|||
|
|||
return $this->setBizAttr('set_pay_mch', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询支付后开票信息接口. |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function get() |
|||
{ |
|||
return $this->setBizAttr('get_pay_mch'); |
|||
} |
|||
|
|||
/** |
|||
* 设置授权页字段信息接口. |
|||
* |
|||
* @param array $userData |
|||
* @param array $bizData |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function setAuthField(array $userData, array $bizData) |
|||
{ |
|||
$params = [ |
|||
'auth_field' => [ |
|||
'user_field' => $userData, |
|||
'biz_field' => $bizData, |
|||
], |
|||
]; |
|||
|
|||
return $this->setBizAttr('set_auth_field', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询授权页字段信息接口. |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function getAuthField() |
|||
{ |
|||
return $this->setBizAttr('get_auth_field'); |
|||
} |
|||
|
|||
/** |
|||
* 查询开票信息. |
|||
* |
|||
* @param string $orderId |
|||
* @param string $appId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function getAuthData(string $appId, string $orderId) |
|||
{ |
|||
$params = [ |
|||
'order_id' => $orderId, |
|||
's_appid' => $appId, |
|||
]; |
|||
|
|||
return $this->httpPost('card/invoice/getauthdata', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $action |
|||
* @param array $params |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
private function setBizAttr(string $action, array $params = []) |
|||
{ |
|||
return $this->httpPostJson('card/invoice/setbizattr', $params, ['action' => $action]); |
|||
} |
|||
} |
|||
@ -0,0 +1,85 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\BasicService\Jssdk\Client as Jssdk; |
|||
use EasyWeChat\Kernel\Support\Arr; |
|||
use function EasyWeChat\Kernel\Support\str_random; |
|||
|
|||
/** |
|||
* Class Jssdk. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class JssdkClient extends Jssdk |
|||
{ |
|||
/** |
|||
* @param bool $refresh |
|||
* @param string $type |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \Psr\SimpleCache\InvalidArgumentException |
|||
*/ |
|||
public function getTicket(bool $refresh = false, string $type = 'wx_card'): array |
|||
{ |
|||
return parent::getTicket($refresh, $type); |
|||
} |
|||
|
|||
/** |
|||
* 微信卡券:JSAPI 卡券发放. |
|||
* |
|||
* @param array $cards |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function assign(array $cards) |
|||
{ |
|||
return json_encode(array_map(function ($card) { |
|||
return $this->attachExtension($card['card_id'], $card); |
|||
}, $cards)); |
|||
} |
|||
|
|||
/** |
|||
* 生成 js添加到卡包 需要的 card_list 项. |
|||
* |
|||
* @param string $cardId |
|||
* @param array $extension |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \Psr\SimpleCache\InvalidArgumentException |
|||
*/ |
|||
public function attachExtension($cardId, array $extension = []) |
|||
{ |
|||
$timestamp = time(); |
|||
$nonce = str_random(6); |
|||
$ticket = $this->getTicket()['ticket']; |
|||
|
|||
$ext = array_merge(['timestamp' => $timestamp, 'nonce_str' => $nonce], Arr::only( |
|||
$extension, |
|||
['code', 'openid', 'outer_id', 'balance', 'fixed_begintimestamp', 'outer_str'] |
|||
)); |
|||
|
|||
$ext['signature'] = $this->dictionaryOrderSignature($ticket, $timestamp, $cardId, $ext['code'] ?? '', $ext['openid'] ?? '', $nonce); |
|||
|
|||
return [ |
|||
'cardId' => $cardId, |
|||
'cardExt' => json_encode($ext), |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
/** |
|||
* Class MeetingTicketClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class MeetingTicketClient extends Client |
|||
{ |
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateUser(array $params) |
|||
{ |
|||
return $this->httpPostJson('card/meetingticket/updateuser', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
/** |
|||
* Class MemberCardClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class MemberCardClient extends Client |
|||
{ |
|||
/** |
|||
* 会员卡接口激活. |
|||
* |
|||
* @param array $info |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function activate(array $info = []) |
|||
{ |
|||
return $this->httpPostJson('card/membercard/activate', $info); |
|||
} |
|||
|
|||
/** |
|||
* 设置开卡字段接口. |
|||
* |
|||
* @param string $cardId |
|||
* @param array $settings |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setActivationForm(string $cardId, array $settings) |
|||
{ |
|||
$params = array_merge(['card_id' => $cardId], $settings); |
|||
|
|||
return $this->httpPostJson('card/membercard/activateuserform/set', $params); |
|||
} |
|||
|
|||
/** |
|||
* 拉取会员信息接口. |
|||
* |
|||
* @param string $cardId |
|||
* @param string $code |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getUser(string $cardId, string $code) |
|||
{ |
|||
$params = [ |
|||
'card_id' => $cardId, |
|||
'code' => $code, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/membercard/userinfo/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* 更新会员信息. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateUser(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('card/membercard/updateuser', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取用户提交资料. |
|||
* |
|||
* @param string $activateTicket |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getActivationForm($activateTicket) |
|||
{ |
|||
$params = [ |
|||
'activate_ticket' => $activateTicket, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/membercard/activatetempinfo/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取开卡组件链接接口. |
|||
* |
|||
* @param array $params 包含会员卡ID和随机字符串 |
|||
* |
|||
* @return string 开卡组件链接 |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getActivateUrl(array $params = []) |
|||
{ |
|||
return $this->httpPostJson('card/membercard/activate/geturl', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
/** |
|||
* Class MovieTicketClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class MovieTicketClient extends Client |
|||
{ |
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateUser(array $params) |
|||
{ |
|||
return $this->httpPostJson('card/movieticket/updateuser', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['card'] = function ($app) { |
|||
return new Card($app); |
|||
}; |
|||
|
|||
$app['card.client'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
|
|||
$app['card.coin'] = function ($app) { |
|||
return new CoinClient($app); |
|||
}; |
|||
|
|||
$app['card.sub_merchant'] = function ($app) { |
|||
return new SubMerchantClient($app); |
|||
}; |
|||
|
|||
$app['card.code'] = function ($app) { |
|||
return new CodeClient($app); |
|||
}; |
|||
|
|||
$app['card.movie_ticket'] = function ($app) { |
|||
return new MovieTicketClient($app); |
|||
}; |
|||
|
|||
$app['card.member_card'] = function ($app) { |
|||
return new MemberCardClient($app); |
|||
}; |
|||
|
|||
$app['card.general_card'] = function ($app) { |
|||
return new GeneralCardClient($app); |
|||
}; |
|||
|
|||
$app['card.boarding_pass'] = function ($app) { |
|||
return new BoardingPassClient($app); |
|||
}; |
|||
|
|||
$app['card.meeting_ticket'] = function ($app) { |
|||
return new MeetingTicketClient($app); |
|||
}; |
|||
|
|||
$app['card.jssdk'] = function ($app) { |
|||
return new JssdkClient($app); |
|||
}; |
|||
|
|||
$app['card.gift_card'] = function ($app) { |
|||
return new GiftCardClient($app); |
|||
}; |
|||
|
|||
$app['card.gift_card_order'] = function ($app) { |
|||
return new GiftCardOrderClient($app); |
|||
}; |
|||
|
|||
$app['card.gift_card_page'] = function ($app) { |
|||
return new GiftCardPageClient($app); |
|||
}; |
|||
|
|||
$app['card.invoice'] = function ($app) { |
|||
return new InvoiceClient($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,121 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Card; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Support\Arr; |
|||
|
|||
/** |
|||
* Class SubMerchantClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class SubMerchantClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 添加子商户. |
|||
* |
|||
* @param array $info |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(array $info = []) |
|||
{ |
|||
$params = [ |
|||
'info' => Arr::only($info, [ |
|||
'brand_name', |
|||
'logo_url', |
|||
'protocol', |
|||
'end_time', |
|||
'primary_category_id', |
|||
'secondary_category_id', |
|||
'agreement_media_id', |
|||
'operator_media_id', |
|||
'app_id', |
|||
]), |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/submerchant/submit', $params); |
|||
} |
|||
|
|||
/** |
|||
* 更新子商户. |
|||
* |
|||
* @param int $merchantId |
|||
* @param array $info |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(int $merchantId, array $info = []) |
|||
{ |
|||
$params = [ |
|||
'info' => array_merge(['merchant_id' => $merchantId], |
|||
Arr::only($info, [ |
|||
'brand_name', |
|||
'logo_url', |
|||
'protocol', |
|||
'end_time', |
|||
'primary_category_id', |
|||
'secondary_category_id', |
|||
'agreement_media_id', |
|||
'operator_media_id', |
|||
'app_id', |
|||
])), |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/submerchant/update', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取子商户信息. |
|||
* |
|||
* @param int $merchantId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(int $merchantId) |
|||
{ |
|||
return $this->httpPostJson('card/submerchant/get', ['merchant_id' => $merchantId]); |
|||
} |
|||
|
|||
/** |
|||
* 批量获取子商户信息. |
|||
* |
|||
* @param int $beginId |
|||
* @param int $limit |
|||
* @param string $status |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(int $beginId = 0, int $limit = 50, string $status = 'CHECKING') |
|||
{ |
|||
$params = [ |
|||
'begin_id' => $beginId, |
|||
'limit' => $limit, |
|||
'status' => $status, |
|||
]; |
|||
|
|||
return $this->httpPostJson('card/submerchant/batchget', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,208 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Comment; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Open article comment. |
|||
* |
|||
* @param string $msgId |
|||
* @param int|null $index |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function open(string $msgId, int $index = null) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/open', $params); |
|||
} |
|||
|
|||
/** |
|||
* Close comment. |
|||
* |
|||
* @param string $msgId |
|||
* @param int|null $index |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function close(string $msgId, int $index = null) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/close', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get article comments. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* @param int $begin |
|||
* @param int $count |
|||
* @param int $type |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(string $msgId, int $index, int $begin, int $count, int $type = 0) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
'begin' => $begin, |
|||
'count' => $count, |
|||
'type' => $type, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/list', $params); |
|||
} |
|||
|
|||
/** |
|||
* Mark elect comment. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* @param int $commentId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function markElect(string $msgId, int $index, int $commentId) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
'user_comment_id' => $commentId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/markelect', $params); |
|||
} |
|||
|
|||
/** |
|||
* Unmark elect comment. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* @param int $commentId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unmarkElect(string $msgId, int $index, int $commentId) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
'user_comment_id' => $commentId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/unmarkelect', $params); |
|||
} |
|||
|
|||
/** |
|||
* Delete comment. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* @param int $commentId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $msgId, int $index, int $commentId) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
'user_comment_id' => $commentId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/delete', $params); |
|||
} |
|||
|
|||
/** |
|||
* Reply to a comment. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* @param int $commentId |
|||
* @param string $content |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function reply(string $msgId, int $index, int $commentId, string $content) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
'user_comment_id' => $commentId, |
|||
'content' => $content, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/reply/add', $params); |
|||
} |
|||
|
|||
/** |
|||
* Delete a reply. |
|||
* |
|||
* @param string $msgId |
|||
* @param int $index |
|||
* @param int $commentId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deleteReply(string $msgId, int $index, int $commentId) |
|||
{ |
|||
$params = [ |
|||
'msg_data_id' => $msgId, |
|||
'index' => $index, |
|||
'user_comment_id' => $commentId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/comment/reply/delete', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
/** |
|||
* ServiceProvider.php. |
|||
* |
|||
* This file is part of the 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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Comment; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['comment'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,230 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\CustomerService; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* List all staffs. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpGet('cgi-bin/customservice/getkflist'); |
|||
} |
|||
|
|||
/** |
|||
* List all online staffs. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function online() |
|||
{ |
|||
return $this->httpGet('cgi-bin/customservice/getonlinekflist'); |
|||
} |
|||
|
|||
/** |
|||
* Create a staff. |
|||
* |
|||
* @param string $account |
|||
* @param string $nickname |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(string $account, string $nickname) |
|||
{ |
|||
$params = [ |
|||
'kf_account' => $account, |
|||
'nickname' => $nickname, |
|||
]; |
|||
|
|||
return $this->httpPostJson('customservice/kfaccount/add', $params); |
|||
} |
|||
|
|||
/** |
|||
* Update a staff. |
|||
* |
|||
* @param string $account |
|||
* @param string $nickname |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(string $account, string $nickname) |
|||
{ |
|||
$params = [ |
|||
'kf_account' => $account, |
|||
'nickname' => $nickname, |
|||
]; |
|||
|
|||
return $this->httpPostJson('customservice/kfaccount/update', $params); |
|||
} |
|||
|
|||
/** |
|||
* Delete a staff. |
|||
* |
|||
* @param string $account |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $account) |
|||
{ |
|||
return $this->httpPostJson('customservice/kfaccount/del', [], ['kf_account' => $account]); |
|||
} |
|||
|
|||
/** |
|||
* Invite a staff. |
|||
* |
|||
* @param string $account |
|||
* @param string $wechatId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function invite(string $account, string $wechatId) |
|||
{ |
|||
$params = [ |
|||
'kf_account' => $account, |
|||
'invite_wx' => $wechatId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('customservice/kfaccount/inviteworker', $params); |
|||
} |
|||
|
|||
/** |
|||
* Set staff avatar. |
|||
* |
|||
* @param string $account |
|||
* @param string $path |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setAvatar(string $account, string $path) |
|||
{ |
|||
return $this->httpUpload('customservice/kfaccount/uploadheadimg', ['media' => $path], [], ['kf_account' => $account]); |
|||
} |
|||
|
|||
/** |
|||
* Get message builder. |
|||
* |
|||
* @param \EasyWeChat\Kernel\Messages\Message|string $message |
|||
* |
|||
* @return \EasyWeChat\OfficialAccount\CustomerService\Messenger |
|||
*/ |
|||
public function message($message) |
|||
{ |
|||
$messageBuilder = new Messenger($this); |
|||
|
|||
return $messageBuilder->message($message); |
|||
} |
|||
|
|||
/** |
|||
* Send a message. |
|||
* |
|||
* @param array $message |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function send(array $message) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/message/custom/send', $message); |
|||
} |
|||
|
|||
/** |
|||
* Show typing status. |
|||
* |
|||
* @param string $openid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function showTypingStatusToUser(string $openid) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/message/custom/typing', [ |
|||
'touser' => $openid, |
|||
'command' => 'Typing', |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Hide typing status. |
|||
* |
|||
* @param string $openid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function hideTypingStatusToUser(string $openid) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/message/custom/typing', [ |
|||
'touser' => $openid, |
|||
'command' => 'CancelTyping', |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Get messages history. |
|||
* |
|||
* @param int $startTime |
|||
* @param int $endTime |
|||
* @param int $msgId |
|||
* @param int $number |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function messages($startTime, $endTime, int $msgId = 1, int $number = 10000) |
|||
{ |
|||
$params = [ |
|||
'starttime' => is_numeric($startTime) ? $startTime : strtotime($startTime), |
|||
'endtime' => is_numeric($endTime) ? $endTime : strtotime($endTime), |
|||
'msgid' => $msgId, |
|||
'number' => $number, |
|||
]; |
|||
|
|||
return $this->httpPostJson('customservice/msgrecord/getmsglist', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,165 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\CustomerService; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\RuntimeException; |
|||
use EasyWeChat\Kernel\Messages\Message; |
|||
use EasyWeChat\Kernel\Messages\Raw as RawMessage; |
|||
use EasyWeChat\Kernel\Messages\Text; |
|||
|
|||
/** |
|||
* Class MessageBuilder. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Messenger |
|||
{ |
|||
/** |
|||
* Messages to send. |
|||
* |
|||
* @var \EasyWeChat\Kernel\Messages\Message; |
|||
*/ |
|||
protected $message; |
|||
|
|||
/** |
|||
* Messages target user open id. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $to; |
|||
|
|||
/** |
|||
* Messages sender staff id. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $account; |
|||
|
|||
/** |
|||
* Customer service instance. |
|||
* |
|||
* @var \EasyWeChat\OfficialAccount\CustomerService\Client |
|||
*/ |
|||
protected $client; |
|||
|
|||
/** |
|||
* MessageBuilder constructor. |
|||
* |
|||
* @param \EasyWeChat\OfficialAccount\CustomerService\Client $client |
|||
*/ |
|||
public function __construct(Client $client) |
|||
{ |
|||
$this->client = $client; |
|||
} |
|||
|
|||
/** |
|||
* Set message to send. |
|||
* |
|||
* @param string|Message $message |
|||
* |
|||
* @return Messenger |
|||
*/ |
|||
public function message($message) |
|||
{ |
|||
if (is_string($message)) { |
|||
$message = new Text($message); |
|||
} |
|||
|
|||
$this->message = $message; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Set staff account to send message. |
|||
* |
|||
* @param string $account |
|||
* |
|||
* @return Messenger |
|||
*/ |
|||
public function by(string $account) |
|||
{ |
|||
$this->account = $account; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @param string $account |
|||
* |
|||
* @return Messenger |
|||
*/ |
|||
public function from(string $account) |
|||
{ |
|||
return $this->by($account); |
|||
} |
|||
|
|||
/** |
|||
* Set target user open id. |
|||
* |
|||
* @param string $openid |
|||
* |
|||
* @return Messenger |
|||
*/ |
|||
public function to($openid) |
|||
{ |
|||
$this->to = $openid; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Send the message. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
*/ |
|||
public function send() |
|||
{ |
|||
if (empty($this->message)) { |
|||
throw new RuntimeException('No message to send.'); |
|||
} |
|||
|
|||
if ($this->message instanceof RawMessage) { |
|||
$message = json_decode($this->message->get('content'), true); |
|||
} else { |
|||
$prepends = [ |
|||
'touser' => $this->to, |
|||
]; |
|||
if ($this->account) { |
|||
$prepends['customservice'] = ['kf_account' => $this->account]; |
|||
} |
|||
$message = $this->message->transformForJsonRequest($prepends); |
|||
} |
|||
|
|||
return $this->client->send($message); |
|||
} |
|||
|
|||
/** |
|||
* Return property. |
|||
* |
|||
* @param string $property |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __get(string $property) |
|||
{ |
|||
if (property_exists($this, $property)) { |
|||
return $this->$property; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\CustomerService; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['customer_service'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
|
|||
$app['customer_service_session'] = function ($app) { |
|||
return new SessionClient($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\CustomerService; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class SessionClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class SessionClient extends BaseClient |
|||
{ |
|||
/** |
|||
* List all sessions of $account. |
|||
* |
|||
* @param string $account |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list(string $account) |
|||
{ |
|||
return $this->httpGet('customservice/kfsession/getsessionlist', ['kf_account' => $account]); |
|||
} |
|||
|
|||
/** |
|||
* List all the people waiting. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function waiting() |
|||
{ |
|||
return $this->httpGet('customservice/kfsession/getwaitcase'); |
|||
} |
|||
|
|||
/** |
|||
* Create a session. |
|||
* |
|||
* @param string $account |
|||
* @param string $openid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(string $account, string $openid) |
|||
{ |
|||
$params = [ |
|||
'kf_account' => $account, |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('customservice/kfsession/create', $params); |
|||
} |
|||
|
|||
/** |
|||
* Close a session. |
|||
* |
|||
* @param string $account |
|||
* @param string $openid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function close(string $account, string $openid) |
|||
{ |
|||
$params = [ |
|||
'kf_account' => $account, |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('customservice/kfsession/close', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get a session. |
|||
* |
|||
* @param string $openid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function get(string $openid) |
|||
{ |
|||
return $this->httpGet('customservice/kfsession/getsession', ['openid' => $openid]); |
|||
} |
|||
} |
|||
@ -0,0 +1,340 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\DataCube; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 获取用户增减数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function userSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getusersummary', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取累计用户数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function userCumulate(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getusercumulate', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取图文群发每日数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function articleSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getarticlesummary', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取图文群发总数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function articleTotal(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getarticletotal', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取图文统计数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function userReadSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getuserread', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取图文统计分时数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function userReadHourly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getuserreadhour', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取图文分享转发数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function userShareSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getusershare', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取图文分享转发分时数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function userShareHourly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getusersharehour', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息发送概况数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsg', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息分送分时数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageHourly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsghour', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息发送周数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageWeekly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsgweek', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息发送月数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageMonthly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsgmonth', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息发送分布数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageDistSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsgdist', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息发送分布周数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageDistWeekly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsgdistweek', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取消息发送分布月数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function upstreamMessageDistMonthly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getupstreammsgdistmonth', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取接口分析数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function interfaceSummary(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getinterfacesummary', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 获取接口分析分时数据. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function interfaceSummaryHourly(string $from, string $to) |
|||
{ |
|||
return $this->query('datacube/getinterfacesummaryhour', $from, $to); |
|||
} |
|||
|
|||
/** |
|||
* 拉取卡券概况数据接口. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* @param int $condSource |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function cardSummary(string $from, string $to, $condSource = 0) |
|||
{ |
|||
$ext = [ |
|||
'cond_source' => intval($condSource), |
|||
]; |
|||
|
|||
return $this->query('datacube/getcardbizuininfo', $from, $to, $ext); |
|||
} |
|||
|
|||
/** |
|||
* 获取免费券数据接口. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* @param int $condSource |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function freeCardSummary(string $from, string $to, int $condSource = 0, string $cardId = '') |
|||
{ |
|||
$ext = [ |
|||
'cond_source' => intval($condSource), |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->query('datacube/getcardcardinfo', $from, $to, $ext); |
|||
} |
|||
|
|||
/** |
|||
* 拉取会员卡数据接口. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* @param int $condSource |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function memberCardSummary(string $from, string $to, $condSource = 0) |
|||
{ |
|||
$ext = [ |
|||
'cond_source' => intval($condSource), |
|||
]; |
|||
|
|||
return $this->query('datacube/getcardmembercardinfo', $from, $to, $ext); |
|||
} |
|||
|
|||
/** |
|||
* 拉取单张会员卡数据接口. |
|||
* |
|||
* @param string $from |
|||
* @param string $to |
|||
* @param string $cardId |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function memberCardSummaryById(string $from, string $to, string $cardId) |
|||
{ |
|||
$ext = [ |
|||
'card_id' => $cardId, |
|||
]; |
|||
|
|||
return $this->query('datacube/getcardmembercarddetail', $from, $to, $ext); |
|||
} |
|||
|
|||
/** |
|||
* 查询数据. |
|||
* |
|||
* @param string $api |
|||
* @param string $from |
|||
* @param string $to |
|||
* @param array $ext |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function query(string $api, string $from, string $to, array $ext = []) |
|||
{ |
|||
$params = array_merge([ |
|||
'begin_date' => $from, |
|||
'end_date' => $to, |
|||
], $ext); |
|||
|
|||
return $this->httpPostJson($api, $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\DataCube; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['data_cube'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,251 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Device; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @see http://iot.weixin.qq.com/wiki/new/index.html |
|||
* |
|||
* @author soone <66812590@qq.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param string $deviceId |
|||
* @param string $openid |
|||
* @param string $content |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function message(string $deviceId, string $openid, string $content) |
|||
{ |
|||
$params = [ |
|||
'device_type' => $this->app['config']['device_type'], |
|||
'device_id' => $deviceId, |
|||
'open_id' => $openid, |
|||
'content' => base64_encode($content), |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/transmsg', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get device qrcode. |
|||
* |
|||
* @param array $deviceIds |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function qrCode(array $deviceIds) |
|||
{ |
|||
$params = [ |
|||
'device_num' => count($deviceIds), |
|||
'device_id_list' => $deviceIds, |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/create_qrcode', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $devices |
|||
* @param string $productId |
|||
* @param int $opType |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function authorize(array $devices, string $productId, int $opType = 0) |
|||
{ |
|||
$params = [ |
|||
'device_num' => count($devices), |
|||
'device_list' => $devices, |
|||
'op_type' => $opType, |
|||
'product_id' => $productId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/authorize_device', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取 device id 和二维码 |
|||
* |
|||
* @param string $productId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function createId(string $productId) |
|||
{ |
|||
$params = [ |
|||
'product_id' => $productId, |
|||
]; |
|||
|
|||
return $this->httpGet('device/getqrcode', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* @param string $deviceId |
|||
* @param string $ticket |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bind(string $openid, string $deviceId, string $ticket) |
|||
{ |
|||
$params = [ |
|||
'ticket' => $ticket, |
|||
'device_id' => $deviceId, |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/bind', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* @param string $deviceId |
|||
* @param string $ticket |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unbind(string $openid, string $deviceId, string $ticket) |
|||
{ |
|||
$params = [ |
|||
'ticket' => $ticket, |
|||
'device_id' => $deviceId, |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/unbind', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* @param string $deviceId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function forceBind(string $openid, string $deviceId) |
|||
{ |
|||
$params = [ |
|||
'device_id' => $deviceId, |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/compel_bind', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* @param string $deviceId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function forceUnbind(string $openid, string $deviceId) |
|||
{ |
|||
$params = [ |
|||
'device_id' => $deviceId, |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpPostJson('device/compel_unbind', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $deviceId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function status(string $deviceId) |
|||
{ |
|||
$params = [ |
|||
'device_id' => $deviceId, |
|||
]; |
|||
|
|||
return $this->httpGet('device/get_stat', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $ticket |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function verify(string $ticket) |
|||
{ |
|||
$params = [ |
|||
'ticket' => $ticket, |
|||
]; |
|||
|
|||
return $this->httpPost('device/verify_qrcode', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $deviceId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function openid(string $deviceId) |
|||
{ |
|||
$params = [ |
|||
'device_type' => $this->app['config']['device_type'], |
|||
'device_id' => $deviceId, |
|||
]; |
|||
|
|||
return $this->httpGet('device/get_openid', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $openid |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function listByOpenid(string $openid) |
|||
{ |
|||
$params = [ |
|||
'openid' => $openid, |
|||
]; |
|||
|
|||
return $this->httpGet('device/get_bind_device', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Device; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author soone <66812590@qq.com |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['device'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,113 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Goods; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author her-cat <hxhsoft@foxmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Add the goods. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function add(array $data) |
|||
{ |
|||
return $this->httpPostJson('scan/product/v2/add', [ |
|||
'product' => $data, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Update the goods. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(array $data) |
|||
{ |
|||
return $this->httpPostJson('scan/product/v2/add', [ |
|||
'product' => $data, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Get add or update goods results. |
|||
* |
|||
* @param string $ticket |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function status(string $ticket) |
|||
{ |
|||
return $this->httpPostJson('scan/product/v2/status', [ |
|||
'status_ticket' => $ticket, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Get goods information. |
|||
* |
|||
* @param string $pid |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(string $pid) |
|||
{ |
|||
return $this->httpPostJson('scan/product/v2/getinfo', [ |
|||
'product' => [ |
|||
'pid' => $pid, |
|||
], |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Get a list of goods. |
|||
* |
|||
* @param string $context |
|||
* @param int $page |
|||
* @param int $size |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(string $context = '', int $page = 1, int $size = 10) |
|||
{ |
|||
return $this->httpPostJson('scan/product/v2/getinfobypage', [ |
|||
'page_context' => $context, |
|||
'page_num' => $page, |
|||
'page_size' => $size, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Goods; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author her-cat <hxhsoft@foxmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['goods'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,301 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Material; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
use EasyWeChat\Kernel\Http\StreamResponse; |
|||
use EasyWeChat\Kernel\Messages\Article; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Allow media type. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $allowTypes = ['image', 'voice', 'video', 'thumb', 'news_image']; |
|||
|
|||
/** |
|||
* Upload image. |
|||
* |
|||
* @param string $path |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function uploadImage(string $path) |
|||
{ |
|||
return $this->upload('image', $path); |
|||
} |
|||
|
|||
/** |
|||
* Upload voice. |
|||
* |
|||
* @param string $path |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function uploadVoice(string $path) |
|||
{ |
|||
return $this->upload('voice', $path); |
|||
} |
|||
|
|||
/** |
|||
* Upload thumb. |
|||
* |
|||
* @param string $path |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function uploadThumb(string $path) |
|||
{ |
|||
return $this->upload('thumb', $path); |
|||
} |
|||
|
|||
/** |
|||
* Upload video. |
|||
* |
|||
* @param string $path |
|||
* @param string $title |
|||
* @param string $description |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function uploadVideo(string $path, string $title, string $description) |
|||
{ |
|||
$params = [ |
|||
'description' => json_encode( |
|||
[ |
|||
'title' => $title, |
|||
'introduction' => $description, |
|||
], JSON_UNESCAPED_UNICODE), |
|||
]; |
|||
|
|||
return $this->upload('video', $path, $params); |
|||
} |
|||
|
|||
/** |
|||
* Upload articles. |
|||
* |
|||
* @param array|Article $articles |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function uploadArticle($articles) |
|||
{ |
|||
if ($articles instanceof Article || !empty($articles['title'])) { |
|||
$articles = [$articles]; |
|||
} |
|||
|
|||
$params = ['articles' => array_map(function ($article) { |
|||
if ($article instanceof Article) { |
|||
return $article->transformForJsonRequestWithoutType(); |
|||
} |
|||
|
|||
return $article; |
|||
}, $articles)]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/material/add_news', $params); |
|||
} |
|||
|
|||
/** |
|||
* Update article. |
|||
* |
|||
* @param string $mediaId |
|||
* @param array|Article $article |
|||
* @param int $index |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateArticle(string $mediaId, $article, int $index = 0) |
|||
{ |
|||
if ($article instanceof Article) { |
|||
$article = $article->transformForJsonRequestWithoutType(); |
|||
} |
|||
|
|||
$params = [ |
|||
'media_id' => $mediaId, |
|||
'index' => $index, |
|||
'articles' => isset($article['title']) ? $article : (isset($article[$index]) ? $article[$index] : []), |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/material/update_news', $params); |
|||
} |
|||
|
|||
/** |
|||
* Upload image for article. |
|||
* |
|||
* @param string $path |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function uploadArticleImage(string $path) |
|||
{ |
|||
return $this->upload('news_image', $path); |
|||
} |
|||
|
|||
/** |
|||
* Fetch material. |
|||
* |
|||
* @param string $mediaId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(string $mediaId) |
|||
{ |
|||
$response = $this->requestRaw('cgi-bin/material/get_material', 'POST', ['json' => ['media_id' => $mediaId]]); |
|||
|
|||
if (false !== stripos($response->getHeaderLine('Content-disposition'), 'attachment')) { |
|||
return StreamResponse::buildFromPsrResponse($response); |
|||
} |
|||
|
|||
return $this->castResponseToType($response, $this->app['config']->get('response_type')); |
|||
} |
|||
|
|||
/** |
|||
* Delete material by media ID. |
|||
* |
|||
* @param string $mediaId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $mediaId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/material/del_material', ['media_id' => $mediaId]); |
|||
} |
|||
|
|||
/** |
|||
* List materials. |
|||
* |
|||
* example: |
|||
* |
|||
* { |
|||
* "total_count": TOTAL_COUNT, |
|||
* "item_count": ITEM_COUNT, |
|||
* "item": [{ |
|||
* "media_id": MEDIA_ID, |
|||
* "name": NAME, |
|||
* "update_time": UPDATE_TIME |
|||
* }, |
|||
* // more... |
|||
* ] |
|||
* } |
|||
* |
|||
* @param string $type |
|||
* @param int $offset |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(string $type, int $offset = 0, int $count = 20) |
|||
{ |
|||
$params = [ |
|||
'type' => $type, |
|||
'offset' => $offset, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/material/batchget_material', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get stats of materials. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function stats() |
|||
{ |
|||
return $this->httpGet('cgi-bin/material/get_materialcount'); |
|||
} |
|||
|
|||
/** |
|||
* Upload material. |
|||
* |
|||
* @param string $type |
|||
* @param string $path |
|||
* @param array $form |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function upload(string $type, string $path, array $form = []) |
|||
{ |
|||
if (!file_exists($path) || !is_readable($path)) { |
|||
throw new InvalidArgumentException(sprintf('File does not exist, or the file is unreadable: "%s"', $path)); |
|||
} |
|||
|
|||
$form['type'] = $type; |
|||
|
|||
return $this->httpUpload($this->getApiByType($type), ['media' => $path], $form); |
|||
} |
|||
|
|||
/** |
|||
* Get API by type. |
|||
* |
|||
* @param string $type |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getApiByType(string $type) |
|||
{ |
|||
switch ($type) { |
|||
case 'news_image': |
|||
return 'cgi-bin/media/uploadimg'; |
|||
default: |
|||
return 'cgi-bin/material/add_material'; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
/** |
|||
* ServiceProvider.php. |
|||
* |
|||
* This file is part of the 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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Material; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['material'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Menu; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get all menus. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpGet('cgi-bin/menu/get'); |
|||
} |
|||
|
|||
/** |
|||
* Get current menus. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function current() |
|||
{ |
|||
return $this->httpGet('cgi-bin/get_current_selfmenu_info'); |
|||
} |
|||
|
|||
/** |
|||
* Add menu. |
|||
* |
|||
* @param array $buttons |
|||
* @param array $matchRule |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(array $buttons, array $matchRule = []) |
|||
{ |
|||
if (!empty($matchRule)) { |
|||
return $this->httpPostJson('cgi-bin/menu/addconditional', [ |
|||
'button' => $buttons, |
|||
'matchrule' => $matchRule, |
|||
]); |
|||
} |
|||
|
|||
return $this->httpPostJson('cgi-bin/menu/create', ['button' => $buttons]); |
|||
} |
|||
|
|||
/** |
|||
* Destroy menu. |
|||
* |
|||
* @param int $menuId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(int $menuId = null) |
|||
{ |
|||
if (is_null($menuId)) { |
|||
return $this->httpGet('cgi-bin/menu/delete'); |
|||
} |
|||
|
|||
return $this->httpPostJson('cgi-bin/menu/delconditional', ['menuid' => $menuId]); |
|||
} |
|||
|
|||
/** |
|||
* Test conditional menu. |
|||
* |
|||
* @param string $userId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function match(string $userId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/menu/trymatch', ['user_id' => $userId]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Menu; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['menu'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\OAuth; |
|||
|
|||
use Overtrue\Socialite\SocialiteManager as Socialite; |
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['oauth'] = function ($app) { |
|||
$socialite = (new Socialite([ |
|||
'wechat' => [ |
|||
'client_id' => $app['config']['app_id'], |
|||
'client_secret' => $app['config']['secret'], |
|||
'redirect' => $this->prepareCallbackUrl($app), |
|||
], |
|||
], $app['request']))->driver('wechat'); |
|||
|
|||
$scopes = (array) $app['config']->get('oauth.scopes', ['snsapi_userinfo']); |
|||
|
|||
if (!empty($scopes)) { |
|||
$socialite->scopes($scopes); |
|||
} |
|||
|
|||
return $socialite; |
|||
}; |
|||
} |
|||
|
|||
/** |
|||
* Prepare the OAuth callback url for wechat. |
|||
* |
|||
* @param Container $app |
|||
* |
|||
* @return string |
|||
*/ |
|||
private function prepareCallbackUrl($app) |
|||
{ |
|||
$callback = $app['config']->get('oauth.callback'); |
|||
if (0 === stripos($callback, 'http')) { |
|||
return $callback; |
|||
} |
|||
$baseUrl = $app['request']->getSchemeAndHttpHost(); |
|||
|
|||
return $baseUrl.'/'.ltrim($callback, '/'); |
|||
} |
|||
} |
|||
@ -0,0 +1,85 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\OCR; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author joyeekk <xygao2420@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Allow image parameter type. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $allowTypes = ['photo', 'scan']; |
|||
|
|||
/** |
|||
* ID card OCR. |
|||
* |
|||
* @param string $path |
|||
* @param string $type |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function idCard(string $path, string $type = 'photo') |
|||
{ |
|||
if (!\in_array($type, $this->allowTypes, true)) { |
|||
throw new InvalidArgumentException(sprintf("Unsupported type: '%s'", $type)); |
|||
} |
|||
|
|||
return $this->httpGet('cv/ocr/idcard', [ |
|||
'type' => $type, |
|||
'img_url' => $path, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Bank card OCR. |
|||
* |
|||
* @param string $path |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function bankCard(string $path) |
|||
{ |
|||
return $this->httpGet('cv/ocr/bankcard', [ |
|||
'img_url' => $path, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Vehicle license OCR. |
|||
* |
|||
* @param string $path |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function vehicleLicense(string $path) |
|||
{ |
|||
return $this->httpGet('cv/ocr/driving', [ |
|||
'img_url' => $path, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\OCR; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author joyeekk <xygao2420@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['ocr'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,145 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\POI; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get POI supported categories. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function categories() |
|||
{ |
|||
return $this->httpGet('cgi-bin/poi/getwxcategory'); |
|||
} |
|||
|
|||
/** |
|||
* Get POI by ID. |
|||
* |
|||
* @param int $poiId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(int $poiId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/poi/getpoi', ['poi_id' => $poiId]); |
|||
} |
|||
|
|||
/** |
|||
* List POI. |
|||
* |
|||
* @param int $offset |
|||
* @param int $limit |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(int $offset = 0, int $limit = 10) |
|||
{ |
|||
$params = [ |
|||
'begin' => $offset, |
|||
'limit' => $limit, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/poi/getpoilist', $params); |
|||
} |
|||
|
|||
/** |
|||
* Create a POI. |
|||
* |
|||
* @param array $baseInfo |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(array $baseInfo) |
|||
{ |
|||
$params = [ |
|||
'business' => [ |
|||
'base_info' => $baseInfo, |
|||
], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/poi/addpoi', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $databaseInfo |
|||
* |
|||
* @return int |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public function createAndGetId(array $databaseInfo) |
|||
{ |
|||
/** @var array $response */ |
|||
$response = $this->detectAndCastResponseToType($this->create($databaseInfo), 'array'); |
|||
|
|||
return $response['poi_id']; |
|||
} |
|||
|
|||
/** |
|||
* Update a POI. |
|||
* |
|||
* @param int $poiId |
|||
* @param array $baseInfo |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(int $poiId, array $baseInfo) |
|||
{ |
|||
$params = [ |
|||
'business' => [ |
|||
'base_info' => array_merge($baseInfo, ['poi_id' => $poiId]), |
|||
], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/poi/updatepoi', $params); |
|||
} |
|||
|
|||
/** |
|||
* Delete a POI. |
|||
* |
|||
* @param int $poiId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(int $poiId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/poi/delpoi', ['poi_id' => $poiId]); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\POI; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['poi'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Semantic; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get the semantic content of giving string. |
|||
* |
|||
* @param string $keyword |
|||
* @param string $categories |
|||
* @param array $optional |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function query(string $keyword, string $categories, array $optional = []) |
|||
{ |
|||
$params = [ |
|||
'query' => $keyword, |
|||
'category' => $categories, |
|||
'appid' => $this->app['config']['app_id'], |
|||
]; |
|||
|
|||
return $this->httpPostJson('semantic/semproxy/search', array_merge($params, $optional)); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Semantic; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['semantic'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Server; |
|||
|
|||
use EasyWeChat\Kernel\ServerGuard; |
|||
|
|||
/** |
|||
* Class Guard. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Guard extends ServerGuard |
|||
{ |
|||
/** |
|||
* @return bool |
|||
*/ |
|||
protected function shouldReturnRawResponse(): bool |
|||
{ |
|||
return !is_null($this->app['request']->get('echostr')); |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Server\Handlers; |
|||
|
|||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface; |
|||
use EasyWeChat\Kernel\Decorators\FinallyResult; |
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
|
|||
/** |
|||
* Class EchoStrHandler. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class EchoStrHandler implements EventHandlerInterface |
|||
{ |
|||
/** |
|||
* @var ServiceContainer |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* EchoStrHandler constructor. |
|||
* |
|||
* @param ServiceContainer $app |
|||
*/ |
|||
public function __construct(ServiceContainer $app) |
|||
{ |
|||
$this->app = $app; |
|||
} |
|||
|
|||
/** |
|||
* @param mixed $payload |
|||
* |
|||
* @return FinallyResult|null |
|||
*/ |
|||
public function handle($payload = null) |
|||
{ |
|||
if ($str = $this->app['request']->get('echostr')) { |
|||
return new FinallyResult($str); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\Server; |
|||
|
|||
use EasyWeChat\Kernel\Encryptor; |
|||
use EasyWeChat\OfficialAccount\Server\Handlers\EchoStrHandler; |
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
!isset($app['encryptor']) && $app['encryptor'] = function ($app) { |
|||
return new Encryptor( |
|||
$app['config']['app_id'], |
|||
$app['config']['token'], |
|||
$app['config']['aes_key'] |
|||
); |
|||
}; |
|||
|
|||
!isset($app['server']) && $app['server'] = function ($app) { |
|||
$guard = new Guard($app); |
|||
$guard->push(new EchoStrHandler($app)); |
|||
|
|||
return $guard; |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function register($data) |
|||
{ |
|||
return $this->httpPostJson('shakearound/account/register', $data); |
|||
} |
|||
|
|||
/** |
|||
* Get audit status. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function status() |
|||
{ |
|||
return $this->httpGet('shakearound/account/auditstatus'); |
|||
} |
|||
|
|||
/** |
|||
* Get shake info. |
|||
* |
|||
* @param string $ticket |
|||
* @param bool $needPoi |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function user(string $ticket, bool $needPoi = false) |
|||
{ |
|||
$params = [ |
|||
'ticket' => $ticket, |
|||
]; |
|||
|
|||
if ($needPoi) { |
|||
$params['need_poi'] = 1; |
|||
} |
|||
|
|||
return $this->httpPostJson('shakearound/user/getshakeinfo', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $ticket |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
*/ |
|||
public function userWithPoi(string $ticket) |
|||
{ |
|||
return $this->user($ticket, true); |
|||
} |
|||
} |
|||
@ -0,0 +1,190 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class DeviceClient. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class DeviceClient extends BaseClient |
|||
{ |
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function apply(array $data) |
|||
{ |
|||
return $this->httpPostJson('shakearound/device/applyid', $data); |
|||
} |
|||
|
|||
/** |
|||
* Get audit status. |
|||
* |
|||
* @param int $applyId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function status(int $applyId) |
|||
{ |
|||
$params = [ |
|||
'apply_id' => $applyId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/applystatus', $params); |
|||
} |
|||
|
|||
/** |
|||
* Update a device comment. |
|||
* |
|||
* @param array $deviceIdentifier |
|||
* @param string $comment |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(array $deviceIdentifier, string $comment) |
|||
{ |
|||
$params = [ |
|||
'device_identifier' => $deviceIdentifier, |
|||
'comment' => $comment, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/update', $params); |
|||
} |
|||
|
|||
/** |
|||
* Bind location for device. |
|||
* |
|||
* @param array $deviceIdentifier |
|||
* @param int $poiId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bindPoi(array $deviceIdentifier, int $poiId) |
|||
{ |
|||
$params = [ |
|||
'device_identifier' => $deviceIdentifier, |
|||
'poi_id' => $poiId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/bindlocation', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $deviceIdentifier |
|||
* @param int $poiId |
|||
* @param string $appId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bindThirdPoi(array $deviceIdentifier, int $poiId, string $appId) |
|||
{ |
|||
$params = [ |
|||
'device_identifier' => $deviceIdentifier, |
|||
'poi_id' => $poiId, |
|||
'type' => 2, |
|||
'poi_appid' => $appId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/bindlocation', $params); |
|||
} |
|||
|
|||
/** |
|||
* Fetch batch of devices by deviceIds. |
|||
* |
|||
* @param array $deviceIdentifiers |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function listByIds(array $deviceIdentifiers) |
|||
{ |
|||
$params = [ |
|||
'type' => 1, |
|||
'device_identifiers' => $deviceIdentifiers, |
|||
]; |
|||
|
|||
return $this->search($params); |
|||
} |
|||
|
|||
/** |
|||
* Pagination to get batch of devices. |
|||
* |
|||
* @param int $lastId |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function list(int $lastId, int $count) |
|||
{ |
|||
$params = [ |
|||
'type' => 2, |
|||
'last_seen' => $lastId, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->search($params); |
|||
} |
|||
|
|||
/** |
|||
* Fetch batch of devices by applyId. |
|||
* |
|||
* @param int $applyId |
|||
* @param int $lastId |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
*/ |
|||
public function listByApplyId(int $applyId, int $lastId, int $count) |
|||
{ |
|||
$params = [ |
|||
'type' => 3, |
|||
'apply_id' => $applyId, |
|||
'last_seen' => $lastId, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->search($params); |
|||
} |
|||
|
|||
/** |
|||
* Fetch batch of devices. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function search(array $params) |
|||
{ |
|||
return $this->httpPostJson('shakearound/device/search', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,167 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class GroupClient. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class GroupClient extends BaseClient |
|||
{ |
|||
/** |
|||
* Add device group. |
|||
* |
|||
* @param string $name |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(string $name) |
|||
{ |
|||
$params = [ |
|||
'group_name' => $name, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/add', $params); |
|||
} |
|||
|
|||
/** |
|||
* Update a device group name. |
|||
* |
|||
* @param int $groupId |
|||
* @param string $name |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(int $groupId, string $name) |
|||
{ |
|||
$params = [ |
|||
'group_id' => $groupId, |
|||
'group_name' => $name, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/update', $params); |
|||
} |
|||
|
|||
/** |
|||
* Delete device group. |
|||
* |
|||
* @param int $groupId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(int $groupId) |
|||
{ |
|||
$params = [ |
|||
'group_id' => $groupId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/delete', $params); |
|||
} |
|||
|
|||
/** |
|||
* List all device groups. |
|||
* |
|||
* @param int $begin |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(int $begin, int $count) |
|||
{ |
|||
$params = [ |
|||
'begin' => $begin, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/getlist', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get detail of a device group. |
|||
* |
|||
* @param int $groupId |
|||
* @param int $begin |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(int $groupId, int $begin, int $count) |
|||
{ |
|||
$params = [ |
|||
'group_id' => $groupId, |
|||
'begin' => $begin, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/getdetail', $params); |
|||
} |
|||
|
|||
/** |
|||
* Add one or more devices to a device group. |
|||
* |
|||
* @param int $groupId |
|||
* @param array $deviceIdentifiers |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function addDevices(int $groupId, array $deviceIdentifiers) |
|||
{ |
|||
$params = [ |
|||
'group_id' => $groupId, |
|||
'device_identifiers' => $deviceIdentifiers, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/adddevice', $params); |
|||
} |
|||
|
|||
/** |
|||
* Remove one or more devices from a device group. |
|||
* |
|||
* @param int $groupId |
|||
* @param array $deviceIdentifiers |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function removeDevices(int $groupId, array $deviceIdentifiers) |
|||
{ |
|||
$params = [ |
|||
'group_id' => $groupId, |
|||
'device_identifiers' => $deviceIdentifiers, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/group/deletedevice', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class MaterialClient. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class MaterialClient extends BaseClient |
|||
{ |
|||
/** |
|||
* Upload image material. |
|||
* |
|||
* @param string $path |
|||
* @param string $type |
|||
* |
|||
* @return string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function uploadImage(string $path, string $type = 'icon') |
|||
{ |
|||
if (!file_exists($path) || !is_readable($path)) { |
|||
throw new InvalidArgumentException(sprintf('File does not exist, or the file is unreadable: "%s"', $path)); |
|||
} |
|||
|
|||
return $this->httpUpload('shakearound/material/add', ['media' => $path], [], ['type' => strtolower($type)]); |
|||
} |
|||
} |
|||
@ -0,0 +1,110 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class PageClient. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class PageClient extends BaseClient |
|||
{ |
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(array $data) |
|||
{ |
|||
return $this->httpPostJson('shakearound/page/add', $data); |
|||
} |
|||
|
|||
/** |
|||
* @param int $pageId |
|||
* @param array $data |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(int $pageId, array $data) |
|||
{ |
|||
return $this->httpPostJson('shakearound/page/update', array_merge(['page_id' => $pageId], $data)); |
|||
} |
|||
|
|||
/** |
|||
* Fetch batch of pages by pageIds. |
|||
* |
|||
* @param array $pageIds |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function listByIds(array $pageIds) |
|||
{ |
|||
$params = [ |
|||
'type' => 1, |
|||
'page_ids' => $pageIds, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/page/search', $params); |
|||
} |
|||
|
|||
/** |
|||
* Pagination to get batch of pages. |
|||
* |
|||
* @param int $begin |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list(int $begin, int $count) |
|||
{ |
|||
$params = [ |
|||
'type' => 2, |
|||
'begin' => $begin, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/page/search', $params); |
|||
} |
|||
|
|||
/** |
|||
* delete a page. |
|||
* |
|||
* @param int $pageId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(int $pageId) |
|||
{ |
|||
$params = [ |
|||
'page_id' => $pageId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/page/delete', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class RelationClient. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class RelationClient extends BaseClient |
|||
{ |
|||
/** |
|||
* Bind pages for device. |
|||
* |
|||
* @param array $deviceIdentifier |
|||
* @param array $pageIds |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bindPages(array $deviceIdentifier, array $pageIds) |
|||
{ |
|||
$params = [ |
|||
'device_identifier' => $deviceIdentifier, |
|||
'page_ids' => $pageIds, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/device/bindpage', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get pageIds by deviceId. |
|||
* |
|||
* @param array $deviceIdentifier |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function listByDeviceId(array $deviceIdentifier) |
|||
{ |
|||
$params = [ |
|||
'type' => 1, |
|||
'device_identifier' => $deviceIdentifier, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/relation/search', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get devices by pageId. |
|||
* |
|||
* @param int $pageId |
|||
* @param int $begin |
|||
* @param int $count |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function listByPageId(int $pageId, int $begin, int $count) |
|||
{ |
|||
$params = [ |
|||
'type' => 2, |
|||
'page_id' => $pageId, |
|||
'begin' => $begin, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/relation/search', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['shake_around'] = function ($app) { |
|||
return new ShakeAround($app); |
|||
}; |
|||
|
|||
$app['shake_around.device'] = function ($app) { |
|||
return new DeviceClient($app); |
|||
}; |
|||
|
|||
$app['shake_around.page'] = function ($app) { |
|||
return new PageClient($app); |
|||
}; |
|||
|
|||
$app['shake_around.material'] = function ($app) { |
|||
return new MaterialClient($app); |
|||
}; |
|||
|
|||
$app['shake_around.group'] = function ($app) { |
|||
return new GroupClient($app); |
|||
}; |
|||
|
|||
$app['shake_around.relation'] = function ($app) { |
|||
return new RelationClient($app); |
|||
}; |
|||
|
|||
$app['shake_around.stats'] = function ($app) { |
|||
return new StatsClient($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class Card. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
* |
|||
* @property \EasyWeChat\OfficialAccount\ShakeAround\DeviceClient $device |
|||
* @property \EasyWeChat\OfficialAccount\ShakeAround\GroupClient $group |
|||
* @property \EasyWeChat\OfficialAccount\ShakeAround\MaterialClient $material |
|||
* @property \EasyWeChat\OfficialAccount\ShakeAround\RelationClient $relation |
|||
* @property \EasyWeChat\OfficialAccount\ShakeAround\StatsClient $stats |
|||
*/ |
|||
class ShakeAround extends Client |
|||
{ |
|||
/** |
|||
* @param string $property |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public function __get($property) |
|||
{ |
|||
if (isset($this->app["shake_around.{$property}"])) { |
|||
return $this->app["shake_around.{$property}"]; |
|||
} |
|||
|
|||
throw new InvalidArgumentException(sprintf('No shake_around service named "%s".', $property)); |
|||
} |
|||
} |
|||
@ -0,0 +1,110 @@ |
|||
<?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. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OfficialAccount\ShakeAround; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class StatsClient. |
|||
* |
|||
* @author allen05ren <allen05ren@outlook.com> |
|||
*/ |
|||
class StatsClient extends BaseClient |
|||
{ |
|||
/** |
|||
* Fetch statistics data by deviceId. |
|||
* |
|||
* @param array $deviceIdentifier |
|||
* @param int $beginTime (Unix timestamp) |
|||
* @param int $endTime (Unix timestamp) |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deviceSummary(array $deviceIdentifier, int $beginTime, int $endTime) |
|||
{ |
|||
$params = [ |
|||
'device_identifier' => $deviceIdentifier, |
|||
'begin_date' => $beginTime, |
|||
'end_date' => $endTime, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/statistics/device', $params); |
|||
} |
|||
|
|||
/** |
|||
* Fetch all devices statistics data by date. |
|||
* |
|||
* @param int $timestamp |
|||
* @param int $pageIndex |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function devicesSummary(int $timestamp, int $pageIndex) |
|||
{ |
|||
$params = [ |
|||
'date' => $timestamp, |
|||
'page_index' => $pageIndex, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/statistics/devicelist', $params); |
|||
} |
|||
|
|||
/** |
|||
* Fetch statistics data by pageId. |
|||
* |
|||
* @param int $pageId |
|||
* @param int $beginTime (Unix timestamp) |
|||
* @param int $endTime (Unix timestamp) |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function pageSummary(int $pageId, int $beginTime, int $endTime) |
|||
{ |
|||
$params = [ |
|||
'page_id' => $pageId, |
|||
'begin_date' => $beginTime, |
|||
'end_date' => $endTime, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/statistics/page', $params); |
|||
} |
|||
|
|||
/** |
|||
* Fetch all pages statistics data by date. |
|||
* |
|||
* @param int $timestamp |
|||
* @param int $pageIndex |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function pagesSummary(int $timestamp, int $pageIndex) |
|||
{ |
|||
$params = [ |
|||
'date' => $timestamp, |
|||
'page_index' => $pageIndex, |
|||
]; |
|||
|
|||
return $this->httpPostJson('shakearound/statistics/pagelist', $params); |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue