2017 © Pedro Peláez
 

yii2-extension yii2-easywechat

easywechat 4 for yii2

image

blackhive/yii2-easywechat

easywechat 4 for yii2

  • Saturday, April 14, 2018
  • by haobing
  • Repository
  • 1 Watchers
  • 2 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 12 % Grown

The README.md

yii2-easywechat

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

easywechat 4 for yii2, (*2)

基于 overtrue/wechat, (*3)

友情提示,微信支付的沙箱不要用,它和支付宝的沙箱不是一个东西。。。, (*4)

安装

composer require --prefer-dist blackhive/yii2-easywechat -vvv

配置

config/main.php 添加应用组件:, (*5)

'components' => [
    // ...
    'wechat' => [
        'class' => 'blackhive\easywechat\Wechat',
        //'openidName' => 'wx.openid',
    ],
]

config/params_local.php 中添加配置参数:, (*6)

[
    'wechat' => [
        // 微信商户平台
        'pay' => [
            'app_id' => '',
            'mch_id' => '',
            'key' => '',
            'cert_path' => dirname(__FILE__) . '/path/to/apiclient_cert.pem', // 绝对路径!!!!
            'key_path' => dirname(__FILE__) . '/path/to/apiclient_key.pem',  // 绝对路径!!!!
            'notify_url' => '',
        ],
        // 微信公众平台
        'mp' => [
            'app_id' => '',
            'secret' => '',
            'oauth' => [
                'scopes'   => ['snsapi_base'],
                'callback' => '/wechat/oauth-callback',
            ],
        ],
        // 微信开放平台
        'open' => [
            'app_id'   => '',
            'secret'   => '',
            'token'    => '',
            'aes_key'  => ''
        ]
]

使用

// 微信支付客户端
$payment = Yii::$app->wechat->payment;

// 微信公众号客户端
$officialAccount = Yii::$app->wechat->officialAccount;

// 微信公众平台客户端
$openPlatform = Yii::$app->wechat->openPlatform;

// 是否在微信客户端内
if (Yii::$app->wechat->isWechat()){
    // 微信内的操作
}


Yii::$app->wechat->openid = 'jfdjdjfjdaj';

// 从 session 中获取 openid
Yii::$app->wechat->openid;

// 微信网页授权:
if (Yii::$app->wechat->inWechat && !Yii::$app->wechat->openid) {// 从 session 中获取 openid
    Yii::$app->wechat->returnUrl = ['user/order', 'id' => 1];
    return Yii::$app->wechat->officialAccount->oauth->redirect()->send();
}

// 网页授权回调控制器 /wechat/oauth-callback
$oauth  = Yii::$app->wechat->officialAccount->oauth;
Yii::$app->wechat->openid = $oauth->user()->getId();// 向 session 中保存 openid
return $this->redirect(Yii::$app->wechat->returnUrl);

具体使用请参考 EasyWeChat文档, (*7)

The Versions

14/04 2018

dev-master

9999999-dev

easywechat 4 for yii2

  Sources   Download

MIT

The Requires

 

by Liam Wang

yii2 wechat easywechat

14/04 2018

0.1.5

0.1.5.0

easywechat 4 for yii2

  Sources   Download

MIT

The Requires

 

by Liam Wang

yii2 wechat easywechat

12/04 2018

0.1.4

0.1.4.0

easywechat 4 for yii2

  Sources   Download

MIT

The Requires

 

by Liam Wang

yii2 wechat easywechat

10/04 2018

dev-develop

dev-develop

easywechat 4 for yii2

  Sources   Download

MIT

The Requires

 

by Liam Wang

yii2 wechat easywechat

10/04 2018

0.1.3

0.1.3.0

easywechat 4 for yii2

  Sources   Download

MIT

The Requires

 

by Liam Wang

yii2 wechat easywechat