myshero/yii2-easy-wechat

为yii2 php框架提供的Easywechat sdk

维护者

详细信息

github.com/myshero/wechat

源代码

问题

安装: 8

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 0

分支: 0

公开问题: 0

类型:yii2-extension

0.1.1 2018-05-07 03:30 UTC

This package is not auto-updated.

Last update: 2024-09-22 08:36:31 UTC


README

借鉴了一些其他 EasyWeChat SDK for Yii2,但似乎都是针对 EasyWeChat V3 版本的。

我瞎捣鼓了一个针对 EasyWeChat V4 的,欢迎各位大佬指点。

谢谢。

安装

composer require myshero/yii2-easy-wechat --dev

配置

在YII2配置中添加 wechat 组件

更多参数说明

'components' => [
    // ...
    'wechat'=>[
        'class'=>'Myshero\Wechat\Wechat',
        // 微信参数
        'config' => [
            'app_id' => 'app_id',
            'secret' => 'secret',
            'log' => [
                'level' => 'debug',
                'permission' => 0777,
                'file' => Yii::getAlias("@frontend") . '/runtime/wechat.log',
            ],
            /**
             * OAuth 配置
             *
             * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
             * callback:OAuth授权完成后的回调页地址
             */
            'oauth' => [
                'scopes' => ['snsapi_userinfo'],
                'callback' => 'wechat/oauth',
            ],
        ],
    ],
    // ...
],

使用方法

// here are some representative examples that will help you:

// 微信网页授权:
public function actionIndex()
{
    $wechat = \Yii::$app->wechat;
    if ($wechat->isGuest()) {
        // 跳转微信服务器授权
        return $wechat->prepareOauth();
    }else{
        // do something ...
    }
}

/**
 * 授权回调
 */
public function actionOauth()
{
    $wechat = \Yii::$app->wechat;
    return $wechat->oauth();
}

------

\Yii::$app->wechat->officialAccount;  // 公众号
\Yii::$app->wechat->miniProgram;      // 小程序
\Yii::$app->wechat->openPlatform;     // 开放平台
\Yii::$app->wechat->payment;          // 微信支付
\Yii::$app->wechat->work;             // 企业微信

更多文档

EasyWeChat 文档.

感谢 overtrue/wechat