优化登录背景插件

This commit is contained in:
tao 2022-01-12 16:12:09 +08:00
parent 160dc08cc0
commit 7f6ac7af08
41 changed files with 3006 additions and 45 deletions

View File

@ -207,57 +207,43 @@ class Addons extends AdminController
Files::mkdirs($addons_dir);
$package_file = $addons_dir . $data['name'] .'.zip'; //升级的压缩包文件
// halt($package_file);
$cpfile = copy($file_url,$package_file);
if(!$cpfile)
{
return json(['code'=>-1,'msg'=>'下载升级文件失败']);
}
if(!$cpfile) return json(['code'=>-1,'msg'=>'下载升级文件失败']);
$uzip = new Zip();
$zipDir = strstr($package_file, '.zip',true); //返回文件名后缀前的字符串
$zipPath = Files::getDirPath($zipDir); //转换为带/的路径 压缩文件解压到的路径
$unzip_res = $uzip->unzip($package_file,$zipPath,true);
if(!$unzip_res) return json(['code'=>-1,'msg'=>'解压失败']);
if(!$unzip_res)
{
return json(['code'=>-1,'msg'=>'解压失败']);
}
//升级插件
if(is_dir($zipPath))
{
//升级前的写入文件权限检查
$allUpdateFiles = Files::getAllFile($zipPath);
if (empty($allUpdateFiles)) return json(['code' => -1, 'msg' => '无可更新文件。']);
$checkString = '';
foreach ($allUpdateFiles as $updateFile) {
$coverFile = ltrim(str_replace($zipPath, '', $updateFile), DIRECTORY_SEPARATOR);
$dirPath = dirname('../'.$coverFile);
if (file_exists('../'.$coverFile)) {
if (!is_writable('../'.$coverFile)) $checkString .= $coverFile . '&nbsp;[<span class="text-red">' . '无写入权限' . '</span>]<br>';
} else {
if (!is_dir($dirPath)) @mkdir($dirPath, 0777, true);
if (!is_writable($dirPath)) $checkString .= $dirPath . '&nbsp;[<span class="text-red">' . '无写入权限' . '</span>]<br>';
}
}
//升级前的写入文件权限检查
$allUpdateFiles = Files::getAllFile($zipPath);
if (!empty($checkString)) return json(['code' => -1, 'msg' => $checkString]);
$addonsPath = '../';
$cpRes = Files::copyDirs($zipPath,$addonsPath);
$cpData = $cpRes->getData();
//更新失败
if($cpData['code'] == -1)
{
return json(['code'=>-1,'msg'=>$cpData['msg']]);
}
if (empty($allUpdateFiles)) return json(['code' => -1, 'msg' => '无可更新文件。']);
$checkString = '';
foreach ($allUpdateFiles as $updateFile) {
$coverFile = ltrim(str_replace($zipPath, '', $updateFile), DIRECTORY_SEPARATOR);
$dirPath = dirname('../'.$coverFile);
if (file_exists('../'.$coverFile)) {
if (!is_writable('../'.$coverFile)) $checkString .= $coverFile . '&nbsp;[<span class="text-red">' . '无写入权限' . '</span>]<br>';
} else {
if (!is_dir($dirPath)) @mkdir($dirPath, 0777, true);
if (!is_writable($dirPath)) $checkString .= $dirPath . '&nbsp;[<span class="text-red">' . '无写入权限' . '</span>]<br>';
}
}
//清除
Files::delDirAndFile('../runtime/addons/');
if (!empty($checkString)) return json(['code' => -1, 'msg' => $checkString]);
$addonsPath = '../';
$cpRes = Files::copyDirs($zipPath,$addonsPath);
$cpData = $cpRes->getData();
//更新失败
if($cpData['code'] == -1) return json(['code'=>-1,'msg'=>$cpData['msg']]);
Files::delDirAndFile('../runtime/addons/');
}
return json(['code'=>0,'msg'=>'插件安装成功!']);
return json(['code'=>0,'msg'=>'插件安装成功!']);
}
/**

View File

@ -43,7 +43,7 @@ class Auth
}
//没有登录及当前非登录页重定向登录页
if(!Session::has('admin_id') && $path !== 'admin/login/index' && !stristr($request->pathinfo(),"captcha.html") )
if(!Session::has('admin_id') && $path !== 'admin/login/index' && !(stristr($request->pathinfo(),"captcha.html") || stristr($request->pathinfo(),"addons")) )
{
return redirect((string) url('admin/login/index'));
}

View File

@ -27,7 +27,8 @@
"firebase/php-jwt": "^5.2",
"lotofbadcode/phpspirit_databackup": "^1.1",
"wamkj/thinkphp6.0-databackup": "^1.0",
"taoser/think-addons": "^1.0"
"taoser/think-addons": "^1.0",
"liliuwei/thinkphp-social": "^1.3"
},
"require-dev": {
"symfony/var-dumper": "^4.2",

134
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3ef61427e5d1c98f5ca1e197d25ef688",
"content-hash": "9a2defc1ce427f4ab5f63c13400425c3",
"packages": [
{
"name": "firebase/php-jwt",
@ -288,6 +288,87 @@
],
"time": "2021-11-21T11:48:40+00:00"
},
{
"name": "liliuwei/thinkphp-social",
"version": "v1.3",
"source": {
"type": "git",
"url": "https://github.com/liliuwei/thinkphp-social.git",
"reference": "2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/liliuwei/thinkphp-social/zipball/2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970",
"reference": "2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.6.0",
"topthink/framework": "^5.1 || ^6.0",
"topthink/think-installer": "^2.0"
},
"type": "think-extend",
"extra": {
"think-config": {
"social": "src/config/config.php"
},
"think": {
"config": {
"social": "src/config/config.php"
}
}
},
"autoload": {
"psr-4": {
"liliuwei\\social\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liliuwei",
"email": "974829947@qq.com"
}
],
"description": "适用于thinkphp5.1和6.0的社会化登录扩展",
"keywords": [
"Facebook登录",
"Gitee登录",
"Github登录",
"Google登录",
"Oschina登录",
"QQ登录",
"oauth",
"think-social",
"thinkphp",
"thinkphp-social",
"thinkphp5.1",
"thinkphp6.0",
"小米登录",
"微信登录",
"抖音登录",
"新浪登录",
"淘宝登录",
"百度登录",
"第三方授权登录",
"谷歌登录",
"钉钉登录"
],
"support": {
"issues": "https://github.com/liliuwei/thinkphp-social/issues",
"source": "https://github.com/liliuwei/thinkphp-social/tree/v1.3"
},
"time": "2021-01-13T05:11:12+00:00"
},
{
"name": "lotofbadcode/phpspirit_databackup",
"version": "v1.1",
@ -1008,6 +1089,57 @@
},
"time": "2021-12-15T04:27:55+00:00"
},
{
"name": "topthink/think-installer",
"version": "v2.0.5",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-installer.git",
"reference": "38ba647706e35d6704b5d370c06f8a160b635f88"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-installer/zipball/38ba647706e35d6704b5d370c06f8a160b635f88",
"reference": "38ba647706e35d6704b5d370c06f8a160b635f88",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"composer-plugin-api": "^1.0||^2.0"
},
"require-dev": {
"composer/composer": "^1.0||^2.0"
},
"type": "composer-plugin",
"extra": {
"class": "think\\composer\\Plugin"
},
"autoload": {
"psr-4": {
"think\\composer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"support": {
"issues": "https://github.com/top-think/think-installer/issues",
"source": "https://github.com/top-think/think-installer/tree/v2.0.5"
},
"time": "2021-01-14T12:12:14+00:00"
},
{
"name": "topthink/think-multi-app",
"version": "v1.0.14",

85
config/social.php Normal file
View File

@ -0,0 +1,85 @@
<?php
/**
* User: liliuwei
* Date: 2017/5/23
*/
return [
//腾讯QQ登录配置
'qq' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//微信扫码登录配置
'weixin' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//新浪登录配置
'sina' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Baidu登录配置
'baidu' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Gitee登录配置
'gitee' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Github登录配置
'github' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Google登录配置
'google' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Facebook登录配置
'facebook' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Oschina登录配置
'oschina' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Taobao登录配置
'taobao' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Douyin登录配置
'douyin' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Xiaomi登录配置
'xiaomi' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Dingtalk登录配置
'dingtalk' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
]
];

