Skip to content

Commit

Permalink
Merge pull request #182 from XueSiLf/2.x
Browse files Browse the repository at this point in the history
feat(openPlatform): 添加开放平台代商家管理小程序部分业务接口
  • Loading branch information
XueSiLf authored Sep 24, 2022
2 parents c392067 + a11e6a6 commit 80a2722
Show file tree
Hide file tree
Showing 24 changed files with 1,130 additions and 49 deletions.
8 changes: 7 additions & 1 deletion src/OpenPlatform/Authorizer/MiniProgram/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @property QrCodeJump\Client $qrCodeJump
* @property Setting\Client $setting
* @property Tester\Client $tester
* @property Embedded\Client $embedded
* @property Record\Client $record
*/
class Application extends MiniProgram
{
Expand All @@ -31,6 +33,8 @@ class Application extends MiniProgram
const QrCodeJump = 'qrCodeJump';
const Setting = 'setting';
const Tester = 'tester';
const Embedded = 'embedded';
const Record = 'record';

public function __construct(array $config = null, string $name = null, array $values = [])
{
Expand All @@ -45,7 +49,9 @@ public function __construct(array $config = null, string $name = null, array $va
PrivacyInterface\ServiceProvider::class,
QrCodeJump\ServiceProvider::class,
Setting\ServiceProvider::class,
Tester\ServiceProvider::class
Tester\ServiceProvider::class,
Embedded\ServiceProvider::class,
Record\ServiceProvider::class,
];

foreach ($providers as $provider) {
Expand Down
43 changes: 43 additions & 0 deletions src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,47 @@ public function speedupAudit(int $auditId)

return $this->checkResponse($response);
}

/**
* 代小程序实现业务 - 代码管理 - 查询小程序版本信息
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/getVersionInfo.html
*
* @return mixed
* @throws HttpException
*/
public function getVersionInfo()
{
$response = $this->getClient()
->setMethod("POST")
->setBody(new Stream('{}'))
->send($this->buildUrl(
"/wxa/getversioninfo",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

$this->checkResponse($response, $data);

return $data;
}

/**
* 代小程序实现业务 - 代码管理 - 获取隐私接口检测结果
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/getCodePrivacyInfo.html
*
* @return mixed
* @throws HttpException
*/
public function getCodePrivacyInfo()
{
$response = $this->getClient()
->setMethod("GET")
->send($this->buildUrl(
"/wxa/security/get_code_privacy_info",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

$this->checkResponse($response, $data);

return $data;
}
}
36 changes: 21 additions & 15 deletions src/OpenPlatform/Authorizer/MiniProgram/Domain/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Client extends BaseClient
{
/**
* 代小程序实现业务 - 基础信息设置 - 设置服务器域名
* 代小程序实现业务 - 小程序域名管理 - 配置小程序服务器域名
* doc link: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Server_Address_Configuration.html
*
* @param array $params
Expand All @@ -33,8 +33,8 @@ public function modify(array $params)
}

/**
* 代小程序实现业务 - 基础信息设置 - 设置业务域名
* doc link: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Server_Address_Configuration.html
* 代小程序实现业务 - 小程序域名管理 - 配置小程序业务域名
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/modifyJumpDomain.html
* 设置小程序业务域名
*
* @param array $domains
Expand Down Expand Up @@ -77,9 +77,7 @@ public function modifyServerDomainDirectly(array $params)
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

$this->checkResponse($response, $data);

return $data;
return $this->checkResponse($response);
}

/**
Expand Down Expand Up @@ -127,7 +125,9 @@ public function modifyJumpDomainDirectly(array $domains, $action = 'add')
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
$this->checkResponse($response, $data);

return $data;
}

/**
Expand All @@ -142,13 +142,15 @@ public function getEffectiveServerDomain()
{
$response = $this->getClient()
->setMethod("POST")
->setBody(new Stream(json_encode(new \stdClass())))
->setBody(new Stream('{}'))
->send($this->buildUrl(
"/wxa/get_effective_domain",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
$this->checkResponse($response, $data);

return $data;
}

/**
Expand All @@ -163,13 +165,15 @@ public function getEffectiveJumpDomain()
{
$response = $this->getClient()
->setMethod("POST")
->setBody(new Stream(json_encode(new \stdClass())))
->setBody(new Stream('{}'))
->send($this->buildUrl(
"/wxa/get_effective_webviewdomain",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
$this->checkResponse($response, $data);

return $data;
}

/**
Expand All @@ -189,24 +193,26 @@ public function getPrefetchDomain()
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
$this->checkResponse($response, $data);

return $data;
}

/**
* 代小程序实现业务 - 小程序域名管理 - 设置 DNS 预解析域名
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/setPrefetchDomain.html
* 设置 DNS 预解析域名
*
* @param $dns_domain
* @param $prefetchDnsDomain
* @return mixed
* @throws HttpException
*/
public function setPrefetchDomain(array $dns_domain)
public function setPrefetchDomain(array $prefetchDnsDomain)
{
$response = $this->getClient()
->setMethod("POST")
->setBody($this->jsonDataToStream([
'prefetch_dns_domain' => $dns_domain,
'prefetch_dns_domain' => $prefetchDnsDomain,
]))
->send($this->buildUrl(
"/wxa/set_prefetchdnsdomain",
Expand Down
161 changes: 161 additions & 0 deletions src/OpenPlatform/Authorizer/MiniProgram/Embedded/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php
/**
* This file is part of EasySwoole.
*
* @link https://www.easyswoole.com
* @document https://www.easyswoole.com
* @contact https://www.easyswoole.com/Preface/contact.html
* @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
*/

namespace EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\Embedded;

use EasySwoole\WeChat\Kernel\Exceptions\HttpException;
use EasySwoole\WeChat\Kernel\ServiceProviders;
use EasySwoole\WeChat\OpenPlatform\BaseClient;

class Client extends BaseClient
{
/**
* 代商家管理小程序 - 半屏小程序管理 - 添加半屏小程序
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/addEmbedded.html
* @param string $appid 添加的半屏小程序 appid
* @param string $applyReason 申请理由,不超过 30 个字
*
* @return bool
* @throws HttpException
*/
public function addEmbedded(string $appid, string $applyReason = "")
{
$response = $this->getClient()
->setMethod("POST")
->setBody($this->jsonDataToStream([
'appid' => $appid,
'apply_reason' => $applyReason
]))
->send($this->buildUrl(
"/wxaapi/wxaembedded/add_embedded",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
}

/**
* 代商家管理小程序 - 半屏小程序管理 - 删除半屏小程序
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/deleteEmbedded.html
* @param string $appid 已添加的半屏小程序 appid
*
* @return bool
* @throws HttpException
*/
public function deleteEmbedded(string $appid)
{
$response = $this->getClient()
->setMethod("POST")
->setBody($this->jsonDataToStream(['appid' => $appid]))
->send($this->buildUrl(
"/wxaapi/wxaembedded/del_embedded",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
}

/**
* 代商家管理小程序 - 半屏小程序管理 - 取消授权小程序
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/deleteAuthorizedEmbedded.html
* @param int $flag 半屏小程序授权方式。0表示需要管理员验证;1表示自动通过;2表示自动拒绝。
*
* @return bool
* @throws HttpException
*/
public function deleteAuthorizedEmbedded(int $flag)
{
$response = $this->getClient()
->setMethod("POST")
->setBody($this->jsonDataToStream(['flag' => $flag]))
->send($this->buildUrl(
"/wxaapi/wxaembedded/del_authorize",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
}

/**
* 代商家管理小程序 - 半屏小程序管理 - 获取半屏小程序调用列表
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/getEmbeddedList.html
* @param int $start 分页起始值 ,默认值为0
* @param int $num 一次拉取最大值,最大 1000,默认值为10
*
* @return mixed
* @throws HttpException
*/
public function getEmbeddedList(int $start = 0, int $num = 10)
{
$response = $this->getClient()
->setMethod("GET")
->send($this->buildUrl(
"/wxaapi/wxaembedded/get_list",
[
'access_token' => $this->app[ServiceProviders::AccessToken]->getToken(),
'start' => $start,
'num' => $num
]
));

$this->checkResponse($response, $data);

return $data;
}

/**
* 代商家管理小程序 - 半屏小程序管理 - 获取半屏小程序授权列表
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/getOwnList.html
* @param int $start 分页起始值 ,默认值为0
* @param int $num 一次拉取最大值,最大 1000,默认值为10
*
* @return mixed
* @throws HttpException
*/
public function getOwnList(int $start = 0, int $num = 10)
{
$response = $this->getClient()
->setMethod("GET")
->send($this->buildUrl(
"/wxaapi/wxaembedded/get_own_list",
[
'access_token' => $this->app[ServiceProviders::AccessToken]->getToken(),
'start' => $start,
'num' => $num
]
));

$this->checkResponse($response, $data);

return $data;
}

/**
* 代商家管理小程序 - 半屏小程序管理 - 设置授权方式
* doc link: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/setAuthorizedEmbedded.html
*
* @param int $flag 半屏小程序授权方式。0表示需要管理员验证;1表示自动通过;2表示自动拒绝。
*
* @return bool
* @throws HttpException
*/
public function setAuthorizedEmbedded(int $flag)
{
$response = $this->getClient()
->setMethod("POST")
->setBody($this->jsonDataToStream(['flag' => $flag]))
->send($this->buildUrl(
"/wxaapi/wxaembedded/set_authorize",
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]
));

return $this->checkResponse($response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* This file is part of EasySwoole.
*
* @link https://www.easyswoole.com
* @document https://www.easyswoole.com
* @contact https://www.easyswoole.com/Preface/contact.html
* @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
*/

namespace EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\Embedded;

use EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\Application;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

class ServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app[Application::Embedded] = function ($app) {
return new Client($app);
};
}
}
Loading

0 comments on commit 80a2722

Please sign in to comment.