PHPackages                             deng-php/wechat - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. deng-php/wechat

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

deng-php/wechat
===============

wechat:login

0195PHP

Since Mar 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/qq1415551519/php-composer-wechat)[ Packagist](https://packagist.org/packages/deng-php/wechat)[ RSS](/packages/deng-php-wechat/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-composer-wx-login
=====================

[](#php-composer-wx-login)

tp+laravel config配置 wx.php
--------------------------

[](#tplaravel-config配置-wxphp)

```
// +----------------------------------------------------------------------
// | 微信设置
// +----------------------------------------------------------------------
return [
    'app_id' => 'wxxxxxxxxxxxxxxx77e',
    'secret' => '242eaxxxxxxxxxxxxxxxxxxxxxx5e1bed55',
    'login_url' => "https://api.weixin.qq.com/sns/jscode2session?".
        "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"
];
```

```

1.通过code获取openid：

Array (
    [open_id] => objb**************GPoUjJwcy04
    [app_id] => wx5dc******009b1
    [secret] => 2b6b170********d902456fd9e3
    [session_key] => Lzh*******mQoq4eMyw==
)

```

```
    //  入口，通过code获取open_id等[laravel6+tp5]
    public function getToken($paramArray = [])
    {
        $code = !empty($paramArray['code'])?$paramArray['code']:'';

        if ($code) {
            $weChatService = new WeChatService();
            $WxData = $weChatService->getDataByCode($code);

            $open_id = $WxData['open_id'];
            $session_key = $WxData['session_key'];
            print_r($WxData);exit;
        }
        return;
    }

        /**
         * @param $code
         * @return array
         * @throws ParamException
         * @author:  deng    (2020-03-28 19:24)
         */
        public function getDataByCode($code)
        {
            $weChatConfig = Config::get('wechat');

            $app_id = $weChatConfig['app_id'];
            $secret = $weChatConfig['secret'];
            $login_url = $weChatConfig['login_url'];

            $paramArray = [
                'app_id' => $app_id,
                'secret' => $secret,
                'login_url' => $login_url
            ];

            $wxLogin = new WeChat($paramArray, $code);
            $wxResult = $wxLogin->get();

            if (empty($wxResult)) {
                // 为什么以empty判断是否错误，这是根据微信返回
                // 这种情况通常是由于传入不合法的code
                throw new ParamException('获取session_key及openid异常，微信内部错误');
            }

            // 建议用明确的变量来表示是否成功
            // 微信服务器并不会将错误标记为400，无论成功还是失败都标记成200
            // 这样非常不好判断，只能使用errcode是否存在来判断
            $loginFail = array_key_exists('errcode',$wxResult);

            if ($loginFail) {
                throw new ParamException($wxResult['errmsg']);
            }

            return [
                'open_id' => $wxResult['openid'],
                'app_id' => $app_id,
                'secret' => $secret,
                'session_key' => $wxResult['session_key']
            ];
        }
```

```
=stdClass Object (
[phoneNumber] => 1507xxxx357,
[purePhoneNumber] => 1507xxxx357,
[countryCode] => 86 ,
[watermark] => stdClass
    Object (
        [timestamp] => 1585xxxx828
        [appid] => wx5d60xxxx635009b1
    )
)
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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/9f3e539fdd4bf3a5db23065baa33aac556cc2f16adcddcf323e09dfce7d6fdff?d=identicon)[qq1415551519](/maintainers/qq1415551519)

---

Top Contributors

[![1535050440](https://avatars.githubusercontent.com/u/35022279?v=4)](https://github.com/1535050440 "1535050440 (3 commits)")

### Embed Badge

![Health badge](/badges/deng-php-wechat/health.svg)

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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