View File

@ -7,7 +7,7 @@ return [
//应用名,此项不可更改
'appname' => 'TaoLer',
//版本配置
'version' => '1.8.21',
'version' => '1.8.22',
//加盐
'salt' => 'taoler',
//数据库备份目录

View File

@ -168,6 +168,7 @@ layui.define(["table", "form", "upload"], function (exports) {
},
});
} else if (obj.event === "install") {
var index = layer.load(1);
//安装插件
$.post(
addonsInstall,
@ -183,6 +184,7 @@ layui.define(["table", "form", "upload"], function (exports) {
anim: 6,
});
}
layer.close(index);
}
);
} else if (obj.event === "config") {

View File

@ -9,12 +9,14 @@ return array(
'wamkj\\thinkphp\\' => array($vendorDir . '/wamkj/thinkphp6.0-databackup/src'),
'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'),
'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'),
'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'),
'think\\' => array($vendorDir . '/topthink/framework/src/think', $vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/think-template/src'),
'taoser\\think\\' => array($vendorDir . '/taoser/think-auth/src'),
'taoser\\' => array($vendorDir . '/taoser/think-addons/src'),
'phpspirit\\databackup\\' => array($vendorDir . '/lotofbadcode/phpspirit_databackup/src'),
'liliuwei\\social\\' => array($vendorDir . '/liliuwei/thinkphp-social/src'),
'app\\' => array($baseDir . '/app'),
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),

View File

