fixed 登录的问题
微信服务器返回的用户数据调整 修改一些基本问题(@service,@tableid)
This commit is contained in:
parent
d4dce97afe
commit
5129b79a3f
@ -34,6 +34,7 @@ public class ResponseExceptionConfig {
|
||||
@ResponseBody
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ApiResult exceptionHandler(HttpServletRequest req, Exception e) {
|
||||
e.printStackTrace();
|
||||
return ApiResult.error(-1, "App Internal Error:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.xiaoyan.point.api.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@ -10,6 +12,7 @@ import java.io.Serializable;
|
||||
@Accessors(chain = true)
|
||||
@Builder
|
||||
public class Point implements Serializable {
|
||||
@TableId(type = IdType.NONE)
|
||||
private Integer uid;
|
||||
private Integer totalPoint;
|
||||
private Integer validPoint;
|
||||
|
@ -2,6 +2,7 @@ package me.xiaoyan.point.api.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@ -12,6 +13,7 @@ import java.util.Date;
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Builder
|
||||
@TableName("userinfo")
|
||||
public class UserInfo implements Serializable {
|
||||
/**
|
||||
* 用户id
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.xiaoyan.point.api.pojo.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -21,6 +22,7 @@ public class CodeSessionData implements Serializable {
|
||||
/**
|
||||
* 会话密钥,用于签名或解密
|
||||
*/
|
||||
@SerializedName("session_key")
|
||||
private String sessionKey;
|
||||
/**
|
||||
* 用户在开放平台的唯一标识符
|
||||
|
@ -7,10 +7,12 @@ import me.xiaoyan.point.api.pojo.Point;
|
||||
import me.xiaoyan.point.api.pojo.PointRecord;
|
||||
import me.xiaoyan.point.api.service.PointRecordService;
|
||||
import me.xiaoyan.point.api.service.PointService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class PointRecordServiceImpl extends ServiceImpl<PointRecordMapper, PointRecord>
|
||||
implements PointRecordService {
|
||||
@Resource
|
||||
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import me.xiaoyan.point.api.mapper.PointMapper;
|
||||
import me.xiaoyan.point.api.pojo.Point;
|
||||
import me.xiaoyan.point.api.service.PointService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PointServiceImpl extends ServiceImpl<PointMapper, Point>
|
||||
implements PointService {
|
||||
|
||||
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import me.xiaoyan.point.api.mapper.SignRecordMapper;
|
||||
import me.xiaoyan.point.api.pojo.SignRecord;
|
||||
import me.xiaoyan.point.api.service.SignRecordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SignRecordServiceImpl extends ServiceImpl<SignRecordMapper, SignRecord>
|
||||
implements SignRecordService {
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@ -45,7 +48,9 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
private int recommendPoint;
|
||||
|
||||
|
||||
@Resource
|
||||
private PointService pointService;
|
||||
@Resource
|
||||
private PointRecordService pointRecordService;
|
||||
|
||||
public void firstLogin(UserInfo info) {
|
||||
@ -55,8 +60,8 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
Point point = Point.builder()
|
||||
.uid(info.getId())
|
||||
.expirePoint(0)
|
||||
.totalPoint(firstLoginPoint)
|
||||
.validPoint(firstLoginPoint)
|
||||
.totalPoint(0)
|
||||
.validPoint(0)
|
||||
.build();
|
||||
pointService.save(point);
|
||||
// 新增积分记录
|
||||
@ -73,7 +78,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
// 使用code换取登录session相关数据
|
||||
CodeSessionData sessionData = getOpenIdByCode(data.getCode());
|
||||
// 使用openid查询用户信息
|
||||
final UserInfo userInfo = this.getBaseMapper().selectOneByOpenId(sessionData.getOpenid());
|
||||
UserInfo userInfo = this.getBaseMapper().selectOneByOpenId(sessionData.getOpenid());
|
||||
// 判断用户信息是否存在
|
||||
if (userInfo == null) {
|
||||
// 先解码获取用户数据
|
||||
@ -82,8 +87,10 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
sessionData.getSessionKey(),
|
||||
data.getIv()
|
||||
);
|
||||
userInfo = wechatUserInfo.getUserinfo().setOpenId(sessionData.getOpenid());
|
||||
//
|
||||
// 不存在走 第一次登录流程
|
||||
firstLogin(wechatUserInfo.getUserinfo());
|
||||
firstLogin(userInfo);
|
||||
}
|
||||
// 首先
|
||||
return userInfo;
|
||||
@ -112,8 +119,9 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
|
||||
final String content = EntityUtils.toString(response.getEntity());
|
||||
Gson gson = new Gson();
|
||||
final CodeSessionData data = gson.fromJson(content, CodeSessionData.class);
|
||||
if (data.getErrcode() != 0) {
|
||||
throw BizException.create(1101, "换取session失败(" + data.getErrmsg() + ")");
|
||||
if (!StringUtils.hasLength(data.getOpenid()) || !StringUtils.hasLength(data.getSessionKey())
|
||||
|| (data.getErrcode() != null && data.getErrcode() != 0)) {
|
||||
throw BizException.create(1101, "换取session失败");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ public class WechatDecryptDataUtil {
|
||||
* @return
|
||||
*/
|
||||
public static WechatUserInfo decryptData(String encryptDataB64, String sessionKeyB64, String ivB64) {
|
||||
System.out.println("encryptDataB64:" + encryptDataB64);
|
||||
System.out.println("sessionKeyB64:" +sessionKeyB64);
|
||||
System.out.println("ivB64:" + ivB64);
|
||||
String result = new String(
|
||||
decryptOfDiyIV(
|
||||
Base64.getDecoder().decode(encryptDataB64),
|
||||
@ -33,6 +36,7 @@ public class WechatDecryptDataUtil {
|
||||
Base64.getDecoder().decode(ivB64)
|
||||
)
|
||||
);
|
||||
System.out.println(result);
|
||||
if(!StringUtils.hasLength(result)){
|
||||
throw new RuntimeException("解码失败");
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 8001
|
||||
port: 8080
|
||||
wechat:
|
||||
app_id: wxafc2a812fe936d88
|
||||
app_secret: 3e5f5a577cb06b7d1815db146d552b95
|
||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Loading…
x
Reference in New Issue
Block a user