@ -3,7 +3,9 @@ package com.logpm.factorydata.zbom.util;
import cn.hutool.core.map.MapUtil ;
import cn.hutool.core.map.MapUtil ;
import cn.hutool.http.HttpResponse ;
import cn.hutool.http.HttpResponse ;
import cn.hutool.http.HttpUtil ;
import cn.hutool.http.HttpUtil ;
import cn.hutool.json.JSONUtil ;
import com.logpm.factorydata.zbom.pros.ZbFactoryProperties ;
import com.logpm.factorydata.zbom.pros.ZbFactoryProperties ;
import lombok.extern.slf4j.Slf4j ;
import org.springblade.common.constant.HttpConstants ;
import org.springblade.common.constant.HttpConstants ;
import org.springblade.common.utils.CommonUtil ;
import org.springblade.common.utils.CommonUtil ;
@ -18,19 +20,22 @@ import java.util.Map;
* @author zhaoqiaobo
* @author zhaoqiaobo
* @create 2024 - 03 - 21 15 : 23
* @create 2024 - 03 - 21 15 : 23
* /
* /
@Slf4j
public class ZbomUtil {
public class ZbomUtil {
/ * *
/ * *
* 推送数据
* 推送数据
*
* @param zbProperties 志邦配置信息
* @param zbProperties 志邦配置信息
* @param body 请求提
* @param body 请求提
* @param method 请求方法
* @param method 请求方法
* @return 返回请求结果
* @return 返回请求结果
* @throws Exception
* @throws Exception
* /
* /
public static String pushZbomSystem ( ZbFactoryProperties zbProperties , String body , String method ) throws Exception {
public static String pushZbomSystem ( ZbFactoryProperties zbProperties , String body , String method ) throws Exception {
// 构建请求url
// 构建请求url
String url = ZbomUtil . buildUrl ( zbProperties , body , method ) ;
String url = ZbomUtil . buildUrl ( zbProperties , body , method ) ;
log . info ( "推送志邦url:{}" , url ) ;
// 请求数据
// 请求数据
HashMap < String , String > headers = MapUtil . of ( HttpConstants . HTTP . HEADER_NAME . CONTENT_TYPE , HttpConstants . HTTP . HEADER_VALUE . JSON ) ;
HashMap < String , String > headers = MapUtil . of ( HttpConstants . HTTP . HEADER_NAME . CONTENT_TYPE , HttpConstants . HTTP . HEADER_VALUE . JSON ) ;
HttpResponse execute = HttpUtil . createPost ( url ) . headerMap ( headers , false ) . body ( body ) . timeout ( 5 * 1000 ) . execute ( ) ;
HttpResponse execute = HttpUtil . createPost ( url ) . headerMap ( headers , false ) . body ( body ) . timeout ( 5 * 1000 ) . execute ( ) ;
@ -47,8 +52,11 @@ public class ZbomUtil {
params . put ( "sign_method" , "md5" ) ;
params . put ( "sign_method" , "md5" ) ;
params . put ( "timestamp" , CommonUtil . dateToStringGeneral ( new Date ( ) ) ) ;
params . put ( "timestamp" , CommonUtil . dateToStringGeneral ( new Date ( ) ) ) ;
params . put ( "v" , "1.0" ) ;
params . put ( "v" , "1.0" ) ;
log . info ( "推送志邦参数:{}" , JSONUtil . toJsonStr ( params ) ) ;
String body = bodyParam . replaceAll ( "\\s+" , "" ) ;
String body = bodyParam . replaceAll ( "\\s+" , "" ) ;
log . info ( "推送志邦请求体:{}" , body ) ;
String sign = QmSignUntil . signTopRequest ( params , zbProperties . getSecretkey ( ) , "md5" , body ) ;
String sign = QmSignUntil . signTopRequest ( params , zbProperties . getSecretkey ( ) , "md5" , body ) ;
log . info ( "推送志邦签名:{}" , sign ) ;
String url = getZbUrl ( zbProperties . getUrl ( ) + "/api/edi/ots/in?" , params , sign ) ;
String url = getZbUrl ( zbProperties . getUrl ( ) + "/api/edi/ots/in?" , params , sign ) ;
return url ;
return url ;
}
}