PHPackages                             weixin/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. weixin/weixin

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

weixin/weixin
=============

A simple PHP client library for weixin

722539[2 issues](https://github.com/handsomegyr/weixin/issues)[1 PRs](https://github.com/handsomegyr/weixin/pulls)PHP

Since Jun 25Pushed 9y ago14 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

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

### 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

	//如果之前获得access_token，那么在生成WeixinClient对象的时候，直接指定
	//$access_token = "RWRVPpT1O9SEyN615puzCOQ9uQfgQK0SA63gWUxNo2ABjgHFdnCL82BnFB_wQGeZH4prBLfn17Qz0WSwcwdLW6A2YvX1yN46dDB2-BggdXkqpM0AZXO4lfZ0LSC_5ABj8NxKLxJkqv565EBja32Gpw";
	//$client = new Weixin\WeixinClient($appid,$secret,$access_token);

	//如果之前没有获得过access_token，那么通过getAccessToken方法 获取access_token
	$client = new Weixin\WeixinClient($appid,$secret);
	$rst = $client->getAccessToken();
	$access_token = $rst['access_token'];

	echo $access_token;
	echo "";

	$openid="xxxxxxxxxxxxxxx";

	//发送客服文本消息
	$client->getWeixinMsgManager()->getWeixinCustomMsgSender()->sendText($openid, "测试");

	//下载多媒体文件
	$mediaId= "xxxxxxxxxxxxxxx";
	$ret= $client->getWeixinMediaManager()->get($mediaId);
	$fileContent = base64_decode($ret['content']);
	$tmpfname = sys_get_temp_dir().'/'.uniqid().'.jpg';
	//保存在本地
	file_put_contents($tmpfname, $fileContent);

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

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

	//获取ticket
	$ticket = urlencode($ticketInfo['ticket']);
	$url = $client->getWeixinQrcodeManager()->getQrcodeUrl($ticket);
	echo $url;
	echo "";
} catch (Exception $e) {
	echo($e->getMessage());
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![handsomegyr](https://avatars.githubusercontent.com/u/3962588?v=4)](https://github.com/handsomegyr "handsomegyr (106 commits)")

### Embed Badge

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

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

###  Alternatives

[palantirnet/drupal-skeleton

A Drupal project template.

141.4k](/packages/palantirnet-drupal-skeleton)

PHPackages © 2026

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