Commit d91ee44e authored by 技术部-任文超's avatar 技术部-任文超

增补微信绑定动作的log

parent feccc210
......@@ -27,7 +27,6 @@ import cn.quantgroup.xyqb.util.IPUtil;
import cn.quantgroup.xyqb.util.MqUtils;
import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
......@@ -470,32 +469,44 @@ public class UserController implements IBaseController {
}
}
/**
* 绑定微信
* @param openId - 微信openId
* @return
*/
@RequestMapping("/associate_wechat")
public JsonResult associateWithWechat(String openId) {
User user = getCurrentUserFromRedis();
Long userId = user.getId();
WechatUserInfo userInfo = wechatService.findWechatUserInfoFromDb(openId);
LOGGER.info("微信关联openId,user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
if (Objects.isNull(userInfo) && !Objects.isNull(userId)) {
if (Objects.isNull(userInfo) && Objects.nonNull(userId)) {
userInfo = wechatService.queryByUserId(userId);
}
if (userInfo == null || StringUtils.isNotEmpty(userInfo.getPhoneNo())) {
return JsonResult.buildSuccessResult(null, null);
}
// 未绑定信用钱包用户
if (userInfo.getUserId() == null) {
userInfo.setUserId(userId);
userInfo.setPhoneNo(user.getPhoneNo());
try {
wechatService.saveWechatUserInfo(userInfo);
} catch (Exception ex) {
// 不做绑定
return JsonResult.buildErrorStateResult("该手机号已绑定其他微信号码", null);
}
return JsonResult.buildSuccessResult(null, null);
}
return JsonResult.buildSuccessResult(null, null);
LOGGER.info("微信关联:user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
// 无微信信息
if (userInfo == null) {
LOGGER.warn("微信关联失败,缺少微信信息:user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
return JsonResult.buildErrorStateResult("还没有保存微信信息", null);
}
// 排他性 - 先入为主
if (Objects.nonNull(userInfo.getUserId()) && userInfo.getUserId()>0 && !Objects.equals(userId, userInfo.getUserId())) {
LOGGER.warn("微信关联失败,该微信已经被其他用户绑定:user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
return JsonResult.buildErrorStateResult("该微信已经被其他用户绑定", null);
}
/*
* 未绑定信用钱包用户
*/
userInfo.setUserId(userId);
userInfo.setPhoneNo(user.getPhoneNo());
try {
userInfo = wechatService.saveWechatUserInfo(userInfo);
LOGGER.info("微信关联成功:user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
} catch (Exception ex) {
// 不做绑定
LOGGER.warn("微信关联失败,该手机号已绑定其他微信号码:user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
return JsonResult.buildErrorStateResult("该手机号已绑定其他微信号码", null);
}
return JsonResult.buildSuccessResult("微信关联成功", null);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment