PHPackages                             mejinke/wechat - 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. mejinke/wechat

ActiveLibrary[API Development](/categories/api)

mejinke/wechat
==============

简单实用的微信接口开发包

0.1.1(8y ago)060MITPHPPHP &gt;=5.4

Since Nov 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mejinke/wechat)[ Packagist](https://packagist.org/packages/mejinke/wechat)[ Docs](https://github.com/mejinke/wechat)[ RSS](/packages/mejinke-wechat/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

\#一、安装

```
composer require mejinke/wechat

```

\#二、快速使用

```
require __DIR__.'/../vendor/autoload.php';

//配置
$options = [
	'appid' => 'xx',
	'appsecret' => 'xx',
	'mchid' => 'xx',
	'key' => 'xx'
];
//例实化
$wechat = new \Wechat\Wechat($options);

```

### 配置项：

[](#配置项)

NameDefaultDescappid-微信appidappsecret-app secretmchid-商户IDkey-商户keyssl\_cert-证书绝对路径ssl\_key-证书key绝对路径pay\_notify\_url-支付成功后回调地址cache\_file-存储微信accessToken相关重要票据信息的文件地址log\_dir-日志文件存放绝对路径\##1、发送消息

```
$tp = new \Wechat\Component\MessageTemplate();
$tp->setId('xx'); //模板ID
$tp->setTouser('xxx'); //接收人openid
$tp->setData([
	'first' => ['value' => '测试标题'],
	'keyword1' => ['value' => '测试'],
	'remark' => ['value' => '马上开始吧.']
]);
$tp->setUrl('xxx');//消息跳转的URL

//发送
$wechat->service('Message')->send($tp);

```

\##2、事件处理

```
$event = $wechat->service('Event');

//关注事件
$event->subscribe(function(\Wechat\Component\Event $e){
    //...
});

//取消关注事件
$event->unsubscribe(function(\Wechat\Component\Event $e){
    //..
});
//扫描带参数二维码事件
$event->scan(function(\Wechat\Component\Event $e){
    //..
});
//上报地理位置事件
$event->location(function(\Wechat\Component\Event $e){
    //..
});

//执行事件派发
$event->dispatch();

```

\##3、支付

```
//下单
$order = new \Wechat\Component\PayOrder();
$order->setBody("xxxxx"); //标题
$order->setAttach("xxxx"); //附件值
$order->setOutTradeNo("xxxxx"); //订单号
$order->setTotalFee(10 * 100); //总金额
$order->setTimeStart(date("YmdHis")); //时间戳
$order->setTimeExpire(date("YmdHis", time() + 600)); //过期时间
$order->setTradeType('JSAPI'); //支付方式
$order->setOpenid("xxxxx"); //用户openid

$pay = $wechat->service('Pay');
//提交订单
$result = $pay->createOrder($order);

//获取JSAPI参数
$pay->getJsApiParameters($result);

//获取回调
$pay->notifyProcess(function($data){
	//....
});

```

\##4、退款

```
//创建退款组件
$refund = new \Wechat\Component\PayRefund();
$refund->setTransactionId('4200000074201802089227802768'); //微信生成的订单号，在支付通知中有返回
//$refund->setsetOutTradeNo('1217752501201407033233368018'); //商户系统内部订单号,可选；和transactionId 二选一
$refund->setOutRefundNo(date("YmdHis")); //商户唯一退款单号
$refund->setTotalFee(10); //订单金额：分
$refund->setRefundFee(10); //退款金额：分
//发起退款
$wechat->service('Pay')->refund($re);

```

\##5、自定义菜单

```
$menu = new \Wechat\Component\Menu();

//添加一个View Button
$id = $menu->addViewButton('官网', 'http://www.xxxx.com');
//添加子菜单
$menu->addViewButton('主页', 'http://www.xxxx.com', $id);

//添加一个Click Button
$menu->addClickButton('最新', 'news');

//提交创建
$wechat->service('Menu')->create($menu);

```

\##6、多媒体

```
//下载多媒体资源
$wechat->service('Media')->download('xxxxxxx-media_id', '保存路径');
//下载speex格式高质量语音文件
$wechat->service('Media')->downloadSpeex('xxxxxxx-media_id', '保存路径');

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

3084d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/da5d67b2903176fd7c11c73da2c98227269bc90a53658d04cd804baaad3e0712?d=identicon)[mejinke](/maintainers/mejinke)

---

Top Contributors

[![mejinke](https://avatars.githubusercontent.com/u/1456784?v=4)](https://github.com/mejinke "mejinke (15 commits)")

---

Tags

apipayweixin

### Embed Badge

![Health badge](/badges/mejinke-wechat/health.svg)

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

###  Alternatives

[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)

PHPackages © 2026

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