@ -27,6 +27,7 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
'think\\view\\driver\\' => 18,
'think\\trace\\' => 12,
'think\\composer\\' => 15,
'think\\captcha\\' => 14,
'think\\app\\' => 10,
'think\\' => 6,
@ -37,6 +38,10 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
'phpspirit\\databackup\\' => 21,
),
'l' =>
array (
'liliuwei\\social\\' => 16,
),
'a' =>
array (
'app\\' => 4,
@ -82,6 +87,10 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
0 => __DIR__ . '/..' . '/topthink/think-trace/src',
),
'think\\composer\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-installer/src',
),
'think\\captcha\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-captcha/src',
@ -109,6 +118,10 @@ class ComposerStaticInit1b32198725235c8d6500c87262ef30c2
array (
0 => __DIR__ . '/..' . '/lotofbadcode/phpspirit_databackup/src',
),
'liliuwei\\social\\' =>
array (
0 => __DIR__ . '/..' . '/liliuwei/thinkphp-social/src',
),
'app\\' =>
array (
0 => __DIR__ . '/../..' . '/app',

View File

@ -290,6 +290,90 @@
],
"install-path": "../league/mime-type-detection"
},
{
"name": "liliuwei/thinkphp-social",
"version": "v1.3",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/liliuwei/thinkphp-social.git",
"reference": "2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/liliuwei/thinkphp-social/zipball/2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970",
"reference": "2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.6.0",
"topthink/framework": "^5.1 || ^6.0",
"topthink/think-installer": "^2.0"
},
"time": "2021-01-13T05:11:12+00:00",
"type": "think-extend",
"extra": {
"think-config": {
"social": "src/config/config.php"
},
"think": {
"config": {
"social": "src/config/config.php"
}
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"liliuwei\\social\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liliuwei",
"email": "974829947@qq.com"
}
],
"description": "适用于thinkphp5.1和6.0的社会化登录扩展",
"keywords": [
"Facebook登录",
"Gitee登录",
"Github登录",
"Google登录",
"Oschina登录",
"QQ登录",
"oauth",
"think-social",
"thinkphp",
"thinkphp-social",
"thinkphp5.1",
"thinkphp6.0",
"小米登录",
"微信登录",
"抖音登录",
"新浪登录",
"淘宝登录",
"百度登录",
"第三方授权登录",
"谷歌登录",
"钉钉登录"
],
"support": {
"issues": "https://github.com/liliuwei/thinkphp-social/issues",
"source": "https://github.com/liliuwei/thinkphp-social/tree/v1.3"
},
"install-path": "../liliuwei/thinkphp-social"
},
{
"name": "lotofbadcode/phpspirit_databackup",
"version": "v1.1",
@ -1399,6 +1483,60 @@
},
"install-path": "../topthink/think-helper"
},
{
"name": "topthink/think-installer",
"version": "v2.0.5",
"version_normalized": "2.0.5.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-installer.git",
"reference": "38ba647706e35d6704b5d370c06f8a160b635f88"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-installer/zipball/38ba647706e35d6704b5d370c06f8a160b635f88",
"reference": "38ba647706e35d6704b5d370c06f8a160b635f88",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"composer-plugin-api": "^1.0||^2.0"
},
"require-dev": {
"composer/composer": "^1.0||^2.0"
},
"time": "2021-01-14T12:12:14+00:00",
"type": "composer-plugin",
"extra": {
"class": "think\\composer\\Plugin"
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"think\\composer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"support": {
"issues": "https://github.com/top-think/think-installer/issues",
"source": "https://github.com/top-think/think-installer/tree/v2.0.5"
},
"install-path": "../topthink/think-installer"
},
{
"name": "topthink/think-multi-app",
"version": "v1.0.14",

View File

@ -5,7 +5,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '3e8741aae6a9a6de29bf9a55d5c22e9cf86f922c',
'reference' => '260604abd3f6eb2b7f43706b8dd2b7cc35acc93c',
'name' => 'taoser/taoler',
'dev' => true,
),
@ -46,6 +46,15 @@
'reference' => 'aa70e813a6ad3d1558fc927863d47309b4c23e69',
'dev_requirement' => false,
),
'liliuwei/thinkphp-social' => array(
'pretty_version' => 'v1.3',
'version' => '1.3.0.0',
'type' => 'think-extend',
'install_path' => __DIR__ . '/../liliuwei/thinkphp-social',
'aliases' => array(),
'reference' => '2067fc2c2cc3b3d109602bc19c3e5a99c5f4c970',
'dev_requirement' => false,
),
'lotofbadcode/phpspirit_databackup' => array(
'pretty_version' => 'v1.1',
'version' => '1.1.0.0',
@ -151,7 +160,7 @@
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '3e8741aae6a9a6de29bf9a55d5c22e9cf86f922c',
'reference' => '260604abd3f6eb2b7f43706b8dd2b7cc35acc93c',
'dev_requirement' => false,
),
'taoser/think-addons' => array(
@ -199,6 +208,15 @@
'reference' => '769acbe50a4274327162f9c68ec2e89a38eb2aff',
'dev_requirement' => false,
),
'topthink/think-installer' => array(
'pretty_version' => 'v2.0.5',
'version' => '2.0.5.0',
'type' => 'composer-plugin',
'install_path' => __DIR__ . '/../topthink/think-installer',
'aliases' => array(),
'reference' => '38ba647706e35d6704b5d370c06f8a160b635f88',
'dev_requirement' => false,
),
'topthink/think-multi-app' => array(
'pretty_version' => 'v1.0.14',
'version' => '1.0.14.0',

View File

201
vendor/liliuwei/thinkphp-social/LICENSE vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,99 @@
## thinkphp-social
适用于thinkphp5.1 thinkphp6.0的社会化登录扩展
目前已支持QQ、微信、新浪、百度、Gitee、Github、Oschina、Google、Facebook、淘宝、抖音、小米、钉钉
欢迎提交pr或者建议!
有问题可以联系邮箱974829947@qq.com
## 安装(扩展包)
```php
composer require liliuwei/thinkphp-social
```
# 配置Config信息
```php
// 安装之后会在config目录里自动生成social.php配置文件
<?php
return [
//腾讯QQ登录配置
'qq' => [
'app_key' => '*******', //应用注册成功后分配的 APP ID
'app_secret' => '*******', //应用注册成功后分配的KEY
'callback' => 'http://www.youquanya.com/oauth/callback/type/qq', // 应用回调地址
],
//微信扫码登录配置
'weixin' => [
'app_key' => '*******', //应用注册成功后分配的 APP ID
'app_secret' => '*******', //应用注册成功后分配的KEY
'callback' => 'http://www.youquanya.com/oauth/callback/type/weixin', // 应用回调地址
],
];
```
## 用法示例
````
<a href="{:url('Oauth/login',['type'=>'qq'])}">QQ登录</a>
<a href="{:url('Oauth/login',['type'=>'sina'])}">新浪微博登录</a>
<a href="{:url('Oauth/login',['type'=>'weixin'])}">微信登录</a>
<a href="{:url('Oauth/login',['type'=>'baidu'])}">百度登录</a>
<a href="{:url('Oauth/login',['type'=>'gitee'])}">gitee登录</a>
<a href="{:url('Oauth/login',['type'=>'github'])}">github登录</a>
<a href="{:url('Oauth/login',['type'=>'oschaina'])}">oschaina登录</a>
<a href="{:url('Oauth/login',['type'=>'google'])}">google登录</a>
<a href="{:url('Oauth/login',['type'=>'facebook'])}">facebook登录</a>
<a href="{:url('Oauth/login',['type'=>'taobao'])}">淘宝登录</a>
<a href="{:url('Oauth/login',['type'=>'douyin'])}">抖音登录</a>
<a href="{:url('Oauth/login',['type'=>'xiaomi'])}">小米登录</a>
<a href="{:url('Oauth/login',['type'=>'dingtalk'])}">钉钉登录</a>
````
```php
//设置路由
Route::get('oauth/callback','index/oauth/callback');
```
```php
<?php
namespace app\index\controller;
use think\Controller;
class Oauth extends Controller
{
//登录地址
public function login($type = null)
{
if ($type == null) {
$this->error('参数错误');
}
// 获取对象实例
$sns = \liliuwei\social\Oauth::getInstance($type);
//跳转到授权页面
$this->redirect($sns->getRequestCodeURL());
}
//授权回调地址
public function callback($type = null, $code = null)
{
if ($type == null || $code == null) {
$this->error('参数错误');
}
$sns = \liliuwei\social\Oauth::getInstance($type);
// 获取TOKEN
$token = $sns->getAccessToken($code);
//获取当前第三方登录用户信息
if (is_array($token)) {
$user_info = \liliuwei\social\GetInfo::getInstance($type, $token);
dump($user_info);// 获取第三方用户资料
$sns->openid();//统一使用$sns->openid()获取openid
//$sns->unionid();//QQ和微信、淘宝可以获取unionid
dump($sns->openid());
echo '登录成功!!';
echo '正在持续开发中,敬请期待!!';
} else {
echo "获取第三方用户的基本信息失败";
}
}
}
```

View File

@ -0,0 +1,33 @@
{
"name": "liliuwei/thinkphp-social",
"description": "适用于thinkphp5.1和6.0的社会化登录扩展",
"keywords": ["第三方授权登录","QQ登录","微信登录","新浪登录","百度登录","谷歌登录","Google登录","Facebook登录","Gitee登录","Github登录","Oschina登录","淘宝登录","抖音登录","小米登录","钉钉登录","think-social","thinkphp-social","oauth", "thinkphp","thinkphp5.1","thinkphp6.0"],
"license": "Apache-2.0",
"type": "think-extend",
"require": {
"php": ">=5.6.0",
"topthink/think-installer": "^2.0",
"topthink/framework": "^5.1 || ^6.0"
},
"authors": [
{
"name": "liliuwei",
"email": "974829947@qq.com"
}
],
"autoload" : {
"psr-4" : {
"liliuwei\\social\\" : "src/"
}
},
"extra": {
"think-config": {
"social": "src/config/config.php"
},
"think": {
"config": {
"social": "src/config/config.php"
}
}
}
}

View File

@ -0,0 +1,280 @@
<?php
/**
* 获取第三方用户信息类
*/
namespace liliuwei\social;
final class GetInfo
{
public static function getInstance($type, $token)
{
return self::$type($token);
}
//QQ用户信息
public static function qq($token)
{
$qq = Oauth::getInstance('qq', $token);
$data = $qq->call('user/get_user_info');
if ($data['ret'] == 0) {
$userInfo['type'] = 'qq';
$userInfo['name'] = $data['nickname'];
$userInfo['nickname'] = $data['nickname'];
$userInfo['avatar'] = $data['figureurl_2'];
$userInfo['gender'] = $data['gender'];
return $userInfo;
} else {
throw new \Exception("获取腾讯QQ用户信息失败{$data['msg']}");
}
}
//微信用户信息
public static function weixin($token)
{
$weixin = Oauth::getInstance('weixin', $token);
$data = $weixin->call('sns/userinfo');
if (isset($data['errcode'])) {
throw new \Exception("获取微信用户信息失败errcode:{$data['errcode']} errmsg: {$data['errmsg']}");
}
if ($data['openid']) {
$userInfo['type'] = 'weixin';
$userInfo['name'] = $data['nickname'];
$userInfo['nickname'] = $data['nickname'];
$userInfo['avatar'] = $data['headimgurl'];
$userInfo['openid'] = $data['openid'];
$userInfo['unionid'] = $data['unionid'];
$userInfo['province'] = $data['province'];
$userInfo['city'] = $data['city'];
$userInfo['country'] = $data['country'];
$userInfo['sex'] = $data['sex']==1?'男':'女';
return $userInfo;
} else {
throw new \Exception("获取微信用户信息失败");
}
}
//新浪微博用户信息
public static function sina($token)
{
$sina = Oauth::getInstance('sina', $token);
$data = $sina->call('users/show',"uid={$sina->openid()}");
if ($data['id']) {
$userInfo['type'] = 'sina';
$userInfo['name'] = $data['name'];
$userInfo['nickname'] = $data['screen_name'];
$userInfo['avatar'] = $data['avatar_large'];
$userInfo['openid'] = $data['id'];
$userInfo['idstr'] = $data['idstr'];
$userInfo['province'] = $data['province'];
$userInfo['city'] = $data['city'];
$userInfo['location'] = $data['location'];
$userInfo['created_at'] = $data['created_at'];
$userInfo['gender'] = $data['gender']=='m'?'男':($data['gender']=='f'?'女':'未知');
$userInfo['followers_count'] = $data['followers_count'];
$userInfo['friends_count'] = $data['friends_count'];
$userInfo['statuses_count'] = $data['statuses_count'];
$userInfo['favourites_count'] = $data['favourites_count'];
$userInfo['description'] = $data['description'];
$userInfo['url'] = $data['url'];
$userInfo['profile_url'] = $data['profile_url'];
return $userInfo;
} else {
throw new \Exception("获取新浪微博用户信息失败:{$data['error']}");
}
}
//Baidu用户信息
public static function baidu($token)
{
$baidu = Oauth::getInstance('baidu', $token);
$data = $baidu->call('passport/users/getInfo');
if (isset($data['userid'])) {
$userInfo['type'] = 'baidu';
$userInfo['name'] = $data['username'];
$userInfo['nickname'] = isset($data['realname'])?$data['realname']:'';
$userInfo['avatar'] = 'http://tb.himg.baidu.com/sys/portrait/item/'.$data['portrait'];
$userInfo['openid'] = $data['userid'];
$userInfo['sex'] = $data['sex']==1?'男':'女';
return $userInfo;
} else {
throw new \Exception("获取Baidu用户信息失败");
}
}
//Gitee用户信息
public static function gitee($token)
{
$google = Oauth::getInstance('gitee', $token);
$data = $google->call('user');
if (isset($data['id'])) {
$userInfo['type'] = 'gitee';
$userInfo['name'] = $data['name'];
$userInfo['nickname'] = $data['login'];
$userInfo['avatar'] = $data['avatar_url'];
$userInfo['openid'] = $data['id'];
$userInfo['html_url'] = $data['html_url'];
$userInfo['blog'] = $data['blog'];
$userInfo['email'] = $data['email'];
return $userInfo;
} else {
throw new \Exception("获取Gitee用户信息失败");
}
}
//Github用户信息
public static function github($token)
{
$google = Oauth::getInstance('github', $token);
$data = $google->call('user');
if (isset($data['id'])) {
$userInfo['type'] = 'github';
$userInfo['name'] = $data['name'];
$userInfo['nickname'] = $data['login'];
$userInfo['avatar'] = $data['avatar_url'];
$userInfo['openid'] = $data['id'];
$userInfo['html_url'] = $data['html_url'];
$userInfo['blog'] = $data['blog'];
$userInfo['email'] = $data['email'];
return $userInfo;
} else {
throw new \Exception("获取Gitee用户信息失败");
}
}
//Google用户信息
public static function google($token)
{
$google = Oauth::getInstance('google', $token);
$data = $google->call('userinfo');
if (isset($data['id'])) {
$userInfo['type'] = 'google';
$userInfo['name'] = $data['name'];
$userInfo['nickname'] = $data['name'];
$userInfo['avatar'] = $data['picture'];
$userInfo['openid'] = $data['id'];
$userInfo['given_name'] = $data['given_name'];
$userInfo['family_name'] = $data['family_name'];
$userInfo['locale'] = $data['locale'];
$userInfo['email'] = $data['email'];
return $userInfo;
} else {
throw new \Exception("获取Google用户信息失败");
}
}
//Facebook用户信息
public static function facebook($token)
{
$facebook = Oauth::getInstance('facebook', $token);
$data = $facebook->call('me', 'fields=name,picture,first_name,last_name,short_name,email');
if (isset($data['id'])) {
$userInfo['type'] = 'facebook';
$userInfo['name'] = $data['name'];
$userInfo['nickname'] = $data['name'];
$userInfo['avatar'] = $data['picture']['data']['url'];
$userInfo['openid'] = $data['id'];
$userInfo['first_name'] = $data['first_name'];
$userInfo['last_name'] = $data['last_name'];
$userInfo['short_name'] = $data['short_name'];
$userInfo['email'] = $data['email'];
return $userInfo;
} else {
throw new \Exception("获取Facebook用户信息失败");
}
}
//Oschina用户信息
public static function oschina($token)
{
$oschina = Oauth::getInstance('oschina', $token);
$data = $oschina->call('action/openapi/user');
if (isset($data['id'])) {
$userInfo['type'] = 'gitee';
$userInfo['name'] = $data['name'];
$userInfo['nickname'] = $data['name'];
$userInfo['avatar'] = $data['avatar'];
$userInfo['openid'] = $data['id'];
$userInfo['email'] = $data['email'];
$userInfo['location'] = $data['location'];
return $userInfo;
} else {
throw new \Exception("获取Gitee用户信息失败");
}
}
//Taobao用户信息
public static function taobao($token)
{
$data = $token;
if (isset($data['taobao_user_id'])) {
$userInfo['type'] = 'taobao';
$userInfo['name'] = urldecode($data['taobao_user_nick']);
$userInfo['nickname'] = urldecode($data['taobao_user_nick']);
$userInfo['avatar'] = '';
$userInfo['openid'] = $data['taobao_user_id'];
$userInfo['taobao_open_uid'] = $data['taobao_open_uid'];
return $userInfo;
} else {
throw new \Exception("获取淘宝用户信息失败");
}
}
//Douyin用户信息
public static function douyin($token)
{
$douyin = Oauth::getInstance('douyin', $token);
$data = $douyin->call('oauth/userinfo');
$data = $data['data'];
if (isset($data['open_id'])) {
$userInfo['type'] = 'douyin';
$userInfo['name'] = $data['nickname'];
$userInfo['nickname'] = $data['nickname'];
$userInfo['avatar'] = $data['avatar'];
$userInfo['openid'] = $data['open_id'];
$userInfo['unionid'] = $data['union_id'];
$userInfo['gender'] = $data['sex']==1?'男':'女';
$userInfo['city'] = $data['city'];
$userInfo['province'] = $data['province'];
$userInfo['country'] = $data['country'];
return $userInfo;
} else {
throw new \Exception("获取抖音用户信息失败");
}
}
//Xiaomi用户信息
public static function xiaomi($token)
{
$xiaomi = Oauth::getInstance('xiaomi', $token);
$data = $xiaomi->call('user/profile');
$data = $data['data'];
if (isset($data['unionId'])) {
$userInfo['type'] = 'xiaomi';
$userInfo['name'] = $data['miliaoNick'];
$userInfo['nickname'] = $data['miliaoNick'];
$userInfo['avatar'] = $data['miliaoIcon'];
$userInfo['openid'] = array_key_exists('userId',$data)?$data['userId']:$data['unionId'];
$userInfo['unionid'] = $data['unionId'];
return $userInfo;
} else {
throw new \Exception("获取小米用户信息失败");
}
}
//Dingtalk用户信息
public static function dingtalk($token)
{
$data = $token;
if ($data['openid']) {
$userInfo['type'] = 'dingtalk';
$userInfo['name'] = $data['nick'];
$userInfo['nickname'] = $data['nick'];
$userInfo['avatar'] = '';
$userInfo['openid'] = $data['openid'];
$userInfo['unionid'] = $data['unionid'];
return $userInfo;
} else {
throw new \Exception("获取钉钉用户信息失败");
}
}
}

View File

@ -0,0 +1,267 @@
<?php
/**
* User: liliuwei
* Date: 2017/5/23
*/
namespace liliuwei\social;
abstract class Oauth
{
/**
* oauth版本
* @var string
*/
protected $Version = '2.0';
/**
* 申请应用时分配的app_key
* @var string
*/
protected $AppKey = '';
/**
* 申请应用时分配的 app_secret
* @var string
*/
protected $AppSecret = '';
/**
* 授权类型 response_type 目前只能为code
* @var string
*/
protected $ResponseType = 'code';
/**
* grant_type 目前只能为 authorization_code
* @var string
*/
protected $GrantType = 'authorization_code';
/**
* 回调页面URL 可以通过配置文件配置
* @var string
*/
protected $Callback = '';
/**
* 获取request_code的额外参数 URL查询字符串格式
* @var srting
*/
protected $Authorize = '';
/**
* 获取request_code请求的URL
* @var string
*/
protected $GetRequestCodeURL = '';
/**
* 获取access_token请求的URL
* @var string
*/
protected $GetAccessTokenURL = '';
/**
* API根路径
* @var string
*/
protected $ApiBase = '';
/**
* 授权后获取到的TOKEN信息
* @var array
*/
protected $Token = null;
/**
* 调用接口类型
* @var string
*/
private $Type = '';
/**
* 构造方法,配置应用信息
* @param array $token
*/
public function __construct($token = null)
{
//设置SDK类型
$class = get_class($this);
$re_str = str_replace("liliuwei\\social\\sdk\\", '', $class);
$this->Type = strtolower($re_str);
//获取应用配置
$config = config("social.{$this->Type}");
if (empty($config['app_key']) || empty($config['app_secret'])) {
throw new \Exception('请配置您申请的app_key和app_secret');
} else {
$this->AppKey = $config['app_key'];
$this->AppSecret = $config['app_secret'];
$this->Token = $token; //设置获取到的TOKEN
}
}
/**
* 取得Oauth实例
* @static
* @return mixed 返回Oauth
*/
public static function getInstance($type, $token = null)
{
$sdk = [
'Qq', 'Weixin', 'Sina', 'Baidu', 'Gitee', 'Github', 'Google', 'Facebook', 'Taobao', 'Oschina', 'Douyin', 'Xiaomi', 'Dingtalk'
];
$name = ucfirst(strtolower($type));
if (in_array($name, $sdk)) {
$class = '\\liliuwei\\social\\sdk\\' . $name;
return new $class($token);
} else {
header('content-type:text/html;charset=utf-8');
throw new \Exception('暂时还不支持该' . $name . '的扩展');
}
}
/**
* 初始化配置
*/
protected function config()
{
$config = config("social.{$this->Type}");
if (!empty($config['authorize']))
$this->Authorize = $config['authorize'];
if (!empty($config['callback']))
$this->Callback = $config['callback'];
else
throw new \Exception('请配置回调页面地址');
}
/**
* 请求code
*/
public function getRequestCodeURL()
{
$this->config();
//Oauth 标准参数
$params = array(
'client_id' => $this->AppKey,
'redirect_uri' => $this->Callback,
'response_type' => $this->ResponseType,
);
//获取额外参数
if ($this->Authorize) {
parse_str($this->Authorize, $_param);
if (is_array($_param)) {
$params = array_merge($params, $_param);
} else {
throw new \Exception('AUTHORIZE配置不正确');
}
}
return $this->GetRequestCodeURL . '?' . http_build_query($params);
}
/**
* 获取access_token
* @param string $code 上一步请求到的code
*/
public function getAccessToken($code, $extend = null)
{
$this->config();
$params = array(
'client_id' => $this->AppKey,
'client_secret' => $this->AppSecret,
'grant_type' => $this->GrantType,
'code' => $code,
'redirect_uri' => $this->Callback,
);
$data = $this->http($this->GetAccessTokenURL, $params, 'POST');
$this->Token = $this->parseToken($data, $extend);
return $this->Token;
}
/**
* 合并默认参数和额外参数
* @param array $params 默认参数
* @param array/string $param 额外参数
* @return array:
*/
protected function param($params, $param)
{
if (is_string($param))
parse_str($param, $param);
return array_merge($params, $param);
}
/**
* 获取指定API请求的URL
* @param string $api API名称
* @param string $fix api后缀
* @return string 请求的完整URL
*/
protected function url($api = '', $fix = '')
{
return $this->ApiBase . $api . $fix;
}
/**
* 发送HTTP请求方法目前只支持CURL发送请求
* @param string $url 请求URL
* @param array $params 请求参数
* @param string $method 请求方法GET/POST
* @return array $data 响应数据
*/
protected function http($url, $params, $method = 'GET', $header = array(), $multi = false)
{
$opts = array(
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $header
);
/* 根据请求类型设置特定参数 */
switch (strtoupper($method)) {
case 'GET':
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
break;
case 'POST':
//判断是否传输文件
$params = $multi ? $params : http_build_query($params);
$opts[CURLOPT_URL] = $url;
$opts[CURLOPT_POST] = 1;
$opts[CURLOPT_POSTFIELDS] = $params;
break;
default:
throw new \Exception('不支持的请求方式!');
}
/* 初始化并执行curl请求 */
$ch = curl_init();
curl_setopt_array($ch, $opts);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error) throw new \Exception('请求发生错误:' . $error);
return $data;
}
/**
* 抽象方法在SNSSDK中实现
* 组装接口调用参数 并调用接口
*/
abstract protected function call($api, $param = '', $method = 'GET', $multi = false);
/**
* 抽象方法在SNSSDK中实现
* 解析access_token方法请求后的返回值
*/
abstract protected function parseToken($result, $extend);
/**
* 抽象方法在SNSSDK中实现
* 获取当前授权用户的SNS标识
*/
abstract public function openid();
}

