Coder Social home page Coder Social logo

think-wxminihelper's Introduction

think-wxminihelper

基于ThinkPHP5.0的微信小程序composer包。

安装方法:

composer require xxh/think-wxminihelper

你只需要两部就可以实现微信的登录验证,验证成功后会自动返回一个3rd_session,和用户的基本信息

这里要注意的是,获取3rd_session因为微信官网建议Linux下面读取/dev/urandom设备, 所以这段代码只适合用于linux系统,但是如果你需要在Windows系统上测试,那么可以修改 WXLoginHelper下的randomFromDev方法

1.在config.php配置文件中加入必须的配置

// wx配置
'wx'  => [
    'url' => 'https://api.weixin.qq.com/sns/jscode2session',
    'appid' => 'wxde3ea15f3a18f7f6',
    'secret' => '53b1a4e12b88d78f3bcc2786fb72adcf',
    'grant_type' => 'authorization_code'
]

2.使用checkLogin进行验证

$code = input("code", '', 'htmlspecialchars_decode');
$rawData = input("rawData", '', 'htmlspecialchars_decode');
$signature = input("signature", '', 'htmlspecialchars_decode');
$encryptedData = input("encryptedData", '', 'htmlspecialchars_decode');
$iv = input("iv", '', 'htmlspecialchars_decode');

$wxHelper = new WXLoginHelper();
$data = $wxHelper->checkLogin($code, $rawData, $signature, $encryptedData, $iv);

当然,如果你自己有一套登录验证流程,你也可以使用decryptData进行解密验证前面的正确性

$appid = 'wx4f4bc4dec97d474b';
$sessionKey = 'tiihtNczf5v6AKRyjwEUhQ==';

$encryptedData="CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZM
                QmRzooG2xrDcvSnxIMXFufNstNGTyaGS
                9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+
                3hVbJSRgv+4lGOETKUQz6OYStslQ142d
                NCuabNPGBzlooOmB231qMM85d2/fV6Ch
                evvXvQP8Hkue1poOFtnEtpyxVLW1zAo6
                /1Xx1COxFvrc2d7UL/lmHInNlxuacJXw
                u0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn
                /Hz7saL8xz+W//FRAUid1OksQaQx4CMs
                8LOddcQhULW4ucetDf96JcR3g0gfRK4P
                C7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB
                6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns
                /8wR2SiRS7MNACwTyrGvt9ts8p12PKFd
                lqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYV
                oKlaRv85IfVunYzO0IKXsyl7JCUjCpoG
                20f0a04COwfneQAGGwd5oa+T8yO5hzuy
                Db/XcxxmK01EpqOyuxINew==";

$iv = 'r7BXXKkLb8qrSNn05n0qiA==';

$pc = new \think\wxmini\WXBizDataCrypt($appid, $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $data );

if ($errCode == 0) {
    print($data . "\n");
} else {
    print($errCode . "\n");
}

think-wxminihelper's People

Contributors

wulongtao avatar

Watchers

James Cloos avatar indiboy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.