南网oss登录接口修改
This commit is contained in:
parent
79ce2d3ce2
commit
bbdbfa8bb5
|
|
@ -143,7 +143,7 @@ public class TokenController {
|
|||
}
|
||||
|
||||
|
||||
@ApiOperation("南网注册")
|
||||
@ApiOperation("用户中心注册")
|
||||
@PostMapping("/registers")
|
||||
public AjaxResult addNw(HttpServletRequest request, @RequestBody RegisterForms registerForms) {
|
||||
AccountRegister accountRegister = new AccountRegister();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 南网注册登陆 基类
|
||||
* @author caoxianfei
|
||||
* @Version 1.0
|
||||
* @date 2021-08-13 0:38
|
||||
*/
|
||||
@Data
|
||||
public class BaseLoginEntity {
|
||||
private String token;
|
||||
private String appId;
|
||||
private String appSecret;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class CloudUserVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty(name = "userId",value = "用户id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户姓名
|
||||
*/
|
||||
@ApiModelProperty(name = "userName",value = "用户姓名")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ApiModelProperty(name = "userAccount",value = "用户账号")
|
||||
private String userAccount;
|
||||
|
||||
/**
|
||||
* 是否原有用户
|
||||
*/
|
||||
@ApiModelProperty(name = "isOriginalUser",value = "是否原有用户")
|
||||
private Integer isOriginalUser;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel(description = "平台用户")
|
||||
public class LbcloudUserVo {
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
*/
|
||||
@ApiModelProperty(value = "应用id")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
@ApiModelProperty(value = "用户账号")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@ApiModelProperty(value = "手机号码")
|
||||
private String mobilePhone;
|
||||
|
||||
/**
|
||||
* 用户id集合
|
||||
*/
|
||||
@ApiModelProperty(value = "用户id集合")
|
||||
private List<String> userIds = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -12,12 +12,6 @@ import lombok.Data;
|
|||
@Data
|
||||
public class NwApp {
|
||||
|
||||
/* PC(1, NwLoginConstants.appId, NwLoginConstants.appsecret),
|
||||
H5(2, NwLoginConstants.h5AppId, NwLoginConstants.h5Appsecret),
|
||||
WECHAT(3, NwLoginConstants.wechatAppId, NwLoginConstants.wechatAppsecret),
|
||||
APP(4, NwLoginConstants.appAppId, NwLoginConstants.appAppsecret)
|
||||
;*/
|
||||
|
||||
private Integer code;
|
||||
private String appId;
|
||||
private String appsecret;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class NwLoginConstants {
|
||||
|
||||
public final static int ZERO = 0;
|
||||
|
||||
public final static int ONE = 1;
|
||||
public final static int TWO = 2;
|
||||
public final static int THREE = 3;
|
||||
public final static int FOUR = 4;
|
||||
/**
|
||||
* 授权回调地址
|
||||
*/
|
||||
|
|
@ -21,6 +27,8 @@ public class NwLoginConstants {
|
|||
public static final String CODE = "code";
|
||||
|
||||
public static final String DATA = "data";
|
||||
|
||||
public static final String REGISTERED = "REGISTERED";
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
|
|
@ -40,6 +48,9 @@ public class NwLoginConstants {
|
|||
|
||||
public static final String IP_NULL_MSG = "IP地址为空";
|
||||
|
||||
public static final String USER_NAME_EXISTS_CODE = "33-019";
|
||||
public static final String USER_NAME_EXISTS_MSG = "用户名已存在,请重新输入";
|
||||
|
||||
public static final String PARAM_IS_NULL_ERROR_CODE = "0-0001";
|
||||
|
||||
public static final String PARAM_IS_NULL_ERROR_CODE_MSG = "参数为空:%s";
|
||||
|
|
@ -58,7 +69,14 @@ public class NwLoginConstants {
|
|||
|
||||
public static final String AGAIN_PASSWORD_NOT_NULL_CODE = "33-018";
|
||||
public static final String AGAIN_PASSWORD_NOT_NULL_MSG = "确认密码不能为空";
|
||||
|
||||
public static final String CHECK_MOBILEPHONECODE_WRONG_ERROR_CODE = "31-002";
|
||||
public static final String CHECK_MOBILEPHONECODE_WRONG_ERROR_CODE_MSG = "短信验证码错误";
|
||||
|
||||
public static final Long PLATFORM_ID = 20L;
|
||||
|
||||
public static final String REGISTERIP_SUCCESS = "注册成功";
|
||||
public static final String REGISTERIP_FAIL = "注册失败";
|
||||
/**
|
||||
* 授权范围
|
||||
*/
|
||||
|
|
@ -68,6 +86,88 @@ public class NwLoginConstants {
|
|||
|
||||
public static final String HTTP_RESPONSE_CODE_200 = "200";
|
||||
|
||||
/**
|
||||
* 南网 ExternalId
|
||||
*/
|
||||
public static final String USER_LBCLOUD_EXTERNA_ID = "userId";
|
||||
|
||||
public static final String USER_EXTERNAL_ID = "userId";
|
||||
|
||||
/**
|
||||
* 脱敏参数
|
||||
*/
|
||||
public static final String CACEL_DESENSITIZATION = "cancelDesensitization";
|
||||
|
||||
/**
|
||||
* 状态值
|
||||
*/
|
||||
public static final String TRUE = "true";
|
||||
|
||||
public static final String LBCLOUD_ACCESS_KEY = "X-LBCloud-Access-Key";
|
||||
|
||||
public static final String CONCAT_ACCESS_KEY = "Client ";
|
||||
|
||||
public static final String CONCAT_SIGN_WORD = ":";
|
||||
|
||||
public static final String HTTP_ERQUEST_FAILED_CODE = "33-036";
|
||||
public static final String HTTP_ERQUEST_FAILED_MSG = "Http远程请求错误";
|
||||
|
||||
public static final String USER_DATA_QUERY_FAILED_MSG = "南网用户信息获取失败";
|
||||
/**
|
||||
* 返回数据
|
||||
*/
|
||||
public static final String USER_RECORDS = "records";
|
||||
|
||||
/**
|
||||
* 南网id
|
||||
*/
|
||||
public static final String USER_LBCLOUD_ID = "id";
|
||||
|
||||
/**
|
||||
* 用户姓名
|
||||
*/
|
||||
public static final String USER_LBCLOUD_NAME = "userName";
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
public static final String USER_LBCLOUD_ACCOUNT = "userAccount";
|
||||
|
||||
//用户注册 手机号注册
|
||||
public static String registerPhone;
|
||||
|
||||
//短信验证码校验
|
||||
public static String verifyPhoneCode;
|
||||
|
||||
@Value("${verifyPhoneCode}")
|
||||
public void setVerifyPhoneCode(String verifyPhoneCode) {
|
||||
NwLoginConstants.verifyPhoneCode = verifyPhoneCode;
|
||||
}
|
||||
|
||||
// 绑定默认系统角色
|
||||
public static String userBindUrl;
|
||||
|
||||
@Value("${userBindUrl}")
|
||||
public void setUserBindUrl(String userBindUrl) {
|
||||
NwLoginConstants.userBindUrl = userBindUrl;
|
||||
}
|
||||
|
||||
@Value("${registerPhone}")
|
||||
public void setRegisterPhone(String registerPhone) {
|
||||
NwLoginConstants.registerPhone = registerPhone;
|
||||
}
|
||||
|
||||
//用户列表查询(简单信息)
|
||||
public static String personEasyList;
|
||||
|
||||
@Value("${getPersonDetailData}")
|
||||
public void setGetPersonDetailData(String getPersonDetailData) {
|
||||
NwLoginConstants.getPersonDetailData = getPersonDetailData;
|
||||
}
|
||||
|
||||
//用户信息查询 详细信息
|
||||
public static String getPersonDetailData;
|
||||
|
||||
//微服务平台认证接口
|
||||
public static String onlineApprove;
|
||||
|
||||
|
|
@ -87,6 +187,11 @@ public class NwLoginConstants {
|
|||
NwLoginConstants.appAppsecret = appAppsecret;
|
||||
}*/
|
||||
|
||||
@Value("${personEasyList}")
|
||||
public void setPersonEasyList(String personEasyList) {
|
||||
NwLoginConstants.personEasyList = personEasyList;
|
||||
}
|
||||
|
||||
public static String appsecret;
|
||||
|
||||
public static String h5Appsecret;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import com.bonus.sgzb.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*@author: LYJ
|
||||
*@date: 2021/8/13 14:18
|
||||
*@description: 用于南网的注册Vo
|
||||
*/
|
||||
@Data
|
||||
public class RegistersVo extends BaseLoginEntity {
|
||||
|
||||
@ApiModelProperty(name = "phone",value = "手机号")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty(name = "code",value = "验证码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(name = "userName",value = "用户姓名")
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty(name = "nickName",value = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty(name = "userAccount",value = "用户账号")
|
||||
private String userAccount;
|
||||
|
||||
@ApiModelProperty(name = "psCode",value = "密码")
|
||||
private String psCode;
|
||||
|
||||
@ApiModelProperty(name = "confirmPsCode",value = "确认密码")
|
||||
private String confirmPsCode;
|
||||
|
||||
@ApiModelProperty(name = "name",value = "客户名称")
|
||||
private String name;
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.bonus.sgzb.auth.service;
|
|||
|
||||
|
||||
import com.bonus.sgzb.auth.form.RegisterForms;
|
||||
import com.bonus.sgzb.common.core.domain.R;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
|
@ -19,6 +20,6 @@ public interface NwRegisterService {
|
|||
* @param registerForms
|
||||
* @return
|
||||
*/
|
||||
String registersNew(HttpServletRequest request, RegisterForms registerForms);
|
||||
R registersNew(HttpServletRequest request, RegisterForms registerForms);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
package com.bonus.sgzb.auth.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Maps;
|
||||
import com.bonus.sgzb.auth.form.*;
|
||||
import com.bonus.sgzb.auth.service.NwRegisterService;
|
||||
import com.bonus.sgzb.auth.utils.HttpUtils;
|
||||
import com.bonus.sgzb.common.core.domain.R;
|
||||
import com.bonus.sgzb.common.core.exception.base.BaseException;
|
||||
import com.bonus.sgzb.common.core.utils.ip.IpUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
|
|
@ -25,25 +30,25 @@ import java.util.regex.Pattern;
|
|||
public class NwRegisterServiceImpl implements NwRegisterService {
|
||||
|
||||
@Override
|
||||
public String registersNew(HttpServletRequest request, RegisterForms registerForms) {
|
||||
/* log.info("统一个人手机注册 registersForPersonal方法 入参 request:{}, registerForms:{}", request, JSON.toJSONString(registerForms));
|
||||
*//* 校验请求参数 *//*
|
||||
public R registersNew(HttpServletRequest request, RegisterForms registerForms) {
|
||||
log.info("统一个人手机注册 registersForPersonal方法 入参 request:{}, registerForms:{}", request, JSON.toJSONString(registerForms));
|
||||
/**校验请求参数*/
|
||||
this.checkRequestParam(request, registerForms);
|
||||
Integer loginModeType = registerForms.getLoginModeType();
|
||||
NwApp nwApp = new NwApp();
|
||||
if (loginModeType == 1) {
|
||||
if (loginModeType == NwLoginConstants.ONE) {
|
||||
nwApp.setCode(1);
|
||||
nwApp.setAppId(NwLoginConstants.appId);
|
||||
nwApp.setAppsecret(NwLoginConstants.appsecret);
|
||||
} else if (loginModeType == 2) {
|
||||
} else if (loginModeType == NwLoginConstants.TWO) {
|
||||
nwApp.setCode(2);
|
||||
nwApp.setAppId(NwLoginConstants.h5AppId);
|
||||
nwApp.setAppsecret(NwLoginConstants.h5Appsecret);
|
||||
} else if (loginModeType == 3) {
|
||||
} else if (loginModeType == NwLoginConstants.THREE) {
|
||||
nwApp.setCode(3);
|
||||
nwApp.setAppId(NwLoginConstants.wechatAppId);
|
||||
nwApp.setAppsecret(NwLoginConstants.wechatAppsecret);
|
||||
} else if (loginModeType == 4) {
|
||||
} else if (loginModeType == NwLoginConstants.FOUR) {
|
||||
nwApp.setCode(4);
|
||||
nwApp.setAppId(NwLoginConstants.appAppId);
|
||||
nwApp.setAppsecret(NwLoginConstants.appAppsecret);
|
||||
|
|
@ -51,63 +56,28 @@ public class NwRegisterServiceImpl implements NwRegisterService {
|
|||
try {
|
||||
//发送注册请求(调用南网的注册方法)
|
||||
RespLoginData respLoginData = null;
|
||||
//用户中心用户id
|
||||
String ossExternalId = null;
|
||||
*//* 查询商城是否存在当前用户 *//*
|
||||
// UserAccount mallUser = this.queryUserByMall(registerForms);
|
||||
*//* 查询用户中心是否存在当前用户 *//*
|
||||
/*查询用户中心是否存在当前用户*/
|
||||
CloudUserVo cloudUserVo = this.queryUserBySso(registerForms);
|
||||
*//* 数据幂等性操作 记录日志 *//*
|
||||
/*数据幂等性操作 记录日志*/
|
||||
RegistersVo registersVo = getRegisterVo(registerForms);
|
||||
log.error("check001_registersVo:{}", JsonUtils.object2Json(registersVo));
|
||||
log.error("check001_registersVo:{}", JSON.toJSONString(registersVo));
|
||||
|
||||
if (null != mallUser) {
|
||||
if (mallUser.getMobile().equals(registerForms.getMobilePhone())) {
|
||||
throw new BaseException(ExceptionDict.PHONE_NUMBER_EXISTS_CODE, ExceptionDict.PHONE_NUMBER_EXISTS_MSG);
|
||||
if (null == cloudUserVo) {
|
||||
log.info("系统不存在,用户中心不存在,同步数据到用户中心");
|
||||
respLoginData = HttpUtils.postJson(NwLoginConstants.registerPhone, registersVo, null, Map.class, null);
|
||||
} else {
|
||||
throw new BaseException(ExceptionDict.USER_NAME_EXISTS_CODE, ExceptionDict.USER_NAME_EXISTS_MSG);
|
||||
log.info("系统不存在,用户中心存在,操作绑定业务");
|
||||
respLoginData = this.bindSsoUser(registerForms);
|
||||
}
|
||||
}
|
||||
*//* 添加商城用户逻辑 *//*
|
||||
log.error("check002_respLoginData:{}", JsonUtils.object2Json(respLoginData));
|
||||
if (respLoginData.getCode().equals(CodeConstants.HTTP_RESPONSE_CODE_200)) {
|
||||
if (null != cloudUserVo) {
|
||||
if (IsOriginalUserEnum.YES.getCode().equals(cloudUserVo.getIsOriginalUser())) {
|
||||
registerForms.setUserAccount(cloudUserVo.getUserAccount());
|
||||
}
|
||||
Map<String, String> param = new HashMap();
|
||||
param.put(CodeConstants.USER_LBCLOUD_ID, registerForms.getExternalId());
|
||||
RespLoginData userDetailInfo = HttpUtils.postJsonForApi(LoginConstants.getPersonDetailData, null, null, Map.class, param, nwAppEnum);
|
||||
if (CodeConstants.HTTP_RESPONSE_CODE_200.equals(userDetailInfo.getCode())) {
|
||||
Map<String, String> userData = (Map<String, String>) userDetailInfo.getData();
|
||||
ossExternalId = userData.get(CodeConstants.USER_LBCLOUD_EXTERNA_ID);
|
||||
log.error("check002_respLoginData:{}", JSON.toJSONString(respLoginData));
|
||||
if (respLoginData.getCode().equals(NwLoginConstants.HTTP_RESPONSE_CODE_200)) {
|
||||
return R.ok(NwLoginConstants.REGISTERIP_SUCCESS);
|
||||
} else {
|
||||
this.deleteKey(registerForms);
|
||||
this.deleteInterceptor();
|
||||
throw new BaseException(respLoginData.getCode(), respLoginData.getMessage());
|
||||
return R.fail(NwLoginConstants.REGISTERIP_FAIL);
|
||||
}
|
||||
} else {
|
||||
Map<String, String> data = (Map<String, String>) respLoginData.getData();
|
||||
ossExternalId = data.get(CodeConstants.USER_EXTERNAL_ID);
|
||||
}
|
||||
} else {
|
||||
Map<String, String> data = (Map<String, String>) respLoginData.getData();
|
||||
ossExternalId = data.get(CodeConstants.USER_EXTERNAL_ID);
|
||||
}
|
||||
if (null == ossExternalId) {
|
||||
throw new BaseException(ExceptionDict.USER_NAME_EXISTS_CODE, "获取统一用户中心userExternalId数据失败,请联系管理员");
|
||||
}
|
||||
//添加商城账号(个人/企业)
|
||||
this.addMallUser(registerForms, ossExternalId);
|
||||
//发送短信提醒用户
|
||||
platformClient.sendMessageNew(CodeConstants.PLATFORM_ID, registerForms.getMobilePhone(), PropertyNameConstants.USER_REGISTERED_APPROVED);
|
||||
return AccountRegisterConstants.REGISTERIP_SUCCESS;
|
||||
} catch (Exception e) {
|
||||
deleteInterceptor();
|
||||
deleteKey(registerForms);
|
||||
throw new UserException("9999", e.getMessage());
|
||||
}*/
|
||||
return null;
|
||||
throw new BaseException("9999", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRequestParam(HttpServletRequest request, RegisterForms registerForms) {
|
||||
|
|
@ -174,4 +144,116 @@ public class NwRegisterServiceImpl implements NwRegisterService {
|
|||
return Pattern.matches(regex, phone);
|
||||
}
|
||||
|
||||
|
||||
private CloudUserVo queryUserBySso(RegisterForms registerForms) throws Exception {
|
||||
try {
|
||||
LbcloudUserVo lbcloudUserVo = new LbcloudUserVo();
|
||||
lbcloudUserVo.setMobilePhone(registerForms.getMobilePhone());
|
||||
HashMap<String, String> requestMap = Maps.newHashMap();
|
||||
requestMap.put(NwLoginConstants.CACEL_DESENSITIZATION, NwLoginConstants.TRUE); //查询用户信息 不脱敏查询
|
||||
NwApp nwApp = new NwApp();
|
||||
nwApp.setCode(1);
|
||||
nwApp.setAppId(NwLoginConstants.appId);
|
||||
nwApp.setAppsecret(NwLoginConstants.appsecret);
|
||||
RespLoginData mobileResult = HttpUtils.postJsonForApi(NwLoginConstants.personEasyList, lbcloudUserVo, null, Map.class, requestMap, nwApp);
|
||||
Map<String, Object> resultMap = (Map<String, Object>) mobileResult.getData();
|
||||
JSONArray dataArray = (JSONArray) resultMap.get(NwLoginConstants.USER_RECORDS);
|
||||
|
||||
if (!NwLoginConstants.HTTP_RESPONSE_CODE_200.equals(mobileResult.getCode())) {
|
||||
log.info("调用南网用户信息接口失败:{}", JSON.toJSONString(mobileResult));
|
||||
throw new BaseException(mobileResult.getCode(), mobileResult.getMessage());
|
||||
}
|
||||
if (CollectionUtils.isEmpty(dataArray)) {
|
||||
return null;
|
||||
}
|
||||
CloudUserVo cloudUserVo = new CloudUserVo();
|
||||
if (CollectionUtils.isNotEmpty(dataArray)) {
|
||||
JSONObject dataObject = (JSONObject) dataArray.get(NwLoginConstants.ZERO);
|
||||
String userId = dataObject.get(NwLoginConstants.USER_LBCLOUD_ID) != null ? dataObject.get(NwLoginConstants.USER_LBCLOUD_ID).toString() : null;
|
||||
String userName = dataObject.get(NwLoginConstants.USER_LBCLOUD_NAME) != null ? dataObject.get(NwLoginConstants.USER_LBCLOUD_NAME).toString() : null;
|
||||
String userAccount = dataObject.get(NwLoginConstants.USER_LBCLOUD_ACCOUNT) != null ? dataObject.get(NwLoginConstants.USER_LBCLOUD_ACCOUNT).toString() : null;
|
||||
cloudUserVo.setUserId(userId);
|
||||
cloudUserVo.setUserAccount(userAccount);
|
||||
cloudUserVo.setUserName(userName);
|
||||
}
|
||||
cloudUserVo.setIsOriginalUser(StringUtils.isBlank(cloudUserVo.getUserAccount()) ? NwLoginConstants.ZERO : NwLoginConstants.ONE);
|
||||
registerForms.setExternalId(cloudUserVo.getUserId());
|
||||
return cloudUserVo;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info("调用南网用户信息接口异常:{}", e.getMessage());
|
||||
throw new Exception(NwLoginConstants.USER_DATA_QUERY_FAILED_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装南网需要的注册信息
|
||||
*
|
||||
* @author: LYJ
|
||||
* @date: 2021/8/17 8:57
|
||||
*/
|
||||
private RegistersVo getRegisterVo(RegisterForms registerForms) {
|
||||
RegistersVo registersVo = new RegistersVo();
|
||||
if (null != registerForms.getEnterpriseName()) {
|
||||
registersVo.setName(registerForms.getEnterpriseName());
|
||||
}
|
||||
if (null != registerForms.getMobilePhone()) {
|
||||
registersVo.setPhone(registerForms.getMobilePhone());
|
||||
}
|
||||
if (null != registerForms.getMobilePhoneCode()) {
|
||||
registersVo.setCode(registerForms.getMobilePhoneCode());
|
||||
}
|
||||
if (null != registerForms.getUserAccount()) {
|
||||
registersVo.setUserAccount(registerForms.getUserAccount());
|
||||
}
|
||||
NwApp nwApp = new NwApp();
|
||||
Integer loginModeType = registerForms.getLoginModeType();
|
||||
if (loginModeType == NwLoginConstants.ONE) {
|
||||
nwApp.setCode(1);
|
||||
nwApp.setAppId(NwLoginConstants.appId);
|
||||
nwApp.setAppsecret(NwLoginConstants.appsecret);
|
||||
} else if (loginModeType == NwLoginConstants.TWO) {
|
||||
nwApp.setCode(2);
|
||||
nwApp.setAppId(NwLoginConstants.h5AppId);
|
||||
nwApp.setAppsecret(NwLoginConstants.h5Appsecret);
|
||||
} else if (loginModeType == NwLoginConstants.THREE) {
|
||||
nwApp.setCode(3);
|
||||
nwApp.setAppId(NwLoginConstants.wechatAppId);
|
||||
nwApp.setAppsecret(NwLoginConstants.wechatAppsecret);
|
||||
} else if (loginModeType == NwLoginConstants.FOUR) {
|
||||
nwApp.setCode(4);
|
||||
nwApp.setAppId(NwLoginConstants.appAppId);
|
||||
nwApp.setAppsecret(NwLoginConstants.appAppsecret);
|
||||
}
|
||||
registersVo.setAppId(nwApp.getAppId());
|
||||
registersVo.setAppSecret(nwApp.getAppsecret());
|
||||
registersVo.setUserName(registerForms.getUserAccount());
|
||||
registersVo.setPsCode(registerForms.getUserPassword());
|
||||
registersVo.setConfirmPsCode(registerForms.getAgainPassword());
|
||||
return registersVo;
|
||||
}
|
||||
|
||||
private RespLoginData bindSsoUser(RegisterForms registerForms) {
|
||||
//手机验证码校验
|
||||
Map<String, String> paraMap = new HashMap<String, String>();
|
||||
paraMap.put("verificationCodeType", NwLoginConstants.REGISTERED);
|
||||
paraMap.put("verificationCode", registerForms.getMobilePhoneCode());
|
||||
paraMap.put("phone", registerForms.getMobilePhone());
|
||||
RespLoginData verifyResult = HttpUtils.postJson(NwLoginConstants.verifyPhoneCode, null, null, Boolean.class, paraMap);
|
||||
log.info("verifyResult:{}", JSON.toJSONString(verifyResult));
|
||||
if (NwLoginConstants.HTTP_RESPONSE_CODE_200.equals(verifyResult.getCode())) {
|
||||
Boolean result = (Boolean) verifyResult.getData();
|
||||
if (!result) {
|
||||
throw new BaseException(NwLoginConstants.CHECK_MOBILEPHONECODE_WRONG_ERROR_CODE, NwLoginConstants.CHECK_MOBILEPHONECODE_WRONG_ERROR_CODE_MSG);
|
||||
}
|
||||
} else {
|
||||
throw new BaseException(verifyResult.getCode(), verifyResult.getMessage());
|
||||
}
|
||||
LbcloudUserVo lbcloudUserVo = new LbcloudUserVo();
|
||||
lbcloudUserVo.setUserId(registerForms.getExternalId());
|
||||
lbcloudUserVo.setAppId(NwLoginConstants.appId);
|
||||
lbcloudUserVo.setAccount(registerForms.getUserAccount());
|
||||
return HttpUtils.postJson(NwLoginConstants.userBindUrl, lbcloudUserVo, null, Map.class, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,21 @@
|
|||
package com.bonus.sgzb.auth.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.sgzb.auth.form.NwApp;
|
||||
import com.bonus.sgzb.auth.form.NwLoginConstants;
|
||||
import com.bonus.sgzb.auth.form.OnlineApprove;
|
||||
import com.bonus.sgzb.auth.form.RespLoginData;
|
||||
import com.bonus.sgzb.common.core.exception.base.BaseException;
|
||||
import com.bonus.sgzb.common.core.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
|
@ -25,7 +30,6 @@ import java.util.Set;
|
|||
@Slf4j
|
||||
public class HttpUtils {
|
||||
|
||||
|
||||
public static Map<String, Object> postFormForOauth2(String url, Object params, Map<String, String> map, OnlineApprove onlineApprove) throws Exception {
|
||||
log.info("进入post请求,入参为 url={},params={}", url, params);
|
||||
String finalUrl = NwLoginConstants.baseUrl + url;
|
||||
|
|
@ -95,4 +99,105 @@ public class HttpUtils {
|
|||
}
|
||||
return new RespLoginData(body, className);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* className 传入返回对象的class
|
||||
* 传入的兑现必须 继承 BaseLoginEntity
|
||||
*
|
||||
* @param url
|
||||
* @param params
|
||||
* @param token
|
||||
* @param className
|
||||
* @param nwApp
|
||||
* @param map post请求如果路径上上有拼接参数,传入map 字段为key 值为value
|
||||
* @return
|
||||
*/
|
||||
public static RespLoginData postJsonForApi(String url, Object params, String token, Class className, Map<String, String> map, NwApp nwApp) throws Exception {
|
||||
log.info("进入post请求,入参为 url={},params={},token={}", url, params, token);
|
||||
RestTemplate client = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
//定义请求参数类型,这里用json所以是MediaType.APPLICATION_JSON
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
if (!StringUtils.isBlank(token)) {
|
||||
headers.setBearerAuth(token);
|
||||
} else {
|
||||
headers.set(NwLoginConstants.LBCLOUD_ACCESS_KEY, NwLoginConstants.CONCAT_ACCESS_KEY + getLBCloudAccessKey(nwApp.getAppId(), nwApp.getAppsecret()));
|
||||
}
|
||||
String body;
|
||||
try {
|
||||
HttpEntity<Object> request = new HttpEntity<>(params, headers);
|
||||
String finalUrl = NwLoginConstants.baseUrl + url;
|
||||
if (Objects.nonNull(map)) {
|
||||
StringBuffer path = new StringBuffer();
|
||||
path.append("?");
|
||||
Set<Map.Entry<String, String>> entries = map.entrySet();
|
||||
for (Map.Entry<String, String> entry : entries) {
|
||||
path.append(entry.getKey() + "=" + entry.getValue() + "&");
|
||||
}
|
||||
finalUrl = finalUrl + path.substring(0, path.length() - 1).toString();
|
||||
}
|
||||
log.info("请求时入参,finalUrl={},request={}", finalUrl, request);
|
||||
body = client.postForEntity(finalUrl, request, String.class).getBody();
|
||||
log.info("finalUrl={},出参为,body={}", finalUrl, body);
|
||||
} catch (Exception e) {
|
||||
log.error("HttpUtils.postJson exception: ", e);
|
||||
throw new Exception(NwLoginConstants.HTTP_ERQUEST_FAILED_MSG);
|
||||
}
|
||||
return new RespLoginData(body, className);
|
||||
}
|
||||
|
||||
/**
|
||||
* className 传入返回对象的class
|
||||
* 传入的兑现必须 继承 BaseLoginEntity
|
||||
*
|
||||
* @param url
|
||||
* @param params
|
||||
* @param token
|
||||
* @param className
|
||||
* @param map post请求如果路径上上有拼接参数,传入map 字段为key 值为value
|
||||
* @return
|
||||
*/
|
||||
public static RespLoginData postJson(String url, Object params, String token, Class className, Map<String, String> map) {
|
||||
log.info("进入post请求,入参为 url={},params={},token={},map:{}", url, params, token, map);
|
||||
RestTemplate client = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
//定义请求参数类型,这里用json所以是MediaType.APPLICATION_JSON
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
if (!org.apache.commons.lang3.StringUtils.isBlank(token)) {
|
||||
headers.setBearerAuth(token);
|
||||
}
|
||||
String body;
|
||||
try {
|
||||
HttpEntity<Object> request = new HttpEntity<>(params, headers);
|
||||
String finalUrl = NwLoginConstants.baseUrl + url;
|
||||
if (Objects.nonNull(map)) {
|
||||
StringBuffer path = new StringBuffer();
|
||||
path.append("?");
|
||||
Set<Map.Entry<String, String>> entries = map.entrySet();
|
||||
for (Map.Entry<String, String> entry : entries) {
|
||||
path.append(entry.getKey() + "=" + entry.getValue() + "&");
|
||||
}
|
||||
finalUrl = finalUrl + path.substring(0, path.length() - 1).toString();
|
||||
}
|
||||
log.info("请求时入参,finalUrl={},request={}", finalUrl, request);
|
||||
body = client.postForEntity(finalUrl, request, String.class).getBody();
|
||||
log.info("finalUrl={},出参为,body={}", finalUrl, body);
|
||||
} catch (Exception e) {
|
||||
log.error("HttpUtils.postJson exception: ", e);
|
||||
throw new BaseException("500", "Http请求错误");
|
||||
}
|
||||
return new RespLoginData(body, className);
|
||||
}
|
||||
|
||||
private static String getLBCloudAccessKey(String username, String password) {
|
||||
Assert.notNull(username, "Username must not be null");
|
||||
Assert.notNull(password, "Password must not be null");
|
||||
log.error("check0003_appId=" + username + ",security=" + password);
|
||||
long time = System.currentTimeMillis();
|
||||
String sign = DigestUtils.md5Hex(time + NwLoginConstants.CONCAT_SIGN_WORD + password);
|
||||
byte[] encode = Base64.getEncoder().encode((time + NwLoginConstants.CONCAT_SIGN_WORD + username + NwLoginConstants.CONCAT_SIGN_WORD + sign).getBytes());
|
||||
String cloudAccessKey = new String(encode);
|
||||
return cloudAccessKey;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue