Fastadmin中使用小程序登录

在fastadmin中使用三方登录插件原有没有小程序登录,需要增加小程序登录

目录

增加小程序登录

安装

修改配置

增加服务提供者

注册服务提供者

登录调用

总结


增加小程序登录

安装

首先在插件管理中找到三方登录插件安装

安装最新的1.4.7

修改配置

在third/config.php文件中,weibo配置下仿照上面的配置增加wechatmini配置,

如下:

php 复制代码
[
    'name' => 'wechatmini',
    'title' => '微信小程序',
    'type' => 'array',
    'content' => [
        'app_id' => '',
        'app_secret' => '',
        'scope' => 'snsapi_userinfo',
    ],
    'value' => [
        'app_id' => '',
        'secret' => '',
        'scope' => 'get_user_info',
    ],
    'rule' => 'required',
    'msg' => '',
    'tip' => '',
    'ok' => '',
    'extend' => '',
],

修改后保存后,在三方登录配置中增加微信小程序配置内容,如下:

增加服务提供者

在third/library中增加wechatmini.php文件,为小程序登录处理。

文件内容如下:

php 复制代码
<?php

namespace addons\third\library;

use fast\Http;
use think\Config;
use think\Session;
use EasyWeChat\Factory;

/**
 * 微信小程序
 */
class Wechatmini
{
    /**
     * 配置信息
     * @var array
     */
    private $config = [];

    public function __construct($options = [])
    {
        if ($config = Config::get('third.wechatmini')) {
            $this->config = array_merge($this->config, $config);
        }
        $this->config = array_merge(
$this->config, is_array($options) ? $options : []);
    }


    /**
     * 获取用户信息
     * @param array $params
     * @return array
     */
    public function getUserInfo($params = [])
    {
        $params = $params ?: $_GET;
        if (isset($params['code'])) {
            if ($params['code']) {
                $config = $this->config;
                $app = Factory::miniProgram($config);
                $sns = $app->auth->session($params['code']);
                if (isset($sns['openid']) && $sns['openid']) {
                    return $sns;
                }
            }
        }
        return [];
    }
}

注册服务提供者

在third/library/Application.php中注册服务提供者。

登录调用

在api/User.php的third方法中处理登录时,可通过platform参数传递wechatmini,

调用小程序登录方法,如下:

总结

在fastadmin中使用三方登录插件原有没有小程序登录,需要增加小程序登录

相关推荐
.痞老板.10 小时前
java ee--网络编程套接字
网络·java-ee·php
djxzyr15 小时前
微信小程序传感器实战:罗盘、加速计、陀螺仪与加速度实时波形
微信小程序·小程序
JianZhen✓2 天前
IM 聊天列表为什么总“消息乱跳“:有序插入、时间轴派生、本地截断、已读回执
开发语言·前端·php
FungLeo2 天前
FengCMS · PHP+MySQL 升级实录· 代码审计怎么闭环:REVIEW到 CLOSURE 四件套,12 个域90 篇修复文档跟到底
开发语言·mysql·php·代码审计·fengcms
FungLeo2 天前
FengCMS · PHP+MySQL 升级实录 · 一个不懂PHP 的后端,三天 216次提交完成十三年老站安全升级(项目复盘)
mysql·安全·php·安全加固·fengcms
pps-key2 天前
网络攻防入门:从“黑客梦”到合法实操(生存篇)
开发语言·web安全·php
驭渊的小故事2 天前
订单服务如何调用商品服务?一次 RestTemplate 跨服务调用入门
java·开发语言·php
Risehuxyc3 天前
来自PHP项目devnexen的回信
开发语言·php
饿了吃洗衣凝珠3 天前
SELinux
服务器·开发语言·php
李纲明3 天前
微信小程序开了 Skyline 后样式全乱、滚动对不上甚至部分组件不能用?Skyline 怎么接才稳
javascript·微信小程序·小程序·devdiy