|
|
@@ -67,7 +67,11 @@ public class AppAgencyController {
|
|
|
@ResponseBody
|
|
|
public Result userLogin(@RequestBody @ApiParam(name="登录请求实体",value="传入json格式",required=true) LoginVo loginVo) {
|
|
|
|
|
|
- if (!StringUtils.isNoneBlank(loginVo.getWxCode(), loginVo.getIv(), loginVo.getRawData(), loginVo.getEncryptedData())) {
|
|
|
+ if (!StringUtils.isNoneBlank(loginVo.getWxCode(), loginVo.getIv()
|
|
|
+ ,loginVo.getRawData()
|
|
|
+ ,loginVo.getEncryptedData()
|
|
|
+ ,loginVo.getWxUserInfoDto().getAvatarUrl()
|
|
|
+ ,loginVo.getWxUserInfoDto().getNickName())) {
|
|
|
throw new CommonBaseException(ResultCodeEnum.D017);
|
|
|
}
|
|
|
|
|
|
@@ -89,20 +93,12 @@ public class AppAgencyController {
|
|
|
try {
|
|
|
resultJson = WXCore.decrypt(wxOpenId, loginVo.getEncryptedData(), wxSessionKey, loginVo.getIv());
|
|
|
|
|
|
- System.out.println("---------------------------------------------------------");
|
|
|
- System.out.println(resultJson);
|
|
|
- System.out.println("---------------------------------------------------------");
|
|
|
-
|
|
|
log.info("微信返回的敏感数据json={}", resultJson.toJSONString());
|
|
|
if (null == resultJson) {
|
|
|
throw new CommonBaseException(ResultCodeEnum.D101, "微信敏感数据Json解析失败");
|
|
|
}
|
|
|
wxUserInfoDto = JSONObject.parseObject(resultJson.toJSONString(), WxUserInfoDto.class);
|
|
|
|
|
|
- System.out.println("---------------------------------------------------------");
|
|
|
- System.out.println(wxUserInfoDto);
|
|
|
- System.out.println("---------------------------------------------------------");
|
|
|
-
|
|
|
if (null == wxUserInfoDto) {
|
|
|
throw new CommonBaseException(ResultCodeEnum.D101, "转换微信敏感数据dto失败");
|
|
|
}
|
|
|
@@ -112,10 +108,14 @@ public class AppAgencyController {
|
|
|
throw new CommonBaseException(ResultCodeEnum.D101);
|
|
|
}
|
|
|
|
|
|
+ WxUserInfoDto wxUserInfoDtoTmp = loginVo.getWxUserInfoDto();
|
|
|
+ String avatarUrl = wxUserInfoDtoTmp.getAvatarUrl();
|
|
|
+ String nickName = wxUserInfoDtoTmp.getNickName();
|
|
|
+
|
|
|
//先通过手机号获取用户表,查看用户是否已经存在
|
|
|
TmAgency dbAgency = agencyService.getAgencyByPhone(wxUserInfoDto.getOpenId());
|
|
|
if (null == dbAgency || 1 != dbAgency.getEnable()) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D029);
|
|
|
+ dbAgency = agencyService.addNewAgency("", wxOpenId, nickName, avatarUrl);
|
|
|
}else{
|
|
|
if(StringUtils.isBlank(dbAgency.getWxOpenId())){
|
|
|
UpdateWrapper<TmAgency> updateWrapper = new UpdateWrapper<>();
|
|
|
@@ -123,6 +123,8 @@ public class AppAgencyController {
|
|
|
updateWrapper.last("limit 1");
|
|
|
dbAgency.setLastModifyDatetime(new Date());
|
|
|
dbAgency.setWxOpenId(wxOpenId);
|
|
|
+ dbAgency.setName(nickName);
|
|
|
+ dbAgency.setAvatar(avatarUrl);
|
|
|
int update = tmAgencyDao.update(dbAgency , updateWrapper);
|
|
|
if(update != 1){
|
|
|
log.error("更新经纪人:{}的微信openid失败" ,dbAgency.getAgencyUserId());
|
|
|
@@ -146,6 +148,52 @@ public class AppAgencyController {
|
|
|
return Result.success(jsonObject);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "获取手机号")
|
|
|
+ @RequestMapping(value = "/getPhoneNum", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public Result getPhone(@RequestBody @ApiParam(name="登录请求实体",value="传入json格式",required=true) LoginVo loginVo) {
|
|
|
+
|
|
|
+ if (!StringUtils.isNoneBlank(loginVo.getWxCode(), loginVo.getIv(), loginVo.getPhoneNum())) {
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D017);
|
|
|
+ }
|
|
|
+ Map<String, Object> wxResult = WxOpUtils.tryLoginWx(loginVo.getWxCode() , agencyWxAppId, agencyWxAppSecret);
|
|
|
+ String wxSessionKey = (String) wxResult.get(WxOpUtils.SESSION_KEY);
|
|
|
+ String wxOpenId = (String) wxResult.get(WxOpUtils.WX_OPEN_ID_KEY);
|
|
|
+ String decryptPhoneNum = null;
|
|
|
+ WxUserInfoDto wxUserInfoDto = null;
|
|
|
+ try {
|
|
|
+ JSONObject resultJson = WXCore.decrypt(wxOpenId, loginVo.getPhoneNum(), wxSessionKey, loginVo.getIv());
|
|
|
+ decryptPhoneNum = null != resultJson ? resultJson.getString(CommonConstants.WxConstant.WX_PHONE_NUMBER) : "";
|
|
|
+ log.info("经纪人解密出来的手机号码为:{}", decryptPhoneNum);
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error("解密手机号出现异常:{}", e);
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D039);
|
|
|
+ }
|
|
|
+
|
|
|
+ //先通过手机号获取用户表,查看用户是否已经存在
|
|
|
+ TmAgency dbAgency = tmAgencyDao.selectTmAgencyById(loginVo.getAgencyUserId());
|
|
|
+ if (null == dbAgency || 1 != dbAgency.getEnable()) {
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D029);
|
|
|
+ }else{
|
|
|
+ if(StringUtils.isBlank(dbAgency.getWxOpenId())){
|
|
|
+ UpdateWrapper<TmAgency> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("agency_user_id" ,dbAgency.getAgencyUserId());
|
|
|
+ updateWrapper.last("limit 1");
|
|
|
+ dbAgency.setLastModifyDatetime(new Date());
|
|
|
+ dbAgency.setWxOpenId(wxOpenId);
|
|
|
+ dbAgency.setPhone(decryptPhoneNum);
|
|
|
+ int update = tmAgencyDao.update(dbAgency , updateWrapper);
|
|
|
+ if(update != 1){
|
|
|
+ log.error("更新经纪人:{}的微信openid失败" ,dbAgency.getAgencyUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //返回用户信息和token给前端
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
+ jsonObject.put("agency", dbAgency);
|
|
|
+ return Result.success(jsonObject);
|
|
|
+ }
|
|
|
|
|
|
@ApiOperation(value = "根据经纪人ID拉取经纪人详情")
|
|
|
@ApiImplicitParam(name = "agency_user_id", value = "经纪人唯一标识ID(32位)", paramType = "query", required = true, dataType = "String")
|
|
|
@@ -187,6 +235,7 @@ public class AppAgencyController {
|
|
|
return Result.failure("新增客源失败");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@ApiOperation(value = "经纪人修改客源信息")
|
|
|
@PostMapping(value = "/update/customer")
|
|
|
@ResponseBody
|