View File

@ -0,0 +1,85 @@
<?php
/**
* User: liliuwei
* Date: 2017/5/23
*/
return [
//腾讯QQ登录配置
'qq' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//微信扫码登录配置
'weixin' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//新浪登录配置
'sina' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Baidu登录配置
'baidu' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Gitee登录配置
'gitee' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Github登录配置
'github' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Google登录配置
'google' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Facebook登录配置
'facebook' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Oschina登录配置
'oschina' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Taobao登录配置
'taobao' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Douyin登录配置
'douyin' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Xiaomi登录配置
'xiaomi' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
],
//Dingtalk登录配置
'dingtalk' => [
'app_key' => '', //应用注册成功后分配的 APP ID
'app_secret' => '', //应用注册成功后分配的KEY
'callback' => '', // 应用回调地址
]
];

View File

@ -0,0 +1,74 @@
<?php
/**
* Baidu SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Baidu extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://openapi.baidu.com/oauth/2.0/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://openapi.baidu.com/oauth/2.0/token';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://openapi.baidu.com/rest/2.0/';
/**
* 组装接口调用参数 并调用接口
* @param string $api 百度 API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* 百度调用公共参数 */
$params = array(
'access_token' => $this->Token['access_token'],
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['expires_in'] && $data['refresh_token']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取百度ACCESS_TOKEN出错{$data['error']}");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->call('passport/users/getInfo');
if (isset($data['userid']))
return $data['userid'];
else
throw new \Exception('没有获取到百度用户ID');
}
}

