diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java index 2d664713c..4711499d4 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java @@ -93,10 +93,6 @@ public class AsyncDataServiceImpl implements IAsyncDataService { private final IFactoryPackageDetailService factoryPackageDetailService; - //工厂查询 - private final IOuPaiFactoryService ouPaiFactoryService; - - /** * 处理皮阿诺数据推送到汇通老库 */ diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java index 693bdf22e..52487f82e 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java @@ -1,7 +1,9 @@ package com.logpm.factory.config; -import com.logpm.factory.interceptor.FactoryAccountsInterceptor; import com.logpm.factory.comfac.service.IFactoryTokenService; +import com.logpm.factory.interceptor.FactoryAccountsInterceptor; +import com.logpm.factory.interceptor.ZbFactoryAccountsInterceptor; +import com.logpm.factory.props.ZbFactoryProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistration; @@ -13,13 +15,18 @@ public class InterceptorAdapterConfig implements WebMvcConfigurer { @Autowired IFactoryTokenService factoryTokenService; + @Autowired + ZbFactoryProperties zbFactoryProperties; @Override public void addInterceptors(InterceptorRegistry interceptorRegistry) { InterceptorRegistration registry = interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(factoryTokenService)); registry.addPathPatterns("/factory/**"). excludePathPatterns("/factory/auth/token"). - excludePathPatterns("/factory/oupai/**") + excludePathPatterns("/factory/oupai/**"). + excludePathPatterns("/factory/zb/**") .excludePathPatterns("/factory/common/**"); + InterceptorRegistration registryZbFactory = interceptorRegistry.addInterceptor(new ZbFactoryAccountsInterceptor(zbFactoryProperties)); + registryZbFactory.addPathPatterns("/factory/zb/**"); } } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/ZbFactoryAccountsInterceptor.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/ZbFactoryAccountsInterceptor.java new file mode 100644 index 000000000..dcb80599c --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/ZbFactoryAccountsInterceptor.java @@ -0,0 +1,86 @@ +package com.logpm.factory.interceptor; + +import com.alibaba.fastjson.JSONObject; +import com.logpm.factory.config.RequestWrapper; +import com.logpm.factory.props.ZbFactoryProperties; +import com.logpm.factory.zb.untils.QmSignUntil; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.core.tool.api.R; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +@Log4j2 +@AllArgsConstructor +public class ZbFactoryAccountsInterceptor implements HandlerInterceptor { + + private final ZbFactoryProperties zbFactoryProperties; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + log.info("#################preHandle: 志邦权限 验证开始"); + RequestWrapper myRequestWrapper = new RequestWrapper(request); + + String method = request.getParameter("method"); + String timestamp = request.getParameter("timestamp"); + String format = request.getParameter("format"); + String appKey = request.getParameter("app_key"); + String v = request.getParameter("v"); + String sign = request.getParameter("sign"); + String signMethod = request.getParameter("sign_method"); + String customerId = request.getParameter("customerId"); + + String body = myRequestWrapper.getBody(); + JSONObject bodyJson = JSONObject.parseObject(body); + + Map params = new HashMap<>(); + params.put("app_key",appKey); + params.put("customerId",customerId); + params.put("format",format); + params.put("method",method); + params.put("sign_method",signMethod); + params.put("timestamp",timestamp); + params.put("v",v); + + String newSign = QmSignUntil.signTopRequest(params, zbFactoryProperties.getSecretkey(), signMethod, bodyJson.toJSONString()); + if(!newSign.equals(sign)){ + returnJson(response,JSONObject.toJSONString(R.fail(203,"签名认证失败"))); + return false; + } + return true; + } + + + private void returnJson(HttpServletResponse response, String json) { + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + try { + writer = response.getWriter(); + writer.print(json); + + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + if (writer != null) + writer.close(); + } + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { + HandlerInterceptor.super.afterCompletion(request, response, handler, ex); + } +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/SyncWarehouseDataToNew.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/SyncWarehouseDataToNew.java index 6125e6482..41134c88f 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/SyncWarehouseDataToNew.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/SyncWarehouseDataToNew.java @@ -134,8 +134,8 @@ public class SyncWarehouseDataToNew { goodsAreaEntity.setCreateDept(1649331096241836033L); goodsAreaEntity.setWarehouseId(newWarehouseId); goodsAreaEntity.setHeadline(cargoEntity.getTitle()); - goodsAreaEntity.setEnableStatus(1); - goodsAreaEntity.setAreaType(2); + goodsAreaEntity.setEnableStatus("1"); + goodsAreaEntity.setAreaType("2"); goodsAreaEntity.setOldId(cargoId); Long newAreaId = basicdataGoodsAreaClient.addCargo(goodsAreaEntity); if(Objects.isNull(newAreaId)){ diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/props/ZbFactoryProperties.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/props/ZbFactoryProperties.java new file mode 100644 index 000000000..0a3500c23 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/props/ZbFactoryProperties.java @@ -0,0 +1,16 @@ +package com.logpm.factory.props; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Data +@ConfigurationProperties(prefix = "zb") +@Component +public class ZbFactoryProperties { + + private String appKey; + private String customerid; + private String secretkey; + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/untils/QmSignUntil.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/untils/QmSignUntil.java new file mode 100644 index 000000000..9eb8a1956 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/untils/QmSignUntil.java @@ -0,0 +1,128 @@ +package com.logpm.factory.zb.untils; + +import javax.crypto.Mac; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.MessageDigest; +import java.util.Arrays; +import java.util.Map; + +public class QmSignUntil { + + public static String signTopRequest(Map params, String secret, String signMethod, String body) throws Exception { + // 第一步:检查参数是否已经排序 + String[] keys = params.keySet().toArray(new String[0]); + Arrays.sort(keys); + + // 第二步:把所有参数名和参数值串在一起 + StringBuilder query = new StringBuilder(); + if ("md5".equalsIgnoreCase(signMethod)) { + query.append(secret); + } + for (String key : keys) { + String value = params.get(key); + String[] array = new String[2]; + array[0] = key; + array[1] = value; + if (areNotEmpty(array)) { + query.append(key).append(value); + } + } + + // 第三步:使用MD5/HMAC加密 + byte[] bytes; + if ("hmac".equalsIgnoreCase(signMethod)) { + bytes = encryptHMAC(query.toString(), secret); + } else { + query.append(body).append(secret); + bytes = encryptMD5(query.toString()); + } + + // 第四步:把二进制转化为大写的十六进制(正确签名应该为32大写字符串,此方法需要时使用) + return byte2hex(bytes); + } + + public static boolean areNotEmpty(String[] values) { + boolean result = true; + if ((values == null) || (values.length == 0)) + result = false; + else { + for (String value : values) { + result &= !isEmpty(value); + } + } + return result; + } + static boolean isEmpty(String value) { + int strLen; + if ((value == null) || ((strLen = value.length()) == 0)) + return true; + for (int i = 0; i < strLen; i++) { + if (!Character.isWhitespace(value.charAt(i))) { + return false; + } + } + return true; + } + + static byte[] encryptHMAC(String data, String secret) throws IOException { + byte[] bytes = null; + try { + SecretKey secretKey = new SecretKeySpec(secret.getBytes("utf-8"), "HmacMD5"); + Mac mac = Mac.getInstance(secretKey.getAlgorithm()); + mac.init(secretKey); + bytes = mac.doFinal(data.getBytes("utf-8")); + } catch (GeneralSecurityException gse) { + throw new IOException(gse.toString()); + } + return bytes; + } + + public static byte[] encryptMD5(String data) throws Exception { + MessageDigest md = MessageDigest.getInstance("MD5"); + + byte[] bytes = md.digest(data.getBytes("utf-8")); + return bytes; +// return encryptMD5(data.getBytes(Constants.CHARSET_UTF8)); + } + + public static String byte2hex(byte[] bytes) { + StringBuilder sign = new StringBuilder(); + for (int i = 0; i < bytes.length; i++) { + String hex = Integer.toHexString(bytes[i] & 0xFF); + if (hex.length() == 1) { + sign.append("0"); + } + sign.append(hex.toUpperCase()); + } + return sign.toString(); + } + + +// public static void main(String[] args) { +// +// Map params = new HashMap<>(); +// params.put("app_key","HT"); +// params.put("customerid","HT"); +// params.put("format","json"); +// params.put("method","entry.order.create"); +// params.put("sign_method","md5"); +// params.put("timestamp","2015-04-26 00:00:07"); +// params.put("v","1.0"); +// +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("name","name12345"); +// jsonObject.put("age",10); +// +// try { +// String s = QmSignUntil.signTopRequest(params, "test", "md5", jsonObject.toJSONString()); +// System.out.println(s); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + + +}