Commit 1d98ae83 authored by guangjing.gao's avatar guangjing.gao

根据用户ID或手机号或应用名称 查询微信openId

parent b441c085
package cn.quantgroup.xyqb.controller.middleoffice.wx;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.ITenantService;
......@@ -41,18 +43,23 @@ public class WxController {
if (tenantId == null) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult();
}
/* 校验租户ID */
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
wechatUserInfo = tenantService.getTenantCustomerInfo(wechatUserInfo, tenantId);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}else {
User user = userService.findById(userId);
if (user == null) {
return JsonResult.buildSuccessResult();
}
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo == null) {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(tenantCustomerInfo.getSourceOpenId());
}
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}
/**
......@@ -64,18 +71,28 @@ public class WxController {
*/
@GetMapping("/userId/{userId}/{appName}")
public JsonResult openId(@PathVariable Long userId,@PathVariable String appName, @RequestParam(required = false) Integer tenantId) {
//默认羊小咩租户
if (tenantId == null) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId,appName);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult();
}
/* 校验租户ID */
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
wechatUserInfo = tenantService.getTenantCustomerInfo(wechatUserInfo, tenantId);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}else {
User user = userService.findById(userId);
if (user == null) {
return JsonResult.buildSuccessResult();
}
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo == null) {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
return JsonResult.buildSuccessResultGeneric(tenantCustomerInfo.getSourceOpenId());
}
}
/**
......@@ -89,18 +106,23 @@ public class WxController {
if (tenantId == null) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoByPhoneNo(phoneNo);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult();
}
/* 校验租户ID */
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
wechatUserInfo = tenantService.getTenantCustomerInfo(wechatUserInfo, tenantId);
if (wechatUserInfo == null) {
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}else {
User user = userService.findByPhoneInDb(phoneNo);
if (user == null) {
return JsonResult.buildSuccessResult();
}
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo == null) {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(tenantCustomerInfo.getSourceOpenId());
}
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
}
@RequestMapping("/code/{key}/{extdata}")
......
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.model.UserBrief;
import java.util.List;
......@@ -18,7 +18,7 @@ public interface ITenantService {
UserBrief getTenantCustomerInfo(UserDetail userDetail, Integer tenantId);
WechatUserInfo getTenantCustomerInfo(WechatUserInfo wechatUserInfo, Integer tenantId);
CustomerInfoEntity getTenantCustomerInfo(User user, Integer tenantId);
/**
......
......@@ -102,12 +102,12 @@ public class TenantServiceImpl implements ITenantService {
}
@Override
public WechatUserInfo getTenantCustomerInfo(WechatUserInfo wechatUserInfo, Integer tenantId) {
public CustomerInfoEntity getTenantCustomerInfo(User user, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), wechatUserInfo.getUserId());
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), user.getId());
if (productLogin != null) {
if (!wechatUserInfo.getPhoneNo().equals(productLogin.getPhoneNo())) {
if (!user.getPhoneNo().equals(productLogin.getPhoneNo())) {
return null;
}
......@@ -115,7 +115,7 @@ public class TenantServiceImpl implements ITenantService {
if (customerInfo == null) {
return null;
}
return wechatUserInfo;
return customerInfo;
}
}
return null;
......
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