Browse Source

Merge branch 'dev_staff_transfer' into dev_temp

dev_shibei_match
sunyuchao 5 years ago
parent
commit
229eb4e434
  1. 21
      epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java
  2. 39
      epmet-auth/src/main/java/com/epmet/dto/form/GetResiWxPhoneFormDTO.java
  3. 9
      epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java
  4. 38
      epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java

21
epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java

@ -2,13 +2,11 @@ package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.LoginFormDTO;
import com.epmet.dto.form.StaffOrgsFormDTO;
import com.epmet.dto.form.ThirdStaffOrgsFormDTO;
import com.epmet.dto.form.ThirdWxmpEnteOrgFormDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.StaffOrgsResultDTO;
import com.epmet.dto.result.UserTokenResultDTO;
import com.epmet.service.ThirdLoginService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -91,4 +89,19 @@ public class ThirdLoginController {
return new Result<List<StaffOrgsResultDTO>>().ok(staffOrgs);
}
/**
* @param formDTO
* @return
* @author sun
* @description 单客户-获取微信用户手机号
**/
@PostMapping("getresiwxphone")
public Result getResiWxPhone(@RequestBody GetResiWxPhoneFormDTO formDTO) {
String phone = thirdLoginService.getResiWxPhone(formDTO);
if (StringUtils.isNotBlank(phone) && !"null".equals(phone)) {
return new Result().ok(phone);
}
return new Result().ok("");
}
}

39
epmet-auth/src/main/java/com/epmet/dto/form/GetResiWxPhoneFormDTO.java

@ -0,0 +1,39 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 单客户-获取微信用户手机号
*
* @author sun
*/
@Data
public class GetResiWxPhoneFormDTO implements Serializable {
private static final long serialVersionUID = 4381236451736209332L;
/**
* 小程序appId
*/
@NotBlank(message = "appId不能为空",groups = {AddUserInternalGroup.class})
private String appId;
/**
* 微信code
*/
@NotBlank(message = "wxCode不能为空",groups = {AddUserInternalGroup.class})
private String wxCode;
/**
* 用户信息
*/
@NotBlank(message = "encryptedData不能为空",groups = {AddUserInternalGroup.class})
private String encryptedData;
/**
* 加密算法的初始向量
*/
@NotBlank(message = "iv不能为空",groups = {AddUserInternalGroup.class})
private String iv;
public interface AddUserInternalGroup {}
}

9
epmet-auth/src/main/java/com/epmet/service/ThirdLoginService.java

@ -1,5 +1,6 @@
package com.epmet.service;
import com.epmet.dto.form.GetResiWxPhoneFormDTO;
import com.epmet.dto.form.LoginFormDTO;
import com.epmet.dto.form.ThirdStaffOrgsFormDTO;
import com.epmet.dto.form.ThirdWxmpEnteOrgFormDTO;
@ -53,4 +54,12 @@ public interface ThirdLoginService {
* @description 单客户-手机号密码获取组织
**/
List<StaffOrgsResultDTO> getMyOrgByPassword(ThirdStaffOrgsFormDTO formDTO);
/**
* @param formDTO
* @return
* @author sun
* @description 单客户-获取微信用户手机号
**/
String getResiWxPhone(GetResiWxPhoneFormDTO formDTO);
}

38
epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java

@ -1,6 +1,8 @@
package com.epmet.service.impl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epmet.common.token.constant.LoginConstant;
@ -549,4 +551,40 @@ public class ThirdLoginServiceImpl implements ThirdLoginService {
return userWechatDTO;
}
/**
* @param formDTO
* @return
* @author sun
* @description 单客户-获取微信用户手机号
* 此接口只适配第三方客户对于党群e事通客户还是走原接口
**/
@Override
public String getResiWxPhone(GetResiWxPhoneFormDTO formDTO) {
String phone = "";
try {
//1.根据wxcode获取sessionKey
WxLoginFormDTO resiLoginFormDTO = new WxLoginFormDTO();
resiLoginFormDTO.setAppId(formDTO.getAppId());
resiLoginFormDTO.setWxCode(formDTO.getWxCode());
//此方法会校验appId是否授权,然后在判断客户是否存在,之后才是获取sessionKey,如果只想获取sessionKey需要写新接口
UserWechatDTO userWechatDTO = this.getUserWeChat(resiLoginFormDTO);
if (null == userWechatDTO || null == userWechatDTO.getSessionKey()) {
logger.error(String.format("调用生成third服务wxcode获取sessionKey失败,对应appId->" + formDTO.getAppId()));
throw new RenException("获取本机号码失败");
}
//2.使用sessionKey解密获取手机号
WxMaPhoneNumberInfo phoneNoInfo = WxMaPhoneNumberInfo.fromJson(WxMaCryptUtils.decrypt(userWechatDTO.getSessionKey(),
formDTO.getEncryptedData(),
formDTO.getIv()));
if (null != phoneNoInfo) {
phone = phoneNoInfo.getPurePhoneNumber();
}
} catch (Exception e) {
e.printStackTrace();
log.error(String.format("获取用户微信绑定的手机号接口异常%s", e.getMessage()));
}
return phone;
}
}

Loading…
Cancel
Save