Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
e265a754
Commit
e265a754
authored
May 11, 2018
by
Junling Bu
Browse files
update[litemall-wx,litemall-wx-api]: 微信小程序wx.getUserInfo接口被调整,这里也进行相应调整。
parent
4b0bf05c
Changes
6
Hide whitespace changes
Inline
Side-by-side
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/FullUserInfo.java
deleted
100644 → 0
View file @
4b0bf05c
package
org.linlinjava.litemall.wx.dao
;
public
class
FullUserInfo
{
private
String
encryptedData
;
private
String
errMsg
;
private
String
iv
;
private
String
rawData
;
private
String
signature
;
private
UserInfo
userInfo
;
public
void
setEncryptedData
(
String
encryptedData
)
{
this
.
encryptedData
=
encryptedData
;
}
public
void
setErrMsg
(
String
errMsg
)
{
this
.
errMsg
=
errMsg
;
}
public
void
setIv
(
String
iv
)
{
this
.
iv
=
iv
;
}
public
void
setRawData
(
String
rawData
)
{
this
.
rawData
=
rawData
;
}
public
void
setSignature
(
String
signature
)
{
this
.
signature
=
signature
;
}
public
void
setUserInfo
(
UserInfo
userInfo
)
{
this
.
userInfo
=
userInfo
;
}
public
String
getEncryptedData
()
{
return
encryptedData
;
}
public
String
getErrMsg
()
{
return
errMsg
;
}
public
String
getIv
()
{
return
iv
;
}
public
String
getRawData
()
{
return
rawData
;
}
public
String
getSignature
()
{
return
signature
;
}
public
UserInfo
getUserInfo
()
{
return
userInfo
;
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/dao/WxLoginInfo.java
0 → 100644
View file @
e265a754
package
org.linlinjava.litemall.wx.dao
;
public
class
WxLoginInfo
{
private
String
code
;
private
UserInfo
userInfo
;
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
UserInfo
getUserInfo
()
{
return
userInfo
;
}
public
void
setUserInfo
(
UserInfo
userInfo
)
{
this
.
userInfo
=
userInfo
;
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java
View file @
e265a754
...
...
@@ -9,7 +9,7 @@ import org.linlinjava.litemall.db.domain.LitemallUser;
import
org.linlinjava.litemall.db.service.LitemallUserService
;
import
org.linlinjava.litemall.core.util.JacksonUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.wx.dao.
FullUser
Info
;
import
org.linlinjava.litemall.wx.dao.
WxLogin
Info
;
import
org.linlinjava.litemall.wx.dao.UserInfo
;
import
org.linlinjava.litemall.wx.dao.UserToken
;
import
org.linlinjava.litemall.wx.service.UserTokenManager
;
...
...
@@ -100,7 +100,7 @@ public class WxAuthController {
/**
* 微信登录
*
* @param
body
请求内容,{ code: xxx, userInfo: xxx }
* @param
wxLoginInfo
请求内容,{ code: xxx, userInfo: xxx }
* @param request 请求对象
* @return 登录结果
* 成功则
...
...
@@ -117,15 +117,13 @@ public class WxAuthController {
* 失败则 { errno: XXX, errmsg: XXX }
*/
@RequestMapping
(
"login_by_weixin"
)
public
Object
loginByWeixin
(
@RequestBody
String
body
,
HttpServletRequest
request
)
{
String
code
=
JacksonUtil
.
parseString
(
body
,
"c
ode
"
);
Full
UserInfo
fullU
serInfo
=
JacksonUtil
.
parseObject
(
body
,
"userInfo"
,
Full
UserInfo
.
class
);
if
(
code
==
null
||
fullU
serInfo
==
null
){
public
Object
loginByWeixin
(
@RequestBody
WxLoginInfo
wxLoginInfo
,
HttpServletRequest
request
)
{
String
code
=
wxLoginInfo
.
getC
ode
(
);
UserInfo
u
serInfo
=
wxLoginInfo
.
get
UserInfo
(
);
if
(
code
==
null
||
u
serInfo
==
null
){
return
ResponseUtil
.
badArgument
();
}
UserInfo
userInfo
=
fullUserInfo
.
getUserInfo
();
String
sessionKey
=
null
;
String
openId
=
null
;
try
{
...
...
@@ -140,14 +138,6 @@ public class WxAuthController {
return
ResponseUtil
.
fail
();
}
//验证用户信息完整性
if
(!
this
.
wxService
.
getUserService
().
checkUserInfo
(
sessionKey
,
fullUserInfo
.
getRawData
(),
fullUserInfo
.
getSignature
()))
{
return
ResponseUtil
.
fail
();
}
// 解密用户信息
// WxMaUserInfo wxMaUserInfo = this.wxService.getUserService().getUserInfo(sessionKey, fullUserInfo.getEncryptedData(), fullUserInfo.getIv());
LitemallUser
user
=
userService
.
queryByOid
(
openId
);
if
(
user
==
null
){
user
=
new
LitemallUser
();
...
...
litemall-wx/pages/auth/login/login.js
View file @
e265a754
...
...
@@ -29,10 +29,16 @@ Page({
// 页面关闭
},
wxLogin
:
function
()
{
wxLogin
:
function
(
e
)
{
if
(
e
.
detail
.
userInfo
==
undefined
){
app
.
globalData
.
hasLogin
=
false
;
util
.
showErrorToast
(
'
微信登录失败
'
);
return
;
}
user
.
checkLogin
().
catch
(()
=>
{
user
.
loginByWeixin
().
then
(
res
=>
{
user
.
loginByWeixin
(
e
.
detail
.
userInfo
).
then
(
res
=>
{
app
.
globalData
.
hasLogin
=
true
;
wx
.
navigateBack
({
...
...
litemall-wx/pages/auth/login/login.wxml
View file @
e265a754
...
...
@@ -26,7 +26,7 @@
<navigator url="/pages/auth/reset/reset" class="reset">忘记密码</navigator>
</view>
<button type="primary" class="login-btn" bind
tap
="wxLogin">微信直接登录</button>
<button type="primary"
open-type="getUserInfo"
class="login-btn" bind
getuserinfo
="wxLogin">微信直接登录</button>
</view>
</view>
\ No newline at end of file
litemall-wx/services/user.js
View file @
e265a754
...
...
@@ -41,60 +41,15 @@ function login() {
});
}
/**
* Promise封装wx.getUserInfo
*/
function
getUserInfo
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
wx
.
getUserInfo
({
withCredentials
:
true
,
success
:
function
(
res
)
{
resolve
(
res
);
},
fail
:
function
(
err
)
{
wx
.
showModal
({
title
:
'
用户未授权
'
,
content
:
'
请给予您的用户信息授权。
'
,
success
:
function
(
res
)
{
if
(
res
.
confirm
)
{
wx
.
openSetting
({
success
:
(
res
)
=>
{
if
(
res
.
authSetting
[
"
scope.userInfo
"
]
===
true
)
{
wx
.
getUserInfo
({
withCredentials
:
true
,
success
:
function
(
res
)
{
resolve
(
res
);
},
})
}
}
})
}
else
if
(
res
.
cancel
)
{
wx
.
navigateBack
({
delta
:
1
})
}
}
})
}
})
});
}
/**
* 调用微信登录
*/
function
loginByWeixin
()
{
function
loginByWeixin
(
userInfo
)
{
let
code
=
null
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
login
().
then
((
res
)
=>
{
code
=
res
.
code
;
return
getUserInfo
();
}).
then
((
userInfo
)
=>
{
//登录远程服务器
util
.
request
(
api
.
AuthLoginByWeixin
,
{
code
:
code
,
userInfo
:
userInfo
},
'
POST
'
).
then
(
res
=>
{
util
.
request
(
api
.
AuthLoginByWeixin
,
{
code
:
res
.
code
,
userInfo
:
userInfo
},
'
POST
'
).
then
(
res
=>
{
if
(
res
.
errno
===
0
)
{
//存储用户信息
wx
.
setStorageSync
(
'
userInfo
'
,
res
.
data
.
userInfo
);
...
...
Write
Preview
Supports
Markdown
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