Download the PHP package yoolo-mine/wecom-crypto without Composer

On this page you can find all versions of the php package yoolo-mine/wecom-crypto. 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-crypto

wecom-crypto

企业微信回调消息加解密库,适用于 Laravel。基于企业微信官方加解密方案 PHP 示例封装为 Composer 包。

环境要求

安装

安装后 Laravel 会自动发现并注册服务提供者,无需在 config/app.php 中手动添加。

配置

方式一:使用环境变量(推荐)

在项目 .env 中配置:

无需发布配置文件,包会通过默认配置读取上述环境变量。

方式二:发布配置文件

如需在应用内直接修改配置,可发布配置文件到 config/wecom_crypto.php

发布后可在 config/wecom_crypto.php 中修改 encodingAesKeytokencorpId

Laravel 集成说明

自动发现

包在 composer.json 中声明了 extra.laravel.providers,Laravel 5.5+ 会在执行 composer install/update 时自动发现并注册 WecomCryptoServiceProvider无需config/app.phpproviders 数组中手动添加。

配置来源与优先级

  1. 若执行过 php artisan vendor:publish --tag=wecom-crypto-config,应用会使用 config/wecom_crypto.php 中的值(该文件通常通过 env() 读取 .env)。
  2. 若未发布配置,包会使用包内默认配置mergeConfigFrom),即直接读取 config('wecom_crypto.xxx'),而该值来自包自带的 config/wecom_crypto.php,其中已写 env('WECHAT_WORK_*', ''),因此只要在 .env 中配置即可生效。

多应用 / 多套回调配置

若需要对接多个企业微信应用或不同 ReceiveId(如自建应用与第三方应用),不要使用单例 app('wxcrypt'),而是在业务处按需实例化:

也可在配置文件中为不同应用定义多组 key,再按应用选择后传入 WXBizMsgCrypt

手动注册服务提供者(可选)

若自动发现未生效(例如 Laravel 版本较旧或自定义了发现逻辑),可在 config/app.phpproviders 数组中手动添加:

注意事项

使用

在 Laravel 中通过容器使用

包注册了单例 wxcrypt,可直接注入或从容器解析:

验证回调 URL(VerifyURL)

企业微信在配置回调 URL 时会发起 GET 校验,用本方法验证并返回需回显的明文:

解密回调消息(DecryptMsg)

收到企业微信 POST 的加密消息时,先解密再处理:

加密回复消息(EncryptMsg)

需要对企业微信回复加密消息时:

不使用 Laravel 容器时

也可直接实例化,适用于非 Laravel 或需要多套配置的场景:

示例:路由与控制器

以下为在企业微信后台配置的「接收消息服务器」对应的路由与控制器示例,便于直接接入 GET 校验与 POST 消息。

路由

routes/web.phproutes/api.php 中定义(企业微信要求回调 URL 可公网访问,若用 web.php 需注意 CSRF 排除):

若使用 routes/web.php 且启用了 CSRF,需在 app/Http/Middleware/VerifyCsrfToken.php$except 中排除该 URI,例如:

控制器示例

企业微信后台配置

  1. 进入企业微信管理后台 → 应用管理 → 自建应用(或对应应用)→ 接收消息。
  2. 设置「接收消息服务器」URL 为:https://你的域名/wecom/callback(与上面路由一致)。
  3. 填写 Token、EncodingAESKey,并保存后使用「验证」按钮;验证通过即会请求上述 GET 接口并校验通过。

错误码

企业微信官方文档一致,可使用 YooloMine\WecomCrypto\CallBack\ErrorCode 常量判断:

常量 说明
ErrorCode::OK 0 成功
ErrorCode::ValidateSignatureError -40001 签名验证错误
ErrorCode::ParseXmlError -40002 xml 解析失败
ErrorCode::ComputeSignatureError -40003 sha 加密生成签名失败
ErrorCode::IllegalAesKey -40004 EncodingAESKey 非法
ErrorCode::ValidateCorpidError -40005 ReceiveId 校验错误
ErrorCode::EncryptAESError -40006 AES 加密失败
ErrorCode::DecryptAESError -40007 AES 解密失败
ErrorCode::IllegalBuffer -40008 解密后得到的 buffer 非法
ErrorCode::EncodeBase64Error -40009 base64 加密失败
ErrorCode::DecodeBase64Error -40010 base64 解密失败
ErrorCode::GenReturnXmlError -40011 生成 xml 失败

协议与参考


All versions of wecom-crypto with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-openssl Version *
ext-dom Version *
ext-libxml Version *
illuminate/support Version ^8.0|^9.0
illuminate/config Version ^8.0
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 yoolo-mine/wecom-crypto contains the following files

Loading the files please wait ...