Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
数据应用
ThinkLibrary
提交
ac60be73
T
ThinkLibrary
项目概览
数据应用
/
ThinkLibrary
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
T
ThinkLibrary
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ac60be73
编写于
7月 18, 2020
作者:
李光春
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 优化代码
- 优化Api控制器的加密相关参数 - 请求门面增加获取客户端类型和获取手机设备类型
上级
a74522a7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
92 addition
and
11 deletion
+92
-11
CHANGELOG.md
CHANGELOG.md
+5
-0
src/ApiController.php
src/ApiController.php
+50
-8
src/common.php
src/common.php
+1
-1
src/facade/Requests.php
src/facade/Requests.php
+2
-0
src/helper/Requests.php
src/helper/Requests.php
+32
-0
src/service/Ip/IpIpService.php
src/service/Ip/IpIpService.php
+1
-1
src/service/QqWryService.php
src/service/QqWryService.php
+1
-1
未找到文件。
CHANGELOG.md
浏览文件 @
ac60be73
## v6.0.88 / 2020-07-18
-
优化代码
-
优化Api控制器的加密相关参数
-
请求门面增加获取客户端类型和获取手机设备类型
## v6.0.87 / 2020-07-17
-
优化代码
...
...
src/ApiController.php
浏览文件 @
ac60be73
...
...
@@ -49,6 +49,13 @@ class ApiController extends stdClass
*/
private
$aes_decrypt_data
;
/**
* 加密相关的东西
* @var string
*/
private
$aes_md5
=
''
;
private
$aes_md5_iv
=
''
;
/**
* ApiController constructor.
* @param App $app
...
...
@@ -97,19 +104,41 @@ class ApiController extends stdClass
]));
}
/**
* key
* @param string $name 参数名
* @return $this
*/
public
function
setAesMd5
(
$name
=
'sniff_h5'
)
{
$value
=
$this
->
app
->
config
->
get
(
"dtapp.md5.
{
$name
}
"
);
$this
->
aes_md5
=
$value
;
return
$this
;
}
/**
* iv
* @return $this
*/
private
function
setAesMd5Iv
()
{
$value
=
$this
->
app
->
config
->
get
(
"dtapp.md5.bcw"
);
$this
->
aes_md5_iv
=
$value
;
return
$this
;
}
/**
* 返回成功的操作
* @param mixed $data 返回数据
* @param mixed $msg 消息内容
* @param integer $code 返回代码
* @param string $name 参数名
*/
public
function
aesSuccess
(
$data
=
[],
$msg
=
'success'
,
$code
=
0
,
$name
=
'sniff_h5'
)
public
function
aesSuccess
(
$data
=
[],
$msg
=
'success'
,
$code
=
0
)
{
$timestamp
=
time
();
throw
new
HttpResponseException
(
json
([
'code'
=>
$code
,
'msg'
=>
$msg
,
'timestamp'
=>
$timestamp
,
'data'
=>
[
'aes'
=>
$this
->
encrypt
(
$data
,
$
name
,
$
timestamp
)
'aes'
=>
$this
->
encrypt
(
$data
,
$timestamp
)
],
]));
}
...
...
@@ -202,14 +231,21 @@ class ApiController extends stdClass
/**
* 加密
* @param $data
* @param string $name
* @param int $timestamp
* @return bool|string
*/
private
function
encrypt
(
$data
,
string
$name
,
int
$timestamp
)
private
function
encrypt
(
$data
,
int
$timestamp
)
{
if
(
!
empty
(
is_array
(
$data
)))
$data
=
json_encode
(
$data
);
return
urlencode
(
base64_encode
(
openssl_encrypt
(
$data
,
'AES-128-CBC'
,
config
(
"dtapp.md5.
{
$name
}
"
),
1
,
config
(
"dtapp.md5.bcw"
)
.
$timestamp
)));
if
(
empty
(
$this
->
aes_md5
))
{
$this
->
setAesMd5
();
}
if
(
empty
(
$this
->
aes_md5_iv
))
{
$this
->
setAesMd5Iv
();
}
if
(
!
empty
(
is_array
(
$data
)))
{
$data
=
json_encode
(
$data
);
}
return
urlencode
(
base64_encode
(
openssl_encrypt
(
$data
,
'AES-128-CBC'
,
$this
->
aes_md5
,
1
,
$this
->
aes_md5_iv
.
$timestamp
)));
}
/**
...
...
@@ -221,6 +257,12 @@ class ApiController extends stdClass
*/
private
function
decrypt
(
string
$data
,
string
$name
,
int
$timestamp
)
{
return
openssl_decrypt
(
base64_decode
(
urldecode
(
$data
)),
"AES-128-CBC"
,
config
(
"dtapp.md5.
{
$name
}
"
),
true
,
config
(
"dtapp.md5.bcw"
)
.
$timestamp
);
if
(
empty
(
$this
->
aes_md5
))
{
$this
->
setAesMd5
();
}
if
(
empty
(
$this
->
aes_md5_iv
))
{
$this
->
setAesMd5Iv
();
}
return
openssl_decrypt
(
base64_decode
(
urldecode
(
$data
)),
"AES-128-CBC"
,
$this
->
aes_md5
,
true
,
$this
->
aes_md5_iv
.
$timestamp
);
}
}
src/common.php
浏览文件 @
ac60be73
...
...
@@ -28,7 +28,7 @@ use think\db\exception\ModelNotFoundException;
/**
* 定义当前版本
*/
const
VERSION
=
'6.0.8
7
'
;
const
VERSION
=
'6.0.8
8
'
;
if
(
!
function_exists
(
'get_ip_info'
))
{
/**
...
...
src/facade/Requests.php
浏览文件 @
ac60be73
...
...
@@ -44,6 +44,8 @@ use think\Facade;
* @method static bool isAliPay() 判断是否支付宝内置浏览器访问
* @method static bool isQQ() 判断是否QQ内置浏览器访问
* @method static bool isQQBrowser() 判断是否QQ浏览器访问
* @method static string getDeviceType() 获取客户端类型
* @method static string getMobileType() 获取手机设备类型
* @method static string getWebsiteAddress() 获取域名地址
*/
class
Requests
extends
Facade
...
...
src/helper/Requests.php
浏览文件 @
ac60be73
...
...
@@ -210,6 +210,38 @@ class Requests
return
false
;
}
/**
* 获取客户端类型
* @return string
*/
public
function
getDeviceType
()
{
$agent
=
strtolower
(
request
()
->
server
(
'HTTP_USER_AGENT'
));
if
(
strpos
(
$agent
,
'iphone'
)
||
strpos
(
$agent
,
'ipad'
)
||
strpos
(
$agent
,
'android'
))
{
$type
=
'mobile'
;
}
else
{
$type
=
'computer'
;
}
return
$type
;
}
/**
* 获取手机设备类型
* @return string
*/
public
function
getMobileType
()
{
$agent
=
strtolower
(
request
()
->
server
(
'HTTP_USER_AGENT'
));
$type
=
'other'
;
if
(
strpos
(
$agent
,
'iphone'
)
||
strpos
(
$agent
,
'ipad'
))
{
$type
=
'mobile'
;
}
if
(
strpos
(
$agent
,
'android'
))
{
$type
=
'android'
;
}
return
$type
;
}
/**
* 获取域名地址
* @return string
...
...
src/service/Ip/IpIpService.php
浏览文件 @
ac60be73
...
...
@@ -46,7 +46,7 @@ class IpIpService extends Service
*/
public
function
__construct
(
App
$app
)
{
$this
->
ipPath
=
config
(
'dtapp.ip_path'
,
''
);
$this
->
ipPath
=
$this
->
app
->
config
->
get
(
'dtapp.ip_path'
,
''
);
if
(
empty
(
$this
->
ipPath
))
{
throw
new
DtaException
(
'请检查配置文件是否配置了IP数据库文件存放位置'
);
}
...
...
src/service/QqWryService.php
浏览文件 @
ac60be73
...
...
@@ -74,7 +74,7 @@ class QqWryService extends Service
*/
public
function
__construct
(
App
$app
)
{
$this
->
ipPath
=
config
(
'dtapp.ip_path'
,
''
);
$this
->
ipPath
=
$this
->
app
->
config
->
get
(
'dtapp.ip_path'
,
''
);
if
(
empty
(
$this
->
ipPath
))
{
throw
new
DtaException
(
'请检查配置文件是否配置了IP数据库文件存放位置'
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录