集成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类…...
uniapp 对接腾讯云IM群组成员管理(增删改查)
UniApp 实战:腾讯云IM群组成员管理(增删改查) 一、前言 在社交类App开发中,群组成员管理是核心功能之一。本文将基于UniApp框架,结合腾讯云IM SDK,详细讲解如何实现群组成员的增删改查全流程。 权限校验…...

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
题目:3442. 奇偶频次间的最大差值 I 思路 :哈希,时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况,哈希表这里用数组即可实现。 C版本: class Solution { public:int maxDifference(string s) {int a[26]…...
【根据当天日期输出明天的日期(需对闰年做判定)。】2022-5-15
缘由根据当天日期输出明天的日期(需对闰年做判定)。日期类型结构体如下: struct data{ int year; int month; int day;};-编程语言-CSDN问答 struct mdata{ int year; int month; int day; }mdata; int 天数(int year, int month) {switch (month){case 1: case 3:…...

云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地
借阿里云中企出海大会的东风,以**「云启出海,智联未来|打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办,现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...
pam_env.so模块配置解析
在PAM(Pluggable Authentication Modules)配置中, /etc/pam.d/su 文件相关配置含义如下: 配置解析 auth required pam_env.so1. 字段分解 字段值说明模块类型auth认证类模块,负责验证用户身份&am…...
【AI学习】三、AI算法中的向量
在人工智能(AI)算法中,向量(Vector)是一种将现实世界中的数据(如图像、文本、音频等)转化为计算机可处理的数值型特征表示的工具。它是连接人类认知(如语义、视觉特征)与…...
leetcodeSQL解题:3564. 季节性销售分析
leetcodeSQL解题:3564. 季节性销售分析 题目: 表:sales ---------------------- | Column Name | Type | ---------------------- | sale_id | int | | product_id | int | | sale_date | date | | quantity | int | | price | decimal | -…...

优选算法第十二讲:队列 + 宽搜 优先级队列
优选算法第十二讲:队列 宽搜 && 优先级队列 1.N叉树的层序遍历2.二叉树的锯齿型层序遍历3.二叉树最大宽度4.在每个树行中找最大值5.优先级队列 -- 最后一块石头的重量6.数据流中的第K大元素7.前K个高频单词8.数据流的中位数 1.N叉树的层序遍历 2.二叉树的锯…...
在Ubuntu24上采用Wine打开SourceInsight
1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...
Web中间件--tomcat学习
Web中间件–tomcat Java虚拟机详解 什么是JAVA虚拟机 Java虚拟机是一个抽象的计算机,它可以执行Java字节码。Java虚拟机是Java平台的一部分,Java平台由Java语言、Java API和Java虚拟机组成。Java虚拟机的主要作用是将Java字节码转换为机器代码&#x…...