Browse Source

公众号wxcodetotken接口调整

dev_shibei_match
sunyuchao 5 years ago
parent
commit
292ea6c65b
  1. 17
      epmet-auth/src/main/java/com/epmet/controller/PublicUserLoginController.java
  2. 4
      epmet-auth/src/main/java/com/epmet/dto/form/PaWxCodeFormDTO.java
  3. 5
      epmet-auth/src/main/java/com/epmet/service/impl/PublicUserLoginServiceImpl.java
  4. 12
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RegisterByAuthFormDTO.java
  5. 9
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RegisterInfoFormDTO.java
  6. 6
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SaveUserVisitedFormDTO.java
  7. 28
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/WxCodeToTokenFormDTO.java
  8. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PaUserController.java
  9. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java
  10. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java
  11. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserVisitedDao.java
  12. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserWechatDao.java
  13. 6
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PaUserService.java
  14. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PaUserWechatService.java
  15. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java
  16. 28
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserServiceImpl.java
  17. 6
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserWechatServiceImpl.java
  18. 20
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml
  19. 2
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml
  20. 1
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserVisitedDao.xml
  21. 31
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserWechatDao.xml

17
epmet-auth/src/main/java/com/epmet/controller/PublicUserLoginController.java

@ -1,6 +1,7 @@
package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.constant.Constant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
@ -12,11 +13,12 @@ import com.epmet.dto.form.PublicSendSmsCodeFormDTO;
import com.epmet.dto.form.RegisterFormDTO;
import com.epmet.dto.result.UserTokenResultDTO;
import com.epmet.service.PublicUserLoginService;
import com.netflix.ribbon.proxy.annotation.Http;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.*;
/**
* 描述一下
@ -38,8 +40,10 @@ public class PublicUserLoginController {
* @description 解析wxcode获取用户信息并生成token
**/
@PostMapping(value = "/wxcodetotoken")
public Result<UserTokenResultDTO> wxCodeToToken(@RequestBody PaWxCodeFormDTO formDTO) {
public Result<UserTokenResultDTO> wxCodeToToken(@RequestHeader("source") String source, @RequestBody PaWxCodeFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, PaWxCodeFormDTO.AddUserInternalGroup.class);
formDTO.setSource(source);
return new Result<UserTokenResultDTO>().ok(publicUserLoginService.wxCodeToToken(formDTO));
}
@ -66,8 +70,9 @@ public class PublicUserLoginController {
* @Description 公众号-手机验证码登陆
**/
@PostMapping(value = "/loginbyphone")
public Result<UserTokenResultDTO> loginByPhone(@LoginUser TokenDto tokenDTO, @RequestBody LoginByPhoneFormDTO formDTO) {
public Result<UserTokenResultDTO> loginByPhone(@RequestHeader("source") String source, @LoginUser TokenDto tokenDTO, @RequestBody LoginByPhoneFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, LoginByPhoneFormDTO.AddUserShowGroup.class, LoginByPhoneFormDTO.LoginByPhone.class);
System.out.println(source);
return new Result<UserTokenResultDTO>().ok(publicUserLoginService.loginByPhone(tokenDTO, formDTO));
}

4
epmet-auth/src/main/java/com/epmet/dto/form/PaWxCodeFormDTO.java

@ -20,4 +20,8 @@ public class PaWxCodeFormDTO implements Serializable {
*/
@NotBlank(message = "wxCode不能为空",groups = {AddUserInternalGroup.class})
private String wxCode;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

5
epmet-auth/src/main/java/com/epmet/service/impl/PublicUserLoginServiceImpl.java

@ -70,10 +70,13 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService {
public UserTokenResultDTO wxCodeToToken(PaWxCodeFormDTO formDTO) {
//1.通过微信code获取用户基本信息
WxMpUser wxMpUser = this.getWxMpUser(formDTO.getWxCode());
WxCodeToTokenFormDTO dto = new WxCodeToTokenFormDTO();
dto.setWxMpUser(wxMpUser);
dto.setSource(formDTO.getSource());
//2.将获取的用户基本信息初始化到数据库
String url = ThirdApiConstant.THIRD_PAUSER_SAVEUSER;
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(wxMpUser));
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(dto));
if (!result.success()) {
throw new RenException(PublicUserLoginConstant.SAVE_USER_EXCEPTION);
}

12
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RegisterByAuthFormDTO.java

@ -1,7 +1,9 @@
package com.epmet.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
@ -12,10 +14,20 @@ import java.io.Serializable;
public class RegisterByAuthFormDTO implements Serializable {
private static final long serialVersionUID = -6547893374373422628L;
public interface AddUserInternalGroup {
}
public interface AddUserShowGroup extends CustomerClientShowGroup {
}
/**
* 初始化状态0:已初始化1:未初始化
* */
private Integer initState;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
@NotBlank(message = "数据来源不能为空", groups = {RegisterByAuthFormDTO.AddUserInternalGroup.class, RegisterByAuthFormDTO.AddUserShowGroup.class})
private String source;
}

9
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/RegisterInfoFormDTO.java

@ -1,5 +1,6 @@
package com.epmet.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.Min;
@ -17,6 +18,8 @@ public class RegisterInfoFormDTO implements Serializable {
public interface AddUserInternalGroup {
}
public interface AddUserShowGroup extends CustomerClientShowGroup {
}
/**
* 当前页
@ -29,4 +32,10 @@ public class RegisterInfoFormDTO implements Serializable {
* */
private Integer pageSize = 20;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
@NotBlank(message = "数据来源不能为空", groups = {RegisterInfoFormDTO.AddUserInternalGroup.class, RegisterInfoFormDTO.AddUserShowGroup.class})
private String source;
}

6
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SaveUserVisitedFormDTO.java

@ -31,4 +31,10 @@ public class SaveUserVisitedFormDTO implements Serializable {
*/
private String phone;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

28
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/WxCodeToTokenFormDTO.java

@ -0,0 +1,28 @@
package com.epmet.dto.form;
import lombok.Data;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import java.io.Serializable;
import java.util.Date;
/**
* 公众号-wxcode换取token保存微信用户信息-接口入参
* @Author sun
*/
@Data
public class WxCodeToTokenFormDTO implements Serializable {
private static final long serialVersionUID = -6163303184086480522L;
/**
* 微信用户信息
*/
private WxMpUser wxMpUser;
/**
* 数据来源(dev:开发 test:体验 prod:生产)
*/
private String source;
}

10
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/PaUserController.java

@ -23,14 +23,14 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.WxCodeToTokenFormDTO;
import com.epmet.dto.result.CustomerUserResultDTO;
import com.epmet.dto.result.SaveUserResultDTO;
import com.epmet.excel.PaUserExcel;
import com.epmet.service.PaUserService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -95,14 +95,14 @@ public class PaUserController {
}
/**
* @param wxMpUser
* @param formDTO
* @return
* @Author sun
* @Description 根据openId新增或更新用户信息
**/
@PostMapping(value = "/saveuser")
public Result<SaveUserResultDTO> saveUser(@RequestBody WxMpUser wxMpUser) {
return new Result<SaveUserResultDTO>().ok(paUserService.saveUser(wxMpUser));
public Result<SaveUserResultDTO> saveUser(@RequestBody WxCodeToTokenFormDTO formDTO) {
return new Result<SaveUserResultDTO>().ok(paUserService.saveUser(formDTO));
}
/**

4
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java

@ -49,9 +49,9 @@ public interface CustomerMpDao extends BaseDao<CustomerMpEntity> {
* @param
* @return
* @Author sun
* @Description 查询所有客户小程序的授权信息
* @Description 根据数据来源查询所有客户小程序的授权信息
**/
List<CustomerMpDTO> selectAll();
List<CustomerMpDTO> selectAll(@Param("source")String source);
/**
* @Description 查询授权的数量

4
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaCustomerDao.java

@ -49,9 +49,9 @@ public interface PaCustomerDao extends BaseDao<PaCustomerEntity> {
* @param
* @return
* @Author sun
* @Description 查询公众号注册的客户信息列表
* @Description 根据数据来源查询公众号注册的客户信息列表
**/
List<CustomerAgencyResultDTO> registerInfo();
List<CustomerAgencyResultDTO> registerInfo(@Param("source") String source);
/**
* @param dto

4
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserVisitedDao.java

@ -36,7 +36,7 @@ public interface PaUserVisitedDao extends BaseDao<PaUserVisitedEntity> {
* @param openId
* @return
* @Author sun
* @Description 根据openId查询登陆访问记录数据按时间倒序
* @Description 根据数据来源和openId查询登陆访问记录数据按时间倒序
**/
PaUserVisitedDTO selectByOpenId(@Param("openId") String openId);
PaUserVisitedDTO selectByOpenId(@Param("openId") String openId, @Param("source") String source);
}

4
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserWechatDao.java

@ -38,9 +38,9 @@ public interface PaUserWechatDao extends BaseDao<PaUserWechatEntity> {
* @param openId
* @return
* @Author sun
* @Description 根据openId查询user_wechat表信息
* @Description 根据数据来源和openId查询user_wechat表信息
**/
List<PaUserWechatDTO> selectWechatByOpenId(@Param("openId") String openId);
List<PaUserWechatDTO> selectWechatByOpenId(@Param("openId") String openId, @Param("source") String source);
/**
* @param dto

6
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PaUserService.java

@ -20,10 +20,10 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.WxCodeToTokenFormDTO;
import com.epmet.dto.result.CustomerUserResultDTO;
import com.epmet.dto.result.SaveUserResultDTO;
import com.epmet.entity.PaUserEntity;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import java.util.List;
import java.util.Map;
@ -97,12 +97,12 @@ public interface PaUserService extends BaseService<PaUserEntity> {
void delete(String[] ids);
/**
* @param wxMpUser
* @param formDTO
* @return
* @Author sun
* @Description 根据openId新增或更新用户信息
**/
SaveUserResultDTO saveUser(WxMpUser wxMpUser);
SaveUserResultDTO saveUser(WxCodeToTokenFormDTO formDTO);
/**
* @param phone

4
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/PaUserWechatService.java

@ -97,7 +97,7 @@ public interface PaUserWechatService extends BaseService<PaUserWechatEntity> {
* @param openId
* @return
* @Author sun
* @Description 根据openId查询user_wechat表信息
* @Description 根据数据来源和openId查询user_wechat表信息
**/
List<PaUserWechatDTO> getWechatByOpenId(String openId);
List<PaUserWechatDTO> getWechatByOpenId(String openId, String source);
}

4
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java

@ -408,9 +408,9 @@ public class PaCustomerServiceImpl extends BaseServiceImpl<PaCustomerDao, PaCust
//分页参数
PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize());
//1.查询客户组织信息
List<CustomerAgencyResultDTO> list = baseDao.registerInfo();
List<CustomerAgencyResultDTO> list = baseDao.registerInfo(formDTO.getSource());
//2.查询客户小程序授权信息
List<CustomerMpDTO> mpList = customerMpDao.selectAll();
List<CustomerMpDTO> mpList = customerMpDao.selectAll(formDTO.getSource());
//3.封装数据
list.forEach(l -> {
mpList.forEach(mp -> {

28
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserServiceImpl.java

@ -34,12 +34,15 @@ import com.epmet.dto.PaCustomerDTO;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.PaUserVisitedDTO;
import com.epmet.dto.PaUserWechatDTO;
import com.epmet.dto.form.SaveUserVisitedFormDTO;
import com.epmet.dto.form.WxCodeToTokenFormDTO;
import com.epmet.dto.result.CustomerUserResultDTO;
import com.epmet.dto.result.SaveUserResultDTO;
import com.epmet.entity.PaUserEntity;
import com.epmet.entity.PaUserWechatEntity;
import com.epmet.redis.PaUserRedis;
import com.epmet.service.PaUserService;
import com.epmet.service.PaUserVisitedService;
import com.epmet.service.PaUserWechatService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.commons.lang3.StringUtils;
@ -72,6 +75,8 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity>
private PaUserWechatDao paUserWechatDao;
@Autowired
private PaUserVisitedDao paUserVisitedDao;
@Autowired
private PaUserVisitedService paUserVisitedService;
@Override
public PageData<PaUserDTO> page(Map<String, Object> params) {
@ -126,22 +131,24 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity>
}
/**
* @param wxMpUser
* @param formDTO
* @return
* @Author sun
* @Description 根据openId新增或更新用户信息
**/
@Override
@Transactional(rollbackFor = Exception.class)
public SaveUserResultDTO saveUser(WxMpUser wxMpUser) {
public SaveUserResultDTO saveUser(WxCodeToTokenFormDTO formDTO) {
WxMpUser wxMpUser = formDTO.getWxMpUser();
SaveUserResultDTO resultDTO = new SaveUserResultDTO();
//1.根据openId查询user_wechat表是否存在用户信息(user表和user_wechat表数据多对多关系)
List<PaUserWechatDTO> wechatDTO = paUserWechatService.getWechatByOpenId(wxMpUser.getOpenId());
//1.根据openId查询user_wechat表是否存在用户信息(user表和user_wechat表数据多对多关系)
List<PaUserWechatDTO> wechatDTO = paUserWechatService.getWechatByOpenId(wxMpUser.getOpenId(), formDTO.getSource());
//2.不存在则新增用户信息,存在则更新user_wechat表信息
if (null == wechatDTO || wechatDTO.size() < NumConstant.ONE) {
//2.1、user表新增数据
PaUserEntity userEntity = new PaUserEntity();
userEntity.setSource(formDTO.getSource());
baseDao.insert(userEntity);
//2.2、user_wechat表新增数据
PaUserWechatEntity wechatEntity = new PaUserWechatEntity();
@ -157,9 +164,16 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity>
wechatEntity.setLanguage(null == wxMpUser.getLanguage() ? "" : wxMpUser.getLanguage());
paUserWechatService.insert(wechatEntity);
//2.3、pa_user_visited表新增访问记录数据
SaveUserVisitedFormDTO visited = new SaveUserVisitedFormDTO();
visited.setUserId(userEntity.getId());
visited.setLogonUserId(userEntity.getId());
visited.setSource(formDTO.getSource());
paUserVisitedService.saveUserVisited(visited);
resultDTO.setUserId(userEntity.getId());
} else {
//2.3、批量更新user_wechat表数据
//2.4、批量更新user_wechat表数据
List<PaUserWechatEntity> wechatEntity = ConvertUtils.sourceToTarget(wechatDTO, PaUserWechatEntity.class);
for(PaUserWechatEntity entity : wechatEntity){
entity.setGender(wxMpUser.getSex().toString());
@ -172,8 +186,8 @@ public class PaUserServiceImpl extends BaseServiceImpl<PaUserDao, PaUserEntity>
}
paUserWechatService.updateBatchById(wechatEntity);
//2.4、根据openid查询用户登陆访问记录表数据,按登陆时间倒序
PaUserVisitedDTO visitedDTO = paUserVisitedDao.selectByOpenId(wxMpUser.getOpenId());
//2.5、根据openid查询用户登陆访问记录表数据,按登陆时间倒序
PaUserVisitedDTO visitedDTO = paUserVisitedDao.selectByOpenId(wxMpUser.getOpenId(), formDTO.getSource());
if (null == visitedDTO || "".equals(visitedDTO.getUserId())) {
logger.error("根据openid查询用户访问记录表数据失败,openid->"+wxMpUser.getOpenId());
throw new RenException(PaConstant.SELECT_VISITED_EXCEPTION);

6
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaUserWechatServiceImpl.java

@ -105,11 +105,11 @@ public class PaUserWechatServiceImpl extends BaseServiceImpl<PaUserWechatDao, Pa
* @param openId
* @return
* @Author sun
* @Description 根据openId查询user_wechat表信息
* @Description 根据数据来源和openId查询user_wechat表信息
**/
@Override
public List<PaUserWechatDTO> getWechatByOpenId(String openId) {
return baseDao.selectWechatByOpenId(openId);
public List<PaUserWechatDTO> getWechatByOpenId(String openId, String source) {
return baseDao.selectWechatByOpenId(openId, source);
}
}

20
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml

@ -61,17 +61,21 @@
<select id="selectAll" resultType="com.epmet.dto.CustomerMpDTO">
SELECT
id,
customer_id,
client,
app_id,
authorization_flag
cm.id,
cm.customer_id,
cm.client,
cm.app_id,
cm.authorization_flag
FROM
customer_mp
customer_mp cm
INNER JOIN pa_customer pc ON cm.customer_id = pc.id
WHERE
del_flag = '0'
cm.del_flag = '0'
AND pc.del_flag = '0'
AND pc.source = '#{source}'
ORDER BY
customer_id ASC, client ASC
cm.customer_id ASC,
cm.client ASC
</select>
<select id="selectAuthFlag" resultType="java.lang.Boolean">
SELECT

2
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaCustomerDao.xml

@ -52,6 +52,7 @@
WHERE
pca.del_flag = '0'
AND pc.del_flag = '0'
AND pc.source = #{source}
ORDER BY
pca.CREATED_TIME DESC
</select>
@ -64,6 +65,7 @@
pa_customer
WHERE
del_flag = '0'
AND source = #{source}
<if test='null != initState and "" != initState'>
AND is_initialize = #{initState}
</if>

1
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserVisitedDao.xml

@ -14,6 +14,7 @@
pa_user_visited
WHERE
del_flag = '0'
AND source = #{source}
AND wx_open_id = #{openId}
ORDER BY
created_time DESC

31
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserWechatDao.xml

@ -5,22 +5,25 @@
<select id="selectWechatByOpenId" resultType="com.epmet.dto.PaUserWechatDTO">
SELECT
id,
user_id,
wx_open_id,
union_id,
gender,
nickname,
head_img_url,
country,
province,
city,
`language`
puw.id,
puw.user_id,
puw.wx_open_id,
puw.union_id,
puw.gender,
puw.nickname,
puw.head_img_url,
puw.country,
puw.province,
puw.city,
puw.`language`
FROM
pa_user_wechat
pa_user_wechat puw
INNER JOIN pa_user pu ON puw.user_id = pu.id
WHERE
del_flag = '0'
AND wx_open_id = #{openId}
puw.del_flag = '0'
AND pu.del_flag = '0'
AND pu.source = #{source}
AND puw.wx_open_id = #{openId}
</select>
<select id="selectWechatByUserId" resultType="com.epmet.entity.PaUserWechatEntity">

Loading…
Cancel
Save