Commit ef7cc114 authored by 董建华's avatar 董建华

用户中心增加小程序登录接口

parent 4d71199d
......@@ -2,7 +2,10 @@ package cn.quantgroup.xyqb.controller.applet;
import cn.quantgroup.xyqb.entity.AppletParamEntry;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.applet.IAppletService;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -20,14 +23,21 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/middle_office/applet")
public class AppletController {
private final IAppletService iAppletService;
@Autowired
AppletController(IAppletService iAppletService){
this.iAppletService = iAppletService;
}
/**
*
* @return
*/
@PostMapping("/relevance")
public JsonResult relevance(@Validated @RequestBody AppletParamEntry appletParamEntry){
return JsonResult.buildSuccessResult();
public JsonResult relevance(@Validated @RequestBody AppletParamEntry appletParamEntry) {
Long userId = iAppletService.relevance(appletParamEntry);
return JsonResult.buildSuccessResultGeneric(ImmutableMap.of("userId", userId));
}
}
......@@ -152,7 +152,7 @@ public class UserController implements IBaseController {
@RequestParam(required = false) String dimension,
@RequestParam(name = "click_id", required = false) String clickId,
HttpServletRequest request) {
log.info("login/fastV1 -> channelId:{},appChennel:{},createdFrom:{},key:{},btRegisterChannelId:{},dimension:{},clickId:{}", channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension, clickId);
log.info("login/fastV1 -> channelId:{},ZappChennel:{},createdFrom:{},key:{},btRegisterChannelId:{},dimension:{},clickId:{}", channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension, clickId);
return loginFast(channelId, appChannel, createdFrom, key, btRegisterChannelId, dimension, clickId, request);
}
......
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.util.ValidationUtil;
import lombok.Getter;
import lombok.Setter;
......@@ -36,7 +37,7 @@ public class AppletParamEntry {
* 手机号
*/
@NotNull(message = "04:mobile 不能为空")
@Pattern(regexp = "/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$/", message = "手机号格式不对")
@Pattern(regexp = ValidationUtil.phoneRegExp, message = "手机号格式不对")
private String mobile;
/**
* 用户全局唯一标识
......@@ -70,4 +71,5 @@ public class AppletParamEntry {
* 语言
*/
private String language;
}
......@@ -43,12 +43,9 @@ public class AppletServiceImpl implements IAppletService {
public Long relevance(AppletParamEntry appletParamEntry) {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(appletParamEntry.getOpenId(), appletParamEntry.getAppName());
//这个接口先不考虑更换手机号的情况只要有userid就直接返回
if (null != wechatUserInfo && null != wechatUserInfo.getUserId()) {
return wechatUserInfo.getUserId();
}
//这个接口先不考虑更换手机号的情况
wechatUserInfo = new WechatUserInfo();
wechatUserInfo = (wechatUserInfo == null ? new WechatUserInfo() : wechatUserInfo);
wechatUserInfo.setNickName(appletParamEntry.getNickName());
wechatUserInfo.setCity(appletParamEntry.getCity());
wechatUserInfo.setCountry(appletParamEntry.getCountry());
......@@ -59,18 +56,18 @@ public class AppletServiceImpl implements IAppletService {
wechatUserInfo.setOpenId(appletParamEntry.getOpenId());
wechatUserInfo.setSex(appletParamEntry.getGender());
wechatUserInfo.setUnionId(appletParamEntry.getUnionId());
wechatUserInfo.setPhoneNo(appletParamEntry.getMobile());
User user = userService.findByPhoneInDb(appletParamEntry.getMobile());
//如果不存在就去注册一下
if (null == user) {
user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile());
if (null == wechatUserInfo.getUserId()) {//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了
User user = userService.findByPhoneInDb(appletParamEntry.getMobile());
//如果不存在就去注册一下
if (null == user) {
user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile());
}
wechatUserInfo.setUserId(user.getId());
}
//如果存在就更新在微信表里
Long id = user.getId();
wechatUserInfo.setUserId(id);
wechatUserInfo.setPhoneNo(user.getPhoneNo());
iWeChatUserRepository.save(wechatUserInfo);
return id;
return wechatUserInfo.getUserId();
}
}
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