Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzuaa
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzuaa
提交
2d39b177
提交
2d39b177
编写于
6月 23, 2020
作者:
laizhilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
授权成功后信息存到本地localStorage
上级
ad1b5612
变更
11
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
108 行增加
和
347 行删除
+108
-347
dingdingRedirect.html
app_web/public/assets/dingdingRedirect.html
+6
-1
qqRedirect.html
app_web/public/assets/qqRedirect.html
+6
-1
weixinRedirect.html
app_web/public/assets/weixinRedirect.html
+6
-1
dingdingLoginRedirect.vue
app_web/src/components/login/dingdingLoginRedirect.vue
+9
-40
qqLoginRedirect.vue
app_web/src/components/login/qqLoginRedirect.vue
+9
-41
weixinLoginRedirect.vue
app_web/src/components/login/weixinLoginRedirect.vue
+9
-42
DevBootSecurityConfig.java
...rc/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
+0
-3
UserDingtalkRegisterService.java
...e/uaa/extensions/service/UserDingtalkRegisterService.java
+4
-2
UserDingtalkRegisterResource.java
...lab/api/rest/extensions/UserDingtalkRegisterResource.java
+16
-57
UserQQRegisterResource.java
...n/ibizlab/api/rest/extensions/UserQQRegisterResource.java
+20
-61
UserWechatRegisterResource.java
...izlab/api/rest/extensions/UserWechatRegisterResource.java
+23
-98
未找到文件。
app_web/public/assets/dingdingRedirect.html
浏览文件 @
2d39b177
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
success
:
function
(
data
)
{
success
:
function
(
data
)
{
// console.log(JSON.stringify(data));
// console.log(JSON.stringify(data));
if
(
data
)
{
if
(
data
)
{
if
(
data
.
openid
)
{
localStorage
.
setItem
(
'openid'
,
data
.
openid
);
}
if
(
data
.
nickname
)
{
localStorage
.
setItem
(
'nickname'
,
data
.
nickname
);
}
if
(
data
.
token
)
{
if
(
data
.
token
)
{
localStorage
.
setItem
(
'token'
,
data
.
token
);
localStorage
.
setItem
(
'token'
,
data
.
token
);
}
}
...
@@ -52,7 +58,6 @@
...
@@ -52,7 +58,6 @@
}
}
});
});
}
else
{
}
else
{
alert
(
"钉钉授权登录失败!"
);
// 回到登录页
// 回到登录页
window
.
location
.
href
=
"../"
;
window
.
location
.
href
=
"../"
;
}
}
...
...
app_web/public/assets/qqRedirect.html
浏览文件 @
2d39b177
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
success
:
function
(
data
)
{
success
:
function
(
data
)
{
// console.log(JSON.stringify(data));
// console.log(JSON.stringify(data));
if
(
data
)
{
if
(
data
)
{
if
(
data
.
openid
)
{
localStorage
.
setItem
(
'openid'
,
data
.
openid
);
}
if
(
data
.
nickname
)
{
localStorage
.
setItem
(
'nickname'
,
data
.
nickname
);
}
if
(
data
.
token
)
{
if
(
data
.
token
)
{
localStorage
.
setItem
(
'token'
,
data
.
token
);
localStorage
.
setItem
(
'token'
,
data
.
token
);
}
}
...
@@ -52,7 +58,6 @@
...
@@ -52,7 +58,6 @@
}
}
});
});
}
else
{
}
else
{
alert
(
"微信授权登录失败!"
);
// 回到登录页
// 回到登录页
window
.
location
.
href
=
"../"
;
window
.
location
.
href
=
"../"
;
}
}
...
...
app_web/public/assets/weixinRedirect.html
浏览文件 @
2d39b177
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
success
:
function
(
data
)
{
success
:
function
(
data
)
{
// console.log(JSON.stringify(data));
// console.log(JSON.stringify(data));
if
(
data
)
{
if
(
data
)
{
if
(
data
.
openid
)
{
localStorage
.
setItem
(
'openid'
,
data
.
openid
);
}
if
(
data
.
nickname
)
{
localStorage
.
setItem
(
'nickname'
,
data
.
nickname
);
}
if
(
data
.
token
)
{
if
(
data
.
token
)
{
localStorage
.
setItem
(
'token'
,
data
.
token
);
localStorage
.
setItem
(
'token'
,
data
.
token
);
}
}
...
@@ -52,7 +58,6 @@
...
@@ -52,7 +58,6 @@
}
}
});
});
}
else
{
}
else
{
alert
(
"微信授权登录失败!"
);
// 回到登录页
// 回到登录页
window
.
location
.
href
=
"../"
;
window
.
location
.
href
=
"../"
;
}
}
...
...
app_web/src/components/login/dingdingLoginRedirect.vue
浏览文件 @
2d39b177
...
@@ -156,8 +156,15 @@
...
@@ -156,8 +156,15 @@
this
.
goLogin
();
this
.
goLogin
();
}
}
else
{
else
{
// 根据code获取钉钉用户信息
// 从local中获取该用户的openid和nickname
this
.
getDingtalkUserInfoByCode
(
this
.
code
);
// console.log("钉钉信息openid:" + localStorage.getItem("openid"));
// console.log("钉钉信息nickname:" + localStorage.getItem("nickname"));
if
(
localStorage
.
getItem
(
"openid"
)
!=
""
)
{
this
.
openid
=
localStorage
.
getItem
(
"openid"
);
}
if
(
localStorage
.
getItem
(
"nickname"
))
{
this
.
nickname
=
localStorage
.
getItem
(
"nickname"
);
}
}
}
}
}
...
@@ -194,44 +201,6 @@
...
@@ -194,44 +201,6 @@
return
null
;
//返回参数值
return
null
;
//返回参数值
}
}
/**
* 根据code获取钉钉用户信息
*/
private
getDingtalkUserInfoByCode
(
code
:
any
)
{
var
param
:
any
=
{};
param
.
code
=
code
;
const
post
:
Promise
<
any
>
=
this
.
$http
.
post
(
'/uaa/getDingtalkUserInfoByCode'
,
param
,
true
);
post
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
const
data
=
response
.
data
;
if
(
data
&&
data
.
openid
)
{
this
.
openid
=
data
.
openid
;
this
.
nickname
=
data
.
nickname
;
}
else
{
this
.
$Message
.
error
({
content
:
"获取钉钉用户信息失败,请重新授权"
,
duration
:
3
,
closable
:
true
});
}
}
}).
catch
((
e
:
any
)
=>
{
const
data
=
e
.
data
;
if
(
data
&&
data
.
message
)
{
this
.
$Message
.
error
({
content
:
data
.
message
,
duration
:
3
,
closable
:
true
});
}
else
{
this
.
$Message
.
error
({
content
:
"获取钉钉用户信息失败,请重新授权"
,
duration
:
3
,
closable
:
true
});
}
});
}
/**
/**
...
...
app_web/src/components/login/qqLoginRedirect.vue
浏览文件 @
2d39b177
...
@@ -161,8 +161,15 @@
...
@@ -161,8 +161,15 @@
this
.
goLogin
();
this
.
goLogin
();
}
}
else
{
else
{
// 根据code获取QQ用户信息
// 从local中获取该用户的openid和nickname
this
.
getQQUserInfoByCode
(
this
.
code
);
// console.log("QQ信息openid:" + localStorage.getItem("openid"));
// console.log("QQ信息nickname:" + localStorage.getItem("nickname"));
if
(
localStorage
.
getItem
(
"openid"
)
!=
""
)
{
this
.
openid
=
localStorage
.
getItem
(
"openid"
);
}
if
(
localStorage
.
getItem
(
"nickname"
))
{
this
.
nickname
=
localStorage
.
getItem
(
"nickname"
);
}
}
}
}
}
...
@@ -198,45 +205,6 @@
...
@@ -198,45 +205,6 @@
return
null
;
//返回参数值
return
null
;
//返回参数值
}
}
/**
* 根据code获取微信用户信息
*/
private
getQQUserInfoByCode
(
code
:
any
)
{
var
param
:
any
=
{};
param
.
code
=
code
;
const
post
:
Promise
<
any
>
=
this
.
$http
.
post
(
'/uaa/getQQUserInfoByCode'
,
param
,
true
);
post
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
const
data
=
response
.
data
;
if
(
data
&&
data
.
openid
)
{
this
.
openid
=
data
.
openid
;
this
.
nickname
=
data
.
nickname
;
}
else
{
this
.
$Message
.
error
({
content
:
"获取QQ用户信息失败,请重新授权"
,
duration
:
3
,
closable
:
true
});
}
}
}).
catch
((
e
:
any
)
=>
{
const
data
=
e
.
data
;
if
(
data
&&
data
.
message
)
{
this
.
$Message
.
error
({
content
:
data
.
message
,
duration
:
3
,
closable
:
true
});
}
else
{
this
.
$Message
.
error
({
content
:
"获取QQ用户信息失败,请重新授权"
,
duration
:
3
,
closable
:
true
});
}
});
}
/**
/**
* 注册处理
* 注册处理
...
...
app_web/src/components/login/weixinLoginRedirect.vue
浏览文件 @
2d39b177
...
@@ -158,8 +158,15 @@
...
@@ -158,8 +158,15 @@
this
.
goLogin
();
this
.
goLogin
();
}
}
else
{
else
{
// 根据code获取微信用户信息
// 从local中获取该用户的openid和nickname
this
.
getWechatUserInfoByCode
(
this
.
code
);
// console.log("微信信息openid:" + localStorage.getItem("openid"));
// console.log("微信信息nickname:" + localStorage.getItem("nickname"));
if
(
localStorage
.
getItem
(
"openid"
)
!=
""
)
{
this
.
openid
=
localStorage
.
getItem
(
"openid"
);
}
if
(
localStorage
.
getItem
(
"nickname"
))
{
this
.
nickname
=
localStorage
.
getItem
(
"nickname"
);
}
}
}
}
}
...
@@ -195,46 +202,6 @@
...
@@ -195,46 +202,6 @@
return
null
;
//返回参数值
return
null
;
//返回参数值
}
}
/**
* 根据code获取微信用户信息
*/
private
getWechatUserInfoByCode
(
code
:
any
)
{
var
param
:
any
=
{};
param
.
code
=
code
;
const
post
:
Promise
<
any
>
=
this
.
$http
.
post
(
'/uaa/getWechatUserInfoByCode'
,
param
,
true
);
post
.
then
((
response
:
any
)
=>
{
if
(
response
&&
response
.
status
===
200
)
{
const
data
=
response
.
data
;
if
(
data
&&
data
.
openid
)
{
this
.
openid
=
data
.
openid
;
this
.
nickname
=
data
.
nickname
;
}
else
{
this
.
$Message
.
error
({
content
:
"获取微信用户信息失败,请重新授权"
,
duration
:
3
,
closable
:
true
});
}
}
}).
catch
((
e
:
any
)
=>
{
const
data
=
e
.
data
;
if
(
data
&&
data
.
message
)
{
this
.
$Message
.
error
({
content
:
data
.
message
,
duration
:
3
,
closable
:
true
});
}
else
{
this
.
$Message
.
error
({
content
:
"获取微信用户信息失败,请重新授权"
,
duration
:
3
,
closable
:
true
});
}
});
}
/**
/**
* 注册处理
* 注册处理
...
...
ibzuaa-boot/src/main/java/cn/ibizlab/config/DevBootSecurityConfig.java
浏览文件 @
2d39b177
...
@@ -110,17 +110,14 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -110,17 +110,14 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.
antMatchers
(
"/uaa/responseTokenToWeiXin"
).
permitAll
()
.
antMatchers
(
"/uaa/responseTokenToWeiXin"
).
permitAll
()
.
antMatchers
(
"/uaa/getWechatAppId"
).
permitAll
()
.
antMatchers
(
"/uaa/getWechatAppId"
).
permitAll
()
.
antMatchers
(
"/uaa/queryWechatUserByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/queryWechatUserByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/getWechatUserInfoByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/bindWechatToRegister"
).
permitAll
()
.
antMatchers
(
"/uaa/bindWechatToRegister"
).
permitAll
()
.
antMatchers
(
"/uaa/getDingtalkAppId"
).
permitAll
()
.
antMatchers
(
"/uaa/getDingtalkAppId"
).
permitAll
()
.
antMatchers
(
"/uaa/queryDingtalkUserByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/queryDingtalkUserByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/getDingtalkUserInfoByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/bindDingtalkToRegister"
).
permitAll
()
.
antMatchers
(
"/uaa/bindDingtalkToRegister"
).
permitAll
()
.
antMatchers
(
"/uaa/getQQAppId"
).
permitAll
()
.
antMatchers
(
"/uaa/getQQAppId"
).
permitAll
()
.
antMatchers
(
"/uaa/queryQQUserByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/queryQQUserByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/getQQUserInfoByCode"
).
permitAll
()
.
antMatchers
(
"/uaa/bindQQtoRegister"
).
permitAll
()
.
antMatchers
(
"/uaa/bindQQtoRegister"
).
permitAll
()
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
// 防止iframe 造成跨域
// 防止iframe 造成跨域
...
...
ibzuaa-core/src/main/java/cn/ibizlab/core/uaa/extensions/service/UserDingtalkRegisterService.java
浏览文件 @
2d39b177
...
@@ -104,11 +104,13 @@ public class UserDingtalkRegisterService {
...
@@ -104,11 +104,13 @@ public class UserDingtalkRegisterService {
}
else
{
}
else
{
//按指定编码转换结果实体为String类型
//按指定编码转换结果实体为String类型
entityJson
=
JSONObject
.
parseObject
(
EntityUtils
.
toString
(
entity
,
"UTF-8"
));
entityJson
=
JSONObject
.
parseObject
(
EntityUtils
.
toString
(
entity
,
"UTF-8"
));
// 是否获取钉钉用户信息成功
// 是否获取钉钉用户信息成功
if
(
entityJson
.
containsKey
(
"user_info"
))
{
if
(
entityJson
.
getInteger
(
"errcode"
)==
0
)
{
// 这里只有简单的信息:nick、openid、unionid
returnObj
=
entityJson
.
getJSONObject
(
"user_info"
);
returnObj
=
entityJson
.
getJSONObject
(
"user_info"
);
}
else
{
}
else
{
throw
new
BadRequestAlertException
(
"获取钉钉授权用户个人信息失败"
,
"UserDingtalkRegisterService"
,
""
);
throw
new
BadRequestAlertException
(
entityJson
.
getString
(
"errmsg"
)
,
"UserDingtalkRegisterService"
,
""
);
}
}
}
}
...
...
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/UserDingtalkRegisterResource.java
浏览文件 @
2d39b177
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
import
cn.ibizlab.core.uaa.extensions.service.UserDingtalkRegisterService
;
import
cn.ibizlab.core.uaa.extensions.service.UserDingtalkRegisterService
;
import
cn.ibizlab.core.uaa.service.ISysPSSystemService
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
cn.ibizlab.util.service.IBZUSERService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -19,9 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping;
...
@@ -19,9 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.UUID
;
...
@@ -31,23 +30,17 @@ public class UserDingtalkRegisterResource {
...
@@ -31,23 +30,17 @@ public class UserDingtalkRegisterResource {
@Autowired
@Autowired
private
UserDingtalkRegisterService
userDingtalkRegisterService
;
private
UserDingtalkRegisterService
userDingtalkRegisterService
;
@Autowired
@Autowired
private
I
SysPSSystemService
iSysPSSystem
Service
;
private
I
BZUSERService
ibzuser
Service
;
@Autowired
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
private
AuthTokenUtil
jwtTokenUtil
;
@Autowired
@Autowired
@Qualifier
(
"UAAUserService"
)
@Qualifier
(
"UAAUserService"
)
private
AuthenticationUserService
userDetailsService
;
private
AuthenticationUserService
userDetailsService
;
@Value
(
"${ibiz.auth.dingtalk.appid:}"
)
// 个人应用开发过程中的唯一性标识AppId,最好在配置文件进行初始化
@Value
(
"${ibiz.auth.dingtalk.appid:
dingoatysxi5rpbluqgzpk
}"
)
// 个人应用开发过程中的唯一性标识AppId,最好在配置文件进行初始化
private
String
DingtalkAppid
;
private
String
DingtalkAppid
;
@Value
(
"${ibiz.auth.dingtalk.appsecret:}"
)
// 个人应用AppSecret,最好在配置文件进行初始化
@Value
(
"${ibiz.auth.dingtalk.appsecret:
z2SuCSciWQJ6VSFX8jvHzTF0G_rEmHpjHrZct0rGnWrLyl8cZiRny72244EvF4SO
}"
)
// 个人应用AppSecret,最好在配置文件进行初始化
private
String
DingtalkAppSecret
;
private
String
DingtalkAppSecret
;
@Value
(
"${ibiz.auth.dingtalk.openid:}"
)
private
String
DingtalkOpenid
;
@Value
(
"${ibiz.auth.dingtalk.nickname:}"
)
private
String
DingtalkNickname
;
private
JSONObject
DingtalkUserInfo
;
// 钉钉用户信息
/**
/**
* 获取钉钉开放平台创建的网站应用appid
* 获取钉钉开放平台创建的网站应用appid
...
@@ -86,20 +79,15 @@ public class UserDingtalkRegisterResource {
...
@@ -86,20 +79,15 @@ public class UserDingtalkRegisterResource {
if
(!
StringUtils
.
isEmpty
(
returnObj
)
&&
!
returnObj
.
containsKey
(
"errcode"
))
{
if
(!
StringUtils
.
isEmpty
(
returnObj
)
&&
!
returnObj
.
containsKey
(
"errcode"
))
{
openid
=
returnObj
.
getString
(
"openid"
);
openid
=
returnObj
.
getString
(
"openid"
);
nickname
=
returnObj
.
getString
(
"nick"
);
nickname
=
returnObj
.
getString
(
"nick"
);
// 将用户信息存到缓存,供当前人后续请求使用
object
.
put
(
"openid"
,
openid
);
DingtalkOpenid
=
openid
;
object
.
put
(
"nickname"
,
nickname
);
DingtalkNickname
=
nickname
;
DingtalkUserInfo
=
returnObj
;
}
}
//根据openid查用户
//根据openid查用户
String
sql
=
"select * from ibzuser where avatar=#{et.avatar}"
;
List
<
IBZUSER
>
ibzusers
=
ibzuserService
.
list
(
Wrappers
.<
IBZUSER
>
query
().
eq
(
"avatar"
,
openid
));
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
sqlParam
.
put
(
"avatar"
,
openid
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
// 该钉钉用户注册过账号,登录系统
// 该钉钉用户注册过账号,登录系统
if
(
select
.
size
()
>
0
)
{
if
(
ibzusers
.
size
()
>
0
)
{
IBZUSER
ibzuser
=
select
.
get
(
0
).
toJavaObject
(
IBZUSER
.
class
);
IBZUSER
ibzuser
=
ibzusers
.
get
(
0
);
object
.
put
(
"ibzuser"
,
ibzuser
);
object
.
put
(
"ibzuser"
,
ibzuser
);
// 生成登录token信息
// 生成登录token信息
...
@@ -117,29 +105,6 @@ public class UserDingtalkRegisterResource {
...
@@ -117,29 +105,6 @@ public class UserDingtalkRegisterResource {
return
ResponseEntity
.
ok
().
body
(
object
);
return
ResponseEntity
.
ok
().
body
(
object
);
}
}
/**
* 根据code获取钉钉用户信息
*
* @param param
* @return
*/
@PostMapping
(
value
=
"/uaa/getDingtalkUserInfoByCode"
)
public
ResponseEntity
<
JSONObject
>
getDingtalkUserInfoByCode
(
@RequestBody
JSONObject
param
)
{
JSONObject
object
=
new
JSONObject
();
// 空校验
String
code
=
param
.
getString
(
"code"
);
if
(
StringUtils
.
isEmpty
(
code
))
throw
new
BadRequestAlertException
(
"code为空"
,
"UserDingtalkRegisterResource"
,
""
);
// 通过code获取微信用户信息
String
openid
=
DingtalkOpenid
;
String
nickname
=
DingtalkNickname
;
object
.
put
(
"openid"
,
openid
);
object
.
put
(
"nickname"
,
nickname
);
return
ResponseEntity
.
ok
().
body
(
object
);
}
/**
/**
* 绑定钉钉并注册
* 绑定钉钉并注册
...
@@ -154,25 +119,19 @@ public class UserDingtalkRegisterResource {
...
@@ -154,25 +119,19 @@ public class UserDingtalkRegisterResource {
String
loginname
=
param
.
getString
(
"loginname"
);
String
loginname
=
param
.
getString
(
"loginname"
);
String
password
=
param
.
getString
(
"password"
);
String
password
=
param
.
getString
(
"password"
);
String
openid
=
param
.
getString
(
"openid"
);
String
openid
=
param
.
getString
(
"openid"
);
if
(
StringUtils
.
isEmpty
(
openid
))
{
openid
=
DingtalkOpenid
;
}
String
nickname
=
param
.
getString
(
"nickname"
);
String
nickname
=
param
.
getString
(
"nickname"
);
if
(
StringUtils
.
isEmpty
(
nickname
))
{
nickname
=
DingtalkNickname
;
}
if
(
StringUtils
.
isEmpty
(
loginname
))
if
(
StringUtils
.
isEmpty
(
loginname
))
throw
new
BadRequestAlertException
(
"用户名为空"
,
"UserDingtalkRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"用户名为空"
,
"UserDingtalkRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
password
))
if
(
StringUtils
.
isEmpty
(
password
))
throw
new
BadRequestAlertException
(
"密码为空"
,
"UserDingtalkRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"密码为空"
,
"UserDingtalkRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
openid
))
throw
new
BadRequestAlertException
(
"钉钉信息openid为空"
,
"UserDingtalkRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
nickname
))
throw
new
BadRequestAlertException
(
"钉钉信息nickname为空"
,
"UserDingtalkRegisterResource"
,
""
);
// 检查用户名是否已被注册
// 检查用户名是否已被注册
String
sql
=
"select loginname from ibzuser where loginname=#{et.loginname}"
;
List
<
IBZUSER
>
ibzusers
=
ibzuserService
.
list
(
Wrappers
.<
IBZUSER
>
query
().
eq
(
"loginname"
,
loginname
));
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
if
(
ibzusers
.
size
()
>
0
)
sqlParam
.
put
(
"loginname"
,
loginname
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
if
(
select
.
size
()
>
0
)
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"UserDingtalkRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"UserDingtalkRegisterResource"
,
""
);
IBZUSER
ibzuser
=
new
IBZUSER
();
IBZUSER
ibzuser
=
new
IBZUSER
();
...
...
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/UserQQRegisterResource.java
浏览文件 @
2d39b177
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
import
cn.ibizlab.core.uaa.extensions.service.UserQQRegisterService
;
import
cn.ibizlab.core.uaa.extensions.service.UserQQRegisterService
;
import
cn.ibizlab.core.uaa.service.ISysPSSystemService
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
cn.ibizlab.util.service.IBZUSERService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -19,9 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping;
...
@@ -19,9 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.UUID
;
...
@@ -31,25 +30,19 @@ public class UserQQRegisterResource {
...
@@ -31,25 +30,19 @@ public class UserQQRegisterResource {
@Autowired
@Autowired
private
UserQQRegisterService
userQQRegisterService
;
private
UserQQRegisterService
userQQRegisterService
;
@Autowired
@Autowired
private
I
SysPSSystemService
iSysPSSystem
Service
;
private
I
BZUSERService
ibzuser
Service
;
@Autowired
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
private
AuthTokenUtil
jwtTokenUtil
;
@Autowired
@Autowired
@Qualifier
(
"UAAUserService"
)
@Qualifier
(
"UAAUserService"
)
private
AuthenticationUserService
userDetailsService
;
private
AuthenticationUserService
userDetailsService
;
@Value
(
"${ibiz.auth.qq.appid:}"
)
// qq互联appid
@Value
(
"${ibiz.auth.qq.appid:
101882103
}"
)
// qq互联appid
private
String
qqAppId
;
private
String
qqAppId
;
@Value
(
"${ibiz.auth.qq.appkey:}"
)
// qq互联appkey
@Value
(
"${ibiz.auth.qq.appkey:
64ebdde56c1aeeacf0c312b49ddc42e1
}"
)
// qq互联appkey
private
String
qqAppKey
;
private
String
qqAppKey
;
@Value
(
"${ibiz.auth.qq.redirect_uri:}"
)
// qq互联应用回调地址
@Value
(
"${ibiz.auth.qq.redirect_uri:
http://passport.ibizlab.cn/assets/qqRedirect.html
}"
)
// qq互联应用回调地址
private
String
qqRedirectUri
;
private
String
qqRedirectUri
;
@Value
(
"${ibiz.auth.qq.openid:}"
)
private
String
qqOpenid
;
@Value
(
"${ibiz.auth.qq.nickname:}"
)
private
String
qqNickname
;
private
JSONObject
qqUserInfo
;
// qq用户信息
/**
/**
...
@@ -87,20 +80,15 @@ public class UserQQRegisterResource {
...
@@ -87,20 +80,15 @@ public class UserQQRegisterResource {
if
(!
StringUtils
.
isEmpty
(
returnObj
)
&&
!
returnObj
.
containsKey
(
"errcode"
))
{
if
(!
StringUtils
.
isEmpty
(
returnObj
)
&&
!
returnObj
.
containsKey
(
"errcode"
))
{
openid
=
returnObj
.
getString
(
"openid"
);
openid
=
returnObj
.
getString
(
"openid"
);
nickname
=
returnObj
.
getString
(
"nickname"
);
nickname
=
returnObj
.
getString
(
"nickname"
);
// 将用户信息存到缓存,供当前人后续请求使用
object
.
put
(
"openid"
,
openid
);
qqOpenid
=
openid
;
object
.
put
(
"nickname"
,
nickname
);
qqNickname
=
nickname
;
qqUserInfo
=
returnObj
;
}
}
//根据openid查用户
//根据openid查用户
String
sql
=
"select * from ibzuser where avatar=#{et.avatar}"
;
List
<
IBZUSER
>
ibzusers
=
ibzuserService
.
list
(
Wrappers
.<
IBZUSER
>
query
().
eq
(
"avatar"
,
openid
));
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
sqlParam
.
put
(
"avatar"
,
openid
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
// 该QQ用户注册过账号,登录系统
// 该QQ用户注册过账号,登录系统
if
(
select
.
size
()
>
0
)
{
if
(
ibzusers
.
size
()
>
0
)
{
IBZUSER
ibzuser
=
select
.
get
(
0
).
toJavaObject
(
IBZUSER
.
class
);
IBZUSER
ibzuser
=
ibzusers
.
get
(
0
);
object
.
put
(
"ibzuser"
,
ibzuser
);
object
.
put
(
"ibzuser"
,
ibzuser
);
// 生成登录token信息
// 生成登录token信息
...
@@ -119,30 +107,6 @@ public class UserQQRegisterResource {
...
@@ -119,30 +107,6 @@ public class UserQQRegisterResource {
}
}
/**
* 根据code获取QQ用户信息
*
* @param param
* @return
*/
@PostMapping
(
value
=
"/uaa/getQQUserInfoByCode"
)
public
ResponseEntity
<
JSONObject
>
getQQUserInfoByCode
(
@RequestBody
JSONObject
param
)
{
JSONObject
object
=
new
JSONObject
();
// 空校验
String
code
=
param
.
getString
(
"code"
);
if
(
StringUtils
.
isEmpty
(
code
))
throw
new
BadRequestAlertException
(
"code为空"
,
"UserQQRegisterResource"
,
""
);
// 通过code获取微信用户信息
String
openid
=
qqOpenid
;
String
nickname
=
qqNickname
;
object
.
put
(
"openid"
,
openid
);
object
.
put
(
"nickname"
,
nickname
);
return
ResponseEntity
.
ok
().
body
(
object
);
}
/**
/**
* 绑定QQ并注册
* 绑定QQ并注册
*
*
...
@@ -158,13 +122,7 @@ public class UserQQRegisterResource {
...
@@ -158,13 +122,7 @@ public class UserQQRegisterResource {
String
code
=
param
.
getString
(
"code"
);
String
code
=
param
.
getString
(
"code"
);
String
state
=
param
.
getString
(
"state"
);
String
state
=
param
.
getString
(
"state"
);
String
openid
=
param
.
getString
(
"openid"
);
String
openid
=
param
.
getString
(
"openid"
);
if
(
StringUtils
.
isEmpty
(
openid
))
{
openid
=
qqOpenid
;
}
String
nickname
=
param
.
getString
(
"nickname"
);
String
nickname
=
param
.
getString
(
"nickname"
);
if
(
StringUtils
.
isEmpty
(
nickname
))
{
nickname
=
qqNickname
;
}
if
(
StringUtils
.
isEmpty
(
loginname
))
if
(
StringUtils
.
isEmpty
(
loginname
))
throw
new
BadRequestAlertException
(
"用户名为空"
,
"UserQQRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"用户名为空"
,
"UserQQRegisterResource"
,
""
);
...
@@ -174,19 +132,20 @@ public class UserQQRegisterResource {
...
@@ -174,19 +132,20 @@ public class UserQQRegisterResource {
throw
new
BadRequestAlertException
(
"QQ授权code为空"
,
"UserQQRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"QQ授权code为空"
,
"UserQQRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
state
))
if
(
StringUtils
.
isEmpty
(
state
))
throw
new
BadRequestAlertException
(
"QQ授权state为空"
,
"UserQQRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"QQ授权state为空"
,
"UserQQRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
openid
))
throw
new
BadRequestAlertException
(
"QQ信息openid为空"
,
"UserWechatRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
nickname
))
throw
new
BadRequestAlertException
(
"QQ信息nickname为空"
,
"UserWechatRegisterResource"
,
""
);
// 检查用户名是否已被注册
// 检查用户名是否已被注册
String
sql
=
"select loginname from ibzuser where loginname=#{et.loginname}"
;
List
<
IBZUSER
>
ibzusers
=
ibzuserService
.
list
(
Wrappers
.<
IBZUSER
>
query
().
eq
(
"loginname"
,
loginname
));
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
if
(
ibzusers
.
size
()
>
0
)
sqlParam
.
put
(
"loginname"
,
loginname
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
if
(
select
.
size
()
>
0
)
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"UserQQRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"UserQQRegisterResource"
,
""
);
IBZUSER
ibzuser
=
new
IBZUSER
();
IBZUSER
ibzuser
=
new
IBZUSER
();
if
(
StringUtils
.
isEmpty
(
openid
))
{
if
(
StringUtils
.
isEmpty
(
openid
))
{
// 通过code获取微信用户信息
// 通过code获取微信用户信息
JSONObject
returnObj
=
userQQRegisterService
.
requestQQUserByCode
(
code
,
qqRedirectUri
,
qqAppId
,
qqAppKey
);
JSONObject
returnObj
=
userQQRegisterService
.
requestQQUserByCode
(
code
,
qqRedirectUri
,
qqAppId
,
qqAppKey
);
if
(!
StringUtils
.
isEmpty
(
returnObj
))
{
if
(!
StringUtils
.
isEmpty
(
returnObj
))
{
if
(
returnObj
.
containsKey
(
"openid"
))
{
if
(
returnObj
.
containsKey
(
"openid"
))
{
// 微信注册
// 微信注册
...
@@ -198,10 +157,10 @@ public class UserQQRegisterResource {
...
@@ -198,10 +157,10 @@ public class UserQQRegisterResource {
ibzuser
.
setNickname
(
returnObj
.
getString
(
"nickname"
));
ibzuser
.
setNickname
(
returnObj
.
getString
(
"nickname"
));
ibzuser
.
setAvatar
(
returnObj
.
getString
(
"openid"
));
ibzuser
.
setAvatar
(
returnObj
.
getString
(
"openid"
));
userQQRegisterService
.
toRegister
(
ibzuser
);
userQQRegisterService
.
toRegister
(
ibzuser
);
}
else
{
}
else
{
throw
new
BadRequestAlertException
(
"获取QQ授权用户相关信息失败!"
,
"UserQQRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"获取QQ授权用户相关信息失败!"
,
"UserQQRegisterResource"
,
""
);
}
}
}
else
{
}
else
{
throw
new
BadRequestAlertException
(
"获取QQ授权用户相关信息失败!"
,
"UserQQRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"获取QQ授权用户相关信息失败!"
,
"UserQQRegisterResource"
,
""
);
}
}
}
else
{
}
else
{
...
...
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/UserWechatRegisterResource.java
浏览文件 @
2d39b177
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
import
cn.ibizlab.core.uaa.extensions.service.UserWechatRegisterService
;
import
cn.ibizlab.core.uaa.extensions.service.UserWechatRegisterService
;
import
cn.ibizlab.core.uaa.service.ISysPSSystemService
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.domain.IBZUSER
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
cn.ibizlab.util.service.AuthenticationUserService
;
import
cn.ibizlab.util.service.IBZUSERService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -19,11 +20,8 @@ import org.springframework.web.bind.annotation.PostMapping;
...
@@ -19,11 +20,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
import
java.io.IOException
;
import
java.util.UUID
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.*
;
@RestController
@RestController
...
@@ -32,56 +30,17 @@ public class UserWechatRegisterResource {
...
@@ -32,56 +30,17 @@ public class UserWechatRegisterResource {
@Autowired
@Autowired
private
UserWechatRegisterService
userWechatRegisterService
;
private
UserWechatRegisterService
userWechatRegisterService
;
@Autowired
@Autowired
private
I
SysPSSystemService
iSysPSSystem
Service
;
private
I
BZUSERService
ibzuser
Service
;
@Autowired
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
private
AuthTokenUtil
jwtTokenUtil
;
@Autowired
@Autowired
@Qualifier
(
"UAAUserService"
)
@Qualifier
(
"UAAUserService"
)
private
AuthenticationUserService
userDetailsService
;
private
AuthenticationUserService
userDetailsService
;
@Value
(
"${ibiz.auth.wechat.appID:}"
)
// 微信开放平台appid,最好在配置文件进行初始化
@Value
(
"${ibiz.auth.wechat.appID:
wx4a7473ac9c617f76
}"
)
// 微信开放平台appid,最好在配置文件进行初始化
private
String
WechatAppid
;
private
String
WechatAppid
;
@Value
(
"${ibiz.auth.wechat.appsecret:}"
)
// 微信开放平台appsecret,最好在配置文件进行初始化
@Value
(
"${ibiz.auth.wechat.appsecret:
c2b308b9245dffa316b049840fd81a79
}"
)
// 微信开放平台appsecret,最好在配置文件进行初始化
private
String
WechatAppsecret
;
private
String
WechatAppsecret
;
@Value
(
"${ibiz.auth.wechat.openid:}"
)
private
String
WechatOpenid
;
@Value
(
"${ibiz.auth.wechat.nickname:}"
)
private
String
WechatNickname
;
private
JSONObject
WechatUserInfo
;
// 微信用户信息
public
static
final
String
TOKEN
=
""
;
// 这里的token要和微信公众测试号网页填写的token一致
/**
* 响应微信公众测试号发送的Token验证
* ps:仅在测试号需要token验证,正式号不需要
* @param signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数
* @param timestamp 时间戳
* @param nonce 随机数
* @param echostr 随机字符串
* @param response 响应对象
* @throws IOException
* @throws NoSuchAlgorithmException
*/
@GetMapping
(
value
=
"/uaa/responseTokenToWeiXin"
)
public
void
responseTokenToWeiXin
(
String
signature
,
String
timestamp
,
String
nonce
,
String
echostr
,
HttpServletResponse
response
)
throws
IOException
,
NoSuchAlgorithmException
{
// 将token、timestamp、nonce三个参数进行字典序排序
System
.
out
.
println
(
"signature:"
+
signature
);
System
.
out
.
println
(
"timestamp:"
+
timestamp
);
System
.
out
.
println
(
"nonce:"
+
nonce
);
System
.
out
.
println
(
"echostr:"
+
echostr
);
System
.
out
.
println
(
"TOKEN:"
+
TOKEN
);
String
[]
params
=
new
String
[]{
TOKEN
,
timestamp
,
nonce
};
Arrays
.
sort
(
params
);
// 将三个参数字符串拼接成一个字符串进行sha1加密
String
clearText
=
params
[
0
]
+
params
[
1
]
+
params
[
2
];
String
algorithm
=
"SHA-1"
;
String
sign
=
new
String
(
org
.
apache
.
commons
.
codec
.
binary
.
Hex
.
encodeHex
(
MessageDigest
.
getInstance
(
algorithm
).
digest
((
clearText
).
getBytes
()),
true
));
// 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
if
(
signature
.
equals
(
sign
))
{
// 确认此次GET请求来自微信服务器,原样返回echostr参数内容,则接入生效,成为开发者成功
response
.
getWriter
().
print
(
echostr
);
}
}
/**
/**
...
@@ -120,20 +79,15 @@ public class UserWechatRegisterResource {
...
@@ -120,20 +79,15 @@ public class UserWechatRegisterResource {
if
(!
StringUtils
.
isEmpty
(
returnObj
)
&&
!
returnObj
.
containsKey
(
"errcode"
))
{
if
(!
StringUtils
.
isEmpty
(
returnObj
)
&&
!
returnObj
.
containsKey
(
"errcode"
))
{
openid
=
returnObj
.
getString
(
"openid"
);
openid
=
returnObj
.
getString
(
"openid"
);
nickname
=
returnObj
.
getString
(
"nickname"
);
nickname
=
returnObj
.
getString
(
"nickname"
);
// 将用户信息存到缓存,供当前人后续请求使用
object
.
put
(
"openid"
,
openid
);
WechatOpenid
=
openid
;
object
.
put
(
"nickname"
,
nickname
);
WechatNickname
=
nickname
;
WechatUserInfo
=
returnObj
;
}
}
//根据openid查用户
//根据openid查用户
String
sql
=
"select * from ibzuser where avatar=#{et.avatar}"
;
List
<
IBZUSER
>
ibzusers
=
ibzuserService
.
list
(
Wrappers
.<
IBZUSER
>
query
().
eq
(
"avatar"
,
openid
));
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
sqlParam
.
put
(
"avatar"
,
openid
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
// 该微信用户注册过账号,登录系统
// 该微信用户注册过账号,登录系统
if
(
select
.
size
()
>
0
)
{
if
(
ibzusers
.
size
()
>
0
)
{
IBZUSER
ibzuser
=
select
.
get
(
0
).
toJavaObject
(
IBZUSER
.
class
);
IBZUSER
ibzuser
=
ibzusers
.
get
(
0
);
object
.
put
(
"ibzuser"
,
ibzuser
);
object
.
put
(
"ibzuser"
,
ibzuser
);
// 生成登录token信息
// 生成登录token信息
...
@@ -152,30 +106,6 @@ public class UserWechatRegisterResource {
...
@@ -152,30 +106,6 @@ public class UserWechatRegisterResource {
}
}
/**
* 根据code获取微信用户信息
*
* @param param
* @return
*/
@PostMapping
(
value
=
"/uaa/getWechatUserInfoByCode"
)
public
ResponseEntity
<
JSONObject
>
getWechatUserInfoByCode
(
@RequestBody
JSONObject
param
)
{
JSONObject
object
=
new
JSONObject
();
// 空校验
String
code
=
param
.
getString
(
"code"
);
if
(
StringUtils
.
isEmpty
(
code
))
throw
new
BadRequestAlertException
(
"code为空"
,
"UserRegisterResource"
,
""
);
// 通过code获取微信用户信息
String
openid
=
WechatOpenid
;
String
nickname
=
WechatNickname
;
object
.
put
(
"openid"
,
openid
);
object
.
put
(
"nickname"
,
nickname
);
return
ResponseEntity
.
ok
().
body
(
object
);
}
/**
/**
* 绑定微信并注册
* 绑定微信并注册
*
*
...
@@ -188,38 +118,33 @@ public class UserWechatRegisterResource {
...
@@ -188,38 +118,33 @@ public class UserWechatRegisterResource {
// 空校验
// 空校验
String
loginname
=
param
.
getString
(
"loginname"
);
String
loginname
=
param
.
getString
(
"loginname"
);
String
password
=
param
.
getString
(
"password"
);
String
password
=
param
.
getString
(
"password"
);
String
code
=
param
.
getString
(
"code"
);
String
state
=
param
.
getString
(
"state"
);
String
openid
=
param
.
getString
(
"openid"
);
String
openid
=
param
.
getString
(
"openid"
);
if
(
StringUtils
.
isEmpty
(
openid
))
{
openid
=
WechatOpenid
;
}
String
nickname
=
param
.
getString
(
"nickname"
);
String
nickname
=
param
.
getString
(
"nickname"
);
if
(
StringUtils
.
isEmpty
(
nickname
))
{
String
code
=
param
.
getString
(
"code"
);
nickname
=
WechatNickname
;
String
state
=
param
.
getString
(
"state"
);
}
if
(
StringUtils
.
isEmpty
(
loginname
))
if
(
StringUtils
.
isEmpty
(
loginname
))
throw
new
BadRequestAlertException
(
"用户名为空"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"用户名为空"
,
"UserWechatRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
password
))
if
(
StringUtils
.
isEmpty
(
password
))
throw
new
BadRequestAlertException
(
"密码为空"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"密码为空"
,
"UserWechatRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
openid
))
throw
new
BadRequestAlertException
(
"微信信息openid为空"
,
"UserWechatRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
nickname
))
throw
new
BadRequestAlertException
(
"微信信息nickname为空"
,
"UserWechatRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
code
))
if
(
StringUtils
.
isEmpty
(
code
))
throw
new
BadRequestAlertException
(
"微信授权code为空"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"微信授权code为空"
,
"UserWechatRegisterResource"
,
""
);
if
(
StringUtils
.
isEmpty
(
state
))
if
(
StringUtils
.
isEmpty
(
state
))
throw
new
BadRequestAlertException
(
"微信授权state为空"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"微信授权state为空"
,
"UserWechatRegisterResource"
,
""
);
// 检查用户名是否已被注册
// 检查用户名是否已被注册
String
sql
=
"select loginname from ibzuser where loginname=#{et.loginname}"
;
List
<
IBZUSER
>
ibzusers
=
ibzuserService
.
list
(
Wrappers
.<
IBZUSER
>
query
().
eq
(
"loginname"
,
loginname
));
Map
<
String
,
Object
>
sqlParam
=
new
HashMap
<>();
if
(
ibzusers
.
size
()
>
0
)
sqlParam
.
put
(
"loginname"
,
loginname
);
List
<
JSONObject
>
select
=
iSysPSSystemService
.
select
(
sql
,
sqlParam
);
if
(
select
.
size
()
>
0
)
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"该用户名已被注册"
,
"UserWechatRegisterResource"
,
""
);
IBZUSER
ibzuser
=
new
IBZUSER
();
IBZUSER
ibzuser
=
new
IBZUSER
();
if
(
StringUtils
.
isEmpty
(
openid
))
{
if
(
StringUtils
.
isEmpty
(
openid
))
{
// 通过code获取微信用户信息
// 通过code获取微信用户信息
JSONObject
returnObj
=
userWechatRegisterService
.
requestWechatUserByCode
(
code
,
state
,
WechatAppid
,
WechatAppsecret
);
JSONObject
returnObj
=
userWechatRegisterService
.
requestWechatUserByCode
(
code
,
null
,
WechatAppid
,
WechatAppsecret
);
if
(!
StringUtils
.
isEmpty
(
returnObj
))
{
if
(!
StringUtils
.
isEmpty
(
returnObj
))
{
if
(
returnObj
.
containsKey
(
"openid"
))
{
if
(
returnObj
.
containsKey
(
"openid"
))
{
// 微信注册
// 微信注册
...
@@ -231,10 +156,10 @@ public class UserWechatRegisterResource {
...
@@ -231,10 +156,10 @@ public class UserWechatRegisterResource {
ibzuser
.
setNickname
(
returnObj
.
getString
(
"nickname"
));
ibzuser
.
setNickname
(
returnObj
.
getString
(
"nickname"
));
ibzuser
.
setAvatar
(
returnObj
.
getString
(
"openid"
));
ibzuser
.
setAvatar
(
returnObj
.
getString
(
"openid"
));
userWechatRegisterService
.
toRegister
(
ibzuser
);
userWechatRegisterService
.
toRegister
(
ibzuser
);
}
else
{
}
else
{
throw
new
BadRequestAlertException
(
"获取微信授权用户相关信息失败!"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"获取微信授权用户相关信息失败!"
,
"UserWechatRegisterResource"
,
""
);
}
}
}
else
{
}
else
{
throw
new
BadRequestAlertException
(
"获取微信授权用户相关信息失败!"
,
"UserWechatRegisterResource"
,
""
);
throw
new
BadRequestAlertException
(
"获取微信授权用户相关信息失败!"
,
"UserWechatRegisterResource"
,
""
);
}
}
}
else
{
}
else
{
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录