Commit 846d771e by guojuxing

二维码类型字典

parent cd228704
......@@ -145,6 +145,11 @@ public class UserDTO implements Serializable{
*/
private Integer markingFlag;
/**
* 微信ID
*/
private String openId;
public Integer getUserId() {
return userId;
}
......@@ -334,6 +339,15 @@ public class UserDTO implements Serializable{
this.markingFlag = markingFlag;
}
public String getOpenId() {
return openId;
}
public UserDTO setOpenId(String openId) {
this.openId = openId;
return this;
}
@Override
public String toString() {
return "UserDTO{" +
......@@ -344,7 +358,7 @@ public class UserDTO implements Serializable{
", passwordType=" + passwordType +
", confirmPassword='" + confirmPassword + '\'' +
", superAdmin=" + superAdmin +
", status=" + deleteFlag +
", deleteFlag=" + deleteFlag +
", createTime=" + createTime +
", updateTime=" + updateTime +
", enterpriseId=" + enterpriseId +
......@@ -359,6 +373,8 @@ public class UserDTO implements Serializable{
", userResourceIds='" + userResourceIds + '\'' +
", operPasswordType=" + operPasswordType +
", accountGroupIds='" + accountGroupIds + '\'' +
", markingFlag=" + markingFlag +
", openId='" + openId + '\'' +
'}';
}
}
......@@ -54,6 +54,22 @@ public interface UserApiService {
ServiceResponse<Void> updateUserPosition(Integer userId, Integer userPosition);
/**
* 修改用户微信信息
* @param userId
* @param openId
* @return
*/
ServiceResponse<Void> updateUserOpenId(Integer userId, String openId);
/**
* 获取管理员二维码url
* @param userId
* @param enterpriseId
* @return 二维码url
*/
ServiceResponse<String> getUserQrcode(Integer userId, Integer enterpriseId);
/**
* 新增超级用户
* @Title: saveAdmin

* @Description:
......
......@@ -98,6 +98,8 @@ public class TabSysUser {
*/
private Integer markingFlag;
private String openId;
public Integer getUserId() {
return userId;
}
......@@ -238,4 +240,13 @@ public class TabSysUser {
this.markingFlag = markingFlag;
return this;
}
public String getOpenId() {
return openId;
}
public TabSysUser setOpenId(String openId) {
this.openId = openId;
return this;
}
}
\ No newline at end of file
......@@ -10,9 +10,11 @@ import com.gic.auth.entity.TabAuditorProjectItemRel;
import com.gic.auth.entity.TabSysUser;
import com.gic.auth.qo.AuditorListQO;
import com.gic.auth.service.*;
import com.gic.auth.utils.qrcode.QrcodeUtils;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GlobalInfo;
import com.gic.commons.util.PageHelperUtils;
import com.gic.enterprise.constant.QrcodeTypeEnum;
import com.gic.enterprise.dto.ProjectItemDTO;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.qo.ProjectItemQO;
......@@ -119,7 +121,7 @@ public class AuditorApiServiceImpl implements AuditorApiService {
TabAuditor auditor = auditorService.getAuditor(auditorDTO.getAuditorId());
String tempQrCodeUrl = null;
if (StringUtils.isBlank(auditor.getOpenid())) {
tempQrCodeUrl = this.getTempQrCodeUrl(auditorDTO.getAuditorId());
tempQrCodeUrl = QrcodeUtils.getTempQrCodeUrl(QrcodeTypeEnum.AUDITOR.getCode(), auditorDTO.getAuditorId(), auditor.getEnterpriseId());
}
return ServiceResponse.success(tempQrCodeUrl);
}
......@@ -164,7 +166,7 @@ public class AuditorApiServiceImpl implements AuditorApiService {
auditorDTO.setAuditedGroupIdList(groupIds);
}
String codeUrl = this.getTempQrCodeUrl(auditorId);
String codeUrl = QrcodeUtils.getTempQrCodeUrl(QrcodeTypeEnum.AUDITOR.getCode(), auditorId, auditor.getEnterpriseId());
auditorDTO.setHeadUrl(codeUrl);
return ServiceResponse.success(auditorDTO);
......@@ -188,26 +190,7 @@ public class AuditorApiServiceImpl implements AuditorApiService {
@Override
public ServiceResponse<Void> receiveOpenid(String qrCodeParam, String openid) {
logger.info("二维码参数:{},openid:{}", qrCodeParam, openid);
if (StringUtils.isNotBlank(qrCodeParam) && StringUtils.isNotBlank(openid)) {
if (qrCodeParam.startsWith(AUDITOR_PRE)) {
String auditorIdStr = qrCodeParam.substring(qrCodeParam.indexOf("auditor_") + 8);
Integer auditorId = Integer.valueOf(auditorIdStr);
TabAuditor auditor = this.auditorService.getAuditor(auditorId);
if (auditor != null) {
boolean repeat = this.auditorService.validOpenidIsRepeat(auditor.getEnterpriseId(), openid, null);
if (repeat) {
logger.warn("receiveOpenid失败,商户:{}下,存在重复的openid:{}", auditor.getEnterpriseId(), openid);
} else {
AuditorDTO auditorDTO = new AuditorDTO();
auditorDTO.setAuditorId(auditorId);
auditorDTO.setOpenid(openid);
auditorDTO.setIsUse(1);
this.auditorService.update(auditorDTO);
}
}
}
}
QrcodeUtils.qrCodeCallback(qrCodeParam, openid);
return ServiceResponse.success();
}
......@@ -302,19 +285,6 @@ public class AuditorApiServiceImpl implements AuditorApiService {
return EnterpriseServiceResponse.success(EntityUtil.changeEntityByJSON(AuditorDTO.class, auditor));
}
private String getTempQrCodeUrl(Integer auditorId) {
logger.info("生成临时带参二维码 auditorId:{}", auditorId);
ServiceResponse<String> serviceResponse = weixinBaseFunService.getTemporaryQRcodeURL(config.getAppkey(), "auditor_" + auditorId, 300);
if (serviceResponse.isSuccess()) {
logger.info("临时带参二维码生成成功:{}", serviceResponse.getResult());
return serviceResponse.getResult();
} else {
logger.warn("临时带参二维码生成失败:{}", serviceResponse.getMessage());
return null;
}
// return "qrCodeUrl";
}
private AuditorDTO getAdminAuditor(Integer enterpriseId) {
TabSysUser adminUser = userService.getUserByEnterpriseId(enterpriseId);
TabAuditor auditor = auditorService.getAuditorByUserId(enterpriseId, adminUser.getUserId());
......
......@@ -11,8 +11,10 @@ import com.gic.auth.entity.*;
import com.gic.auth.qo.UserListQO;
import com.gic.auth.service.*;
import com.gic.auth.utils.ValidSplitUtils;
import com.gic.auth.utils.qrcode.QrcodeUtils;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.PageHelperUtils;
import com.gic.enterprise.constant.QrcodeTypeEnum;
import com.gic.enterprise.constants.Constants;
import com.gic.enterprise.error.ErrorCode;
import com.gic.redis.data.util.RedisUtil;
......@@ -157,6 +159,20 @@ public class UserApiServiceImpl implements UserApiService {
return ServiceResponse.success();
}
@Autowired
public ServiceResponse<Void> updateUserOpenId(Integer userId, String openId) {
UserDTO userDTO = new UserDTO();
userDTO.setUserId(userId);
userDTO.setOpenId(openId);
userService.editUser(userDTO);
return ServiceResponse.success();
}
@Autowired
public ServiceResponse<String> getUserQrcode(Integer userId, Integer enterpriseId) {
return ServiceResponse.success(QrcodeUtils.getTempQrCodeUrl(QrcodeTypeEnum.USER.getCode(), userId, enterpriseId));
}
@Override
public ServiceResponse<Integer> saveAdmin(UserDTO userDTO) {
//valid param
......
package com.gic.auth.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* Spring ApplicationContext 工具类
* @ClassName: ApplicationContextUtils

* @Description: 

* @author guojuxing

* @date 2020/11/11 10:22 AM

*/
@Component
public class ApplicationContextUtils implements ApplicationContextAware{
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ApplicationContextUtils.applicationContext = applicationContext;
}
public static <T> T getBean(String beanName) {
if (applicationContext.containsBean(beanName)) {
return (T) applicationContext.getBean(beanName);
}
return null;
}
public static <T> T getBean(Class<T> clazz) {
return applicationContext.getBean(clazz);
}
}
package com.gic.auth.utils.qrcode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.gic.auth.dto.AuditorDTO;
import com.gic.auth.entity.TabAuditor;
import com.gic.auth.service.AuditorService;
/**
* 审核员二维码回调
* @ClassName:
* @Description: 

* @author guojuxing

* @date 2021/1/5 11:09 AM

*/
@Component
public class AuditorQrcode implements IQrcode{
private static Logger logger = LogManager.getLogger(AuditorQrcode.class);
@Autowired
private AuditorService auditorService;
@Override
public void receiveOpenId(String customParams, String openid) {
Integer auditorId = Integer.valueOf(customParams);
TabAuditor auditor = this.auditorService.getAuditor(auditorId);
if (auditor != null) {
boolean repeat = this.auditorService.validOpenidIsRepeat(auditor.getEnterpriseId(), openid, null);
if (repeat) {
logger.warn("receiveOpenid失败,商户:{}下,存在重复的openid:{}", auditor.getEnterpriseId(), openid);
} else {
AuditorDTO auditorDTO = new AuditorDTO();
auditorDTO.setAuditorId(auditorId);
auditorDTO.setOpenid(openid);
auditorDTO.setIsUse(1);
this.auditorService.update(auditorDTO);
}
}
}
}
package com.gic.auth.utils.qrcode;
/**
* 二维码回调处理
* @ClassName: 

* @Description: 

* @author guojuxing

* @date 2021/1/5 11:04 AM

*/
public interface IQrcode {
/**
* 微信回调
* @param qrCodeParam
* @param openid
*/
void receiveOpenId(String qrCodeParam, String openid);
}
package com.gic.auth.utils.qrcode;
import com.gic.auth.config.Config;
import com.gic.wechat.business.api.service.fwh.WeixinBaseFunService;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.utils.ApplicationContextUtils;
import com.gic.enterprise.constant.QrcodeTypeEnum;
import com.gic.enterprise.dto.QrcodeDTO;
import com.gic.enterprise.service.QrCodeApiService;
/**
* 二维码工具
* @ClassName:
* @Description: 

* @author guojuxing

* @date 2021/1/5 2:02 PM

*/
public class QrcodeUtils {
private static Logger logger = LogManager.getLogger(QrcodeUtils.class);
/**
* 二维码回调
* @param qrCodeParam
* @param openid
*/
public static void qrCodeCallback(String qrCodeParam, String openid) {
logger.info("二维码参数:{},openid:{}", qrCodeParam, openid);
boolean isSuccess = StringUtils.isNotBlank(qrCodeParam) && StringUtils.isNotBlank(openid);
if (isSuccess) {
if (!StringUtils.isNumeric(qrCodeParam)) {
logger.info("管理员二维码回调参数有误");
return;
}
QrCodeApiService qrCodeApiService = ApplicationContextUtils.getBean("qrCodeApiService");
ServiceResponse<QrcodeDTO> qrCodeResponse = qrCodeApiService.getQrcodeDownload(Integer.parseInt(qrCodeParam));
if (qrCodeResponse.isSuccess()) {
QrcodeDTO qrcodeDTO = qrCodeResponse.getResult();
if (QrcodeTypeEnum.AUDITOR.getCode() == qrcodeDTO.getQrCodeType()) {
ApplicationContextUtils.getBean(AuditorQrcode.class).receiveOpenId(qrcodeDTO.getCustomParams(), openid);
} else if (QrcodeTypeEnum.USER.getCode() == qrcodeDTO.getQrCodeType()) {
ApplicationContextUtils.getBean(UserQrcode.class).receiveOpenId(qrcodeDTO.getCustomParams(), openid);
}
}
}
}
/**
* 获取二维码url
* @param qrCodeType
* @param serviceId
* @param enterpriseId
* @return
*/
public static String getTempQrCodeUrl(Integer qrCodeType, Integer serviceId, Integer enterpriseId) {
logger.info("获取临时二维码参数:{}-{}-{}", qrCodeType, serviceId, enterpriseId);
WeixinBaseFunService weixinBaseFunService = ApplicationContextUtils.getBean("weixinBaseFunService");
Config config = ApplicationContextUtils.getBean("config");
//保存二维码
QrCodeApiService qrCodeApiService = ApplicationContextUtils.getBean("qrCodeApiService");
QrcodeDTO qrcodeDTO = new QrcodeDTO();
qrcodeDTO.setType(1);
qrcodeDTO.setQrCodeType(qrCodeType);
qrcodeDTO.setEnterpriseId(enterpriseId);
qrcodeDTO.setCustomParams(String.valueOf(serviceId));
ServiceResponse<Integer> response = qrCodeApiService.saveQrcodeDownload(qrcodeDTO);
if (response.isSuccess()) {
//id用于回调查询使用
Integer id = response.getResult();
ServiceResponse<String> serviceResponse = weixinBaseFunService.getTemporaryQRcodeURL(config.getAppkey(), id.toString(), 300);
if (serviceResponse.isSuccess()) {
logger.info("临时带参二维码生成成功:{}", serviceResponse.getResult());
return serviceResponse.getResult();
} else {
logger.warn("临时带参二维码生成失败:{}", serviceResponse.getMessage());
return null;
}
}
return null;
}
}
package com.gic.auth.utils.qrcode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.gic.auth.service.UserApiService;
/**
* 管理员二维码回调
* @ClassName: 

* @Description: 

* @author guojuxing

* @date 2021/1/5 11:05 AM

*/
@Component
public class UserQrcode implements IQrcode{
private static Logger logger = LogManager.getLogger(UserQrcode.class);
@Autowired
private UserApiService userApiService;
@Override
public void receiveOpenId(String customParams, String openid) {
userApiService.updateUserOpenId(Integer.parseInt(customParams), openid);
}
}
......@@ -74,4 +74,6 @@
<dubbo:reference interface="com.gic.authcenter.api.service.GicDepartmentService" id="gicDepartmentService" timeout="6000" />
<dubbo:reference interface="com.gic.member.filter.api.service.CrowdWidgetApiService" id="crowdWidgetApiService" timeout="6000" />
<dubbo:reference interface="com.gic.open.api.service.EnterpriseLicenseApiService" id="enterpriseLicenseApiService" timeout="6000" />
<dubbo:reference interface="com.gic.enterprise.service.QrCodeApiService" id="qrCodeApiService" timeout="6000" />
</beans>
......@@ -19,10 +19,12 @@
<result column="account_due_date" jdbcType="TIMESTAMP" property="accountDueDate" />
<result column="user_position" jdbcType="INTEGER" property="userPosition" />
<result column="marking_flag" jdbcType="INTEGER" property="markingFlag" />
<result column="open_id" jdbcType="VARCHAR" property="openId" />
</resultMap>
<sql id="Base_Column_List">
user_id, user_name, phone_number, password, super_admin, delete_flag, create_time, update_time,
enterprise_id, phone_area_code, user_group_ids, login_type, password_type, account_type, account_due_date, user_position, marking_flag
enterprise_id, phone_area_code, user_group_ids, login_type, password_type, account_type, account_due_date, user_position, marking_flag,
open_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
......@@ -195,6 +197,9 @@
<if test="userPosition != null">
user_position = #{userPosition,jdbcType=INTEGER},
</if>
<if test="openId != null">
open_id = #{openId,jdbcType=VARCHAR},
</if>
</set>
where user_id = #{userId,jdbcType=INTEGER}
</update>
......
......@@ -9,6 +9,7 @@ import com.gic.auth.dto.UserDTO;
import com.gic.auth.dto.UserResourceDTO;
import com.gic.auth.service.*;
import com.gic.auth.web.vo.ChannelResourceVO;
import com.gic.commons.annotation.HeaderSignIgnore;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.Md5Util;
import com.gic.commons.webapi.reponse.RestResponse;
......@@ -24,6 +25,7 @@ import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.response.EnterpriseRestResponse;
import com.gic.enterprise.service.EnterpriseApiService;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.enterprise.utils.UserDetail;
import com.gic.enterprise.utils.UserDetailUtils;
import com.gic.member.config.api.service.AppletsConfigApiService;
......@@ -78,6 +80,39 @@ public class LoginController {
private static final String MENU_LOCAL_CACHE_KEY = "auth:menu:list:all";
/**
* 用户第一次登陆需要关注达摩服务号,为了获取用户的openId
* @param nationCode
* @param phoneNumber
* @param enterpriseId
* @param password
* @return
*/
@RequestMapping("get-user-qrcode")
@HeaderSignIgnore
public RestResponse getUserQrcode(String nationCode, String phoneNumber, Integer enterpriseId, String password) {
if (StringUtils.isBlank(password) || StringUtils.isBlank(phoneNumber) || enterpriseId == null) {
return EnterpriseRestResponse.failure(ErrorCode.PARAMETER_ERROR);
}
if (StringUtils.isBlank(nationCode)) {
nationCode = Constants.NATION_CODE;
}
Md5Util md5 = new Md5Util();
// password 自身作为盐值
if (password.length() != LoginController.MD5_LENGTH) {
password = md5.encrypt(password + password);
}
ServiceResponse<UserDTO> login = this.userApiService.login(nationCode, phoneNumber, enterpriseId, password);
if (login.isSuccess()) {
UserDTO userDTO = login.getResult();
if (userDTO == null) {
return EnterpriseRestResponse.failure(ErrorCode.LOGIN_ERR);
}
return ResultControllerUtils.commonResult(userApiService.getUserQrcode(userDTO.getUserId(), enterpriseId));
}
return RestResponse.success();
}
@RequestMapping("list-enterprise-by-phone")
public RestResponse listUserEnterprise(String phoneNumber, String nationCode) {
if (StringUtils.isBlank(phoneNumber)) {
......
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