PHPackages                             ygmt/wxxcx - 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. ygmt/wxxcx

ActiveLibrary

ygmt/wxxcx
==========

A WeChat applet (xiaochengxu) plugins for Laravel 5.

v2.0(8y ago)099MITPHPPHP &gt;=5.5.9

Since May 27Pushed 6y agoCompare

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

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

Laravel 5 微信小程序扩展
=================

[](#laravel-5-微信小程序扩展)

> 小程序官方的加解密 SDK 已经非常清楚了，只不过改成 Laravel 风格而已，仅仅相当于搬砖工。至于重复造轮子，我发现其他人的扩展解密用户信息的时候代码出错了，并且需要安装一个 Laravel 的 Curl 扩展也没说。只好自己去根据他们的源码自己写一个0.0 ，不依赖其他扩展，直接安装使用即可。

小程序API接口
--------

[](#小程序api接口)

- 用户登录：[wx.login](https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html)
- 获取用户信息：[wx.getUserInfo](https://mp.weixin.qq.com/debug/wxadoc/dev/api/open.html#wxgetuserinfoobject)

安装
--

[](#安装)

> 由于 PHP7.1 的加密函数 `mcrypt_module_open()` 因为过时而被废弃。使用 PHP7.1 版本的人请安装 2.0 版本的代码

执行以下命令安装最新稳定版本:

**PHP &lt; 7.1**

```
composer require ygmt/wxxcx=1.*
```

**PHP &gt; 7.1**

```
composer require ygmt/wxxcx=2.*
```

或者添加如下信息到你的 `composer.json` 文件中 :

**PHP &lt; 7.1**

```
"ygmt/wxxcx": "^1.0"
```

**PHP &gt; 7.1**

```
"ygmt/wxxcx": "^2.0"
```

然后注册服务提供者到 Laravel中 具体位置：`/config/app.php` 中的 `providers` 数组:

```
ygmt\Wxxcx\WxxcxServiceProvider::class,
```

发布配置文件:

```
php artisan vendor:publish --tag=wxxcx
```

命令完成后，会添加一个`wxxcx.php`配置文件到您的配置文件夹 如 : `/config/wxxcx.php`。

生成配置文件后，将小程序的 `AppID` 和 `AppSecret` 填写到 `/config/wxxcx.php` 文件中

在Laravel 5控制器中使用 (示例)
---------------------

[](#在laravel-5控制器中使用-示例)

```
...

use ygmt\Wxxcx\Wxxcx;

class WxxcxController extends Controller
{
    protected $wxxcx;

    function __construct(Wxxcx $wxxcx)
    {
        $this->wxxcx = $wxxcx;
    }

    /**
     * 小程序登录获取用户信息
     * @author 晚黎
     * @date   2017-05-27T14:37:08+0800
     * @return [type]                   [description]
     */
    public function getWxUserInfo()
    {
        //code 在小程序端使用 wx.login 获取
        $code = request('code', '');
        //encryptedData 和 iv 在小程序端使用 wx.getUserInfo 获取
        $encryptedData = request('encryptedData', '');
        $iv = request('iv', '');

        //根据 code 获取用户 session_key 等信息, 返回用户openid 和 session_key
        $userInfo = $this->wxxcx->getLoginInfo($code);

        //获取解密后的用户信息
        return $this->wxxcx->getUserInfo($encryptedData, $iv);
    }
}
```

用户信息返回格式:

```
{
    "openId": "xxxx",
    "nickName": "晚黎",
    "gender": 1,
    "language": "zh_CN",
    "city": "",
    "province": "Shanghai",
    "country": "CN",
    "avatarUrl": "http://wx.qlogo.cn/mmopen/xxxx",
    "watermark": {
        "timestamp": 1495867603,
        "appid": "your appid"
    }
}

```

小程序端获取 code、iv、encryptedData 向服务端发送请求示例代码：
------------------------------------------

[](#小程序端获取-codeivencrypteddata-向服务端发送请求示例代码)

```
//调用登录接口
wx.login({
    success: function (response) {
        var code = response.code
        wx.getUserInfo({
            success: function (resp) {
                wx.request({
                    url: 'your domain',
                    data: {
                        code: code,
                        iv: resp.iv,
                        encryptedData: resp.encryptedData
                    },
                    success: function (res) {
                        console.log(res.data)
                    }
                })
            }
        })
    },
    fail:function(){
        ...
    }
})
```

> 如有bug，请在 [Issues](https://github.com/lanceWan/wxxcx/issues) 中反馈，非常感谢！

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~11 days

Total

2

Last Release

3258d ago

Major Versions

v1.0 → v2.02017-06-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e9293af6933c9ae2cc3febb6f6bbbae14f46af8bbaaebb6ab0a70d7f89b4b1c?d=identicon)[ygmt](/maintainers/ygmt)

---

Top Contributors

[![lanceWan](https://avatars.githubusercontent.com/u/7288380?v=4)](https://github.com/lanceWan "lanceWan (2 commits)")[![zaxw](https://avatars.githubusercontent.com/u/23615813?v=4)](https://github.com/zaxw "zaxw (2 commits)")[![cyij](https://avatars.githubusercontent.com/u/2336421?v=4)](https://github.com/cyij "cyij (1 commits)")

### Embed Badge

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

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

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)

PHPackages © 2026

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