All Projects → lanceWan → Wxxcx

lanceWan / Wxxcx

Laravel5微信小程序登录获取用户信息扩展

Projects that are alternatives of or similar to Wxxcx

Wechat
Deprecated 微信公众平台企业号 SDK
Stars: ✭ 78 (-38.58%)
Mutual labels:  laravel, wechat
Imall
基于Laravel5.2,Vue.js1.0的微信商城,用于熟悉 Laravel、Vuejs、Webpack、Gulp 的结合使用,已不维护及更新。(1MB单核基础服务器,浏览请耐心等待图片加载...)
Stars: ✭ 168 (+32.28%)
Mutual labels:  laravel, wechat
Hdcms
支持 PC、H5、微信公众号、微信小程序多应用平台
Stars: ✭ 134 (+5.51%)
Mutual labels:  laravel, wechat
Ecjia Daojia
EC+(ecjia)到家是一款可开展O2O业务的移动电商系统。它包含:移动端APP,采用原生模式开发,覆盖使用iOS 及Android系统的移 动终端;后台系统,针对平台日常运营维护的平台后台,针对入驻店铺管理的商家后台,独立并行;移动端H5,能够灵活部署于微信及其他APP、网页等。
Stars: ✭ 547 (+330.71%)
Mutual labels:  laravel, wechat
Workmanger
laravel+vue.js 前后端分离实战项目(项目中wx端等已经存在,因为涉及业务较多,不再更新到github 需要参考可以私聊我)
Stars: ✭ 41 (-67.72%)
Mutual labels:  laravel, wechat
Laravel Pay
可能是我用过的最优雅的 Alipay 和 WeChat 的 laravel 支付扩展包了
Stars: ✭ 856 (+574.02%)
Mutual labels:  laravel, wechat
Weeshop
优雅易用的微信小程序商城,PHP商城。 基于Laravel的基因,来自Symfony的底层技术,来自Drupal Commerce的核心技术,由Drupal中国开源社区维护。QQ群:714023327
Stars: ✭ 337 (+165.35%)
Mutual labels:  laravel, wechat
Socialite
Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.
Stars: ✭ 1,026 (+707.87%)
Mutual labels:  laravel, wechat
Laravel Template
RESTful 模板,企业号/企业微信微信扫码登录/同步通讯录——Laravel vue2 iView
Stars: ✭ 119 (-6.3%)
Mutual labels:  laravel, wechat
Laravelgooglemaps
Laravel Google Maps Package
Stars: ✭ 124 (-2.36%)
Mutual labels:  laravel
Nova Repeatable Fields
A Laravel Nova field for configuring repeatable sets of fields
Stars: ✭ 126 (-0.79%)
Mutual labels:  laravel
Laravel Nuxt
Build a SPA with Laravel and Nuxt.
Stars: ✭ 124 (-2.36%)
Mutual labels:  laravel
Php Ddd Example
🐘🎯 Hexagonal Architecture + DDD + CQRS in PHP using Symfony 5
Stars: ✭ 1,960 (+1443.31%)
Mutual labels:  laravel
Midia
Simple Media manager for your Laravel project
Stars: ✭ 126 (-0.79%)
Mutual labels:  laravel
Laravel And Vue.js Spa Recipe Box
Single Page Application with Laravel 5.4 and Vue.js 2 - Recipe Box
Stars: ✭ 124 (-2.36%)
Mutual labels:  laravel
Xblock Kernel
XBlock - 开发文档
Stars: ✭ 127 (+0%)
Mutual labels:  laravel
Coding
视频代码
Stars: ✭ 124 (-2.36%)
Mutual labels:  laravel
Remove Bg
Programmatically remove backgrounds from your images using the remove.bg api
Stars: ✭ 124 (-2.36%)
Mutual labels:  laravel
Laravel Short Url
A Laravel package to shorten urls
Stars: ✭ 127 (+0%)
Mutual labels:  laravel
Querybuilderparser
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
Stars: ✭ 126 (-0.79%)
Mutual labels:  laravel

Laravel 5 微信小程序扩展

小程序官方的加解密 SDK 已经非常清楚了,只不过改成 Laravel 风格而已,仅仅相当于搬砖工。至于重复造轮子,我发现其他人的扩展解密用户信息的时候代码出错了,并且需要安装一个 Laravel 的 Curl 扩展也没说。只好自己去根据他们的源码自己写一个0.0 ,不依赖其他扩展,直接安装使用即可。

小程序API接口

安装

由于 PHP7.1 的加密函数 mcrypt_module_open() 因为过时而被废弃。使用 PHP7.1 版本的人请安装 2.0 版本的代码

执行以下命令安装最新稳定版本:

PHP < 7.1

composer require iwanli/wxxcx=1.*

PHP > 7.1

composer require iwanli/wxxcx=2.*

或者添加如下信息到你的 composer.json 文件中 :

PHP < 7.1

"iwanli/wxxcx": "^1.0"

PHP > 7.1

"iwanli/wxxcx": "^2.0"

然后注册服务提供者到 Laravel中 具体位置:/config/app.php 中的 providers 数组:

Iwanli\Wxxcx\WxxcxServiceProvider::class,

发布配置文件:

php artisan vendor:publish --tag=wxxcx

命令完成后,会添加一个wxxcx.php配置文件到您的配置文件夹 如 : /config/wxxcx.php

生成配置文件后,将小程序的 AppIDAppSecret 填写到 /config/wxxcx.php 文件中

在Laravel 5控制器中使用 (示例)

...

use Iwanli\Wxxcx\Wxxcx;

class WxxcxController extends Controller
{
    protected $wxxcx;

    function __construct(Wxxcx $wxxcx)
    {
        $this->wxxcx = $wxxcx;
    }

    /**
     * 小程序登录获取用户信息
     * @author 晚黎
     * @date   2017-05-27T14:37:08+0800
     * @return [type]                   [description]
     */
    public function getWxUserInfo()
    {
        //code 在小程序端使用 wx.login 获取
        $code = request('code', '');
        //encryptedData 和 iv 在小程序端使用 wx.getUserInfo 获取
        $encryptedData = request('encryptedData', '');
        $iv = request('iv', '');

        //根据 code 获取用户 session_key 等信息, 返回用户openid 和 session_key
        $userInfo = $this->wxxcx->getLoginInfo($code);

        //获取解密后的用户信息
        return $this->wxxcx->getUserInfo($encryptedData, $iv);
    }
}

用户信息返回格式:

{
    "openId": "xxxx",
    "nickName": "晚黎",
    "gender": 1,
    "language": "zh_CN",
    "city": "",
    "province": "Shanghai",
    "country": "CN",
    "avatarUrl": "http://wx.qlogo.cn/mmopen/xxxx",
    "watermark": {
        "timestamp": 1495867603,
        "appid": "your appid"
    }
}

小程序端获取 code、iv、encryptedData 向服务端发送请求示例代码:

//调用登录接口
wx.login({
    success: function (response) {
        var code = response.code
        wx.getUserInfo({
            success: function (resp) {
                wx.request({
                    url: 'your domain',
                    data: {
                        code: code,
                        iv: resp.iv,
                        encryptedData: resp.encryptedData
                    },
                    success: function (res) {
                        console.log(res.data)
                    }
                })
            }
        })
    },
    fail:function(){
        ...
    }
})

如有bug,请在 Issues 中反馈,非常感谢!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].