View File

@ -0,0 +1,170 @@
<?php
/**
* Dingtalk SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Dingtalk extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://oapi.dingtalk.com/connect/qrconnect';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = '';
/**
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=snsapi_login';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://oapi.dingtalk.com/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Dingtalk API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'POST', $multi = false)
{
$time=$this->getMicrotime();
// 根据timestamp, appSecret计算签名值
$s = hash_hmac('sha256', $time, $this->AppSecret, true);
$signature = base64_encode($s);
$urlencode_signature = urlencode($signature);
/* Dingtalk 调用公共参数 */
$params = array(
'tmp_auth_code'=>$param['code'],
);
$data = $this->http($this->url($api.'?signature='.$urlencode_signature.'&timestamp='.$time.'&accessKey='.$this->AppKey), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 发送HTTP请求方法目前只支持CURL发送请求
* @param string $url 请求URL
* @param array $params 请求参数
* @param string $method 请求方法GET/POST
* @return array $data 响应数据
*/
public function http($url, $params, $method = 'POST', $header = array(), $multi = false)
{
$data_string = json_encode($params);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
return $result;
}
/**
* 时间戳 - 精确到毫秒
* @return float
*/
public function getMicrotime()
{
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
}
/**
* 请求code
*/
public function getRequestCodeURL()
{
$this->config();
//Oauth 标准参数
$params = array(
'appid' => $this->AppKey,
'redirect_uri' => $this->Callback,
'response_type' => $this->ResponseType,
);
//获取额外参数
if ($this->Authorize) {
parse_str($this->Authorize, $_param);
if (is_array($_param)) {
$params = array_merge($params, $_param);
} else {
throw new \Exception('AUTHORIZE配置不正确');
}
}
return $this->GetRequestCodeURL . '?' . http_build_query($params);
}
/**
* 获取access_token
* @param string $code 上一步请求到的code
*/
public function getAccessToken($code, $extend = null)
{
$result = $this->call('sns/getuserinfo_bycode',['code'=>$code]);
$data = $result['user_info'];
$this->Token = [
'nick'=>$data['nick'],
'openid'=>$data['openid'],
'unionid'=>$data['unionid'],
];
return $this->Token;
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend){}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid($unionid=false)
{
if ($unionid){
return $this->unionid();
}
$data = $this->Token;
if (isset($data['openid'])){
return $data['openid'];
}else{
throw new \Exception('没有获取到 Dingtalk 用户openid');
}
}
/**
* 获取当前授权应用的unionid
*/
public function unionid()
{
$data = $this->Token;
if (isset($data['unionid'])){
return $data['unionid'];
}else{
throw new \Exception('没有获取到 Dingtalk 用户unionid');
}
}
}

