riftfox / wechat-clear-quota
微信公众平台重置API调用次数
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/riftfox/wechat-clear-quota
Requires
- psr/http-client: @stable
- psr/http-factory: @stable
- psr/http-message: @stable
- riftfox/wechat-application: @stable
- riftfox/wechat-exception: @stable
Requires (Dev)
- guzzle/http: @dev
- guzzlehttp/psr7: @dev
This package is auto-updated.
Last update: 2025-10-14 02:51:09 UTC
README
wechat-clear-quota 是对 微信公众平台重置 API 调用次数接口 的 PHP SDK 实现。
功能简介
- 封装微信 clear_quota 接口,便于开发者重置公众号/小程序的 API 调用次数。
- 遵循 PSR-7/PSR-17/PSR-18 标准,支持主流 HTTP 客户端。
- 依赖统一的
ApplicationInterface和TokenInterface,可与其它微信 SDK 组件无缝集成。
依赖
- PHP 7.4 及以上
- psr/http-client
- psr/http-factory
- psr/log
- riftfox/wechat-application
- riftfox/wechat-token
- riftfox/wechat-exception
安装
建议通过 Composer 安装(如已发布到 Packagist):
composer require riftfox/wechat-clear-quota
或在本地开发环境中,确保相关依赖已正确引入。
使用方法
1. 实现 ApplicationInterface 和 TokenInterface
你可以直接使用 wechat-application 和 wechat-token 包中的实现,或自定义实现:
use Riftfox\Wechat\Application\ApplicationInterface; use Riftfox\Wechat\Token\TokenInterface; class Application implements ApplicationInterface { // 实现 getAppId/getAppSecret 等方法 } class Token implements TokenInterface { // 实现 getAccessToken 等方法 }
2. 初始化 ClearQuotaProvider
use Riftfox\Wechat\ClearQuota\ClearQuotaProvider; use Riftfox\Wechat\Exception\ExceptionFactoryInterface; use GuzzleHttp\Client; // 仅为示例,需实现 PSR-18 ClientInterface use Nyholm\Psr7\Factory\Psr17Factory; // 需实现 PSR-17 Request/Uri/StreamFactory $client = new Client(); // 实现了 PSR-18 $requestFactory = new Psr17Factory(); $uriFactory = new Psr17Factory(); $streamFactory = new Psr17Factory(); $exceptionFactory = new class implements ExceptionFactoryInterface { public function createException(string $message, int $code, $previous = null): \Exception { return new \Exception($message, $code, $previous); } }; $provider = new ClearQuotaProvider( $client, $requestFactory, $uriFactory, $streamFactory, $exceptionFactory );
3. 重置 API 调用次数
$application = new Application('your-appid', 'your-secret', ApplicationInterface::TYPE_OFFICE); $token = new Token('your-access-token', ...); try { $provider->clearQuota($token, $application); echo 'API 调用次数已重置'; } catch (\Exception $e) { // 处理异常 echo '重置失败:' . $e->getMessage(); }
相关链接
License
MIT