|
@@ -0,0 +1,580 @@
|
|
|
+package info.aspirecn.iov.sjjh.supplier10000057.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
|
|
|
+import info.aspirecn.iov.sjjh.commons.lang.Constant;
|
|
|
+import info.aspirecn.iov.sjjh.commons.lang.PatternTools;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.config.SupplierConfig;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.constant.CommonConstant;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.model.*;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.service.AuthorizationService;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.service.TokenService;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.util.OkHttpUtil;
|
|
|
+import info.aspirecn.iov.sjjh.supplier10000057.util.UnicodeUtil;
|
|
|
+import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.FormBody;
|
|
|
+import okhttp3.RequestBody;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.ConstraintViolation;
|
|
|
+import javax.validation.Validation;
|
|
|
+import javax.validation.Validator;
|
|
|
+import javax.validation.ValidatorFactory;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xusonglin
|
|
|
+ * @version V1.0
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class AuthorizationServiceImpl implements AuthorizationService {
|
|
|
+ @Autowired
|
|
|
+ SupplierConfig supplierConfig;
|
|
|
+ @Autowired
|
|
|
+ StringRedisTemplate stringRedisTemplate;
|
|
|
+ @Autowired
|
|
|
+ TokenService tokenService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject getLocationUser(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ if (outTime <= CommonConstant.PARA_ZERO) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000057.getLocationUser---customBody={},outTime={}", customBody, outTime);
|
|
|
+ GetLocationUserRequestObject requestObject = JSON.toJavaObject(JSON.parseObject(customBody), GetLocationUserRequestObject.class);
|
|
|
+ log.info("supplier10000057.getLocationUser---requestObject={}", requestObject);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateRequestParams(ret, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ // 拼接请求
|
|
|
+ StringBuffer urlStringBuffer = new StringBuffer();
|
|
|
+ urlStringBuffer.append(supplierConfig.getUrl());
|
|
|
+ urlStringBuffer.append(supplierConfig.getLocationUserPath());
|
|
|
+ urlStringBuffer.append("?tel=").append(requestObject.getMobile());
|
|
|
+ if (requestObject.getPage() != null) {
|
|
|
+ urlStringBuffer.append("&page=").append(requestObject.getPage());
|
|
|
+ }
|
|
|
+ if (requestObject.getLimit() != null) {
|
|
|
+ urlStringBuffer.append("&limit=").append(requestObject.getLimit());
|
|
|
+ }
|
|
|
+ String token = stringRedisTemplate.boundValueOps(CommonConstant.REDIS_KEY_LOCATION_TOKEN).get();
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = tokenService.getAuthToken();
|
|
|
+ }
|
|
|
+ token = "JWT " + token;
|
|
|
+ // 请求数据源
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ responseContext = OkHttpUtil.doGet(urlStringBuffer.toString(), outTime, token);
|
|
|
+ log.info("supplier10000057-getLocationUser-responseContext:{}", UnicodeUtil.unicodeToString(responseContext));
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000057.getLocationUser接口-SocketTimeoutException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ OriginalCommonResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext),
|
|
|
+ OriginalCommonResponseObject.class);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = responseObject.getCode();
|
|
|
+ if (responseObject.getCode().equals(CommonConstant.REQUEST_SUCCESS)) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("count", responseObject.getCount());
|
|
|
+ result.put("data", responseObject.getData());
|
|
|
+ ret.setResultBody(result);
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1192);
|
|
|
+ ret.setResultDesc(CommonConstant.SUCCESS_MESSAGE);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1193);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject createLocationUser(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ if (outTime <= CommonConstant.PARA_ZERO) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000057.createLocationUser---customBody={},outTime={}", customBody, outTime);
|
|
|
+ CreateLocationUserRequestObject requestObject = JSON.toJavaObject(JSON.parseObject(customBody),
|
|
|
+ CreateLocationUserRequestObject.class);
|
|
|
+ log.info("supplier10000057.createLocationUser---requestObject={}", requestObject);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateRequestParams(ret, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ String url = supplierConfig.getUrl() + supplierConfig.getLocationUserPath();
|
|
|
+
|
|
|
+ String token = stringRedisTemplate.boundValueOps(CommonConstant.REDIS_KEY_LOCATION_TOKEN).get();
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = tokenService.getAuthToken();
|
|
|
+ }
|
|
|
+ token = "JWT " + token;
|
|
|
+ // 请求数据源
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
+ .add("name", requestObject.getName())
|
|
|
+ .add("tel", requestObject.getMobile())
|
|
|
+ .add("service_tel", requestObject.getServiceTel())
|
|
|
+ .add("message_name", requestObject.getMessageName())
|
|
|
+ .add("price_choice", "0")
|
|
|
+ .add("group", "测试组")
|
|
|
+ .build();
|
|
|
+ responseContext = OkHttpUtil.doPost(url, requestBody, outTime, token);
|
|
|
+ log.info("supplier10000057-createLocationUser-responseContext:{}", UnicodeUtil.unicodeToString(responseContext));
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000057.createLocationUser接口-SocketTimeoutException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ OriginalCommonResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext),
|
|
|
+ OriginalCommonResponseObject.class);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = responseObject.getCode();
|
|
|
+ if (responseObject.getCode().equals(CommonConstant.REQUEST_SUCCESS)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1192);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_139);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_139);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1193);
|
|
|
+ ret.setResultBody(responseObject.getMsg());
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_140);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject deleteLocationUser(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ if (outTime <= CommonConstant.PARA_ZERO) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000057.deleteLocationUser---customBody={},outTime={}", customBody, outTime);
|
|
|
+ DeleteLocationUserRequestObject requestObject = JSON.toJavaObject(JSON.parseObject(customBody),
|
|
|
+ DeleteLocationUserRequestObject.class);
|
|
|
+ log.info("supplier10000057.deleteLocationUser---requestObject={}", requestObject);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateRequestParams(ret, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ String url = supplierConfig.getUrl() + supplierConfig.getLocationUserPath();
|
|
|
+
|
|
|
+ String token = stringRedisTemplate.boundValueOps(CommonConstant.REDIS_KEY_LOCATION_TOKEN).get();
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = tokenService.getAuthToken();
|
|
|
+ }
|
|
|
+ token = "JWT " + token;
|
|
|
+ // 请求数据源
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ JSONObject requestParam = new JSONObject();
|
|
|
+ requestParam.put("tel", requestObject.getMobile());
|
|
|
+ responseContext = OkHttpUtil.doDelete(url, JSON.toJSONString(requestParam), outTime, token);
|
|
|
+ log.info("supplier10000057-deleteLocationUser-responseContext:{}", UnicodeUtil.unicodeToString(responseContext));
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000057.deleteLocationUser接口-SocketTimeoutException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ OriginalCommonResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext),
|
|
|
+ OriginalCommonResponseObject.class);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = responseObject.getCode();
|
|
|
+ if (responseObject.getCode().equals(CommonConstant.REQUEST_SUCCESS)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1192);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_139);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_139);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1193);
|
|
|
+ ret.setResultBody(responseObject.getMsg());
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_140);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject sendMessage(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ if (outTime <= CommonConstant.PARA_ZERO) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000057.sendMessage---customBody={},outTime={}", customBody, outTime);
|
|
|
+ SendMsgRequestObject requestObject = JSON.toJavaObject(JSON.parseObject(customBody),
|
|
|
+ SendMsgRequestObject.class);
|
|
|
+ log.info("supplier10000057.sendMessage---requestObject={}", requestObject);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateRequestParams(ret, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ String url = supplierConfig.getUrl() + supplierConfig.getSendMsgPath();
|
|
|
+
|
|
|
+ String token = stringRedisTemplate.boundValueOps(CommonConstant.REDIS_KEY_LOCATION_TOKEN).get();
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = tokenService.getAuthToken();
|
|
|
+ }
|
|
|
+ token = "JWT " + token;
|
|
|
+ // 请求数据源
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
+ .add("tel", requestObject.getMobile())
|
|
|
+ .add("auth_type", requestObject.getType())
|
|
|
+ .build();
|
|
|
+ responseContext = OkHttpUtil.doPost(url, requestBody, outTime, token);
|
|
|
+ log.info("supplier10000057-sendMessage-responseContext:{}", UnicodeUtil.unicodeToString(responseContext));
|
|
|
+
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000057.sendMessage接口-SocketTimeoutException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ OriginalCommonResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext),
|
|
|
+ OriginalCommonResponseObject.class);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = responseObject.getCode();
|
|
|
+ if (responseObject.getCode().equals(CommonConstant.REQUEST_SUCCESS)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1192);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_139);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_139);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1193);
|
|
|
+ ret.setResultBody(responseObject.getMsg());
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_140);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject agreeAuth(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ if (outTime <= CommonConstant.PARA_ZERO) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000057.agreeAuth---customBody={},outTime={}", customBody, outTime);
|
|
|
+ AuthRequestObject requestObject = JSON.toJavaObject(JSON.parseObject(customBody),
|
|
|
+ AuthRequestObject.class);
|
|
|
+ log.info("supplier10000057.agreeAuth---requestObject={}", requestObject);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateRequestParams(ret, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ String url = supplierConfig.getUrl() + supplierConfig.getAuthPath();
|
|
|
+
|
|
|
+ String token = stringRedisTemplate.boundValueOps(CommonConstant.REDIS_KEY_LOCATION_TOKEN).get();
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = tokenService.getAuthToken();
|
|
|
+ }
|
|
|
+ token = "JWT " + token;
|
|
|
+ // 请求数据源
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
+ .add("tel", requestObject.getMobile())
|
|
|
+ .add("code", requestObject.getCode())
|
|
|
+ .add("auth_status", requestObject.getStatus())
|
|
|
+ .build();
|
|
|
+ responseContext = OkHttpUtil.doPost(url, requestBody, outTime, token);
|
|
|
+ log.info("supplier10000057-agreeAuth-responseContext:{}", UnicodeUtil.unicodeToString(responseContext));
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000057.agreeAuth接口-SocketTimeoutException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ OriginalCommonResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext),
|
|
|
+ OriginalCommonResponseObject.class);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = responseObject.getCode();
|
|
|
+ if (responseObject.getCode().equals(CommonConstant.REQUEST_SUCCESS)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1192);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_139);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_139);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1193);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_140);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_140);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject cancelAuth(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = "" + Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ if (outTime <= CommonConstant.PARA_ZERO) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("supplier10000057.cancelAuth---customBody={},outTime={}", customBody, outTime);
|
|
|
+ AuthRequestObject requestObject = JSON.toJavaObject(JSON.parseObject(customBody),
|
|
|
+ AuthRequestObject.class);
|
|
|
+ log.info("supplier10000057.cancelAuth---requestObject={}", requestObject);
|
|
|
+ // 参数校验
|
|
|
+ if (!validateRequestParams(ret, requestObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ String url = supplierConfig.getUrl() + supplierConfig.getCancelAuthPath();
|
|
|
+
|
|
|
+ String token = stringRedisTemplate.boundValueOps(CommonConstant.REDIS_KEY_LOCATION_TOKEN).get();
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
+ token = tokenService.getAuthToken();
|
|
|
+ }
|
|
|
+ token = "JWT " + token;
|
|
|
+ // 请求数据源
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ RequestBody requestBody = new FormBody.Builder()
|
|
|
+ .add("tel", requestObject.getMobile())
|
|
|
+ .add("code", requestObject.getCode())
|
|
|
+ .add("auth_status", requestObject.getStatus())
|
|
|
+ .build();
|
|
|
+ responseContext = OkHttpUtil.doPost(url, requestBody, outTime, token);
|
|
|
+ log.info("supplier10000057-cancelAuth-responseContext:{}", UnicodeUtil.unicodeToString(responseContext));
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000057.cancelAuth接口-SocketTimeoutException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析返回结果
|
|
|
+ OriginalCommonResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext),
|
|
|
+ OriginalCommonResponseObject.class);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ upstreamCode = responseObject.getCode();
|
|
|
+ if (responseObject.getCode().equals(CommonConstant.REQUEST_SUCCESS)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1192);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_139);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_139);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_1193);
|
|
|
+ ret.setResultBody(Constant.RETURN_MESSAGE_140);
|
|
|
+ ret.setResultDesc(Constant.RETURN_MESSAGE_140);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRequestParams(ChannelTypeHandleResponseObject ret,
|
|
|
+ SendMsgRequestObject requestObject) {
|
|
|
+ if (!validateParamNullValue(requestObject)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getMobile()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_MOBILE_REGEX, requestObject.getMobile())) {
|
|
|
+ ret.setResultCode(Constant.JK_MOBILE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getType()) ||
|
|
|
+ (!requestObject.getType().equals("0") && !requestObject.getType().equals("1"))) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRequestParams(ChannelTypeHandleResponseObject ret,
|
|
|
+ AuthRequestObject requestObject) {
|
|
|
+ if (!validateParamNullValue(requestObject)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getMobile()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_MOBILE_REGEX, requestObject.getMobile())) {
|
|
|
+ ret.setResultCode(Constant.JK_MOBILE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getCode())) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getStatus())
|
|
|
+ || (!requestObject.getStatus().equals("True") && !requestObject.getStatus().equals("False"))) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRequestParams(ChannelTypeHandleResponseObject ret,
|
|
|
+ GetLocationUserRequestObject requestObject) {
|
|
|
+ Pattern numberPattern = Pattern.compile(CommonConstant.NUMBER_REGEX);
|
|
|
+ if (!validateParamNullValue(requestObject)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getMobile()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_MOBILE_REGEX, requestObject.getMobile())) {
|
|
|
+ ret.setResultCode(Constant.JK_MOBILE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if ((requestObject.getLimit() != null && !numberPattern.matcher(requestObject.getLimit().toString()).matches())
|
|
|
+ || (requestObject.getPage() != null && !numberPattern.matcher(requestObject.getPage().toString()).matches())) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRequestParams(ChannelTypeHandleResponseObject ret,
|
|
|
+ CreateLocationUserRequestObject requestObject) {
|
|
|
+ if (!validateParamNullValue(requestObject)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getMobile()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_MOBILE_REGEX, requestObject.getMobile())) {
|
|
|
+ ret.setResultCode(Constant.JK_MOBILE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getName()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_SPECIAL_CN_NAME_REGEX, requestObject.getName())) {
|
|
|
+ ret.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ ret.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRequestParams(ChannelTypeHandleResponseObject ret,
|
|
|
+ DeleteLocationUserRequestObject requestObject) {
|
|
|
+ if (!validateParamNullValue(requestObject)) {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(requestObject.getMobile()) ||
|
|
|
+ !PatternTools.checkResult(Constant.PATTERN_MOBILE_REGEX, requestObject.getMobile())) {
|
|
|
+ ret.setResultCode(Constant.JK_MOBILE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_MOBILE_FORMAT_ERROR);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateParamNullValue(Object jsonResolveObject) {
|
|
|
+ ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
|
|
+ Validator validator = vf.getValidator();
|
|
|
+ Set<ConstraintViolation<Object>> set = validator.validate(jsonResolveObject);
|
|
|
+ for (ConstraintViolation<Object> con : set) {
|
|
|
+ if (StringUtils.isNotBlank(con.getMessage())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|