PHPackages                             vinlon/laravel-wechat-auth - 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. vinlon/laravel-wechat-auth

ActiveLibrary

vinlon/laravel-wechat-auth
==========================

Wechat Authentication in Laravel framework

0.5.0(4y ago)0105↓100%MITPHP

Since Nov 20Pushed 4y ago1 watchersCompare

[ Source](https://github.com/vinlon/laravel-wechat-auth)[ Packagist](https://packagist.org/packages/vinlon/laravel-wechat-auth)[ RSS](/packages/vinlon-laravel-wechat-auth/feed)WikiDiscussions master Synced today

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

Laravel Wechat Auth
===================

[](#laravel-wechat-auth)

更新日志
----

[](#更新日志)

v0.4.0: 升级到laravel8.0, 增加手机号绑定接口 v0.3.0: wxapp/fast\_login接口支持模拟登录，便于在开发环境进行测试

小程序登录
-----

[](#小程序登录)

### 使用指引

[](#使用指引)

1. #### 引入package

    [](#引入package)

    ```
    composer require vinlon/laravel-wechat-auth
    ```
2. #### 发布config文件 (Laravel 版本 &gt; 5.5)

    [](#发布config文件-laravel-版本--55)

    先执行如下命令

    ```
    php artisan vendor:publish --provider="Vinlon\Laravel\WechatAuth\WechatAuthServiceProvider"
    ```

    在应用程序的config目录下，将生成wechat-auth.php文件（注：一般情况下，此文件不需要做任何修改，配置的调整通过环境变量实现）
3. 环境变量

    配置小程序的APPID 和 APPSECRET

    ```
    WECHAT_AUTH_WXAPP_APP_ID=
    WECHAT_AUTH_WXAPP_APP_SECRET=
    WECHAT_AUTH_TEST_CODE_PREFIX=

    ```
4. 创建数据库表

    ```
    php artisan migrate

    ```
5. 生成JWT\_SECRET

    生成JWT\_SECRET, 并自动写入根目录下的.env文件

    ```
    php artisan jwt:secret

    ```
6. 根据实际需要调用对应的接口

    详见[接口说明](#%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E)
7. 使用 auth middleware 对请求的登录状态进行验证

    ```
    Route::group(['middleware' => ['auth:wxapp']], function () {
        //这里放置你的需要登录的 api 路由
    });

    ```

### 接口说明

[](#接口说明)

#### fast\_login

[](#fast_login)

快速登录，小程序端不需要进行授权, 但对于新用户来说，用户表中只会记录openid, 如果需要用户昵称、头像等，需要调用 profile 接口提交用户信息

接口地址: wxapp/fast\_login
请求方式：POST
INPUT:

参数说明code微信客户端调用wx.login得到的codeOUTPUT:

参数说明access\_tokenJWT Token, 具体使用方式见 \[JWT Token 使用说明\](#JWT Token 使用说明)token\_typeBearerexpires\_inaccess\_token有效期user\_info字段命令和微信getUserInfo的返回值保持一致，如果
如果数据中未保存用户信息，则不包含此字段注： 如果用户被禁用，则该接口将返回 `401:Unauthenticated`

示例

```
{
  "access_token": "eyJ0eXAi...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "user_info": {
    "nickName": "测试数据",
    "gender": 1,
    "country": "中国",
    "province": "北京",
    "city": "北京",
    "avatarUrl": "https://thirdwx.qlogo.cn/mm..."
  }
}
```

#### mobile

[](#mobile)

此接口需要在fast\_login登录成功的情况下调用，保存用户微信绑定的手机号

接口地址：wxapp/mobile

请求方式： POST

参数说明code微信客户端调用wx.login得到的codeencrypted\_datawx.getUserInfo返回的数据，包括敏感数据在内的完整用户信息的加密数据ivwx.getUserInfo返回的数据，加密算法的初始向量OUTPUT: \[\]

#### wxapp/profile

[](#wxappprofile)

此接口一般在fast\_login请求成功的情况下调用，直接将wx.getUserInfo中返回的用户信息(未加密)保存到服务器

参数说明nickName用户昵称country国家province省份city城市gender性别，0:未知，1:男，2: 女avatarUrl用户头像地址OUTPUT: \[\]

### JWT Token 使用说明

[](#jwt-token-使用说明)

使用jwt-auth的验证方式， [详见](https://jwt-auth.readthedocs.io/en/develop/quick-start/#authenticated-requests)

```
# Authorization header
Authorization: Bearer eyJhbGciOiJIUzI1NiI...

# Query String
http://example.dev/me?token=eyJhbGciOiJIUzI1NiI...

```

### 异常

[](#异常)

WechatAuthException

### 事件

[](#事件)

- UserAdded

    由于用户记录是在用户第一次调用login接口时创建的，此时记录中并不包含除app\_id和openid以外的其它信息
- UserUpdated

    当用户调用 profile 接口时，如果用户信息发生变化，则会触发该事件
- UserLoggedIn

    用户登录成功后会触发该事件

### WxAppGuard 配置

[](#wxappguard-配置)

下面的配置不需要手动设置，已经通过WechatAuthServiceProvider自动将配置添加到auth config中

```
# guards
'guards' => [
    'wxapp' => [
        'driver' => 'jwt',
        'provider' => 'wxusers',
    ],
],

# providers
'providers' => [
    'wxusers' => [
        'driver' => 'eloquent',
        'model' => vinlon\Laravel\WechatAuth\Models\WxUser::class,
    ],
]

```

引用
--

[](#引用)

参考
--

[](#参考)

[xiaohuilam/laravel-wxapp-login](https://github.com/xiaohuilam/laravel-wxapp-login)
[为什么用jwt-auth而不是laravel/passport](https://stackoverflow.com/questions/45532514/laravel-passport-vs-jwt)

###  Health Score

24

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Recently: every ~46 days

Total

12

Last Release

1544d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/277ca050c3c4260b26cadec49dafbaa2ff68d1487901ee3be0f930ad890b4d1e?d=identicon)[vinlon](/maintainers/vinlon)

---

Top Contributors

[![vinlon](https://avatars.githubusercontent.com/u/3851841?v=4)](https://github.com/vinlon "vinlon (17 commits)")

### Embed Badge

![Health badge](/badges/vinlon-laravel-wechat-auth/health.svg)

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

###  Alternatives

[jadjoubran/laravel5-angular-material-starter

The Laravel Framework.

1.7k17.2k](/packages/jadjoubran-laravel5-angular-material-starter)[simplesquid/nova-enum-field

A Laravel Nova field to add enums to resources.

52382.9k1](/packages/simplesquid-nova-enum-field)[hanson/laravel-admin-wechat

2424.2k](/packages/hanson-laravel-admin-wechat)[rickycezar/laravel-jwt-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

25115.0k](/packages/rickycezar-laravel-jwt-impersonate)[sametsahindogan/laravel-jwtredis

This package allows JWT-authenticated users to be stored and management in Redis with their roles, permissions, statuses and anything you want.

1221.9k](/packages/sametsahindogan-laravel-jwtredis)[tochka-developers/jsonrpc

JsonRpc extension for Laravel

2733.6k1](/packages/tochka-developers-jsonrpc)

PHPackages © 2026

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