记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
d9853f10
Commit
d9853f10
authored
Sep 28, 2021
by
jiangxiulong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
防疫答题-服务号获取用户信息公共接口2个
parent
19d98eb9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
195 additions
and
7 deletions
+195
-7
WechatTokenInfoVo.java
...com/liquidnet/service/sweet/dto/vo/WechatTokenInfoVo.java
+48
-0
WechatUserInfoVo.java
.../com/liquidnet/service/sweet/dto/vo/WechatUserInfoVo.java
+76
-0
pom.xml
liquidnet-bus-service/liquidnet-service-sweet/pom.xml
+6
-0
SweetWechatLoginController.java
.../service/sweet/controller/SweetWechatLoginController.java
+22
-0
SweetWechatLoginServiceImpl.java
...rvice/sweet/service/impl/SweetWechatLoginServiceImpl.java
+30
-5
SweetWechatService.java
...uidnet/service/sweet/service/impl/SweetWechatService.java
+13
-2
No files found.
liquidnet-bus-api/liquidnet-service-sweet-api/src/main/java/com/liquidnet/service/sweet/dto/vo/WechatTokenInfoVo.java
0 → 100644
View file @
d9853f10
package
com
.
liquidnet
.
service
.
sweet
.
dto
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken
;
import
java.io.Serializable
;
/**
* <p>
* WxOAuth2AccessToken vo
* </p>
*
* @author jiangxiulong
* @since 2021-09-28
*/
@Data
@ApiModel
public
class
WechatTokenInfoVo
implements
Serializable
,
Cloneable
{
private
static
final
long
serialVersionUID
=
3404938811111878417L
;
@ApiModelProperty
(
value
=
"openId"
)
private
String
openId
;
@ApiModelProperty
(
value
=
"unionId"
)
private
String
unionId
;
private
static
final
WechatTokenInfoVo
obj
=
new
WechatTokenInfoVo
();
public
static
WechatTokenInfoVo
getNew
()
{
try
{
return
(
WechatTokenInfoVo
)
obj
.
clone
();
}
catch
(
CloneNotSupportedException
e
)
{
return
new
WechatTokenInfoVo
();
}
}
public
WechatTokenInfoVo
copy
(
WxOAuth2AccessToken
source
)
{
if
(
null
==
source
)
return
this
;
this
.
setOpenId
(
source
.
getOpenId
());
this
.
setUnionId
(
source
.
getUnionId
());
return
this
;
}
}
liquidnet-bus-api/liquidnet-service-sweet-api/src/main/java/com/liquidnet/service/sweet/dto/vo/WechatUserInfoVo.java
0 → 100644
View file @
d9853f10
package
com
.
liquidnet
.
service
.
sweet
.
dto
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
me.chanjar.weixin.common.bean.WxOAuth2UserInfo
;
import
java.io.Serializable
;
/**
* <p>
* WxOAuth2UserInfo vo
* </p>
*
* @author jiangxiulong
* @since 2021-09-28
*/
@Data
@ApiModel
public
class
WechatUserInfoVo
implements
Serializable
,
Cloneable
{
private
static
final
long
serialVersionUID
=
5067978046376025813L
;
@ApiModelProperty
(
value
=
"普通用户的标识,对当前开发者帐号唯一"
)
private
String
openid
;
@ApiModelProperty
(
value
=
"普通用户昵称"
)
private
String
nickname
;
@ApiModelProperty
(
value
=
"普通用户性别,1为男性,2为女性"
)
private
Integer
sex
;
@ApiModelProperty
(
value
=
"普通用户个人资料填写的城市"
)
private
String
city
;
@ApiModelProperty
(
value
=
"普通用户个人资料填写的省份"
)
private
String
province
;
@ApiModelProperty
(
value
=
"国家,如中国为CN"
)
private
String
country
;
@ApiModelProperty
(
value
=
"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像) 用户没有头像时该项为空"
)
private
String
headImgUrl
;
@ApiModelProperty
(
value
=
"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的"
)
private
String
unionId
;
@ApiModelProperty
(
value
=
"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"
)
private
String
[]
privileges
;
private
static
final
WechatUserInfoVo
obj
=
new
WechatUserInfoVo
();
public
static
WechatUserInfoVo
getNew
()
{
try
{
return
(
WechatUserInfoVo
)
obj
.
clone
();
}
catch
(
CloneNotSupportedException
e
)
{
return
new
WechatUserInfoVo
();
}
}
public
WechatUserInfoVo
copy
(
WxOAuth2UserInfo
source
)
{
if
(
null
==
source
)
return
this
;
this
.
setOpenid
(
source
.
getOpenid
());
this
.
setNickname
(
source
.
getNickname
());
this
.
setSex
(
source
.
getSex
());
this
.
setCity
(
source
.
getCity
());
this
.
setProvince
(
source
.
getProvince
());
this
.
setCountry
(
source
.
getCountry
());
this
.
setHeadImgUrl
(
source
.
getHeadImgUrl
());
this
.
setUnionId
(
source
.
getUnionId
());
this
.
setPrivileges
(
source
.
getPrivileges
());
return
this
;
}
}
liquidnet-bus-service/liquidnet-service-sweet/pom.xml
View file @
d9853f10
...
...
@@ -69,6 +69,12 @@
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
</dependency>
<dependency>
<groupId>
com.liquidnet
</groupId>
<artifactId>
liquidnet-service-sweet-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<build>
...
...
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/controller/SweetWechatLoginController.java
View file @
d9853f10
package
com
.
liquidnet
.
service
.
sweet
.
controller
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.sweet.dto.vo.WechatTokenInfoVo
;
import
com.liquidnet.service.sweet.dto.vo.WechatUserInfoVo
;
import
com.liquidnet.service.sweet.service.impl.SweetWechatLoginServiceImpl
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
...
...
@@ -59,4 +61,24 @@ public class SweetWechatLoginController {
return
sweetLoginService
.
wxOauth2AccessToken
(
code
,
type
);
}
@ApiOperation
(
value
=
"微信公众号登录 获取openId、unionId"
,
notes
=
"本接口在scope参数为snsapi_base时不再提供unionID字段,只需将scope参数修改为snsapi_userinfo即可重新获得用户unionID"
)
@GetMapping
(
value
=
{
"mpAccessTokenInfo"
})
@ApiImplicitParams
({
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"String"
,
name
=
"code"
,
value
=
"微信code"
,
required
=
true
),
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"Integer"
,
name
=
"type"
,
value
=
"1正在 2摩登"
,
required
=
true
)
})
public
ResponseDto
<
WechatTokenInfoVo
>
mpWxOauth2AccessTokenInfo
(
@RequestParam
String
code
,
@RequestParam
Integer
type
)
{
return
sweetLoginService
.
mpWxOauth2AccessTokenInfo
(
code
,
type
);
}
@ApiOperation
(
value
=
"微信公众号登录 获取用户基本信息"
,
notes
=
"本接口在用户未关注公众号时,将不返回用户unionID信息,已关注的用户,开发者可使用“获取用户基本信息接口”获取unionID,未关注用户,开发者可使用“微信授权登录接口”并将scope参数设置为snsapi_userinfo,获取用户unionID"
)
@GetMapping
(
value
=
{
"mpUserInfo"
})
@ApiImplicitParams
({
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"String"
,
name
=
"code"
,
value
=
"微信code"
,
required
=
true
),
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"Integer"
,
name
=
"type"
,
value
=
"1正在 2摩登"
,
required
=
true
)
})
public
ResponseDto
<
WechatUserInfoVo
>
mpUserInfo
(
@RequestParam
String
code
,
@RequestParam
Integer
type
)
{
return
sweetLoginService
.
mpUserInfo
(
code
,
type
);
}
}
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetWechatLoginServiceImpl.java
View file @
d9853f10
...
...
@@ -9,8 +9,11 @@ import com.liquidnet.commons.lang.util.JsonUtils;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.SqlMapping
;
import
com.liquidnet.service.base.constant.MQConst
;
import
com.liquidnet.service.sweet.dto.vo.WechatTokenInfoVo
;
import
com.liquidnet.service.sweet.dto.vo.WechatUserInfoVo
;
import
com.liquidnet.service.sweet.utils.QueueUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
me.chanjar.weixin.common.bean.WxOAuth2UserInfo
;
import
me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -20,7 +23,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Objects
;
...
...
@@ -89,7 +91,7 @@ public class SweetWechatLoginServiceImpl {
return
ResponseDto
.
success
(
userInfo
);
}
catch
(
Exception
e
)
{
log
.
error
(
"WechatUserInfoError"
,
e
);
log
.
error
(
"WechatUserInfoError
Exception:{}
"
,
e
);
return
ResponseDto
.
failure
();
}
}
...
...
@@ -101,7 +103,7 @@ public class SweetWechatLoginServiceImpl {
params
.
add
(
"mobile"
,
mobile
);
HttpUtil
.
post
(
adamUrl
.
concat
(
"/adam/rsc/reg/mobile"
),
params
);
}
catch
(
Exception
e
)
{
log
.
error
(
"registerByMobile失败"
,
e
);
log
.
error
(
"registerByMobile失败
Exception:{}
"
,
e
);
}
}
...
...
@@ -110,7 +112,7 @@ public class SweetWechatLoginServiceImpl {
WxMaJscode2SessionResult
wxMaJscode2SessionResult
=
sweetWechatService
.
sessionInfo
(
jsCode
,
type
);
return
ResponseDto
.
success
(
wxMaJscode2SessionResult
.
getOpenid
());
}
catch
(
Exception
e
)
{
log
.
error
(
"wxaCode2SessionError"
,
e
);
log
.
error
(
"wxaCode2SessionError
Exception:{}
"
,
e
);
return
ResponseDto
.
failure
();
}
}
...
...
@@ -120,8 +122,31 @@ public class SweetWechatLoginServiceImpl {
WxOAuth2AccessToken
wxOAuth2AccessToken
=
sweetWechatService
.
wxOauth2AccessToken
(
code
,
type
);
return
ResponseDto
.
success
(
wxOAuth2AccessToken
.
getOpenId
());
}
catch
(
Exception
e
)
{
log
.
error
(
"wxaCode2SessionError"
,
e
);
log
.
error
(
"wxaCode2SessionError
Exception:{}
"
,
e
);
return
ResponseDto
.
failure
();
}
}
public
ResponseDto
<
WechatTokenInfoVo
>
mpWxOauth2AccessTokenInfo
(
String
code
,
Integer
type
)
{
try
{
WxOAuth2AccessToken
wxOAuth2AccessToken
=
sweetWechatService
.
wxOauth2AccessToken
(
code
,
type
);
WechatTokenInfoVo
userInfoVo
=
WechatTokenInfoVo
.
getNew
().
copy
(
wxOAuth2AccessToken
);
return
ResponseDto
.
success
(
userInfoVo
);
}
catch
(
Exception
e
)
{
log
.
error
(
"wxaCode2SessionError Exception:{}"
,
e
);
return
ResponseDto
.
failure
();
}
}
public
ResponseDto
<
WechatUserInfoVo
>
mpUserInfo
(
String
code
,
Integer
type
)
{
try
{
WxOAuth2UserInfo
wxOAuth2UserInfo
=
sweetWechatService
.
mpUserInfo
(
code
,
type
);
WechatUserInfoVo
tokenInfoVo
=
WechatUserInfoVo
.
getNew
().
copy
(
wxOAuth2UserInfo
);
return
ResponseDto
.
success
(
tokenInfoVo
);
}
catch
(
Exception
e
)
{
log
.
error
(
"wxaCode2SessionError Exception:{}"
,
e
);
return
ResponseDto
.
failure
();
}
}
}
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetWechatService.java
View file @
d9853f10
...
...
@@ -7,6 +7,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import
com.liquidnet.service.sweet.config.WechatMaConfigure
;
import
com.liquidnet.service.sweet.config.WechatMpConfigure
;
import
lombok.extern.slf4j.Slf4j
;
import
me.chanjar.weixin.common.bean.WxOAuth2UserInfo
;
import
me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken
;
import
me.chanjar.weixin.common.error.WxErrorException
;
import
me.chanjar.weixin.mp.api.WxMpService
;
...
...
@@ -22,6 +23,9 @@ public class SweetWechatService {
@Autowired
WechatMpConfigure
wechatMpConfigure
;
/**
* 小程序--------------
*/
public
WxMaJscode2SessionResult
sessionInfo
(
String
code
,
Integer
anum
)
throws
WxErrorException
{
WxMaService
wxMaService
=
wechatMaConfigure
.
getWxMaService
(
anum
);
log
.
info
(
"isAccessTokenExpired:[{}] "
,
wxMaService
.
getWxMaConfig
().
isAccessTokenExpired
());
...
...
@@ -39,12 +43,19 @@ public class SweetWechatService {
return
wxMaService
.
getUserService
().
getPhoneNoInfo
(
sessionKey
,
encryptedData
,
iv
);
}
/**
* 服务号--------------
*/
public
WxOAuth2AccessToken
wxOauth2AccessToken
(
String
code
,
Integer
type
)
throws
WxErrorException
{
WxMpService
wxMpService
=
wechatMpConfigure
.
getWxMpService
(
type
);
log
.
info
(
"isAccessTokenExpired:[{}] "
,
wxMpService
.
getWxMpConfigStorage
().
isAccessTokenExpired
());
log
.
info
(
"getAccessToken:[{}] "
,
wxMpService
.
getWxMpConfigStorage
().
getAccessToken
());
return
wxMpService
.
getOAuth2Service
().
getAccessToken
(
code
);
}
public
WxOAuth2UserInfo
mpUserInfo
(
String
code
,
Integer
type
)
throws
WxErrorException
{
WxMpService
wxMpService
=
wechatMpConfigure
.
getWxMpService
(
type
);
WxOAuth2AccessToken
wxOAuth2AccessToken
=
wxMpService
.
getOAuth2Service
().
getAccessToken
(
code
);
return
wxMpService
.
getOAuth2Service
().
getUserInfo
(
wxOAuth2AccessToken
,
"zh_CN"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment