|
|
@@ -2,10 +2,10 @@ package com.izouma.immall.service;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
import com.izouma.immall.config.Constants;
|
|
|
import com.izouma.immall.domain.User;
|
|
|
-import com.izouma.immall.security.VipAuthority;
|
|
|
import com.izouma.immall.exception.BusinessException;
|
|
|
import com.izouma.immall.repo.UserRepo;
|
|
|
import com.izouma.immall.service.sms.SmsService;
|
|
|
@@ -19,6 +19,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -42,18 +43,20 @@ public class UserService {
|
|
|
User user = userRepo.findByOpenId(wxMpUser.getOpenId());
|
|
|
if (user == null) {
|
|
|
user = User.builder()
|
|
|
- .username(UUID.randomUUID().toString())
|
|
|
- .nickname(wxMpUser.getNickname())
|
|
|
- .avatar(wxMpUser.getHeadImgUrl())
|
|
|
- .sex(wxMpUser.getSexDesc())
|
|
|
- .country(wxMpUser.getCountry())
|
|
|
- .province(wxMpUser.getProvince())
|
|
|
- .city(wxMpUser.getCity())
|
|
|
- .openId(wxMpUser.getOpenId())
|
|
|
- .language(wxMpUser.getLanguage())
|
|
|
- .enabled(true)
|
|
|
- .authorities(Collections.singleton(VipAuthority.builder().name("NO_VIP").build()))
|
|
|
- .build();
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .nickname(wxMpUser.getNickname())
|
|
|
+ .avatar(wxMpUser.getHeadImgUrl())
|
|
|
+ .sex(wxMpUser.getSexDesc())
|
|
|
+ .country(wxMpUser.getCountry())
|
|
|
+ .province(wxMpUser.getProvince())
|
|
|
+ .city(wxMpUser.getCity())
|
|
|
+ .openId(wxMpUser.getOpenId())
|
|
|
+ .language(wxMpUser.getLanguage())
|
|
|
+ .enabled(true)
|
|
|
+// .invitationCode(invitation())
|
|
|
+ .money(BigDecimal.ZERO)
|
|
|
+// .authorities(Collections.singleton(VipAuthority.builder().name("NO_VIP").build()))
|
|
|
+ .build();
|
|
|
userRepo.save(user);
|
|
|
}
|
|
|
return user;
|
|
|
@@ -69,13 +72,15 @@ public class UserService {
|
|
|
return userInfo;
|
|
|
}
|
|
|
userInfo = User.builder()
|
|
|
- .username(UUID.randomUUID().toString())
|
|
|
- .nickname("用户" + RandomStringUtils.randomAlphabetic(6))
|
|
|
- .openId(openId)
|
|
|
- .avatar(Constants.DEFAULT_AVATAR)
|
|
|
- .enabled(true)
|
|
|
- .authorities(Collections.singleton(VipAuthority.builder().name("NO_VIP").build()))
|
|
|
- .build();
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .nickname("用户" + RandomStringUtils.randomAlphabetic(6))
|
|
|
+ .openId(openId)
|
|
|
+ .avatar(Constants.DEFAULT_AVATAR)
|
|
|
+ .enabled(true)
|
|
|
+// .invitationCode(invitation())
|
|
|
+ .money(BigDecimal.ZERO)
|
|
|
+// .authorities(Collections.singleton(VipAuthority.builder().name("NO_VIP").build()))
|
|
|
+ .build();
|
|
|
userInfo = userRepo.save(userInfo);
|
|
|
return userInfo;
|
|
|
} catch (WxErrorException e) {
|
|
|
@@ -94,8 +99,11 @@ public class UserService {
|
|
|
// 解密用户信息
|
|
|
WxMaUserInfo wxUserInfo = wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
|
|
|
User user = userRepo.findByOpenId(wxUserInfo.getOpenId());
|
|
|
+ WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
|
|
|
+ String phone = phoneNoInfo.getPhoneNumber();
|
|
|
|
|
|
String avatarUrl = Constants.DEFAULT_AVATAR;
|
|
|
+
|
|
|
try {
|
|
|
String path = "image/avatar/" +
|
|
|
new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) +
|
|
|
@@ -109,17 +117,20 @@ public class UserService {
|
|
|
if (user == null) {
|
|
|
|
|
|
user = User.builder()
|
|
|
- .username(UUID.randomUUID().toString())
|
|
|
- .nickname(wxUserInfo.getNickName())
|
|
|
- .openId(wxUserInfo.getOpenId())
|
|
|
- .avatar(avatarUrl)
|
|
|
- .sex(wxUserInfo.getGender())
|
|
|
- .country(wxUserInfo.getCountry())
|
|
|
- .province(wxUserInfo.getProvince())
|
|
|
- .city(wxUserInfo.getCity())
|
|
|
- .enabled(true)
|
|
|
- .authorities(Collections.singleton(VipAuthority.builder().name("NO_VIP").build()))
|
|
|
- .build();
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .nickname(wxUserInfo.getNickName())
|
|
|
+ .openId(wxUserInfo.getOpenId())
|
|
|
+ .avatar(avatarUrl)
|
|
|
+ .sex(wxUserInfo.getGender())
|
|
|
+ .country(wxUserInfo.getCountry())
|
|
|
+ .province(wxUserInfo.getProvince())
|
|
|
+ .city(wxUserInfo.getCity())
|
|
|
+ .enabled(true)
|
|
|
+ .money(BigDecimal.ZERO)
|
|
|
+// .invitationCode(invitation())
|
|
|
+ .phone(phone)
|
|
|
+// .authorities(Collections.singleton(VipAuthority.builder().name("NO_VIP").build()))
|
|
|
+ .build();
|
|
|
user = userRepo.save(user);
|
|
|
|
|
|
} else {
|
|
|
@@ -129,6 +140,7 @@ public class UserService {
|
|
|
user.setCountry(wxUserInfo.getCountry());
|
|
|
user.setProvince(wxUserInfo.getProvince());
|
|
|
user.setCity(wxUserInfo.getCity());
|
|
|
+ user.setPhone(phone);
|
|
|
user = userRepo.save(user);
|
|
|
}
|
|
|
|
|
|
@@ -153,4 +165,16 @@ public class UserService {
|
|
|
userRepo.save(root);
|
|
|
}
|
|
|
}*/
|
|
|
+
|
|
|
+ /*
|
|
|
+ 查看邀请码是否已存在
|
|
|
+ */
|
|
|
+/* private Integer invitation(){
|
|
|
+ Integer invitationCode =(int) ((Math.random() * 9 + 1) * Math.pow(10, 8 - 1));
|
|
|
+ while(userRepo.existsByInvitationCode(invitationCode)){
|
|
|
+ invitationCode =(int) ((Math.random() * 9 + 1) * Math.pow(10, 8 - 1));
|
|
|
+ }
|
|
|
+ return invitationCode;
|
|
|
+ }*/
|
|
|
+
|
|
|
}
|