View File

@ -0,0 +1,141 @@
<?php
/**
* Douyin SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Douyin extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://open.douyin.com/platform/oauth/connect';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://open.douyin.com/oauth/access_token/';
/**
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=user_info';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://open.douyin.com/';
/**
* 请求code
*/
public function getRequestCodeURL()
{
$this->config();
$params = array(
'client_key ' => $this->AppKey,
'redirect_uri' => $this->Callback,
'response_type' => $this->ResponseType,
);
//获取额外参数
if ($this->Authorize) {
parse_str($this->Authorize, $_param);
if (is_array($_param)) {
$params = array_merge($params, $_param);
} else {
throw new \Exception('AUTHORIZE配置不正确');
}
}
return $this->GetRequestCodeURL . '?' . http_build_query($params);
}
/**
* 获取access_token
* @param string $code 上一步请求到的code
*/
public function getAccessToken($code, $extend = null)
{
$this->config();
$params = array(
'client_key' => $this->AppKey,
'client_secret ' => $this->AppSecret,
'grant_type' => $this->GrantType,
'code' => $code,
);
$data = $this->http($this->GetAccessTokenURL, $params, 'GET');
$this->Token = $this->parseToken($data, $extend);
return $this->Token;
}
/**
* 组装接口调用参数 并调用接口
* @param string $api Douyin API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* Douyin 调用公共参数 */
$params = array(
'access_token' => $this->Token['access_token'],
'open_id' => $this->openid(),
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
$data = $data['data'];
if ($data['access_token'] && $data['expires_in']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取 抖音 ACCESS_TOKEN出错未知错误");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid($unionid=false)
{
if ($unionid){
return $this->unionid();
}
$data = $this->call('oauth/userinfo');
$data = $data['data'];
if (isset($data['open_id']))
return $data['open_id'];
else
throw new \Exception('没有获取到 抖音 用户openid');
}
/**
* 获取当前授权应用的unionid
*/
public function unionid()
{
$data = $this->call('oauth/userinfo');
$data = $data['data'];
if (isset($data['union_id']))
return $data['union_id'];
else
exit('没有获取到 抖音 用户unionid');
}
}

View File

@ -0,0 +1,83 @@
<?php
/**
* Facebook SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Facebook extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://www.facebook.com/dialog/oauth';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://graph.facebook.com/oauth/access_token';
/**
* 获取request_code的额外参数 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=email';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://graph.facebook.com/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Facebook API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @param bool $multi
* @return array
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* facebook 调用公共参数 */
$params = array('access_token' => $this->Token['access_token']);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
* @param mix $extend
* @return array
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if (is_array($data) && $data['access_token'] && $data['expires_in']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else {
throw new \Exception("获取 facebook ACCESS_TOKEN出错未知错误");
}
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->call('me');
if (isset($data['id']))
return $data['id'];
else
throw new \Exception('没有获取到 facebook 用户ID');
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* Gitee SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Gitee extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://gitee.com/oauth/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://gitee.com/oauth/token';
/**
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=user_info';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://gitee.com/api/v5/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Gitee API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* Gitee 调用公共参数 */
$params = array();
$header = array("Authorization: bearer {$this->Token['access_token']}");
$data = $this->http($this->url($api), $this->param($params, $param), $method, $header);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['token_type']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取 Gitee ACCESS_TOKEN出错未知错误");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->call('user');
if (isset($data['id']))
return $data['id'];
else
throw new \Exception('没有获取到 Gitee 用户ID');
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* Github SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Github extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://github.com/login/oauth/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://github.com/login/oauth/access_token';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://api.github.com/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Github API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* Github 调用公共参数 */
$params = array();
$header = array("Authorization: bearer {$this->Token['access_token']}","User-Agent:thinkphp-social");
$data = $this->http($this->url($api), $this->param($params, $param), $method, $header);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
parse_str($result, $data);
if ($data['access_token'] && $data['token_type']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取 Github ACCESS_TOKEN出错未知错误");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->call('user');
if (isset($data['id']))
return $data['id'];
else
throw new \Exception('没有获取到 Github 用户ID');
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Google SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Google extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://accounts.google.com/o/oauth2/auth';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://accounts.google.com/o/oauth2/token';
/**
* 获取request_code的额外参数 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'access_type&offline&approval_prompt&auto&scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://www.googleapis.com/oauth2/v1/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Google API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* 新浪微博调用公共参数 */
$params = array(
'access_token' => $this->Token['access_token'],
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['expires_in']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取Google ACCESS_TOKEN 出错:{$result}");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->call('userinfo');
if (isset($data['id']))
return $data['id'];
else
throw new \Exception('没有获取到 Google 用户ID');
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* Oschina SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Oschina extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://www.oschina.net/action/oauth2/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://www.oschina.net/action/openapi/token';
/**
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=user_info';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://www.oschina.net/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Oschina API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* Oschina 调用公共参数 */
$params = array(
'access_token' => $this->Token['access_token'],
'dataType' => 'json'
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['token_type']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取 Oschina ACCESS_TOKEN出错未知错误");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->call('action/openapi/user');
if (isset($data['id']))
return $data['id'];
else
throw new \Exception('没有获取到 Oschina 用户ID');
}
}

View File

@ -0,0 +1,111 @@
<?php
/**
* QQ SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Qq extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://graph.qq.com/oauth2.0/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://graph.qq.com/oauth2.0/token';
/**
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=get_user_info';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://graph.qq.com/';
/**
* 组装接口调用参数 并调用接口
* @param string $api QQ API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* 腾讯QQ调用公共参数 */
$params = array(
'oauth_consumer_key' => $this->AppKey,
'access_token' => $this->Token['access_token'],
'openid' => $this->openid(),
'format' => 'json'
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
parse_str($result, $data);
if ($data['access_token'] && $data['expires_in']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取腾讯QQ ACCESS_TOKEN 出错:{$result}");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid($unionid=false)
{
if ($unionid){
return $this->unionid();
}
$data = $this->Token;
if ($data['access_token']) {
$data = $this->http($this->url('oauth2.0/me'), array('access_token' => $data['access_token']));
$data = json_decode(trim(substr($data, 9), " );\n"), true);
if (isset($data['openid']))
return $data['openid'];
else
throw new \Exception("获取用户openid出错{$data['error_description']}");
} else {
throw new \Exception('没有获取到openid');
}
}
/**
* 获取当前授权应用的unionid
* @return string
*/
public function unionid()
{
$data = $this->Token;
if ($data['access_token']) {
$data = $this->http($this->url('oauth2.0/me'), array('access_token' => $data['access_token'],'unionid'=>1));
$data = json_decode(trim(substr($data, 9), " );\n"), true);
if (isset($data['unionid']))
return $data['unionid'];
else
throw new \Exception("获取用户unionid出错{$data['error_description']}");
} else {
throw new \Exception('没有获取到unionid');
}
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* 新浪SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Sina extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://api.weibo.com/oauth2/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://api.weibo.com/oauth2/access_token';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://api.weibo.com/2/';
/**
* 组装接口调用参数 并调用接口
* @param string $api 微博API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* 新浪微博调用公共参数 */
$params = array(
'access_token' => $this->Token['access_token'],
);
$data = $this->http($this->url($api, '.json'), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['expires_in'] && $data['remind_in'] && $data['uid']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取新浪微博ACCESS_TOKEN出错{$data['error']}");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid()
{
$data = $this->Token;
if (isset($data['uid']))
return $data['uid'];
else
throw new \Exception('没有获取到新浪微博用户ID');
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* Taobao SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Taobao extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://oauth.taobao.com/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://oauth.taobao.com/token';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'http://gw.api.taobao.com/router/rest';
/**
* 组装接口调用参数 并调用接口
* @param string $api 微博API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* 淘宝网调用公共参数 */
$params = array(
'method' => $api,
'access_token' => $this->Token['access_token'],
'format' => 'json',
'v' => '2.0',
);
$paramsAll = $this->param($params, $param);
ksort($paramsAll);
$str = '';
foreach ($paramsAll as $key => $value) {
$str .= $key . $value;
}
$sign = strtoupper(md5($this->AppSecret . $str . $this->AppSecret));
$params_sign = array(
'sign' => $sign,
);
$data = $this->http($this->url(), array_merge($paramsAll, $params_sign), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['expires_in'] && $data['taobao_user_id']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else {
throw new \Exception("获取淘宝网ACCESS_TOKEN出错{$data['error']}");
}
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid($unionid = false)
{
if ($unionid) {
return $this->unionid();
}
$data = $this->Token;
if (isset($data['taobao_user_id'])) {
return $data['taobao_user_id'];
} else {
throw new \Exception('没有获取到淘宝网用户openid');
}
}
/**
* 获取当前授权应用的unionid
* @return string
*/
public function unionid()
{
$data = $this->Token;
if (isset($data['taobao_open_uid'])) {
return $data['taobao_open_uid'];
} else {
throw new \Exception('没有获取到淘宝网用户unionid');
}
}
}

View File

@ -0,0 +1,137 @@
<?php
/**
* 微信SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Weixin extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://open.weixin.qq.com/connect/qrconnect';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://api.weixin.qq.com/sns/oauth2/access_token';
/**
* 获取request_code的额外参数 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=snsapi_login';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://api.weixin.qq.com/';
/**
* 请求code
*/
public function getRequestCodeURL()
{
$this->config();
$params = array(
'appid' => $this->AppKey,
'redirect_uri' => $this->Callback,
'response_type' => $this->ResponseType,
);
//获取额外参数
if ($this->Authorize) {
parse_str($this->Authorize, $_param);
if (is_array($_param)) {
$params = array_merge($params, $_param);
} else {
throw new \Exception('AUTHORIZE配置不正确');
}
}
return $this->GetRequestCodeURL . '?' . http_build_query($params) . "#wechat_redirect";
}
/**
* 获取access_token
* @param string $code 上一步请求到的code
*/
public function getAccessToken($code, $extend = null)
{
$this->config();
$params = array(
'appid' => $this->AppKey,
'secret' => $this->AppSecret,
'grant_type' => $this->GrantType,
'code' => $code,
);
$data = $this->http($this->GetAccessTokenURL, $params, 'POST');
$this->Token = $this->parseToken($data, $extend);
return $this->Token;
}
/**
* 组装接口调用参数 并调用接口
* @param string $api 微信 API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* 微信调用公共参数 */
$params = array(
'access_token' => $this->Token['access_token'],
'openid' => $this->openid(),
'lang' => 'zh_CN',
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['expires_in']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取微信 ACCESS_TOKEN 出错:{$result}");
}
/**
* 获取当前授权应用的openid
*/
public function openid($unionid=false)
{
if ($unionid){
return $this->unionid();
}
$data = $this->Token;
if (isset($data['openid']))
return $data['openid'];
else
exit('没有获取到微信用户openid');
}
/**
* 获取当前授权应用的unionid
*/
public function unionid()
{
$data = $this->Token;
if (isset($data['unionid']))
return $data['unionid'];
else
exit('没有获取到微信用户unionid');
}
}

View File

@ -0,0 +1,104 @@
<?php
/**
* Xiaomi SDK
*/
namespace liliuwei\social\sdk;
use liliuwei\social\Oauth;
class Xiaomi extends Oauth
{
/**
* 获取requestCode的api接口
* @var string
*/
protected $GetRequestCodeURL = 'https://account.xiaomi.com/oauth2/authorize';
/**
* 获取access_token的api接口
* @var string
*/
protected $GetAccessTokenURL = 'https://account.xiaomi.com/oauth2/token';
/**
* 获取request_code的额外参数,可在配置中修改 URL查询字符串格式
* @var srting
*/
protected $Authorize = 'scope=1';
/**
* API根路径
* @var string
*/
protected $ApiBase = 'https://open.account.xiaomi.com/';
/**
* 组装接口调用参数 并调用接口
* @param string $api Xiaomi API
* @param string $param 调用API的额外参数
* @param string $method HTTP请求方法 默认为GET
* @return json
*/
public function call($api, $param = '', $method = 'GET', $multi = false)
{
/* Xiaomi 调用公共参数 */
$params = array(
'token' => $this->Token['access_token'],
'clientId' => $this->AppKey
);
$data = $this->http($this->url($api), $this->param($params, $param), $method);
return json_decode($data, true);
}
/**
* 解析access_token方法请求后的返回值
* @param string $result 获取access_token的方法的返回值
*/
protected function parseToken($result, $extend)
{
$data = json_decode($result, true);
if ($data['access_token'] && $data['token_type']) {
$this->Token = $data;
$data['openid'] = $this->openid();
return $data;
} else
throw new \Exception("获取 Xiaomi ACCESS_TOKEN出错未知错误");
}
/**
* 获取当前授权应用的openid
* @return string
*/
public function openid($unionid=false)
{
if ($unionid){
return $this->unionid();
}
$data = $this->call('user/profile');
if ($data['result']=='ok'){
$data = $data['data'];
if (isset($data['userId'])){
return $data['userId'];
}else{
return $this->unionid();
}
}else{
throw new \Exception('没有获取到 Xiaomi 用户openid');
}
}
/**
* 获取当前授权应用的unionid
* @return string
*/
public function unionid()
{
$data = $this->call('user/profile');
$data = $data['data'];
if (isset($data['unionId']))
return $data['unionId'];
else
throw new \Exception('没有获取到 Xiaomi 用户unionid');
}
}

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2022-01-08 13:48:32
// This file is automatically generated at:2022-01-12 15:56:54
declare (strict_types = 1);
return array (
0 => 'taoser\\addons\\Service',

View File

@ -0,0 +1,3 @@
/.idea
composer.lock
/vendor

View File

@ -0,0 +1,25 @@
{
"name": "topthink/think-installer",
"type": "composer-plugin",
"require": {
"composer-plugin-api": "^1.0||^2.0"
},
"require-dev": {
"composer/composer": "^1.0||^2.0"
},
"license": "Apache-2.0",
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"autoload": {
"psr-4": {
"think\\composer\\": "src"
}
},
"extra": {
"class": "think\\composer\\Plugin"
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace think\composer;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use React\Promise\PromiseInterface;
abstract class LibraryInstaller extends \Composer\Installer\LibraryInstaller
{
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
return $this->makePromise(parent::install($repo, $package));
}
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
return $this->makePromise(parent::update($repo, $initial, $target));
}
protected function makePromise($promise)
{
if ($promise instanceof PromiseInterface) {
return $promise;
}
return new Promise();
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace think\composer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class Plugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io)
{
$manager = $composer->getInstallationManager();
//框架核心
$manager->addInstaller(new ThinkFramework($io, $composer));
//单元测试
$manager->addInstaller(new ThinkTesting($io, $composer));
//扩展
$manager->addInstaller(new ThinkExtend($io, $composer));
}
public function deactivate(Composer $composer, IOInterface $io)
{
}
public function uninstall(Composer $composer, IOInterface $io)
{
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace think\composer;
class Promise
{
public function then($callable)
{
$callable();
}
}

View File

@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\composer;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
class ThinkExtend extends LibraryInstaller
{
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
return parent::install($repo, $package)
->then(function () use ($package) {
$this->copyExtraFiles($package);
});
}
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
return parent::update($repo, $initial, $target)
->then(function () use ($target) {
$this->copyExtraFiles($target);
});
}
protected function copyExtraFiles(PackageInterface $package)
{
if ($this->composer->getPackage()->getType() == 'project') {
$extra = $package->getExtra();
if (!empty($extra['think-config'])) {
$configDir = 'config';
$this->filesystem->ensureDirectoryExists($configDir);
//配置文件
foreach ((array) $extra['think-config'] as $name => $config) {
$target = $configDir . DIRECTORY_SEPARATOR . $name . '.php';
$source = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . $config;
if (is_file($target)) {
$this->io->write("<info>File {$target} exist!</info>");
continue;
}
if (!is_file($source)) {
$this->io->write("<info>File {$target} not exist!</info>");
continue;
}
copy($source, $target);
}
}
}
}
public function supports($packageType)
{
return 'think-extend' === $packageType;
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace think\composer;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use InvalidArgumentException;
class ThinkFramework extends LibraryInstaller
{
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
if ('topthink/framework' !== $package->getPrettyName()) {
throw new InvalidArgumentException('Unable to install this library!');
}
if ($this->composer->getPackage()->getType() !== 'project') {
return parent::getInstallPath($package);
}
if ($this->composer->getPackage()) {
$extra = $this->composer->getPackage()->getExtra();
if (!empty($extra['think-path'])) {
return $extra['think-path'];
}
}
return 'thinkphp';
}
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
return parent::install($repo, $package)
->then(function () use ($package) {
$this->removeTestDir($package);
});
}
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
return parent::update($repo, $initial, $target)
->then(function () use ($target) {
$this->removeTestDir($target);
});
}
protected function removeTestDir(PackageInterface $target)
{
if ($this->composer->getPackage()->getType() == 'project' && $target->getInstallationSource() != 'source') {
//remove tests dir
$this->filesystem->removeDirectory($this->getInstallPath($target) . DIRECTORY_SEPARATOR . 'tests');
}
}
/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return 'think-framework' === $packageType;
}
}

View File

@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\composer;
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use InvalidArgumentException;
class ThinkTesting extends LibraryInstaller
{
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
if ('topthink/think-testing' !== $package->getPrettyName()) {
throw new InvalidArgumentException('Unable to install this library!');
}
return parent::getInstallPath($package);
}
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
return parent::install($repo, $package)
->then(function () use ($package) {
$this->copyTestDir($package);
});
}
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
return parent::update($repo, $initial, $target)
->then(function () use ($target) {
$this->copyTestDir($target);
});
}
private function copyTestDir(PackageInterface $package)
{
$appDir = dirname($this->vendorDir);
$source = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . 'example';
if (!is_file($appDir . DIRECTORY_SEPARATOR . 'phpunit.xml')) {
$this->filesystem->copyThenRemove($source, $appDir);
} else {
$this->filesystem->removeDirectoryPhp($source);
}
}
/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return 'think-testing' === $packageType;
}
}

View File

@ -167,6 +167,7 @@
upload.render({
elem: '#zip-button'
,url: "{:url('article/uploads')}" //改成您自己的上传接口
,data: {type:'zip'}
,accept: 'file' //普通文件
,done: function(res){
if(res.status == 0){