Download the PHP package hyperf-apex/wecom without Composer

On this page you can find all versions of the php package hyperf-apex/wecom. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wecom

hyperf-apex/wecom

企业微信(WeCom / 微信企业号)组件:多企业配置、进程内共用同一个 EasyWeChat 客户端、 access_token 缓存与自愈、OAuth 网页授权 / 扫码登录。

底座是 w7corp/easywechat 6.x 的 EasyWeChat\Work\Application。 本组件只把「多企业 + 凭据缓存 + 错误归一」这三件共性做掉,其余能力(通讯录、消息推送、外部联系人、 回调验签)直接用 EasyWeChat 原生 API,见「拿原生应用实例」一节。

安装

发布配置模板:

配置

config/autoload/wecom.php:

三条必须知道的约束:

快速开始

WeComManager 的能力:

方法 用途
api(?string $alias) 推荐入口:发 GET/POST 并判定 errcode,自带 token 自愈与错误归一
application(?string $alias) 取 EasyWeChat\Work\Application 原生实例(上传素材、回调验签、JS-SDK ticket…)
client(?string $alias) 取带 access_token 的 HTTP 客户端(EasyWeChat 未封装的能力)
accessToken(?string $alias) 取当前 access_token(缓存命中不发请求)
forgetAccessToken(?string $alias) 丢掉缓存的 token,下次取时重新换
account(?string $alias) 取企业配置(WeComAccountDTO,含密钥,勿外传)
defaultAlias() 调用方不指定 alias 时用的企业

access_token 为什么会「被顶掉」,组件怎么处理

企微的 access_token 按企业全局唯一:同一企业在别的系统里重新获取会把这个 token 顶掉。 因此组件做了两层防护:

  1. 缓存提前过期(token_expire_ahead,默认 300 秒):宁可提前换一个新的,也不要在过期边缘 拿一个可能已被顶掉的;
  2. 错误码自愈:api() 拿到 40014 / 42001 会丢掉缓存并重发一次,偶发被顶掉不会变成 用户可见的失败。重发意味着 HTTP 选项必须能重复构造,别往里塞一次性的流。

缓存键由本组件指定({prefix}access_token:{alias}:{corp_id 摘要})。EasyWeChat 默认键是 work.access_token.{corpId}.{secret} —— secret 会进 Redis 键名,而键名会被 KEYS、监控面板、 慢查询日志原样打出来,等于把密钥另存了一份。

企微登录

三种入口一次给全,前端按场景选一个,共用同一个 redirect_uri 与 state:

字段 场景
inAppAuthorizeUrl 企业微信客户端内打开页面(静默授权,用户无感)
qrCodeAuthorizeUrl PC 浏览器,跳转到企微托管的扫码页
loginPanel PC 浏览器,在本页内嵌二维码面板(ww.createWWLoginPanel),见下

前端内嵌面板的用法(面板参数直接就是 params,state 用 loginPanel.state 或顶层 state):

redirect_type、panel_size、lang 是纯前端的交互与展示选择,服务端不感知也不下发。

其余约定:

换成数据库 / 配置中心

企业配置要能在后台改,或者要按租户动态取不同企业时,实现 AccountResolverInterface 并替换绑定:

resolve() 返回 null 表示「这个企业不可用」,组件据此抛 503,而不是拿着空配置去发请求。 两个方法都会在每次取客户端时被调用,允许内部缓存,但必须无副作用。

运行环境与排障

变更记录

破坏性变更与新增能力都记在主仓库 hyperf-apex/apex 的 CHANGELOG.md 里。


All versions of wecom with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
hyperf-apex/core Version ^0.1
hyperf/cache Version ~3.2.0
hyperf/config Version ~3.2.0
hyperf/logger Version ~3.2.0
psr/simple-cache Version ^1.0 || ^2.0 || ^3.0
w7corp/easywechat Version ^6.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hyperf-apex/wecom contains the following files

Loading the files please wait ...