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

小程序

parent e2efeb13
...@@ -152,7 +152,7 @@ public class ExceptionHandlingController implements IBaseController { ...@@ -152,7 +152,7 @@ public class ExceptionHandlingController implements IBaseController {
return null; return null;
} }
@ExceptionHandler(DataException.class) @ExceptionHandler({DataException.class,IllegalArgumentException.class})
@ResponseBody @ResponseBody
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public JsonResult handleDataException(DataException e) { public JsonResult handleDataException(DataException e) {
......
package cn.quantgroup.xyqb.controller.middleoffice.applet; package cn.quantgroup.xyqb.controller.middleoffice.applet;
import cn.quantgroup.xyqb.controller.middleoffice.common.VerifyTypeEnum;
import cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule;
import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry; import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService; import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/** /**
* @author :dongjianhua * @author :dongjianhua
* @date :Created in 2020/5/27 17:24 * @date :Created in 2020/5/27 17:24
...@@ -23,21 +32,49 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -23,21 +32,49 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/middle_office/applet") @RequestMapping("/middle_office/applet")
public class AppletController { public class AppletController {
//先这么干 多了的话建表去存
private static final List<String> appNames = Lists.newArrayList(
"luckii", "xyqb", "wuxi");
private final IAppletService iAppletService; private final IAppletService iAppletService;
private ILoginModule loginModule;
@Autowired @Autowired
AppletController(IAppletService iAppletService){ AppletController(IAppletService iAppletService,
ILoginModule loginModule
) {
this.iAppletService = iAppletService; this.iAppletService = iAppletService;
this.loginModule = loginModule;
} }
/** /**
*
* @return * @return
*/ */
@PostMapping("/relevance") @PostMapping("/relevance")
public JsonResult relevance(@Validated @RequestBody AppletParamEntry appletParamEntry) { public JsonResult relevance(@Validated @RequestBody AppletParamEntry appletParamEntry) {
if (!appNames.contains(appletParamEntry.getAppName())) {
throw new DataException("appName不合法");
}
Long userId = iAppletService.relevance(appletParamEntry); Long userId = iAppletService.relevance(appletParamEntry);
return JsonResult.buildSuccessResultGeneric(ImmutableMap.of("userId", userId));
LoginVo loginVo = loginModule.loginByUserId(appletParamEntry.getChannelId(),
appletParamEntry.getUtmSource(), userId);
return JsonResult
.buildSuccessResultGeneric(
ImmutableMap.of("userId", userId,
"user", loginVo));
} }
/**
* @return
*/
@PostMapping("/login")
public JsonResult login(String appName, String openId, String utmSource) {
if (!appNames.contains(appName)) {
throw new DataException("appName不合法");
}
LoginVo login = iAppletService.login(appName, openId, utmSource);
return JsonResult.buildSuccessResultGeneric(login);
}
} }
...@@ -10,4 +10,6 @@ public interface ILoginModule { ...@@ -10,4 +10,6 @@ public interface ILoginModule {
String verify); String verify);
Boolean modifyPwd(VerifyTypeEnum type, String phoneNo, String password, String verify); Boolean modifyPwd(VerifyTypeEnum type, String phoneNo, String password, String verify);
LoginVo loginByUserId(Long channelId, String appChannel, Long userId);
} }
...@@ -81,5 +81,26 @@ public class LoginModule implements ILoginModule { ...@@ -81,5 +81,26 @@ public class LoginModule implements ILoginModule {
return true; return true;
} }
@Override
public LoginVo loginByUserId(Long channelId, String appChannel, Long userId) {
User user = userService.findById(userId);
if(null == user){
throw new DataException("未找到此用户");
}
LoginProperties loginProperties = LoginProperties.builder()
.createdFrom(user.getRegisteredFrom())
.appChannel(appChannel == null ? "" : appChannel)
.channelId(channelId)
.build();
AuthBean session = sessionService.createSession(user, loginProperties);
return LoginVo.builder()
.hasPassword(user.getHasPassword())
.phoneNo(user.getPhoneNo())
.token(session.getToken())
.userId(user.getId())
.uuid(user.getUuid())
.build();
}
} }
...@@ -42,6 +42,8 @@ public class WechatUserInfo extends BaseEntity implements Serializable { ...@@ -42,6 +42,8 @@ public class WechatUserInfo extends BaseEntity implements Serializable {
private String country; private String country;
@Column(name = "head_img_url") @Column(name = "head_img_url")
private String headImgUrl; private String headImgUrl;
@Column(name = "utm_source")
private String utmSource;
public WechatUserInfo convertEmoji() { public WechatUserInfo convertEmoji() {
......
...@@ -71,5 +71,9 @@ public class AppletParamEntry { ...@@ -71,5 +71,9 @@ public class AppletParamEntry {
* 语言 * 语言
*/ */
private String language; private String language;
/**
* 风控要的字段广告系列来源
*/
private String utmSource;
} }
package cn.quantgroup.xyqb.service.middleoffice.applet; package cn.quantgroup.xyqb.service.middleoffice.applet;
import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry; import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
/** /**
...@@ -11,4 +12,5 @@ import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry; ...@@ -11,4 +12,5 @@ import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
*/ */
public interface IAppletService { public interface IAppletService {
Long relevance(AppletParamEntry appletParamEntry); Long relevance(AppletParamEntry appletParamEntry);
LoginVo login(String appName, String openId,String utmSource);
} }
package cn.quantgroup.xyqb.service.middleoffice.applet.impl; package cn.quantgroup.xyqb.service.middleoffice.applet.impl;
import cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule;
import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry; import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.WechatUserInfo; import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.repository.IWeChatUserRepository; import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService; import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
...@@ -29,12 +32,17 @@ public class AppletServiceImpl implements IAppletService { ...@@ -29,12 +32,17 @@ public class AppletServiceImpl implements IAppletService {
private final IUserRegisterService iUserRegisterService; private final IUserRegisterService iUserRegisterService;
private final IUserService userService; private final IUserService userService;
private ILoginModule loginModule;
@Autowired @Autowired
public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository, IUserRegisterService iUserRegisterService, IUserService userService) { public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository,
IUserRegisterService iUserRegisterService,
IUserService userService,
ILoginModule loginModule) {
this.iWeChatUserRepository = iWeChatUserRepository; this.iWeChatUserRepository = iWeChatUserRepository;
this.iUserRegisterService = iUserRegisterService; this.iUserRegisterService = iUserRegisterService;
this.userService = userService; this.userService = userService;
this.loginModule = loginModule;
} }
@Override @Override
...@@ -56,7 +64,7 @@ public class AppletServiceImpl implements IAppletService { ...@@ -56,7 +64,7 @@ public class AppletServiceImpl implements IAppletService {
wechatUserInfo.setSex(appletParamEntry.getGender()); wechatUserInfo.setSex(appletParamEntry.getGender());
wechatUserInfo.setUnionId(appletParamEntry.getUnionId()); wechatUserInfo.setUnionId(appletParamEntry.getUnionId());
wechatUserInfo.setPhoneNo(appletParamEntry.getMobile()); wechatUserInfo.setPhoneNo(appletParamEntry.getMobile());
wechatUserInfo.setUtmSource(appletParamEntry.getUtmSource());
if (null == wechatUserInfo.getUserId()) {//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了 if (null == wechatUserInfo.getUserId()) {//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了
User user = userService.findByPhoneInDb(appletParamEntry.getMobile()); User user = userService.findByPhoneInDb(appletParamEntry.getMobile());
//如果不存在就去注册一下 //如果不存在就去注册一下
...@@ -70,4 +78,25 @@ public class AppletServiceImpl implements IAppletService { ...@@ -70,4 +78,25 @@ public class AppletServiceImpl implements IAppletService {
iWeChatUserRepository.save(wechatUserInfo); iWeChatUserRepository.save(wechatUserInfo);
return wechatUserInfo.getUserId(); return wechatUserInfo.getUserId();
} }
@Override
public LoginVo login(String appName, String openId, String utmSource) {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName);
if (null == wechatUserInfo) {
log.error("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new DataException("未找到此用户");
}
if (null == wechatUserInfo.getUserId()) {
log.error("用户未绑定到xyqb,appName:{} ,openId:{}", appName, openId);
throw new DataException("未找到此用户绑定信息");
}
User user = userService.findById(wechatUserInfo.getUserId());
LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(),
utmSource == null ? "" : utmSource, user.getId());
return loginVo;
}
} }
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