|
|
|
@ -26,6 +26,7 @@ public class MiniAppService {
|
|
|
|
|
MiniUserMapper miniUserMapper;
|
|
|
|
|
|
|
|
|
|
public MiniUser decryptUserInfo(String userId, String encryptedData, String iv, String signature, String rawData) {
|
|
|
|
|
System.out.println("-------------decryptUserInfo");
|
|
|
|
|
//todo sessionKeyId 查出 sessionKey
|
|
|
|
|
String sessionKey = getSessionKey(userId);
|
|
|
|
|
|
|
|
|
@ -69,50 +70,56 @@ public class MiniAppService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject isNewUser(String code) {
|
|
|
|
|
|
|
|
|
|
WxMaJscode2SessionResult sessionInfo = null;
|
|
|
|
|
try {
|
|
|
|
|
sessionInfo = wxService.getUserService().getSessionInfo(code);
|
|
|
|
|
} catch (WxErrorException e) {
|
|
|
|
|
throw new RuntimeException("获取openid失败", e);
|
|
|
|
|
}
|
|
|
|
|
String sessionKey = sessionInfo.getSessionKey();
|
|
|
|
|
String openid = sessionInfo.getOpenid();
|
|
|
|
|
String unionid = sessionInfo.getUnionid();
|
|
|
|
|
//todo 根据openid去数据库查 该用户 存在 更新一下sessionkey字段 isNew=false sessionkeyid=xx 不存在放并把以上3个字段新建一个用户(外加生成sessionkeyid) 返回结果 isNew=true sessionkeyid=xx
|
|
|
|
|
Map<String, Object> columnMap = new HashMap<>();
|
|
|
|
|
columnMap.put("open_id", openid);
|
|
|
|
|
List<MiniUser> miniUsers = miniUserMapper.selectByMap(columnMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
|
|
|
|
if(miniUsers.size()==0){
|
|
|
|
|
MiniUser miniUser = new MiniUser();
|
|
|
|
|
String id = UUID.randomUUID().toString();
|
|
|
|
|
miniUser.setId(id);
|
|
|
|
|
miniUser.setSessionKey(sessionKey);
|
|
|
|
|
miniUser.setOpenId(openid);
|
|
|
|
|
miniUser.setCreateDate(new Date());
|
|
|
|
|
miniUser.setCertified(false);
|
|
|
|
|
miniUserMapper.insert(miniUser);
|
|
|
|
|
jsonObject.put("isNew",true);
|
|
|
|
|
jsonObject.put("userId",id);
|
|
|
|
|
jsonObject.put("openId",openid);
|
|
|
|
|
}else {
|
|
|
|
|
MiniUser miniUser = miniUsers.get(0);
|
|
|
|
|
miniUser.setSessionKey(sessionKey);
|
|
|
|
|
miniUserMapper.updateById(miniUser);//是否是更新一个字段
|
|
|
|
|
jsonObject.put("isNew",false);
|
|
|
|
|
jsonObject.put("userId",miniUser.getId());
|
|
|
|
|
jsonObject.put("openId",openid);
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("-------------isNewUser");
|
|
|
|
|
WxMaJscode2SessionResult sessionInfo = null;
|
|
|
|
|
try {
|
|
|
|
|
sessionInfo = wxService.getUserService().getSessionInfo(code);
|
|
|
|
|
} catch (WxErrorException e) {
|
|
|
|
|
throw new RuntimeException("获取openid失败", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String sessionKey = sessionInfo.getSessionKey();
|
|
|
|
|
String openid = sessionInfo.getOpenid();
|
|
|
|
|
String unionid = sessionInfo.getUnionid();
|
|
|
|
|
//todo 根据openid去数据库查 该用户 存在 更新一下sessionkey字段 isNew=false sessionkeyid=xx 不存在放并把以上3个字段新建一个用户(外加生成sessionkeyid) 返回结果 isNew=true sessionkeyid=xx
|
|
|
|
|
Map<String, Object> columnMap = new HashMap<>();
|
|
|
|
|
columnMap.put("open_id", openid);
|
|
|
|
|
List<MiniUser> miniUsers = miniUserMapper.selectByMap(columnMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(miniUsers.size()==0){
|
|
|
|
|
MiniUser miniUser = new MiniUser();
|
|
|
|
|
String id = UUID.randomUUID().toString();
|
|
|
|
|
miniUser.setId(id);
|
|
|
|
|
miniUser.setSessionKey(sessionKey);
|
|
|
|
|
miniUser.setOpenId(openid);
|
|
|
|
|
miniUser.setCreateDate(new Date());
|
|
|
|
|
miniUser.setCertified(false);
|
|
|
|
|
miniUserMapper.insert(miniUser);
|
|
|
|
|
jsonObject.put("isNew",true);
|
|
|
|
|
jsonObject.put("userId",id);
|
|
|
|
|
jsonObject.put("openId",openid);
|
|
|
|
|
}else {
|
|
|
|
|
MiniUser miniUser = miniUsers.get(0);
|
|
|
|
|
miniUser.setSessionKey(sessionKey);
|
|
|
|
|
miniUserMapper.updateById(miniUser);//是否是更新一个字段
|
|
|
|
|
jsonObject.put("isNew",false);
|
|
|
|
|
jsonObject.put("userId",miniUser.getId());
|
|
|
|
|
jsonObject.put("openId",openid);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return jsonObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MiniUser decryptPhoneNumber(String userId,String encryptedData ,String ivStr,String signature,String rawData) {
|
|
|
|
|
|
|
|
|
|
System.out.println("-------------decryptPhoneNumber");
|
|
|
|
|
//todo sessionKeyId 查出 sessionKey
|
|
|
|
|
String sessionKey = getSessionKey(userId);
|
|
|
|
|
|
|
|
|
|