Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
glinfo-api
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
林业通
glinfo-api
Commits
8b4323fc
提交
8b4323fc
authored
4月 02, 2023
作者:
林振杰
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加后台airkiss协议接口
上级
520e6002
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
397 行增加
和
0 行删除
+397
-0
AirKissEncoder.java
...n/java/tech/glinfo/enbao/common/utils/AirKissEncoder.java
+138
-0
MD5Util.java
...src/main/java/tech/glinfo/enbao/common/utils/MD5Util.java
+73
-0
ScController.java
...a/tech/glinfo/enbao/modules/smartconfig/ScController.java
+93
-0
SmartConfigController.java
...info/enbao/modules/smartconfig/SmartConfigController.java
+93
-0
没有找到文件。
appapi/src/main/java/tech/glinfo/enbao/common/utils/AirKissEncoder.java
0 → 100644
浏览文件 @
8b4323fc
package
tech
.
glinfo
.
enbao
.
common
.
utils
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Arrays
;
import
java.util.Random
;
@Slf4j
public
class
AirKissEncoder
{
private
int
[]
mEncodedData
=
new
int
[
2
<<
14
];
private
int
mLength
=
0
;
// Random char should be in range [0, 127).
private
char
mRandomChar
=
(
char
)
(
new
Random
().
nextInt
(
0x7F
));
public
AirKissEncoder
(
String
ssid
,
String
password
)
{
int
times
=
5
;
String
data
=
password
+
mRandomChar
+
ssid
;
try
{
data
=
new
String
(
data
.
getBytes
(),
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
log
.
debug
(
"###############data:{}"
,
data
);
while
(
times
--
>
0
)
{
leadingPart
();
magicCode
(
ssid
,
password
);
for
(
int
i
=
0
;
i
<
15
;
++
i
)
{
prefixCode
(
password
);
int
index
;
byte
content
[]
=
new
byte
[
4
];
for
(
index
=
0
;
index
<
data
.
getBytes
().
length
/
4
;
++
index
)
{
System
.
arraycopy
(
data
.
getBytes
(),
index
*
4
,
content
,
0
,
content
.
length
);
sequence
(
index
,
content
);
}
if
(
data
.
getBytes
().
length
%
4
!=
0
)
{
content
=
new
byte
[
data
.
getBytes
().
length
%
4
];
System
.
arraycopy
(
data
.
getBytes
(),
index
*
4
,
content
,
0
,
content
.
length
);
sequence
(
index
,
content
);
}
}
}
}
public
int
[]
getEncodedData
()
{
return
Arrays
.
copyOf
(
mEncodedData
,
mLength
);
}
public
int
getRandomChar
()
{
return
mRandomChar
;
}
private
void
appendEncodedData
(
int
length
)
{
mEncodedData
[
mLength
++]
=
length
;
}
private
int
CRC8
(
byte
data
[])
{
int
len
=
data
.
length
;
int
i
=
0
;
int
crc
=
0x00
;
while
(
len
--
>
0
)
{
int
extract
=
data
[
i
++];
for
(
byte
tempI
=
8
;
tempI
!=
0
;
tempI
--)
{
byte
sum
=
(
byte
)
((
crc
&
0xFF
)
^
(
extract
&
0xFF
));
sum
=
(
byte
)
((
sum
&
0xFF
)
&
0x01
);
crc
=
(
byte
)
((
crc
&
0xFF
)
>>>
1
);
if
(
sum
!=
0
)
{
crc
=
(
byte
)((
crc
&
0xFF
)
^
0x8C
);
}
extract
=
(
byte
)
((
extract
&
0xFF
)
>>>
1
);
}
}
return
(
crc
&
0xFF
);
}
private
int
CRC8
(
String
stringData
)
{
return
CRC8
(
stringData
.
getBytes
());
}
private
void
leadingPart
()
{
for
(
int
i
=
0
;
i
<
50
;
++
i
)
{
for
(
int
j
=
1
;
j
<=
4
;
++
j
)
appendEncodedData
(
j
);
}
}
private
void
magicCode
(
String
ssid
,
String
password
)
{
byte
[]
bSsid
=
ssid
.
getBytes
();
String
u8Ssid
=
null
;
try
{
u8Ssid
=
new
String
(
bSsid
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
int
length
=
u8Ssid
.
getBytes
().
length
+
password
.
length
()+
1
;
int
magicCode
[]
=
new
int
[
4
];
magicCode
[
0
]
=
0x00
|
(
length
>>>
4
&
0xF
);
if
(
magicCode
[
0
]
==
0
)
magicCode
[
0
]
=
0x08
;
magicCode
[
1
]
=
0x10
|
(
length
&
0xF
);
int
crc8
=
CRC8
(
u8Ssid
);
magicCode
[
2
]
=
0x20
|
(
crc8
>>>
4
&
0xF
);
magicCode
[
3
]
=
0x30
|
(
crc8
&
0xF
);
for
(
int
i
=
0
;
i
<
20
;
++
i
)
{
for
(
int
j
=
0
;
j
<
4
;
++
j
)
{
// System.out.println(magicCode[j]);
appendEncodedData
(
magicCode
[
j
]);
}
}
}
private
void
prefixCode
(
String
password
)
{
int
length
=
password
.
length
();
int
prefixCode
[]
=
new
int
[
4
];
prefixCode
[
0
]
=
0x40
|
(
length
>>>
4
&
0xF
);
prefixCode
[
1
]
=
0x50
|
(
length
&
0xF
);
int
crc8
=
CRC8
(
new
byte
[]
{(
byte
)
length
});
prefixCode
[
2
]
=
0x60
|
(
crc8
>>>
4
&
0xF
);
prefixCode
[
3
]
=
0x70
|
(
crc8
&
0xF
);
for
(
int
j
=
0
;
j
<
4
;
++
j
)
appendEncodedData
(
prefixCode
[
j
]);
}
private
void
sequence
(
int
index
,
byte
data
[])
{
byte
content
[]
=
new
byte
[
data
.
length
+
1
];
content
[
0
]
=
(
byte
)(
index
&
0xFF
);
System
.
arraycopy
(
data
,
0
,
content
,
1
,
data
.
length
);
int
crc8
=
CRC8
(
content
);
appendEncodedData
(
0x80
|
crc8
);
appendEncodedData
(
0x80
|
index
);
for
(
byte
aData
:
data
)
{
int
bData
=
(
aData
&
0xff
);
appendEncodedData
(
bData
|
0x100
);
}
}
}
appapi/src/main/java/tech/glinfo/enbao/common/utils/MD5Util.java
0 → 100644
浏览文件 @
8b4323fc
package
tech
.
glinfo
.
enbao
.
common
.
utils
;
import
com.gexin.rp.sdk.base.uitls.StackTraceUtil
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
public
class
MD5Util
{
private
static
ThreadLocal
<
MessageDigest
>
messageDigestHolder
=
new
ThreadLocal
();
static
final
char
[]
hexDigits
=
new
char
[]{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
public
MD5Util
()
{
}
public
static
String
getMD5Format
(
String
data
)
{
try
{
MessageDigest
message
=
(
MessageDigest
)
messageDigestHolder
.
get
();
if
(
message
==
null
)
{
message
=
MessageDigest
.
getInstance
(
"MD5"
);
messageDigestHolder
.
set
(
message
);
}
message
.
update
(
data
.
getBytes
());
byte
[]
b
=
message
.
digest
();
String
digestHexStr
=
""
;
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
digestHexStr
=
digestHexStr
+
byteHEX
(
b
[
i
]);
}
return
digestHexStr
;
}
catch
(
Exception
var5
)
{
throw
new
RuntimeException
(
"MD5格式化时发生异常[{}]: {}"
+
StackTraceUtil
.
getStackTrace
(
var5
),
var5
);
}
}
public
static
String
getMD5Format
(
byte
[]
data
)
{
try
{
MessageDigest
message
=
(
MessageDigest
)
messageDigestHolder
.
get
();
if
(
message
==
null
)
{
message
=
MessageDigest
.
getInstance
(
"MD5"
);
messageDigestHolder
.
set
(
message
);
}
message
.
update
(
data
);
byte
[]
b
=
message
.
digest
();
String
digestHexStr
=
""
;
for
(
int
i
=
0
;
i
<
16
;
++
i
)
{
digestHexStr
=
digestHexStr
+
byteHEX
(
b
[
i
]);
}
return
digestHexStr
;
}
catch
(
Exception
var5
)
{
return
null
;
}
}
private
static
String
byteHEX
(
byte
ib
)
{
char
[]
ob
=
new
char
[]{
hexDigits
[
ib
>>>
4
&
15
],
hexDigits
[
ib
&
15
]};
String
s
=
new
String
(
ob
);
return
s
;
}
static
{
try
{
MessageDigest
message
=
MessageDigest
.
getInstance
(
"MD5"
);
messageDigestHolder
.
set
(
message
);
}
catch
(
NoSuchAlgorithmException
var1
)
{
throw
new
RuntimeException
(
"初始化java.security.MessageDigest失败:"
+
StackTraceUtil
.
getStackTrace
(
var1
),
var1
);
}
}
}
appapi/src/main/java/tech/glinfo/enbao/modules/smartconfig/ScController.java
0 → 100644
浏览文件 @
8b4323fc
package
tech
.
glinfo
.
enbao
.
modules
.
smartconfig
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.*
;
import
tech.glinfo.enbao.common.utils.*
;
import
java.io.IOException
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/sc"
)
@Slf4j
public
class
ScController
{
@Value
(
"${wechat.appId}"
)
private
String
appId
;
@Value
(
"${wechat.appSecret}"
)
private
String
appSecret
;
private
static
final
String
REDIS_KEY
=
"app.smart.token."
;
private
Long
REDIS_KEY_IN
=
21600L
;
@Autowired
private
RedisUtils
redisUtils
;
@GetMapping
(
"/getToken"
)
public
R
getToken
(
@RequestParam
(
"code"
)
String
code
)
{
String
info
=
getWechatInfo
(
code
);
if
(
info
!=
null
)
{
JSONObject
json
=
JSONObject
.
parseObject
(
info
);
String
openid
=
json
.
getString
(
"openid"
);
String
md5
=
MD5Util
.
getMD5Format
(
openid
);
redisUtils
.
set
(
REDIS_KEY
+
md5
,
1
,
REDIS_KEY_IN
);
return
R
.
ok
().
put
(
"data"
,
md5
);
}
else
{
return
R
.
error
(
"获取token失败!"
);
}
}
private
String
getWechatInfo
(
String
code
)
{
String
url
=
"https://api.weixin.qq.com/sns/jscode2session?appid="
+
appId
+
"&secret="
+
appSecret
+
"&js_code="
+
code
+
"&grant_type=authorization_code"
;
//使用HttpClient发送请求
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
//发送Get请求
HttpGet
request
=
new
HttpGet
(
url
);
request
.
addHeader
(
"Content-Type"
,
"application/json"
);
//获得响应
String
result
=
null
;
// 转成string
try
{
CloseableHttpResponse
response
=
httpclient
.
execute
(
request
);
//拿到响应体
HttpEntity
httpEntity
=
response
.
getEntity
();
//使用工具转换
result
=
EntityUtils
.
toString
(
httpEntity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"result:{}"
,
result
);
return
result
;
}
@PostMapping
(
"start"
)
public
R
start
(
@RequestBody
Map
<
String
,
Object
>
params
)
{
String
ssid
=
(
String
)
params
.
get
(
"ssid"
);
String
password
=
(
String
)
params
.
get
(
"password"
);
String
token
=
(
String
)
params
.
get
(
"token"
);
if
(
StringUtils
.
isBlank
(
ssid
,
token
))
{
return
R
.
error
(
"缺少参数!"
);
}
if
(
redisUtils
.
hasKey
(
REDIS_KEY
+
token
))
{
AirKissEncoder
airKissEncoder
=
new
AirKissEncoder
(
ssid
,
password
);
return
R
.
ok
().
put
(
"data"
,
airKissEncoder
);
}
else
{
return
R
.
error
(
"token不存在或非法!"
);
}
}
}
appapi/src/main/java/tech/glinfo/enbao/modules/smartconfig/SmartConfigController.java
0 → 100644
浏览文件 @
8b4323fc
package
tech
.
glinfo
.
enbao
.
modules
.
smartconfig
;
import
com.alibaba.fastjson.JSONObject
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
tech.glinfo.enbao.common.utils.*
;
import
java.io.IOException
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/smartconfig"
)
@Slf4j
public
class
SmartConfigController
{
private
static
final
String
appId
=
"wx983fb930ecd84b4d"
;
private
static
final
String
appSecret
=
"2dce0e531552e9f80965f34309329942"
;
private
static
final
String
REDIS_KEY
=
"app.smart.token."
;
private
Long
REDIS_KEY_IN
=
21600L
;
@Autowired
private
RedisUtils
redisUtils
;
@GetMapping
(
"/getToken"
)
public
R
getToken
(
@RequestParam
(
"code"
)
String
code
)
{
String
info
=
getWechatInfo
(
code
);
if
(
info
!=
null
)
{
JSONObject
json
=
JSONObject
.
parseObject
(
info
);
String
openid
=
json
.
getString
(
"openid"
);
String
md5
=
MD5Util
.
getMD5Format
(
openid
);
redisUtils
.
set
(
REDIS_KEY
+
md5
,
1
,
REDIS_KEY_IN
);
return
R
.
ok
().
put
(
"data"
,
md5
);
}
else
{
return
R
.
error
(
"获取token失败!"
);
}
}
private
String
getWechatInfo
(
String
code
)
{
String
url
=
"https://api.weixin.qq.com/sns/jscode2session?appid="
+
appId
+
"&secret="
+
appSecret
+
"&js_code="
+
code
+
"&grant_type=authorization_code"
;
//使用HttpClient发送请求
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
//发送Get请求
HttpGet
request
=
new
HttpGet
(
url
);
request
.
addHeader
(
"Content-Type"
,
"application/json"
);
//获得响应
String
result
=
null
;
// 转成string
try
{
CloseableHttpResponse
response
=
httpclient
.
execute
(
request
);
//拿到响应体
HttpEntity
httpEntity
=
response
.
getEntity
();
//使用工具转换
result
=
EntityUtils
.
toString
(
httpEntity
,
"UTF-8"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"result:{}"
,
result
);
return
result
;
}
@PostMapping
(
"start"
)
public
R
start
(
@RequestBody
Map
<
String
,
Object
>
params
)
{
String
ssid
=
(
String
)
params
.
get
(
"ssid"
);
String
password
=
(
String
)
params
.
get
(
"password"
);
String
token
=
(
String
)
params
.
get
(
"token"
);
if
(
StringUtils
.
isBlank
(
ssid
,
token
))
{
return
R
.
error
(
"缺少参数!"
);
}
if
(
redisUtils
.
hasKey
(
REDIS_KEY
+
token
))
{
AirKissEncoder
airKissEncoder
=
new
AirKissEncoder
(
ssid
,
password
);
return
R
.
ok
().
put
(
"data"
,
airKissEncoder
);
}
else
{
return
R
.
error
(
"token不存在或非法!"
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论