2017 © Pedro Peláez
 

library yii2-applet

Yii2 component for applet

image

jtcczu/yii2-applet

Yii2 component for applet

  • Tuesday, September 12, 2017
  • by jtcczu
  • Repository
  • 1 Watchers
  • 5 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 11 % Grown

The README.md

Yii2 Applet Extension

Yii2小程序组件 获取用户信息和会话密钥, (*1)

环境需求

  • PHP >= 5.5

安装

composer require jtcczu/yii2-applet

配置

return [
    //...
    'components' => [
        'applet' => [
          'class' => 'Jtcczu\Applet\Applet',
          'appid' => 'APPID',
          'secret' => 'SECRET'
        ]
    ]
]

使用

 $applet = Yii::$app->applet->makeSession($code); 
 $applet->getUser($encryptedData, $iv); //返回用户信息
 $applet->checkSignature($rawData, $signature); //数据签名校验

 $session = $applet->getSession(); 
 $session->getOpenid(); //openid
 $session->getSessionKey(); //session_key
 $session->getUnionid(); //unionid            

微信小程序api文档 https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html#wxloginobject, (*2)

快速开始

小程序代码, (*3)

wx.login({
        success: function (login) {
          wx.getUserInfo({
            success: function (res) {
              wx.request({
                url: 'xxx',
                method : 'post',
                data:{
                    code : login.code,
                    rawData : res.rawData,
                    signature : res.signature,
                    encryptedData : res.encryptedData,
                    iv : res.iv
                },
                dataType : 'json',
                success : function(res){
                }
              })
            }
          })
        }
      })

后端代码, (*4)

public function actionTest(){    
  $contents = file_get_contents('php://input');
  $data = json_decode($contents,true);
  $user = Yii::$app->applet
                   ->makeSession($data['code'])
                   ->getUser($data['encryptedData'],$data['iv']);
}                   

The Versions

12/09 2017

dev-master

9999999-dev

Yii2 component for applet

  Sources   Download

MIT

The Requires

 

by jiangtao

12/09 2017

1.1.1

1.1.1.0

Yii2 component for applet

  Sources   Download

MIT

The Requires

 

by jiangtao

15/08 2017

1.1.0

1.1.0.0

Yii2 component for applet

  Sources   Download

MIT

The Requires

 

by jiangtao

22/07 2017

1.0.0

1.0.0.0

Yii2 component for applet

  Sources   Download

MIT

The Requires

 

by jiangtao