Commit b624e36f authored by 王亮's avatar 王亮

temp commit(jiguang)

parent 270835df
package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.webchat.WechatEventMsg;
import cn.quantgroup.xyqb.repository.IUserRepository;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.ApplicationListener;
import javax.annotation.Resource;
import java.util.Map;
/**
* 微信绑定关系变动。通知某系统
*/
@Slf4j
//@Component
public class NotifyWechatBindEventListener implements ApplicationListener<WechatBindEvent> {
@Resource
private RabbitTemplate wechatRabbitTemplate;
@Resource
private IUserRepository userRepository;
@Override
public void onApplicationEvent(WechatBindEvent event) {
WechatEventMsg wechatEventMsg = event.getWechatEventMsg();
if (wechatEventMsg.getUserId() == null) {
log.info("微信绑定数据,没有用户 ID 信息,openId:{}", wechatEventMsg.getOpenId());
return;
}
User user = userRepository.findByIdAndTenantId(wechatEventMsg.getUserId(),wechatEventMsg.getTenantId());
if (user == null) {
log.info("微信绑定数据,没有用户信息,openId:{},userId:{}", wechatEventMsg.getOpenId(), wechatEventMsg.getUserId());
return;
}
String uuid = user.getUuid();
Map<String, Object> msg = Maps.newHashMapWithExpectedSize(3);
msg.put("uuid", uuid);
msg.put("openId", wechatEventMsg.getOpenId());
msg.put("timestamp", event.getTimestamp());
wechatRabbitTemplate.convertAndSend(msg);
}
}
package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.model.webchat.WechatEventMsg;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;
/**
* 微信用户绑定信息创建或更新事件
*
* @author ag
*/
@Getter
@Setter
public class WechatBindEvent extends ApplicationEvent {
private WechatEventMsg wechatEventMsg;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
public WechatBindEvent(Object source) {
super(source);
}
public WechatBindEvent(Object source, WechatEventMsg wechatEventMsg) {
super(source);
this.wechatEventMsg = wechatEventMsg;
}
}
package cn.quantgroup.xyqb.event;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* user_tag表,用来监听
*/
@Component
public class WechatBindingEventListener implements ApplicationListener<UserLoginEvent> {
@Autowired
private IUserRepository userRepository;
@Autowired
private IWeChatUserRepository weChatUserRepository;
/**
* 进行用户表和微信表关联,通过手机号码和租户号
*
* @param userLoginEvent UserLoginEvent
*/
@Override
public void onApplicationEvent(UserLoginEvent userLoginEvent) {
if (userLoginEvent.getUserTag() != null) {
User user = userRepository.findByIdAndTenantId(userLoginEvent.getUserTag().getUserId(), userLoginEvent.getUserTag().getTenantId());
if (StringUtils.isNotEmpty(user.getPhoneNo())) {
List<WechatUserInfo> wechatUserInfoList = weChatUserRepository.findByPhoneNoAndTenantId(user.getPhoneNo(), user.getTenantId());
wechatUserInfoList.forEach(i -> i.setUserId(user.getId()));
weChatUserRepository.save(wechatUserInfoList);
}
}
}
}
package cn.quantgroup.xyqb.model;
import lombok.Data;
@Data
public class JiGuangRequestParam {
private String loginToken;
private String exID;
}
package cn.quantgroup.xyqb.model;
import lombok.Data;
@Data
public class JiGuangResponseParam {
/**
* 流水号,请求出错时可能为空
*/
private Long id;
/**
* 开发者自定义的 id,若请求时为空返回为空
*/
private String exID;
/**
* 返回码
*/
private Integer code;
/**
* 返回码说明
*/
private String content;
/**
* 加密后的手机号码,需用配置在极光的公钥对应的私钥解密
*/
private String phone;
}
package cn.quantgroup.xyqb.model.v2.login;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@EqualsAndHashCode(callSuper = true)
@Data
public class SMSDirectLoginParam extends BaseLoginParam{
@Size(min = 11,max = 15,message = "手机号码格式不正确")
private String phone;
@NotNull
private String token;
}
package cn.quantgroup.xyqb.remote;
import cn.quantgroup.xyqb.model.*;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(name = "jiGuangApi")
public interface JiGuangRemoteService {
@PostMapping("${user.auth.manager.Urora.properties.loginTokenVerify}")
JiGuangResponseParam webLoginTokenVerify(@RequestBody JiGuangRequestParam param);
@PostMapping("${user.auth.manager.jiguang.auth.web}")
JiGuangResponseParam h5LoginTokenVerify(@RequestBody JiGuangRequestParam param);
}
package cn.quantgroup.xyqb.remote.config;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
public class JIGuangConfiguration {
@Autowired
private Gson gson;
}
...@@ -85,6 +85,8 @@ public interface IWeChatUserRepository extends JpaRepository<WechatUserInfo, Lon ...@@ -85,6 +85,8 @@ public interface IWeChatUserRepository extends JpaRepository<WechatUserInfo, Lon
*/ */
List<WechatUserInfo> findByUserIdAndTenantId(Long userId,Integer tenantId); List<WechatUserInfo> findByUserIdAndTenantId(Long userId,Integer tenantId);
List<WechatUserInfo> findByPhoneNoAndTenantId(String phoneNo,Integer tenantId);
/** /**
* 通过unionId查询相关绑定微信记录 * 通过unionId查询相关绑定微信记录
*/ */
......
...@@ -71,6 +71,8 @@ public class SMSLoginStrategy implements LoginStrategy { ...@@ -71,6 +71,8 @@ public class SMSLoginStrategy implements LoginStrategy {
User user = userService.findByPhoneWithCache(smsLoginParam.getPhone(), sessionStruct.getTenantId()); User user = userService.findByPhoneWithCache(smsLoginParam.getPhone(), sessionStruct.getTenantId());
//需要返回用户是否首次注册
boolean register = user == null;
if (user != null && !user.getEnable()) { if (user != null && !user.getEnable()) {
log.info("用户不存在,或者已经注销,phoneNo:{}", smsLoginParam.getPhone()); log.info("用户不存在,或者已经注销,phoneNo:{}", smsLoginParam.getPhone());
throw new BizException(BizExceptionEnum.ERROR_OR_ENABLE_ERROR); throw new BizException(BizExceptionEnum.ERROR_OR_ENABLE_ERROR);
...@@ -83,10 +85,6 @@ public class SMSLoginStrategy implements LoginStrategy { ...@@ -83,10 +85,6 @@ public class SMSLoginStrategy implements LoginStrategy {
} }
// if (!wechatRelateUserIfNecessary(user, request, appId, tenantId)) {
// return JsonResult.buildErrorStateResult("登录时微信关联失败", null);
// }
if (scIsOpen) { if (scIsOpen) {
try { try {
if (!StringUtils.isEmpty(sessionStruct.getScDeviceId())) { if (!StringUtils.isEmpty(sessionStruct.getScDeviceId())) {
...@@ -121,17 +119,14 @@ public class SMSLoginStrategy implements LoginStrategy { ...@@ -121,17 +119,14 @@ public class SMSLoginStrategy implements LoginStrategy {
AuthBean authBean = sessionService.createSession(user, loginProperties, LoginType.ACCOUNTPASSWORD.ordinal(), sessionStruct.getTenantId()); AuthBean authBean = sessionService.createSession(user, loginProperties, LoginType.ACCOUNTPASSWORD.ordinal(), sessionStruct.getTenantId());
LoginBean loginBean = new LoginBean(); LoginBean loginBean = new LoginBean();
if (authBean != null) { if (authBean != null) {
authBean.setRegister(false);
loginBean.setToken(authBean.getToken()); loginBean.setToken(authBean.getToken());
loginBean.setPhoneNo(authBean.getPhoneNo()); loginBean.setPhoneNo(authBean.getPhoneNo());
loginBean.setUuid(authBean.getUuid()); loginBean.setUuid(authBean.getUuid());
loginBean.setHasPassword(authBean.isHasPassword()); loginBean.setHasPassword(authBean.isHasPassword());
loginBean.setRegister(authBean.getRegister());
loginBean.setUserId(user.getId()); loginBean.setUserId(user.getId());
loginBean.setTenantId(user.getTenantId()); loginBean.setTenantId(user.getTenantId());
} }
//TODO:register是否首次注册,逻辑有点混乱,待处理 loginBean.setRegister(register);
loginBean.setRegister(true);
lockIpv4Service.unLockPhone(smsLoginParam.getPhone()); lockIpv4Service.unLockPhone(smsLoginParam.getPhone());
return loginBean; return loginBean;
......
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