PHPackages                             icatholic/weixin - 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. icatholic/weixin

ActiveLibrary

icatholic/weixin
================

A simple PHP client library for weixin

2119116[1 issues](https://github.com/icatholic/weixin/issues)PHP

Since Mar 14Pushed 3y ago7 watchersCompare

[ Source](https://github.com/icatholic/weixin)[ Packagist](https://packagist.org/packages/icatholic/weixin)[ RSS](/packages/icatholic-weixin/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

微信公众平台开发模式通用接口API(Weixin)
=========================

[](#微信公众平台开发模式通用接口apiweixin)

is a PHP (&gt;= 5.2.11) client library for the 微信公众平台开发模式通用接口API(Weixin)

本库在get post upload download方面依赖于zend framework1.12 如果项目非zend framework1.12 请在composer中引用相关的依赖关系

### Loading the library

[](#loading-the-library)

Weixin relies on the autoloading features of PHP to load its files when needed and complies with the [PSR-0 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) which makes it compatible with most PHP frameworks. Autoloading is handled automatically when dependencies are managed using Composer, but you can also leverage its own autoloader if you are going to use it in a project or script without any PSR-0 compliant autoloading facility:

```
// Prepend a base path if Weixin is not available in your "include_path".
require 'Weixin/Autoloader.php';

Weixin\Autoloader::register();
```

It is possible to easily create a [phar](http://www.php.net/manual/en/intro.phar.php) archive from the repository just by launching `bin/create-phar`. The generated phar contains a stub defining an autoloader function for Weixin, so you just need to require the phar to start using the library. Alternatively, it is also possible to generate one single PHP file that holds every class like older versions of Weixin by launching `bin/create-single-file`, but this practice **is not** encouraged.

### 调用事例

[](#调用事例)

```
try {

	$appid="xxxxxxxxxxxx";//appID
	$secret="xxxxxxxxxxxx";//appsecret
	$verifyToken = 'XXXXXXXXX';

	//token的获取
	$objToken = new \Weixin\Token\Server($appid,$secret);
	$arrAccessToken = $objToken->getAccessToken();
	$strAccessToken = $arrAccessToken['access_token'];

	//微信client对象
	$client = new Weixin\Client();

	//微信推送服务器验证
	$client->verify($verifyToken);

	//对于推送过来的消息，进行签名校验
	$client->checkSignature($verifyToken);

	$client->setAccessToken($strAccessToken);
	//通过微信推送过来的消息，获取相应的两个参数
    $client->setFromAndTo($formUserName,$toUserName);

	//被动消息
	$client->getMsgManager()->getReplySender()->sendText("测试");

	//主动客服消息
	$client->getMsgManager()->getCustomSender()->sendText("测试");

	//下载多媒体文件
	$mediaId= "xxxxxxxxxxxxxxx";
	$rst= $client->getMediaManager()->get($mediaId);
	echo $rst['name'];//文件名称 例如mediaId.jpg
	echo $rst['bytes'];//文件内容，二进制
	echo "";

	//获取微信用户信息
	$userinfo =$client->getUserManager()->getUserInfo($fromUserName);
	print_r($userinfo);
	echo "";

	//生成ticket
	$scene_id =1;
	$ticketInfo = $client->getQrcodeManager()->create($scene_id,false);
	print_r($ticketInfo);
	echo "";

	//获取ticket
	$ticket = urlencode($ticketInfo['ticket']);
	$url = $client->getQrcodeManager()->getQrcodeUrl($ticket);
	echo $url;
	echo "";

	$articles = array();
	$articles[] = array(
	    "thumb_media_id" => "o9S42TG72uC480YMC99_YKLNtaxi7FtzlWIBx2vnL1pw6zJhS5Abtv880YUzoMOl",
	    "author" => "ben",
	    "title" => "扑刺客打刺客",
	    "content_source_url" => "http://www.baidu.com/",
	    "content" => "扑刺客打刺客",
	    "digest" => "扑刺客打刺客",
	    "show_cover_pic" => "1"
	);
	$articles[] = array(
	    "thumb_media_id" => "o9S42TG72uC480YMC99_YKLNtaxi7FtzlWIBx2vnL1pw6zJhS5Abtv880YUzoMOl",
	    "author" => "ben",
	    "title" => "扑刺客打刺客",
	    "content_source_url" => "http://www.baidu.com/",
	    "content" => "扑刺客打刺客",
	    "digest" => "扑刺客打刺客",
	    "show_cover_pic" => "1"
	);
	//上传图文消息素材
	$rst = $client->getMediaManager()->uploadNews($articles);
	print_r($rst);
	echo "";

	//上传视频素材
	$rst = $client->getMediaManager()->uploadVideo("D3uOxo1WNW52dVi4wZE1jwvqySduzVzCApTOmR7pL2hguFECCk2fq82cOxyewF3X", "TITLE", "Description");
	print_r($rst);
	echo "";

	//根据分组进行群发
	$group_id = '0';
	// 发送文本
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendTextByGroup($group_id, 'hello');
	print_r($rst);
	echo "";

	// 发送图片
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendImageByGroup($group_id, 'PTI4V7PGaH2mXtdArQsih6daoyNnEJRHteXo_sJO5yGQQdscEXi7ONRtXsucRYEC');
	print_r($rst);
	echo "";

	// 发送音频
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendVoiceByGroup($group_id, 'yntrDDxEaYYzlBKGheHckrJyszWYL3-a0hEXtYt2oy0dfhWz2hjIZypXnupuEnMk');
	print_r($rst);
	echo "";

	// 发送视频
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendVideoByGroup($group_id, 'g39F9u52K_06kkFzcLilPgyFOgJufnzZr1E39xRjD1NmIu_iEqNI1Kx92eTxipeS');
	print_r($rst);
	echo "";

	// 发送图文
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendGraphTextByGroup($group_id, 'xjZXFr1U7x8b4MZ3CpkF3UGNddGmpHag6La84uak-bKym27gC-D1N0jmQaGzx9bR');
	print_r($rst);
	echo "";

	//根据OpenID列表群发
	$toUsers = array(
	    "oq_9ut1KV35fk7PDFyrfZl3LvVuk",
	    "oq_9ut0Jca_pZA02CFDyuLE0UJCQ"
	);
	// 发送文本
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendTextByOpenid($toUsers, 'hello');
	print_r($rst);
	echo "";

	// 发送图片
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendImageByOpenid($toUsers, 'PTI4V7PGaH2mXtdArQsih6daoyNnEJRHteXo_sJO5yGQQdscEXi7ONRtXsucRYEC');
	print_r($rst);
	echo "";

	// 发送音频
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendVoiceByOpenid($toUsers, 'yntrDDxEaYYzlBKGheHckrJyszWYL3-a0hEXtYt2oy0dfhWz2hjIZypXnupuEnMk');
	print_r($rst);
	echo "";

	// 发送视频
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendVideoByOpenid($toUsers, 'xdJyQzOv2uTjWpickq3sQjGtDRj5mFFb9e-GP4HgV72ZtP_UDO0TnH29aTYLXy5p', 'testing', 'testing');
	print_r($rst);
	echo "";

	// 发送图文
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->sendGraphTextByOpenid($toUsers, 'xjZXFr1U7x8b4MZ3CpkF3UGNddGmpHag6La84uak-bKym27gC-D1N0jmQaGzx9bR');
	print_r($rst);
	echo "";

	// 删除消息
	$rst = $client->getMsgManager()
	    ->getMassSender()
	    ->delete('2347904591');
	print_r($rst);
	echo "";

} catch (Exception $e) {
	echo($e->getMessage());
}
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 65.6% 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.

### Community

Maintainers

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

---

Top Contributors

[![handsomegyr](https://avatars.githubusercontent.com/u/3962588?v=4)](https://github.com/handsomegyr "handsomegyr (198 commits)")[![shanghaiyangming](https://avatars.githubusercontent.com/u/712222?v=4)](https://github.com/shanghaiyangming "shanghaiyangming (99 commits)")[![icatholic](https://avatars.githubusercontent.com/u/6744999?v=4)](https://github.com/icatholic "icatholic (5 commits)")

### Embed Badge

![Health badge](/badges/icatholic-weixin/health.svg)

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

PHPackages © 2026

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