定制 webhubworks/craft-weclapp-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webhubworks/craft-weclapp-api

Composer 安装命令:

composer require webhubworks/craft-weclapp-api

包简介

A Craft CMS wrapper around webhubworks/weclapp-api-core.

README 文档

README

A Craft CMS wrapper around webhubworks/weclapp-api-core.

It is the Craft counterpart to webhubworks/weclapp-api-laravel: instead of a Laravel service provider + facade, it registers a singleton Yii service that exposes a fully configured core Client. The base URL and auth token are read from environment variables, so no per-call configuration is needed.

Requirements

  • Craft CMS 4.0+ or 5.0+
  • PHP 8.3+

Installation

composer require webhubworks/craft-weclapp-api
php craft plugin/install weclapp-api

Configuration

Set the two required environment variables in your .env:

WECLAPP_API_BASE_URL=https://your-tenant.weclapp.com/webapp/api/v2
WECLAPP_AUTH_TOKEN=your-auth-token

# Optional - request/response logging to storage/logs/weclapp-api.log (default: true)
WECLAPP_ENABLE_LOGGING=true

Note: WECLAPP_API_BASE_URL should include the full API path (e.g. /webapp/api/v2). The adapter concatenates this base with the relative endpoint paths produced by the core client.

Usage

The plugin registers the core client behind a singleton api service:

use Webhub\WeclappApiCraft\Plugin;

// Shared, configured core client
$client = Plugin::getInstance()->getClient();

// equivalent to:
$client = Plugin::getInstance()->api->getClient();

$count = $client->getArticleCount();
$articles = $client->getArticle();

getClient() returns the generated Webhubworks\WeclappApiCore\Client, so every endpoint method from the core package is available.

How it works

  • Plugin::config() registers WeclappService as the api component. Craft instantiates Yii components once per request, giving singleton semantics.
  • WeclappService::getClient() reads WECLAPP_API_BASE_URL and WECLAPP_AUTH_TOKEN via craft\helpers\App::env(), then builds the core client with the CraftHttpClient PSR-18 adapter, caching the result.
  • CraftHttpClient implements Psr\Http\Client\ClientInterface on top of Craft::createGuzzleClient(). It prepends the base URL to each relative endpoint URI and attaches the AuthenticationToken header - the same contract the Laravel wrapper fulfils with Laravel's HTTP client.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 54
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固