| @@ -109,9 +109,10 @@ public class BaseController { | |||
| } | |||
| /** | |||
| * 微信端获取当前用户 wx_c_user,非会员 | |||
| * 请尽量多用getTenantId, getUserId | |||
| */ | |||
| public WxCUser getUser() { | |||
| public WxCUser getWxCUser() { | |||
| Long cUserId = getUserId(); | |||
| WxCUser user = wxCUserService.getById(cUserId); | |||
| if (user == null) { | |||
| @@ -166,22 +167,18 @@ public class BaseController { | |||
| } | |||
| public void saveToBasicInfo(WxCUser user) { | |||
| public Long saveToBasicInfoByCUser(String userPhone,String userName,String avatarUrl,Integer sex,Long userId) { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| String phone = user.getPhone(); | |||
| if (phone != null && phone.contains("*")) { | |||
| phone = user.getVerifyCodePhone(); | |||
| } | |||
| if (StringUtils.isBlank(phone)) | |||
| return; | |||
| if (StringUtils.isBlank(userPhone)) | |||
| return null; | |||
| WxCUserBasicInfo byId = null; | |||
| if(user.isBasicInfo()){ | |||
| byId = wxCUserBasicInfoService.getById(user.getUserId()); | |||
| if (null != userId) { | |||
| byId = wxCUserBasicInfoService.getById(userId); | |||
| } | |||
| // List<WxCUserBasicInfo> list = wxCUserBasicInfoService.findByPhone(tenantEntity, phone); | |||
| WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, phone); | |||
| WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(tenantEntity, userPhone); | |||
| if (basicInfo != null) { | |||
| // WxCUserBasicInfo basicInfo = list.get(0); | |||
| @@ -201,38 +198,30 @@ public class BaseController { | |||
| // if (Objects.nonNull(user.getCredit())) { | |||
| // basicInfo.setCredit(user.getCredit()); | |||
| // } | |||
| user.setUserId(basicInfo.getId()); | |||
| wxCUserService.updateUserId(user); | |||
| //wxCUserBasicInfoService.updateObj(basicInfo, user); | |||
| return basicInfo.getId(); | |||
| } else if(byId != null){ | |||
| byId.setPhone(phone); | |||
| byId.setNickName(user.getNickName()); | |||
| byId.setAvatarUrl(user.getAvatarUrl()); | |||
| byId.setPhone(userPhone); | |||
| byId.setNickName(userName); | |||
| byId.setAvatarUrl(avatarUrl); | |||
| wxCUserBasicInfoService.update(byId); | |||
| return null; | |||
| }else{ | |||
| Date cur = new Date(); | |||
| basicInfo = new WxCUserBasicInfo(); | |||
| basicInfo.setId(user.getId()); | |||
| basicInfo.setId(userId); | |||
| basicInfo.updateTenantInfo(tenantEntity); | |||
| basicInfo.undateFinalTenantId(tenantEntity); | |||
| basicInfo.setPhone(phone); | |||
| basicInfo.setNickName(user.getNickName()); | |||
| basicInfo.setAvatarUrl(user.getAvatarUrl()); | |||
| basicInfo.setSex(user.getGender()); | |||
| basicInfo.setPhone(userPhone); | |||
| basicInfo.setNickName(userName); | |||
| basicInfo.setAvatarUrl(avatarUrl); | |||
| basicInfo.setSex(sex); | |||
| basicInfo.setLoginCount(1); | |||
| basicInfo.setActiveTime(cur); | |||
| basicInfo.setCreateDate(cur); | |||
| basicInfo.setUpdateDate(cur); | |||
| wxCUserBasicInfoService.save(basicInfo); | |||
| user.setUserId(basicInfo.getId()); | |||
| wxCUserService.updateUserId(user); | |||
| } | |||
| String key = Constant.tokenPrev + user.getOpenId(); | |||
| if(cUserTokenRedisTemplate.hasKey(key)){ | |||
| cUserTokenRedisTemplate.delete(key); | |||
| return userId; | |||
| } | |||
| } | |||
| @@ -56,7 +56,7 @@ public class WxLiveController extends BaseController { | |||
| @GetMapping("/replayList") | |||
| public ResultData getLiveReplay(Integer room_id, Integer start, Integer limit) { | |||
| ResultData resultData = new ResultData(); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| try { | |||
| WxMaService wxMaService = getWeappService(user.getAppId()); | |||
| resultData.data = wxMaService.getLiveService().getLiveReplay(room_id,start,limit); | |||
| @@ -2,9 +2,11 @@ package com.iformall.controller; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxMsgValidationcode; | |||
| import com.iformall.enums.EnumAssignTagsTrigger; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.Constant; | |||
| import io.swagger.annotations.Api; | |||
| @@ -39,18 +41,23 @@ public class WxMsgValidationcodeController extends BaseController { | |||
| @Autowired | |||
| private WxCUserTagsService wxCUserTagsService; | |||
| @Autowired | |||
| private WxAppinfoService WxAppinfoService; | |||
| @GetMapping("sendvalidationcode") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true)}) | |||
| public ResultData sendvalidationcode(String phone, Integer type) { | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.updateTenantInfo(getTenantInfo()); | |||
| wxMsgValidationcode.setPhone(phone); | |||
| wxMsgValidationcode.setType(type); | |||
| wxMsgValidationcode.setAppid(user.getAppId()); | |||
| //只需要一端发就可以了 | |||
| WxAppinfo appinfo = WxAppinfoService.getCAppInfo(getTenantInfo(), EnumPayWay.PAY_WAY_WECHAT); | |||
| wxMsgValidationcode.setAppid(appinfo.getAppId()); | |||
| return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||
| } | |||
| @@ -60,22 +67,31 @@ public class WxMsgValidationcodeController extends BaseController { | |||
| @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "code", value = "验证码", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData hasvalidationcode(String phone, Integer type, String code) { | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.updateTenantInfo(getTenantInfo()); | |||
| wxMsgValidationcode.setPhone(phone); | |||
| wxMsgValidationcode.setType(type); | |||
| wxMsgValidationcode.setCode(code); | |||
| wxMsgValidationcode.setAppid(user.getAppId()); | |||
| //只需要一端发就可以了 | |||
| WxAppinfo appinfo = WxAppinfoService.getCAppInfo(getTenantInfo(), EnumPayWay.PAY_WAY_WECHAT); | |||
| wxMsgValidationcode.setAppid(appinfo.getAppId()); | |||
| //wxMsgValidationcode.setAppid(user.getAppId()); | |||
| ResultData rd = wxMsgValidationcodeService.hasvalidationcode(wxMsgValidationcode); | |||
| if (rd.code == Result.SUCCESS) { | |||
| // 更新到basicinfo | |||
| Long userId = user.getId(); | |||
| if (user.isBasicInfo()) { | |||
| userId = user.getUserId(); | |||
| } | |||
| Long basicUserId = saveToBasicInfoByCUser(phone, user.getNickName(), user.getAvatarUrl(), user.getGender(), userId); | |||
| if (null != basicUserId) { | |||
| user.setUserId(basicUserId); | |||
| } | |||
| // 更新 WxCUser | |||
| user.setVerifyCodePhone(phone); | |||
| user.setUpdateDate(new Date()); | |||
| wxCUserService.saveOrUpdate(user); | |||
| // 更新到basicinfo | |||
| saveToBasicInfo(user); | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_PHONE,user); | |||
| String key = Constant.tokenPrev + user.getOpenId(); | |||
| @@ -85,6 +101,7 @@ public class WxMsgValidationcodeController extends BaseController { | |||
| } | |||
| return rd; | |||
| } | |||
| } | |||
| @@ -88,7 +88,7 @@ public class WxPayOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (!user.isBasicInfo()) { | |||
| logger.error("暂未成为会员,请授权手机号"); | |||
| return new ResultData(ErrorCode.USER_IS_NOT_MEMBER.getCode(), "暂未成为会员,请授权手机号"); | |||
| @@ -412,7 +412,7 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "parentTenantId不能为空"); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (user.getParentTenantId().equalsIgnoreCase(parentTenantId)) { | |||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||
| request.setAttribute(Constant.TENANT_ID, tenantId); | |||
| @@ -431,7 +431,7 @@ public class WxUserGrantController extends BaseController { | |||
| String scene = map.get("scene"); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (StringUtils.isBlank(user.getScene()) || | |||
| user.getScene().equalsIgnoreCase(Constant.UNDEFINED)) { | |||
| if(StringUtils.isNotBlank(scene) && scene.equalsIgnoreCase(Constant.UNDEFINED)) { | |||
| @@ -450,7 +450,7 @@ public class WxUserGrantController extends BaseController { | |||
| String longitude = map.get("longitude"); | |||
| String latitude = map.get("latitude"); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (!StringUtils.isBlank(longitude)) | |||
| user.setLongitude(BigDecimal.valueOf(Double.valueOf(longitude))); | |||
| if (!StringUtils.isBlank(latitude)) | |||
| @@ -466,7 +466,7 @@ public class WxUserGrantController extends BaseController { | |||
| String systemInfo = map.get("systemInfo"); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (StringUtils.isNotBlank(systemInfo)) { | |||
| JSONObject extraInfo = new JSONObject(); | |||
| extraInfo.put("systemInfo", JSONObject.parseObject(systemInfo)); | |||
| @@ -524,7 +524,7 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "iv不能为空"); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (user != null) { | |||
| logger.debug(user.toString()); | |||
| @@ -612,7 +612,7 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "iv 不能为空"); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (user == null) { | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| @@ -649,8 +649,20 @@ public class WxUserGrantController extends BaseController { | |||
| wxCUserService.saveOrUpdate(user); | |||
| if (!user.getPhone().contains("*")) { // 用户手机非加密 | |||
| String phone = user.getPhone(); | |||
| if (phone != null && phone.contains("*")) { | |||
| phone = user.getVerifyCodePhone(); | |||
| } | |||
| // 更新到basicinfo | |||
| saveToBasicInfo(user); | |||
| Long userId = user.getId(); | |||
| if(user.isBasicInfo()){ | |||
| userId = user.getUserId(); | |||
| } | |||
| Long userBasicId = saveToBasicInfoByCUser(phone, user.getNickName(), user.getAvatarUrl(), user.getGender(), userId); | |||
| if (null != userBasicId) { | |||
| user.setUserId(userBasicId); | |||
| wxCUserService.updateUserId(user); | |||
| } | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_PHONE, user); | |||
| } | |||
| @@ -686,7 +698,7 @@ public class WxUserGrantController extends BaseController { | |||
| @ApiOperation(value = "判断用户是否完成授权", notes = "") | |||
| public ResultData checkWechatStatus() { | |||
| Map resultMap = new HashMap(); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (StringUtils.isNoneEmpty(user.getNickName())) { | |||
| resultMap.put("nickName", user.getNickName()); | |||
| } else { | |||
| @@ -717,7 +729,7 @@ public class WxUserGrantController extends BaseController { | |||
| @ApiOperation(value = "判断用户是否完成昵称授权", notes = "") | |||
| public ResultData checkUserStatus() { | |||
| Map resultMap = new HashMap(); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (StringUtils.isNoneEmpty(user.getNickName())) { | |||
| resultMap.put("nickName", user.getNickName()); | |||
| } else { | |||
| @@ -736,7 +748,7 @@ public class WxUserGrantController extends BaseController { | |||
| @ApiOperation(value = "判断用户是否完成手机授权", notes = "") | |||
| public ResultData checkPhoneStatus() { | |||
| Map resultMap = new HashMap(); | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| if (StringUtils.isNotBlank(user.getPhone())) { | |||
| resultMap.put("phone", user.getPhone()); | |||
| } else { | |||
| @@ -756,7 +768,7 @@ public class WxUserGrantController extends BaseController { | |||
| @ApiOperation("获取当前用户信息") | |||
| @GetMapping("/userinfo") | |||
| public ResultData getUserInfo() { | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| WxCUserVo userVo = new WxCUserVo(); | |||
| org.springframework.beans.BeanUtils.copyProperties(user, userVo); | |||
| userVo.setScore(0); | |||
| @@ -857,7 +869,7 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "iv 不能为空"); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxCUser user = getWxCUser(); | |||
| String session_key = user.getSessionKey(); | |||
| try { | |||