提交 bccdcdc4 authored 作者: 李秋林's avatar 李秋林

微信促销员注册、查询

上级 cd58cc54
package com.wangxiaolu.promotion.controller.wechat; package com.wangxiaolu.promotion.controller.wechat;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo; import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo;
import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService; import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -29,11 +28,7 @@ public class WeChatUserCoreController { ...@@ -29,11 +28,7 @@ public class WeChatUserCoreController {
*/ */
@PostMapping("/temporary/enroll") @PostMapping("/temporary/enroll")
public boolean enrollUserInfo(@RequestBody @Validated WxJsUserInfoVo wxJsUserInfoVo) { public boolean enrollUserInfo(@RequestBody @Validated WxJsUserInfoVo wxJsUserInfoVo) {
System.out.println("=============== controller-WxJsUserInfoVo ==============="); return weChatUserCoreService.saveWxUserInfoTemporary(wxJsUserInfoVo);
System.out.println(JSONObject.toJSONString(wxJsUserInfoVo));
weChatUserCoreService.saveWxUserInfoTemporary(wxJsUserInfoVo);
return true;
} }
} }
package com.wangxiaolu.promotion.controller.wechat; package com.wangxiaolu.promotion.controller.wechat;
import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService;
import com.wangxiaolu.promotion.utils.WxMaUtils; import com.wangxiaolu.promotion.utils.WxMaUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -18,7 +19,10 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -18,7 +19,10 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/user/wechat/query") @RequestMapping("/user/wechat/query")
public class WeChatUserQueryController { public class WeChatUserQueryController {
@Autowired @Autowired
WxMaUtils wxMaUtils; private WxMaUtils wxMaUtils;
@Autowired
private WeChatUserQueryService weChatUserQueryService;
/** /**
* 接收wx临时登录凭证code,查询openid是否已注册 * 接收wx临时登录凭证code,查询openid是否已注册
...@@ -30,8 +34,8 @@ public class WeChatUserQueryController { ...@@ -30,8 +34,8 @@ public class WeChatUserQueryController {
return null; return null;
} }
String userOpenId = wxMaUtils.getWxOpenId(jsCode); String userOpenId = wxMaUtils.getWxOpenId(jsCode);
System.out.println("根据userOpenId查询用户是否存在:" + userOpenId); // String userOpenId = "openid111";
return true; return weChatUserQueryService.queryTemporaryByOpenId(userOpenId);
} }
......
package com.wangxiaolu.promotion.domain.user.dao;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
/**
* @author : liqiulin
* @date : 2024-04-08 16
* @describe :促销员-信息
*/
public interface TemporaryInfoDao {
/**
* 微信-小程序注册的促销员信息
*/
int saveWxTemporaryInfo(WxTemporaryInfoDto temporaryDto);
/**
* 根据OpenId查询人员是否已注册
*/
Boolean existTemporaryByOpenId(String openId);
}
package com.wangxiaolu.promotion.domain.user.dao;
/**
* @author : liqiulin
* @date : 2024-04-08 16
* @describe :微信-促销员-信息
*/
public interface WxTemporaryInfoDao {
void saveTemporaryInfo();
}
package com.wangxiaolu.promotion.domain.user.dao.impl;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
import com.wangxiaolu.promotion.domain.user.mapper.TemporaryInfoMapper;
import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO;
import com.wangxiaolu.promotion.domain.user.wrapper.TemporaryWrapper;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author : liqiulin
* @date : 2024-04-08 16
* @describe :促销员-信息
*/
@Service
public class TemporaryInfoDaoImpl implements TemporaryInfoDao {
@Autowired
TemporaryInfoMapper temporaryInfoMapper;
/**
* 微信-小程序注册的促销员信息
*/
@Override
public int saveWxTemporaryInfo(WxTemporaryInfoDto temporaryDto) {
TemporaryInfoDO entity = new TemporaryInfoDO();
BeanUtils.copyProperties(temporaryDto, entity);
return temporaryInfoMapper.insert(entity);
}
@Override
public Boolean existTemporaryByOpenId(String openId) {
TemporaryWrapper tw = new TemporaryWrapper().setOpenId(openId);
LambdaQueryWrapper qw = buildQueryList(tw);
Integer count = temporaryInfoMapper.selectCount(qw);
return count > 0;
}
private LambdaQueryWrapper buildQueryList(TemporaryWrapper tw){
LambdaQueryWrapper<TemporaryInfoDO> queryWrapper = new LambdaQueryWrapper<>();
if (!StringUtils.isEmpty(tw.getOpenId())){
queryWrapper.eq(TemporaryInfoDO::getOpenId,tw.getOpenId());
}
return queryWrapper;
}
}
package com.wangxiaolu.promotion.domain.user.dao.impl;
import com.wangxiaolu.promotion.domain.user.dao.WxTemporaryInfoDao;
import org.springframework.stereotype.Service;
/**
* @author : liqiulin
* @date : 2024-04-08 16
* @describe :
*/
@Service
public class WxTemporaryInfoDaoImpl implements WxTemporaryInfoDao {
@Override
public void saveTemporaryInfo() {
}
}
package com.wangxiaolu.promotion.domain.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
/**
* @author a02200059
* @description 针对表【temporary_info】的数据库操作Mapper
* @createDate 2024-04-09 18:34:54
* @Entity com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfo
*/
@Mapper
@Repository
public interface TemporaryInfoMapper extends BaseMapper<TemporaryInfoDO> {
}
package com.wangxiaolu.promotion.domain.user.mapper.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName temporary_info
*/
@Data
@TableName(value ="temporary_info")
public class TemporaryInfoDO implements Serializable {
/**
* 主键id
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 姓名
*/
private String name;
/**
* 手机号
*/
private String phone;
/**
* 身份证号码
*/
private String idenNumber;
/**
* 微信openId
*/
private String openId;
/**
* 头像url
*/
private String avatarUrl;
/**
* 头像云存储id
*/
private String avatarUrlFieldId;
/**
* 身份证正面url
*/
private String idenFrontPhotoUrl;
/**
* 身份证正面云存储id
*/
private String idenFrontPhotoFieldId;
/**
* 身份证反面url
*/
private String idenReversePhotoUrl;
/**
* 身份证反面云存储id
*/
private String idenReversePhotoFieldId;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date modifyTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.wangxiaolu.promotion.domain.user.wrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* @author : liqiulin
* @date : 2024-04-09 18
* @describe :
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class TemporaryWrapper {
/**
* openId
*/
String openId;
}
...@@ -45,7 +45,7 @@ public class WxTemporaryInfoDto { ...@@ -45,7 +45,7 @@ public class WxTemporaryInfoDto {
/** /**
* 身份证号 * 身份证号
*/ */
String idenNmber; String idenNumber;
/** /**
* 身份证正面照 * 身份证正面照
......
...@@ -67,7 +67,7 @@ public class WxJsUserInfoVo { ...@@ -67,7 +67,7 @@ public class WxJsUserInfoVo {
* 身份证号 * 身份证号
*/ */
@NotBlank(message = "身份证号不可为空") @NotBlank(message = "身份证号不可为空")
String idenNmber; String idenNumber;
/** /**
* 身份证正面照 * 身份证正面照
......
...@@ -12,5 +12,5 @@ public interface WeChatUserCoreService { ...@@ -12,5 +12,5 @@ public interface WeChatUserCoreService {
/** /**
* 保存促销员用户信息 * 保存促销员用户信息
*/ */
void saveWxUserInfoTemporary(WxJsUserInfoVo wxJsUserInfoVo); boolean saveWxUserInfoTemporary(WxJsUserInfoVo wxJsUserInfoVo);
} }
package com.wangxiaolu.promotion.service.wechat;
import org.springframework.stereotype.Service;
/**
* @author : liqiulin
* @date : 2024-04-09 18
* @describe :微信人员信息查询
*/
public interface WeChatUserQueryService {
Boolean queryTemporaryByOpenId(String userOpenId);
}
package com.wangxiaolu.promotion.service.wechat.impl; package com.wangxiaolu.promotion.service.wechat.impl;
import com.alibaba.fastjson.JSONObject; import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo; import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo;
import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService; import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -14,18 +15,17 @@ import org.springframework.stereotype.Service; ...@@ -14,18 +15,17 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class WeChatUserCoreServiceImpl implements WeChatUserCoreService { public class WeChatUserCoreServiceImpl implements WeChatUserCoreService {
@Autowired
TemporaryInfoDao temporaryInfoDao;
/** /**
* 保存促销员用户信息 * 保存促销员用户信息
*/ */
@Override @Override
public void saveWxUserInfoTemporary(WxJsUserInfoVo wxJsUserInfoVo) { public boolean saveWxUserInfoTemporary(WxJsUserInfoVo wxJsUserInfoVo) {
WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto(); WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto();
BeanUtils.copyProperties(wxJsUserInfoVo, temporaryDto); BeanUtils.copyProperties(wxJsUserInfoVo, temporaryDto);
int saveId = temporaryInfoDao.saveWxTemporaryInfo(temporaryDto);
System.out.println("=============== impl-WxTemporaryInfoDto ==============="); return saveId > 0;
System.out.println(JSONObject.toJSONString(temporaryDto));
} }
} }
package com.wangxiaolu.promotion.service.wechat.impl;
import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author : liqiulin
* @date : 2024-04-09 18
* @describe :微信人员信息查询
*/
@Service
public class WeChatUserQueryServiceImpl implements WeChatUserQueryService {
@Autowired
TemporaryInfoDao temporaryInfoDao;
@Override
public Boolean queryTemporaryByOpenId(String userOpenId) {
Boolean exist = temporaryInfoDao.existTemporaryByOpenId(userOpenId);
return exist;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wangxiaolu.promotion.domain.user.mapper.TemporaryInfoMapper">
<resultMap id="BaseResultMap" type="com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="phone" column="phone" jdbcType="CHAR"/>
<result property="idenNumber" column="iden_number" jdbcType="CHAR"/>
<result property="openId" column="open_id" jdbcType="VARCHAR"/>
<result property="avatarUrl" column="avatar_url" jdbcType="VARCHAR"/>
<result property="avatarUrlFieldId" column="avatar_url_field_id" jdbcType="VARCHAR"/>
<result property="idenFrontPhotoUrl" column="iden_front_photo_url" jdbcType="VARCHAR"/>
<result property="idenFrontPhotoFieldId" column="iden_front_photo_field_id" jdbcType="VARCHAR"/>
<result property="idenReversePhotoUrl" column="iden_reverse_photo_url" jdbcType="VARCHAR"/>
<result property="idenReversePhotoFieldId" column="iden_reverse_photo_field_id" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="modifyTime" column="modify_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,name,phone,
iden_number,open_id,avatar_url,
avatar_url_field_id,iden_front_photo_url,iden_front_photo_field_id,
iden_reverse_photo_url,iden_reverse_photo_field_id,create_time,
modify_time
</sql>
</mapper>
package com.wangxiaolu.promotion.controller.wechat; package com.wangxiaolu.promotion.controller.wechat;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo; import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -20,20 +21,32 @@ class WeChatUserCoreControllerTest { ...@@ -20,20 +21,32 @@ class WeChatUserCoreControllerTest {
@Autowired @Autowired
WeChatUserCoreController weChatUserCoreController; WeChatUserCoreController weChatUserCoreController;
@Autowired
WeChatUserQueryController weChatUserQueryController;
@Test @Test
void enrollUserInfo() { void enrollUserInfo() {
WxJsUserInfoVo vo = new WxJsUserInfoVo() WxJsUserInfoVo vo = new WxJsUserInfoVo()
.setJsCode("js传过来的临时登录code")
.setEncryptedData("用户信息的加密文字")
.setIv("标识iv")
.setOpenId("openid111") .setOpenId("openid111")
.setAvatarUrl("头像") .setAvatarUrl("头像Url")
.setName("姓名") .setName("姓名")
.setPhone("手机号") .setPhone("手机号")
.setIdenNmber("身份证号") .setAvatarUrlFieldId("avatarUrlFieldId")
.setAddress("地址111") .setIdenNumber("身份证号")
.setIdenFrontPhotoUrl("身份证正面照")
.setIdenFrontPhotoFieldId("身份证正面照Id")
.setIdenReversePhotoUrl("身份证反面照")
.setIdenReversePhotoFieldId("身份证反面照Id")
.setPhoneCode("手机验证码")
; ;
System.out.println(JSONObject.toJSONString(vo));
weChatUserCoreController.enrollUserInfo(vo); weChatUserCoreController.enrollUserInfo(vo);
} }
@Test
void getOpenIdByWxcode() {
Boolean openIdByWxcode = weChatUserQueryController.getOpenIdByWxcode("111");
System.out.println(openIdByWxcode);
}
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论