记得上下班打卡 | 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
3d86285a
Commit
3d86285a
authored
Jul 27, 2021
by
jiangxiulong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登陆
parent
bd04ba3c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
0 deletions
+146
-0
SweetLoginController.java
...uidnet/service/sweet/controller/SweetLoginController.java
+41
-0
SweetLoginServiceImpl.java
...net/service/sweet/service/impl/SweetLoginServiceImpl.java
+105
-0
No files found.
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/controller/SweetLoginController.java
0 → 100644
View file @
3d86285a
package
com
.
liquidnet
.
service
.
sweet
.
controller
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.sweet.service.impl.SweetLoginServiceImpl
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
@Api
(
tags
=
"小程序登陆"
)
@RestController
@RequestMapping
(
"/sweet-login"
)
public
class
SweetLoginController
{
@Autowired
private
SweetLoginServiceImpl
sweetLoginService
;
@GetMapping
(
"userInfo"
)
@ApiOperation
(
"code获取用户信息"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"String"
,
name
=
"code"
,
value
=
"微信code"
,
required
=
true
),
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"String"
,
name
=
"encryptedData"
,
value
=
"encryptedData"
,
required
=
true
),
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"String"
,
name
=
"iv"
,
value
=
"iv"
,
required
=
true
),
@ApiImplicitParam
(
type
=
"query"
,
dataType
=
"Integer"
,
name
=
"type"
,
value
=
"1草莓 2五百里 3mdsk"
),
})
public
ResponseDto
userInfo
(
@RequestParam
()
String
code
,
@RequestParam
()
String
encryptedData
,
@RequestParam
()
String
iv
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
type
)
{
sweetLoginService
.
userInfo
(
code
,
encryptedData
,
iv
,
type
);
return
ResponseDto
.
success
();
}
}
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetLoginServiceImpl.java
0 → 100644
View file @
3d86285a
package
com
.
liquidnet
.
service
.
sweet
.
service
.
impl
;
import
cn.binarywang.wx.miniapp.api.WxMaService
;
import
cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl
;
import
cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult
;
import
cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo
;
import
cn.binarywang.wx.miniapp.bean.WxMaUserInfo
;
import
cn.binarywang.wx.miniapp.config.WxMaConfig
;
import
cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl
;
import
com.liquidnet.service.base.ResponseDto
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.Objects
;
/**
* <p>
* 登陆 服务实现类
* </p>
*
* @author liquidnet
* @since 2021-07-23
*/
@Service
public
class
SweetLoginServiceImpl
{
@Value
(
"${liquidnet.wechat.applet.strawberry.appid}"
)
private
String
strawberryAppid
;
@Value
(
"${liquidnet.wechat.applet.strawberry.secret}"
)
private
String
strawberrySecret
;
@Value
(
"${liquidnet.wechat.applet.five.appid}"
)
private
String
fiveAppid
;
@Value
(
"${liquidnet.wechat.applet.five.secret}"
)
private
String
fiveSecret
;
@Value
(
"${liquidnet.wechat.applet.mdsk.appid}"
)
private
String
mdskAppid
;
@Value
(
"${liquidnet.wechat.applet.mdsk.secret}"
)
private
String
mdskSecret
;
public
ResponseDto
userInfo
(
String
code
,
String
encryptedData
,
String
iv
,
Integer
type
)
{
try
{
String
appId
=
""
;
String
appSecret
=
""
;
switch
(
type
)
{
case
1
:
appId
=
strawberryAppid
;
appSecret
=
strawberrySecret
;
break
;
case
2
:
appId
=
fiveAppid
;
appSecret
=
fiveSecret
;
break
;
case
3
:
appId
=
mdskAppid
;
appSecret
=
mdskSecret
;
break
;
}
WxMaConfig
wxMaConfig
=
wxMaConfig
(
appId
,
appSecret
);
WxMaService
wxMaService
=
wxMaService
(
wxMaConfig
);
WxMaJscode2SessionResult
sessionInfo
=
wxMaService
.
getUserService
().
getSessionInfo
(
code
);
if
(
null
==
sessionInfo
)
{
return
ResponseDto
.
failure
(
"login handler error"
);
}
// 解密用户信息
WxMaUserInfo
wxUserInfo
=
wxMaService
.
getUserService
().
getUserInfo
(
sessionInfo
.
getSessionKey
(),
encryptedData
,
iv
);
if
(
null
==
wxUserInfo
)
{
return
ResponseDto
.
failure
(
"wxUser not exist"
);
}
// 解密手机号码信息
WxMaPhoneNumberInfo
wxMaPhoneNumberInfo
=
wxMaService
.
getUserService
().
getPhoneNoInfo
(
sessionInfo
.
getSessionKey
(),
encryptedData
,
iv
);
if
(
Objects
.
isNull
(
wxMaPhoneNumberInfo
)
||
StringUtils
.
isBlank
(
wxMaPhoneNumberInfo
.
getPhoneNumber
()))
{
return
ResponseDto
.
failure
(
"解密手机号码信息错误"
);
}
String
unionId
=
sessionInfo
.
getUnionid
();
String
openId
=
sessionInfo
.
getOpenid
();
return
ResponseDto
.
success
();
}
catch
(
Exception
e
)
{
return
ResponseDto
.
failure
();
}
}
private
WxMaConfig
wxMaConfig
(
String
appId
,
String
appSecret
)
{
WxMaDefaultConfigImpl
config
=
new
WxMaDefaultConfigImpl
();
config
.
setAppid
(
appId
);
config
.
setSecret
(
appSecret
);
config
.
setMsgDataFormat
(
"JSON"
);
return
config
;
}
private
WxMaService
wxMaService
(
WxMaConfig
maConfig
)
{
WxMaService
service
=
new
WxMaServiceImpl
();
service
.
setWxMaConfig
(
maConfig
);
return
service
;
}
}
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