集成Line、Facebook、Twitter、Google、微信、QQ、微博、支付宝的三方登录sdk
下载地址:
https://githubfast.com/anerg2046/sns_auth
安装方式建议使用composer进行安装
如果linux执行composer不方便的话,可以在本地新建个文件夹,然后执行上面的composer命令,把代码sdk和composer文件一起上传到项目适当位置:然后,
示例代码:
<?php//以thinkCMF框架为例namespace app\home\controller;use cmf\controller\HomeBaseController;use think\facade\Db;use anerg\OAuth2\OAuth;class UserController extends HomebaseController{private function getThirdConfig($name){$site='http://xxxx.com'; //更改为自己站点域名//下面的参数需要根据自己的实际需求替换$line_config=['app_id'=>'login_line_appid','app_secret'=>'login_line_secret','scope'=>'profile'];$facebook_config=['app_id'=>'login_facebook_appid','app_secret'=>'login_facebook_secret','scope'=>'public_profile'];$google_config=['app_id'=>'login_google_appid'.'.apps.googleusercontent.com','app_secret'=>'login_google_secret','scope'=>'https://www.googleapis.com/auth/userinfo.profile'];$twitter_config=['app_id'=>'login_twitter_appid','app_secret'=>'login_twitter_secret'];$config=[];switch ($name) {case 'line':$config=$line_config;break;case 'facebook':$config=$facebook_config;break;case 'google':$config=$google_config;break;case 'twitter':$config=$twitter_config;break;}$config['callback']=$site.'/home/user/'.$name.'_callback';return $config;}/*** Line登录*/public function line(){require_once '/sns_auth/vendor/autoload.php';$name='line';$config=$this->getThirdConfig($name);return redirect(OAuth::$name($config)->getRedirectUrl());}/**Line登陆回调**/public function line_callback(){$code= $_GET['code'] ?? '';if($code!=""){$this->third_callback('line');}else{$this->error('三方回调信息获取失败');}}/*** facebook登录*/public function facebook(){require_once '/sns_auth/vendor/autoload.php';$name='facebook';$config=$this->getThirdConfig($name);return redirect(OAuth::$name($config)->getRedirectUrl());}/*** Facebook登陆回调*/public function facebook_callback(){$code= $_GET['code'] ?? '';if($code!=""){$this->third_callback('facebook');}else{$this->error('三方回调信息获取失败');}}/*** Google登录*/public function google(){require_once '/sns_auth/vendor/autoload.php';$name='google';$config=$this->getThirdConfig($name);return redirect(OAuth::$name($config)->getRedirectUrl());}/*** Google登陆回调*/public function google_callback(){$code= $_GET['code'] ?? '';if($code!=""){$this->third_callback('google');}else{$this->error('三方回调信息获取失败');}}/*** twitter登录*/public function twitter(){require_once '/sns_auth/vendor/autoload.php';$name='twitter';$config=$this->getThirdConfig($name);return redirect(OAuth::$name($config)->getRedirectUrl());}/*** twitter登陆回调*/public function twitter_callback(){$code= $_GET['code'] ?? '';if($code!=""){$this->third_callback('twitter');}else{$this->error('三方回调信息获取失败');}}protected function third_callback($name){require_once '/sns_auth/vendor/autoload.php';$config=$this->getThirdConfig($name);$openinfo = OAuth::$name($config)->userinfo();if(!$openinfo){$this->error('三方信息验证失败');return;}/*$openinfo=['openid'=>'唯一标识','channel'=>'line','nick'=>'line昵称','gender'=>'性别','avatar'=>'line头像'];*/$openid=$openinfo['openid'];$channel=$openinfo['channel'];$nickname=$openinfo['nick'];$avatar=$openinfo['avatar'];$userinfo=$this->loginByThird($channel,$openid,$nickname,$avatar);if($userinfo==1001){$this->assign("jumpUrl",'/');$this->error('该账号已被禁用');return;}if($userinfo==1002){$this->assign("jumpUrl",'/');$this->error('该账号已被注销');return;}if($userinfo==1003){$this->assign("jumpUrl",'/');$this->error('该账号已被禁用');return;}$configpub=getConfigPub();session('uid',$userinfo['id']);session('token',$userinfo['token']);session('user',$userinfo);$href='http://xxxx.com'; //替换为自己站点的域名echo "<meta http-equiv=refresh content='0; url=$href'>";}protected function loginByThird($type,$openid,$nickname,$avatar){//实际业务代码,根据自己项目做修改$info=DB::name('user')->where("openid='{$openid}' and login_type='{$type}' and user_type=2")->find();if(!$info){/* 注册 */$user_pass='abcdefg123456';$user_pass=cmf_password($user_pass); //密码加密,方法请自己实现$user_login=$type.'_'.time().rand(100,999);if(!$nickname){$nickname=$type.'用户-'.substr($openid,-4);}else{$nickname=urldecode($nickname);}if(!$avatar){$avatar='/default.jpg';$avatar_thumb='/default_thumb.jpg';}else{$avatar=urldecode($avatar);$avatar_thumb=$avatar;}$data=array('user_login' => $user_login,'user_nickname' =>$nickname,'user_pass' =>$user_pass,'signature' =>'这家伙很懒,什么都没留下','avatar' =>$avatar,'avatar_thumb' =>$avatar_thumb,'last_login_ip' =>get_client_ip(0,true),'create_time' => time(),'user_status' => 1,'openid' => $openid,'login_type' => $type,"user_type" =>2,//会员"source" =>'pc');$uid=DB::name('user')->insertGetId($data);$info['id']=$uid;$info['user_nickname']=$data['user_nickname'];$info['avatar']=$data['avatar'];$info['avatar_thumb']=$data['avatar_thumb'];$info['sex']='2';$info['signature']=$data['signature'];$info['coin']='0';$info['login_type']=$data['login_type'];$info['province']='';$info['city']='';$info['birthday']='';$info['consumption']='0';$info['votestotal']='0';$info['user_status']=1;$info['last_login_time']='';$info['end_bantime']='0';}else{if(!$avatar){$avatar='/default.jpg';$avatar_thumb='/default_thumb.jpg';}else{$avatar=urldecode($avatar);$avatar_thumb=$avatar;}$info['avatar']=$avatar;$info['avatar_thumb']=$avatar_thumb;$data=array('avatar' =>$avatar,'avatar_thumb' =>$avatar_thumb,);}if($info['user_status']=='0'){return 1001; }if($info['user_status']=='3'){return 1002; }if($info['user_status']=='1'&& $info['end_bantime']>time()){return 1003; }$info['isreg']='0';$info['isagent']='0';if($info['last_login_time']=='' ){$info['isreg']='1';$info['isagent']='1';}$info['avatar']=get_upload_path($info['avatar']);$info['avatar_thumb']=get_upload_path($info['avatar_thumb']);return $info;}}
代码中各个配置参数如何获取:
facebook:
Line:
Google:
相关文章:

集成Line、Facebook、Twitter、Google、微信、QQ、微博、支付宝的三方登录sdk
下载地址: https://githubfast.com/anerg2046/sns_auth 安装方式建议使用composer进行安装 如果linux执行composer不方便的话,可以在本地新建个文件夹,然后执行上面的composer命令,把代码sdk和composer文件一起上传到项目适当位…...

2022年09月 Python(五级)真题解析#中国电子学会#全国青少年软件编程等级考试
Python等级考试(1~6级)全部真题・点这里 一、单选题(共25题,每题2分,共50分) 第1题 已知字符串:s=“语文,数学,英语”,执行print(s.split(“,”))语句后结果是?( ) A: [‘语文’, ‘数学’, ‘英语’] B: [语文, 数学, 英语] C: [‘语文, 数学, 英语’] D: [‘语…...
C. Number of Pairs
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array a� of n� integers. Find the number of pairs (i,j)(�,�) (1≤i<j≤n1≤…...

Js 保留关键字
JavaScript 关键字用于标识要执行的操作,和其他任何编程语言一样,JavaScript 保留了一些关键字为自己所用;这些关键字有些在目前的版本中可能没有使用,但在以后 JavaScript 扩展中会用到。 以下是JS中最重要的保留关键字…...

nodejs+vue+python+PHP+微信小程序-安卓-房产中介管理信息系统的设计与实现-计算机毕业设计
目 录 摘 要 I ABSTRACT II 目 录 II 第1章 绪论 1 1.1背景及意义 1 1.2 国内外研究概况 1 1.3 研究的内容 1 第2章 相关技术 3 2.1 nodejs简介 4 2.2 express框架介绍 6 2.4 MySQL数据库 4 第3章 系统分析 5 3.1 需求分析 5 3.2 系统可行性分析 5 3.2.1技术可行性:…...
【系统架构设计】架构核心知识: 3.5 Redis和ORM
目录 一 Redis 1 Redis与MemCache 2 Redis分布式存储方案 3 Redis集群切片的方式 4 Redis数据分片...

linux时间同步
搭建集群时,都会先设置时间同步,否则会出现多种问题。 方式一: 1.安装ntp软件 yum install -y ntp 2.更新时区 删除原有时区:sudo rm -f /etc/localtime 加载新时区:sudo ln -s /usr/share/zoneinfo/Asia/Shangh…...
mysql++库connected与ping方法的区别
mysql库connected与ping方法的区别 前段时间开发公司代码的时候,我写了一个多线程调用数据库的函数,每个线程都是要连接数据库的,为了防止在查找数据之前,线程连接数据库断开,我使用定时器每20s检测一下线程连接数据库…...

拆位线段树 E. XOR on Segment
Problem - E - Codeforces 区间求和,区间异或的操作跟线段树的区间求和、区间相见相似,考虑用线段树。 发现数组初始值最多是1e6,有不到25位,可以知道异或最大值是这些位数全是1的情况。 发现可以对每一位进行运算就和。 我们开…...

JVM及其垃圾回收机制(GC)
目录 一.JVM内存区域划分 二.JVM类加载机制 类加载过程 类加载的时机 双亲委派模型 三.JVM垃圾回收机制(GC) GC工作过程 1.找到垃圾/判断垃圾 (1)引用计数【python/PHP】 (2)可达性分析【Java】 2.对象释放…...
友元的三种实现
友元的三种实现 全局函数做友元类做友元成员函数做友元 #include <iostream> #include <string> using namespace std;//友元的三种实现 // //* 全局函数做友元 //* 类做友元 //* 成员函数做友元class Building {//告诉编译器 goodGay全局函数 是 Building类的好…...
聊聊logback的DuplicateMessageFilter
序 本文主要研究一下logback的DuplicateMessageFilter TurboFilter ch/qos/logback/classic/turbo/TurboFilter.java public abstract class TurboFilter extends ContextAwareBase implements LifeCycle {private String name;boolean start false;/*** Make a decision …...

WordPress 文档主题模板Red Line -v0.2.2
此主题作为框架,做承载第三方页面之用,例如飞书文档等, 您可以将视频图片等资源放第三方文档上,通过使用此主题做目录用。 此主题使用前后端分离开发,也使用了一些技术尽量不影响正常的SEO,还望注意。 源码…...

网络和Linux网络_1(网络基础)网络概念+协议概念+网络通信原理
目录 1. 网络简介 1.1 独立模式和互联网络模式 1.2 局域网LAN和广域网WAN 2. 协议和协议分层 2.1 协议的作用 2.2 协议分层 2.3 OSI七层模型 3.2 TCP/IP四层(五层)模型 3. 网络通信原理 3.1 协议报头 3.2 局域网和解包分用 3.3 广域网和跨网络 4. 网络中的地址 4…...

AI生成PPT工具——Gamma,结合GPT生成不错的效果
AI生成PPT工具——Gamma,结合GPT生成不错的效果 先告诉GPT我现在要参加一个比赛,请他帮忙梳理一下内容。当然整个过程需要不断调整,GPT生成的内容也不是一次就是最好的 不断调整之后让其列出提纲即可,如下: 紧接着我们…...
DcatAdmin使用模版文件时模板标签不生效
伪源码 PHP代码如下 public function 方法名(){return view(view_dir.view_name,[key1>value1]); }模版代码如下 <tr><td>键名</td> </tr> <tr><td>{{ $key1 }}</td> </tr>现象: 页面htmlt元素正常展示&…...
【算法】算法题-20231114
这里写目录标题 一、LCR 181. 字符串中的单词反转二、557. 反转字符串中的单词 III三、344. 反转字符串四、给定一个已按照升序排列的有序数组,找到两个数使得它们相加之和等于目标数。五、力扣第49题:字母异位词分组 一、LCR 181. 字符串中的单词反转 …...

时序数据库 TDengine + 高级分析软件 Seeq,助力企业挖掘时序数据潜力
作为一款制造业和工业互联网(IIOT)高级分析软件,Seeq 支持在工艺制造组织中使用机器学习创新的新功能。这些功能使组织能够将自己或第三方机器学习算法部署到前线流程工程师和主题专家使用的高级分析应用程序,从而使单个数据科学家…...
【Rust 日报】2023-11-12 socketioxide
gosub.io正在尝试用Rust构建一个Web浏览器 一个html5的分词器/解析器,正在成为浏览器的项目。 GoSub是Gateway to Optimized Searching and Unlimited Browsing的简称,目前还处于极早期阶段。 GitHub: https://github.com/gosub-browser socketioxide 0.…...

Redis快速入门(基础篇)
简介: 是一个高性能的 key-value数据库。 存在内存中 与其他 key-value 缓存产品有以下三个特点: Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。 Redis不仅仅支持简单的key-value类…...

【JVM】- 内存结构
引言 JVM:Java Virtual Machine 定义:Java虚拟机,Java二进制字节码的运行环境好处: 一次编写,到处运行自动内存管理,垃圾回收的功能数组下标越界检查(会抛异常,不会覆盖到其他代码…...

SpringTask-03.入门案例
一.入门案例 启动类: package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...
CSS设置元素的宽度根据其内容自动调整
width: fit-content 是 CSS 中的一个属性值,用于设置元素的宽度根据其内容自动调整,确保宽度刚好容纳内容而不会超出。 效果对比 默认情况(width: auto): 块级元素(如 <div>)会占满父容器…...
4. TypeScript 类型推断与类型组合
一、类型推断 (一) 什么是类型推断 TypeScript 的类型推断会根据变量、函数返回值、对象和数组的赋值和使用方式,自动确定它们的类型。 这一特性减少了显式类型注解的需要,在保持类型安全的同时简化了代码。通过分析上下文和初始值,TypeSc…...

自然语言处理——文本分类
文本分类 传统机器学习方法文本表示向量空间模型 特征选择文档频率互信息信息增益(IG) 分类器设计贝叶斯理论:线性判别函数 文本分类性能评估P-R曲线ROC曲线 将文本文档或句子分类为预定义的类或类别, 有单标签多类别文本分类和多…...

2.3 物理层设备
在这个视频中,我们要学习工作在物理层的两种网络设备,分别是中继器和集线器。首先来看中继器。在计算机网络中两个节点之间,需要通过物理传输媒体或者说物理传输介质进行连接。像同轴电缆、双绞线就是典型的传输介质,假设A节点要给…...

Spring AOP代理对象生成原理
代理对象生成的关键类是【AnnotationAwareAspectJAutoProxyCreator】,这个类继承了【BeanPostProcessor】是一个后置处理器 在bean对象生命周期中初始化时执行【org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization】方法时…...

aardio 自动识别验证码输入
技术尝试 上周在发学习日志时有网友提议“在网页上识别验证码”,于是尝试整合图像识别与网页自动化技术,完成了这套模拟登录流程。核心思路是:截图验证码→OCR识别→自动填充表单→提交并验证结果。 代码在这里 import soImage; import we…...
CppCon 2015 学习:Reactive Stream Processing in Industrial IoT using DDS and Rx
“Reactive Stream Processing in Industrial IoT using DDS and Rx” 是指在工业物联网(IIoT)场景中,结合 DDS(Data Distribution Service) 和 Rx(Reactive Extensions) 技术,实现 …...
IP选择注意事项
IP选择注意事项 MTP、FTP、EFUSE、EMEMORY选择时,需要考虑以下参数,然后确定后选择IP。 容量工作电压范围温度范围擦除、烧写速度/耗时读取所有bit的时间待机功耗擦写、烧写功耗面积所需要的mask layer...