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

AbandonedArchivedLibrary

yoozi/weixin
============

PHP library for interacting with weixin api.

1.0.1(10y ago)5977MITPHPPHP &gt;=5.3.0

Since Aug 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/yoozi/weixin)[ Packagist](https://packagist.org/packages/yoozi/weixin)[ RSS](/packages/yoozi-weixin/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

Weixin \[WIP\]
==============

[](#weixin-wip)

This library is deprecated and not maintained, use [overtrue/wechat](https://github.com/overtrue/wechat) instead.
-----------------------------------------------------------------------------------------------------------------

[](#this-library-is-deprecated-and-not-maintained-use-overtruewechat-instead)

> This library is part of [Project Golem](http://golem.yoozi.cn/), see [yoozi/golem](https://github.com/yoozi/golem) for more info.

Weixin is a [Laravel](http://laravel.com) [package](http://laravel.com/docs/packages) for interacting with [微信公众平台](https://mp.weixin.qq.com).

Content
-------

[](#content)

- [Installation](#installation)
- [Setup](#setup)
- [Usage](#usage)

Install
-------

[](#install)

You can install this library via [Composer](http://getcomposer.org):

```
$ composer require yoozi/weixin --save
```

Or declare in the `composer.json`:

```
{
  "require": {
    "yoozi/weixin": "dev-master"
  }
}
```

and install it:

```
$ composer install
```

Setup
-----

[](#setup)

### Config

[](#config)

Before using this package, you have to publish the configuration file via:

```
$ php artisan config:publish yoozi/weixin
```

And it will create a configuration file in `your-project/app/config/packages/yoozi/weixin/`.

You should setup your weixin account information in `weixin.php`:

namedescriptiontokenserver side token (required)app\_idyour weixin account app id (required)app\_secretyour weixin account app secret key (required)end\_pointweixin server event receive endpoint (required)### Service &amp; Facades

[](#service--facades)

To enable this package, you should add this following lines to `config/app.php`:

```
return array(

    'providers' => array(
        // Illumniate stuffs...
        'Illuminate\Translation\TranslationServiceProvider',
        'Illuminate\Validation\ValidationServiceProvider',
        'Illuminate\View\ViewServiceProvider',
        'Illuminate\Workbench\WorkbenchServiceProvider',

        // Add weixin provider here:
        'Yoozi\Weixin\WeixinServiceProvider',
    ),

    'aliases' => array(
        'Request'        => 'Illuminate\Support\Facades\Request',
        // Be sure change the Response facade to weixin's:
        'Response'       => 'Yoozi\Weixin\Facades\Response',
        'Route'          => 'Illuminate\Support\Facades\Route',

        // Illuminate stuffs...
        'URL'            => 'Illuminate\Support\Facades\URL',
        'Validator'      => 'Illuminate\Support\Facades\Validator',
        'View'           => 'Illuminate\Support\Facades\View',

        // Add weixin facades here:
        'WeixinInput'    => 'Yoozi\Weixin\Facades\WeixinInput',
        'WeixinRouter'   => 'Yoozi\Weixin\Facades\WeixinRouter',
        'WeixinMessage'  => 'Yoozi\Weixin\Facades\WeixinMessage',
        'OAuthClient'    => 'Yoozi\Weixin\Facades\OAuthClient',
        'WeixinClient'   => 'Yoozi\Weixin\Facades\WeixinClient',
    ),

);
```

Usage
-----

[](#usage)

Weixin will provide you:

- a router for binding server event callback,
- a weixin client for interacting with `api.weixin.qq.com`,
- a OAuth client for performing OAuth login.

### Bind Events

[](#bind-events)

In `routes.php`:

```
// Bind a text event.
WeixinRouter::bind('text', 'MyWeixinEventHandler@text');

// Bind a music event.
WeixinRouter::bind('music', 'MyWeixinEventHandler@music');

// Bind a subscribe event.
WeixinRouter::bindEvent('subscribe', 'MyWeixinEventHandler@subscribe');
// This is equivalent to:
WeixinRouter::bind('event:subscribe', 'MyWeixinEventHandler@subscribe');

// Bind a click event.
WeixinRouter::bindClick('a_key', 'MyWeixinEventHandler@clickAKey');
// This is equivalent to:
WeixinRouter::bindEvent('click:a_key', 'MyWeixinEventHandler@subscribe');
// And:
WeixinRouter::bind('event:click:a_key', 'MyWeixinEventHandler@subscribe');

// Bind a view event.
WeixinRouter::bindView('http://google.com', 'MyWeixinEventHandler@visitGoogle');

// Bind a default event.
WeixinRouter::bindDefault('MyWeixinEventHandler@defaultEvent');
```

In `MyWeixinEventHandler.php`:

```
class MyWeixinEventHandler
{
    public function text()
    {
        $sender = WeixinInput::get('tousername');
        $receiver = WeixinInput::get('fromusername');

        $messge = WeixinMessage::text($receiver, $sender, 'Hello, world!');

        return Response::xml($message);
    }

    // Handle other events...
}
```

### Weixin Client

[](#weixin-client)

Weixin client can be used to:

- retrieve [access token](http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96access_token)
- retrieve [user's basic profile via openid](http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF)

Example:

```
// Notes:
//  You should store this access token in the cache or somewhere else
//  for reuse later.
$accessToken = WeixinClient::getAccessToken();
$openId = 'an_user_openid';

var_dump(WeixinClient::getUserInfo($openId, $accessToken));
```

### OAuth Client

[](#oauth-client)

Weixin OAtuth client provides you:

- generate authorize url with callback
- retrieve access token with OAuth code
- retrieve user's basic profile with access token

Example:

```
// Redirect user to $authorizeUrl and receive the OAuth code ($code)
$authorizeUrl = OAuthClient::getAccessUrl($codeReceiveUrl);

// Get access token from code
$accessTokenAndOpenId = OAuthClient::getAccessToken($code);
$accessToken = $accessTokenAndOpenId['access_token'];
$openId = $accessTokenAndOpenId['openid'];

// Get user profile
var_dump(OAuthClient::getUserInfo($openId, $accessToken));
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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 ~479 days

Total

2

Last Release

3798d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8aba0a256c6e7e6fdaea86b57b31efc56eda0a1fbdd6e24e3f4ac06bd1c87a67?d=identicon)[yangg](/maintainers/yangg)

![](https://www.gravatar.com/avatar/5d9b532dca488145a051349dd37aff78d84c015009f62ba56aacde3952bb01be?d=identicon)[hbc](/maintainers/hbc)

---

Top Contributors

[![bcho](https://avatars.githubusercontent.com/u/1975118?v=4)](https://github.com/bcho "bcho (24 commits)")[![cnsaturn](https://avatars.githubusercontent.com/u/275750?v=4)](https://github.com/cnsaturn "cnsaturn (2 commits)")

### Embed Badge

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

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

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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