PHPackages                             xiayuer/wechat-developer-github - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. xiayuer/wechat-developer-github

ActiveLibrary[API Development](/categories/api)

xiayuer/wechat-developer-github
===============================

WeChat and Alipay Platform Development

v3.2.0(7mo ago)07MITPHPPHP &gt;=5.4

Since Apr 9Pushed 7mo agoCompare

[ Source](https://github.com/x397072174/WeChatDeveloper)[ Packagist](https://packagist.org/packages/xiayuer/wechat-developer-github)[ Docs](https://thinkadmin.top)[ RSS](/packages/xiayuer-wechat-developer-github/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (15)Used By (0)

WeChatDeveloper for PHP
=======================

[](#wechatdeveloper-for-php)

[![star](https://camo.githubusercontent.com/48781833a5c3b25eb8041a55e81b653ee6253bb4f633148765d2ec39fb1a51c6/68747470733a2f2f676974636f64652e636f6d2f5468696e6b41646d696e2f576543686174446576656c6f7065722f737461722f62616467652e737667)](https://gitcode.com/ThinkAdmin/ThinkAdmin)[![star](https://camo.githubusercontent.com/e12eb9f405148fa0705e45147e51345b79f9c0f658f94c481ef64b3537c41d15/68747470733a2f2f67697465652e636f6d2f7a6f756a696e676c692f576543686174446576656c6f7065722f62616467652f737461722e7376673f7468656d653d677670)](https://gitee.com/zoujingli/ThinkAdmin)[![Latest Stable Version](https://camo.githubusercontent.com/4661eb7915351b1e78ab2a6d03e560481ff3df9a0431c7d5c6a908cec7591632/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f7765636861742d646576656c6f7065722f762f737461626c65)](https://packagist.org/packages/zoujingli/wechat-developer)[![Total Downloads](https://camo.githubusercontent.com/211f8ffc36542ce44524be0b8874d75bdaeb0fe08f6980c3da237318f8ef6d07/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f7765636861742d646576656c6f7065722f646f776e6c6f616473)](https://packagist.org/packages/zoujingli/wechat-developer)[![Monthly Downloads](https://camo.githubusercontent.com/3c9c225bac8ea10cccbeabd3f0865c542f4be0c0aedc53585b78046c7306c746/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f7765636861742d646576656c6f7065722f642f6d6f6e74686c79)](https://packagist.org/packages/zoujingli/wechat-developer)[![Daily Downloads](https://camo.githubusercontent.com/1efad56c13164d47428615107a1f642def1b6163c2b515e43d36c446557c2607/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f7765636861742d646576656c6f7065722f642f6461696c79)](https://packagist.org/packages/zoujingli/wechat-developer)[![PHP Version Require](https://camo.githubusercontent.com/a47986fb7bdbaa6f6709209fa167b4cd05365572137aeadb55dd2874d583e774/687474703a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f7765636861742d646576656c6f7065722f726571756972652f706870)](https://packagist.org/packages/wechat-developer)[![License](https://camo.githubusercontent.com/d8e1fdae598c6af61909d2ee7783d4f63baf2792610a191cb40cd484461fc1f6/68747470733a2f2f706f7365722e707567782e6f72672f7a6f756a696e676c692f7765636861742d646576656c6f7065722f6c6963656e7365)](https://packagist.org/packages/zoujingli/wechat-developer)

- WeChatDeveloper 是基于 [wechat-php-sdk](https://github.com/zoujingli/wechat-php-sdk) 重构，优化并完善；
- 运行最底要求 PHP 版本 5.4 , 建议在 PHP7 上运行以获取最佳性能；
- 目前 WeChatDeveloper 针对 access\_token 失效增加了自动刷新机制；
- 微信的部分接口需要缓存数据在本地，因此配置目录并需要对目录有写权限；
- 我们鼓励大家使用 composer 来管理您的第三方库，方便后期更新操作；
- WeChatDeveloper 已历经数个线上项目考验，欢迎 fork 或 star 此项目。
- 微信商户已经支持 v2 和 v3 接口，未加入的接口可以使用通用方式调用。

功能描述
----

[](#功能描述)

- 微信小程序，服务端接口支持
- 微信认证服务号，服务端接口支持
- 微信支付（账单、卡券、红包、退款、转账、App支付、JSAPI支付、Web支付、扫码支付等）
- 支付宝支付（账单、转账、App支付、刷卡支付、扫码支付、Web支付、Wap支付等）

技术帮助
----

[](#技术帮助)

PHP开发技术交流（QQ群 513350915）

[![PHP微信开发群 (SDK)](https://camo.githubusercontent.com/d8a86bc02a44a78d23d0746f300d73b0f9bb7e9a1f9eb6af61b2f159525f317d/687474703a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67)](http://shang.qq.com/wpa/qunwpa?idkey=ae25cf789dafbef62e50a980ffc31242f150bc61a61164458216dd98c411832a)

WeChatDeveloper 是基于官方接口封装，在做微信开发前，必需先阅读微信官方文档。

- 微信官方文档：
- 商户支付文档：

针对 WeChatDeveloper 也有一准备了帮助资料可供参考。

- ThinkAdmin：
- WeChatDeveloper：

代码仓库
----

[](#代码仓库)

WeChatDeveloper 为开源项目，允许把它用于任何地方，不受任何约束，欢迎 fork 项目。

我们的代码仓库已移至 **Github**，而 **Gitee** 和 **Gitcode** 则仅作为国内镜像仓库，方便广大开发者获取和使用。若想提交 **PR** 或 **ISSUE** 请在 [WeChatDeveloper](https://github.com/zoujingli/WeChatDeveloper) 仓库进行操作，如果在其他仓库操作或提交问题将无法处理！

- Gitee 仓库地址：
- GitHub 仓库地址：
- GitCode 仓库地址：

文件说明（后续会根据官方文档增加文件）
-------------------

[](#文件说明后续会根据官方文档增加文件)

文件名类名描述类型加载 ①App.phpAliPay\\App支付宝App支付支付宝支付\\We::AliPayApp()Bill.phpAliPay\\Bill支付宝账单下载支付宝支付\\We::AliPayBill()Pos.phpAliPay\\Pos支付宝刷卡支付支付宝支付\\We::AliPayPos()Scan.phpAliPay\\Scan支付宝扫码支付支付宝支付\\We::AliPayScan()Transfer.phpAliPay\\Transfer支付宝转账支付宝支付\\We::AliPayTransfer()Wap.phpAliPay\\Wap支付宝Wap支付支付宝支付\\We::AliPayWap()Web.phpAliPay\\Web支付宝Web支付支付宝支付\\We::AliPayWeb()Card.phpWeChat\\Card微信卡券接口支持认证服务号\\We::WeChatCard()Custom.phpWeChat\\Custom微信客服消息接口支持认证服务号\\We::WeChatCustom()Media.phpWeChat\\Media微信媒体素材接口支持认证服务号\\We::WeChatMedia()Oauth.phpWeChat\\Oauth微信网页授权消息类接口认证服务号\\We::WeChatOauth()Pay.phpWeChat\\Pay微信支付类接口认证服务号\\We::WeChatPay()Product.phpWeChat\\Product微信商店类接口认证服务号\\We::WeChatProduct()Qrcode.phpWeChat\\Qrcode微信二维码接口支持认证服务号\\We::WeChatQrcode()Receive.phpWeChat\\Receive微信推送事件消息处理支持认证服务号\\We::WeChatReceive()Scan.phpWeChat\\Scan微信扫一扫接口支持认证服务号\\We::WeChatScan()Script.phpWeChat\\Script微信前端JSSDK支持认证服务号\\We::WeChatScript()Shake.phpWeChat\\Shake微信蓝牙设备揺一揺接口认证服务号\\We::WeChatShake()Tags.phpWeChat\\Tags微信粉丝标签接口支持认证服务号\\We::WeChatTags()Template.phpWeChat\\Template微信模板消息接口支持认证服务号\\We::WeChatTemplate()User.phpWeChat\\User微信粉丝管理接口支持认证服务号\\We::WeChatCard()Wifi.phpWeChat\\Wifi微信门店WIFI管理支持认证服务号\\We::WeChatWifi()Draft.phpWeChat\\Draft微信草稿箱认证服务号\\We::WeChatDraft()Freepublish.phpWeChat\\Freepublish微信发布能力认证服务号\\We::WeChatFreepublish()Bill.phpWePay\\Bill微信商户账单及评论微信支付\\We::WePayBill()Coupon.phpWePay\\Coupon微信商户代金券微信支付\\We::WePayCoupon()Order.phpWePay\\Order微信商户订单微信支付\\We::WePayOrder()Redpack.phpWePay\\Redpack微信红包支持微信支付\\We::WePayRedpack()Refund.phpWePay\\Refund微信商户退款微信支付\\We::WePayRefund()Transfers.phpWePay\\Transfers微信商户打款到零钱微信支付\\We::WePayTransfers()TransfersBank.phpWePay\\TransfersBank微信商户打款到银行卡微信支付\\We::WePayTransfersBank()Crypt.phpWeMini\\Crypt微信小程序数据加密处理微信小程序\\We::WeMiniCrypt()Plugs.phpWeMini\\Plugs微信小程序插件管理微信小程序\\We::WeMiniPlugs()Poi.phpWeMini\\Poi微信小程序地址管理微信小程序\\We::WeMiniPoi()Qrcode.phpWeMini\\Qrcode微信小程序二维码管理微信小程序\\We::WeMiniCrypt()Template.phpWeMini\\Template微信小程序模板消息支持微信小程序\\We::WeMiniTemplate()Total.phpWeMini\\Total微信小程序数据接口微信小程序\\We::WeMiniTotal()安装使用
----

[](#安装使用)

1.1 通过 Composer 来管理安装

```
# 首次安装 线上版本（稳定）
composer require zoujingli/wechat-developer

# 首次安装 开发版本（开发）
composer require zoujingli/wechat-developer dev-master

# 更新 WeChatDeveloper
composer update zoujingli/wechat-developer
```

1.2 如果不使用 Composer， 可以下载 WeChatDeveloper 并解压到项目中

```
# 在项目中加载初始化文件
include "您的目录/WeChatDeveloper/include.php";
```

2.1 接口实例所需参数

```
// =====================================================
// 配置缓存处理函数（适配不同环境）
// -----------------------------------------------------
// - 数据缓存（set|get|del）：可存储到本地或 Redis
// - 文件缓存（put）：仅支持本地存储，并返回可读的文件路径
// - 若未设置自定义缓存处理，默认存储在 cache_path 目录
// =====================================================
// \WeChat\Contracts\Tools::$cache_callable = [
//    'set' => function ($name, $value, $expired = 360) {
//        var_dump(func_get_args());
//        return $value;
//    },
//    'get' => function ($name) {
//        var_dump(func_get_args());
//        return $value;
//    },
//    'del' => function ($name) {
//        var_dump(func_get_args());
//        return true;
//    },
//    'put' => function ($name) {
//        var_dump(func_get_args());
//        return $filePath;
//    },
// ];

return [
    // 公众号 APPID（可选）
    'appid'        => 'wx3760xxxxxxxxxxxx',

    // 微信商户号（必填）
    'mch_id'       => '15293xxxxxx',

    // 微信商户 V3 接口密钥（必填）
    'mch_v3_key'   => '98b7fxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // 商户证书序列号（可选）：用于请求签名
    'cert_serial'  => '49055D67B2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',

    // 微信商户证书公钥（必填）：可填写证书内容或文件路径，仅用于提取序列号
    'cert_public'  => $certPublic,

    // 微信商户证书私钥（必填）：可填写证书内容或文件路径，用于请求数据签名
    'cert_private' => $certPrivate,

    // 自定义证书包：支持平台证书或支付公钥（可填写文件路径或证书内容）
    'cert_package' => [
        'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' => $certPayment
    ],

    // 微信平台证书或支付证书序列号（可选）
    // 'mp_cert_serial'  => 'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // 微信平台证书或支付证书内容（可选）
    // 'mp_cert_content' => $certPayment,

    // 运行时文件缓存路径（可选）
    'cache_path'   => ''
];
```

3.1 实例指定接口

```
try {

    // 实例对应的接口对象
    $user = new \WeChat\User($config);

    // 调用接口对象方法
    $list = $user->getUserList();

    // 处理返回的结果
    echo '';
    var_export($list);

} catch (Exception $e) {

    // 出错啦，处理下吧
    echo $e->getMessage() . PHP_EOL;

}
```

微信支付
----

[](#微信支付)

```
  // 创建接口实例
  $wechat = new \WeChat\Pay($config);

  // 组装参数，可以参考官方商户文档
  $options = [
      'body'             => '测试商品',
      'out_trade_no'     => time(),
      'total_fee'        => '1',
      'openid'           => 'o38gpszoJoC9oJYz3UHHf6bEp0Lo',
      'trade_type'       => 'JSAPI',
      'notify_url'       => 'http://a.com/text.html',
      'spbill_create_ip' => '127.0.0.1',
  ];

try {

    // 生成预支付码
    $result = $wechat->createOrder($options);

    // 创建JSAPI参数签名
    $options = $wechat->createParamsForJsApi($result['prepay_id']);

    // @todo 把 $options 传到前端用js发起支付就可以了

} catch (Exception $e) {

    // 出错啦，处理下吧
    echo $e->getMessage() . PHP_EOL;

}
```

- 更多功能请阅读测试代码或SDK封装源码

支付宝支付
-----

[](#支付宝支付)

- 支付参数配置（可用沙箱模式）

```
$config = [
    // 沙箱模式
    'debug'            => true,
    // 签名类型 ( RSA|RSA2 )
    'sign_type'        => 'RSA2',
    // 应用ID
    'appid'            => '2021000122667306',
    // 应用私钥内容 ( 需1行填写，特别注意：这里的应用私钥通常由支付宝密钥管理工具生成 )
    'private_key'      => 'MIIEowIBAAKCAQEAn...',
    // 公钥模式，支付宝公钥内容 ( 需1行填写，特别注意：这里不是应用公钥而是支付宝公钥，通常是上传应用公钥换取支付宝公钥，在网页可以复制 )
    'public_key'       => '',
    // 证书模式，应用公钥证书路径 ( 新版资金类接口转 app_cert_sn，如文件 appCertPublicKey.crt )
    'app_cert_path'    => __DIR__ . '/alipay/appPublicCert.crt', // 'app_cert' => '证书内容',
    // 证书模式，支付宝根证书路径 ( 新版资金类接口转 alipay_root_cert_sn，如文件 alipayRootCert.crt )
    'alipay_root_path' => __DIR__ . '/alipay/alipayRootCert.crt', // 'root_cert' => '证书内容',
    // 证书模式，支付宝公钥证书路径 ( 未填写 public_key 时启用此参数，如文件 alipayPublicCert.crt )
    'alipay_cert_path' => __DIR__ . '/alipay/alipayPublicCert.crt', // 'public_key' => '证书内容'
    // 支付成功通知地址
    'notify_url'       => '',
    // 网页支付回跳地址
    'return_url'       => '',
];
```

- 支付宝发起PC网站支付

```
// 参考公共参数  https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';

try {

    // 实例支付对象
    $pay = We::AliPayWeb($config);
    // $pay = new \AliPay\Web($config);

    // 参考链接：https://docs.open.alipay.com/api_1/alipay.trade.page.pay
    $result = $pay->apply([
        'out_trade_no' => time(), // 商户订单号
        'total_amount' => '1',    // 支付金额
        'subject'      => '支付订单描述', // 支付订单描述
    ]);

    echo $result; // 直接输出HTML（提交表单跳转)

} catch (Exception $e) {

    // 异常处理
    echo $e->getMessage();

}
```

- 支付宝发起手机网站支付

```
// 参考公共参数  https://docs.open.alipay.com/203/107090/
$config['notify_url'] = 'http://pay.thinkadmin.top/test/alipay-notify.php';
$config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';

try {

    // 实例支付对象
    $pay = We::AliPayWap($config);
    // $pay = new \AliPay\Wap($config);

    // 参考链接：https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
    $result = $pay->apply([
        'out_trade_no' => time(), // 商户订单号
        'total_amount' => '1',    // 支付金额
        'subject'      => '支付订单描述', // 支付订单描述
    ]);

    echo $result; // 直接输出HTML（提交表单跳转)

} catch (Exception $e) {

    // 异常处理
    echo $e->getMessage();

}
```

- 更多功能请阅读测试代码或SDK封装源码

版权说明
----

[](#版权说明)

**WeChatDeveloper** 遵循 **MIT** 开源协议发布，并免费提供使用。

本项目包含的第三方源码和二进制文件的版权信息将另行标注，请在对应文件查看。

版权所有 Copyright © 2014-2025 by ThinkAdmin () All rights reserved。

赞助打赏，请作者喝杯茶 ~
-------------

[](#赞助打赏请作者喝杯茶-)

[![赞助](https://camo.githubusercontent.com/4258542dbe2f3d891424cb84a2450086710956f51d85ac41bb56957659813c94/68747470733a2f2f7468696e6b61646d696e2e746f702f7374617469632f696d672f7061792e706e67)](https://camo.githubusercontent.com/4258542dbe2f3d891424cb84a2450086710956f51d85ac41bb56957659813c94/68747470733a2f2f7468696e6b61646d696e2e746f702f7374617469632f696d672f7061792e706e67)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance62

Regular maintenance activity

Popularity4

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 94.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~227 days

Recently: every ~40 days

Total

13

Last Release

232d ago

Major Versions

v1.2.76 → v3.2.02025-09-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/037c64350edc9e62714c3c5ef293bdc5546163cb3c93a7a4c91a9b4536d01585?d=identicon)[x397072174](/maintainers/x397072174)

---

Top Contributors

[![zoujingli](https://avatars.githubusercontent.com/u/4349951?v=4)](https://github.com/zoujingli "zoujingli (490 commits)")[![taochangle](https://avatars.githubusercontent.com/u/7435144?v=4)](https://github.com/taochangle "taochangle (5 commits)")[![qfz9527](https://avatars.githubusercontent.com/u/24431828?v=4)](https://github.com/qfz9527 "qfz9527 (4 commits)")[![fxiaotao](https://avatars.githubusercontent.com/u/35088634?v=4)](https://github.com/fxiaotao "fxiaotao (3 commits)")[![x397072174](https://avatars.githubusercontent.com/u/28582392?v=4)](https://github.com/x397072174 "x397072174 (3 commits)")[![pkkgu](https://avatars.githubusercontent.com/u/3060631?v=4)](https://github.com/pkkgu "pkkgu (2 commits)")[![innovational](https://avatars.githubusercontent.com/u/23117769?v=4)](https://github.com/innovational "innovational (2 commits)")[![kentwangit](https://avatars.githubusercontent.com/u/13048265?v=4)](https://github.com/kentwangit "kentwangit (2 commits)")[![big-dream](https://avatars.githubusercontent.com/u/9215157?v=4)](https://github.com/big-dream "big-dream (1 commits)")[![rootrl](https://avatars.githubusercontent.com/u/2967621?v=4)](https://github.com/rootrl "rootrl (1 commits)")[![imzhi](https://avatars.githubusercontent.com/u/2304019?v=4)](https://github.com/imzhi "imzhi (1 commits)")[![voilaf](https://avatars.githubusercontent.com/u/16870828?v=4)](https://github.com/voilaf "voilaf (1 commits)")[![humengcn](https://avatars.githubusercontent.com/u/9284625?v=4)](https://github.com/humengcn "humengcn (1 commits)")[![gaoyiping](https://avatars.githubusercontent.com/u/1197042?v=4)](https://github.com/gaoyiping "gaoyiping (1 commits)")

---

Tags

alipaywechatwechatpayWeChatDeveloperWeMini

### Embed Badge

![Health badge](/badges/xiayuer-wechat-developer-github/health.svg)

```
[![Health](https://phpackages.com/badges/xiayuer-wechat-developer-github/health.svg)](https://phpackages.com/packages/xiayuer-wechat-developer-github)
```

###  Alternatives

[zoujingli/wechat-developer

WeChat and Alipay Platform Development

1.6k136.9k14](/packages/zoujingli-wechat-developer)[overtrue/laravel-wechat

微信 SDK for Laravel

3.0k1.8M53](/packages/overtrue-laravel-wechat)[jianyan74/yii2-easy-wechat

WeChat SDK for yii2, 基于 overtrue/easywechat

14339.4k1](/packages/jianyan74-yii2-easy-wechat)[zoujingli/weopen-developer

WeChat Open Platform Development

9113.4k2](/packages/zoujingli-weopen-developer)[iwechatpay/openapi

为 wechatpay/wechatpay 增加IDE提示的接口描述包。

406.7k](/packages/iwechatpay-openapi)[hillpy/mini-program-sdk

MiniProgramSDK是一个PHP的小程序开发包。封装微信小程序后端相关接口，比如解密信息（用户信息、手机号）、获取小程序码等。

192.5k](/packages/hillpy-mini-program-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
