update[litemall-wx,litemall-wx-api]: 微信小程序wx.getUserInfo接口被调整,这里也进行相应调整。
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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.FullUserInfo;
|
||||
import org.linlinjava.litemall.wx.dao.WxLoginInfo;
|
||||
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, "code");
|
||||
FullUserInfo fullUserInfo = JacksonUtil.parseObject(body, "userInfo", FullUserInfo.class);
|
||||
if(code == null || fullUserInfo == null){
|
||||
public Object loginByWeixin(@RequestBody WxLoginInfo wxLoginInfo, HttpServletRequest request) {
|
||||
String code = wxLoginInfo.getCode();
|
||||
UserInfo userInfo = wxLoginInfo.getUserInfo();
|
||||
if(code == null || userInfo == 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();
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<navigator url="/pages/auth/reset/reset" class="reset">忘记密码</navigator>
|
||||
</view>
|
||||
|
||||
<button type="primary" class="login-btn" bindtap="wxLogin">微信直接登录</button>
|
||||
<button type="primary" open-type="getUserInfo" class="login-btn" bindgetuserinfo="wxLogin">微信直接登录</button>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user