丽知:新增中台转发根据apicode的推送方法

This commit is contained in:
zhengyf 2024-08-16 16:35:42 +08:00
parent 2707259d5b
commit bc3c3508fa
5 changed files with 147 additions and 4 deletions

View File

@ -41,7 +41,9 @@ public class OverallConstant {
prodOverPublic.put("approveqz", "/u8cloud/api/to/transorder/saveapprove");//调拨订单保存即审批
//其他出入库
prodOverPublic.put("otherinqzCode", "8000370007");//库存其他入库保存即签字
prodOverPublic.put("otherinqz", "/u8cloud/api/ic/otherin/save/sign");//库存其他入库保存即签字
prodOverPublic.put("otheroutqzCode", "8000370008");//库存其他出库保存即签字
prodOverPublic.put("otheroutqz", "/u8cloud/api/ic/otherout/save/sign");//库存其他出库保存即签字
@ -58,12 +60,12 @@ public class OverallConstant {
}
private static void loadDev() {
devOverAll.put("u8cApiUrl", "http://39.170.109.90:9099");//测试U8C
devOverAll.put("u8cApiUsercodePK", "admin");
devOverAll.put("u8cApiPasswordPK", "21232f297a57a5a743894a0e4a801fc3");
devOverAll.put("u8cApiTrantypePK", "pk");
devOverAll.put("u8cApiSystemPK", "lz");
devOverAll.put("u8cApiServiceNamePK", "http://39.170.109.90:9099");//测试U8C
devOverAll.put("u8cApiNeedStackTracePK", "Y");
devOverAll.put("u8cApiZdrPK", "0001A210000000000GVS");//单据制单人---测试环境郑一凡
@ -71,7 +73,6 @@ public class OverallConstant {
devOverAll.put("u8cApiPasswordCode", "e00cf25ad42683b3df678c61f42c6bda");
devOverAll.put("u8cApiTrantypeCode", "code");
devOverAll.put("u8cApiSystemCode", "lz1");
devOverAll.put("u8cApiServiceNameCode", "http://39.170.109.90:9099");//测试U8C
devOverAll.put("u8cApiNeedStackTraceCode", "Y");
devOverAll.put("u8cApiZdrCode", "15932295350");//单据制单人---测试环境郑一凡

View File

@ -40,7 +40,7 @@ public class PushDataByU8cUtil {
.setSocketTimeout(300000) // 读取超时时间为60秒
.build();
HttpPost post = new HttpPost(OverallConstant.getOverAllValue("u8cApiServiceNamePK") + url);
HttpPost post = new HttpPost(OverallConstant.getOverAllValue("u8cApiUrl") + url);
post.setHeader("Content-Type", "application/json;charset=UTF-8");
post.setHeader("usercode", OverallConstant.getOverAllValue("u8cApiUsercodePK"));
post.setHeader("password", OverallConstant.getOverAllValue("u8cApiPasswordPK"));
@ -100,7 +100,7 @@ public class PushDataByU8cUtil {
.setSocketTimeout(300000) // 读取超时时间为60秒
.build();
HttpPost post = new HttpPost(OverallConstant.getOverAllValue("u8cApiServiceNameCode") + url);
HttpPost post = new HttpPost(OverallConstant.getOverAllValue("u8cApiUrl") + url);
post.setHeader("Content-Type", "application/json;charset=UTF-8");
post.setHeader("usercode", OverallConstant.getOverAllValue("u8cApiUsercodeCode"));
post.setHeader("password", OverallConstant.getOverAllValue("u8cApiPasswordCode"));

View File

@ -0,0 +1,17 @@
package com.hzya.frame.plugin.lets.util.pushData;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* U8C返回参数
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Attribute {
private String status;
private String taskNumber;
private String data;
}

View File

@ -0,0 +1,107 @@
package com.hzya.frame.plugin.lets.util.pushData;
import cn.hutool.core.lang.Assert;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.hzya.frame.plugin.lets.constant.OverallConstant;
import com.hzya.frame.plugin.lets.constant.ProfilesActiveConstant;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
/**
* 通过中台推送U8C推送工具类.
*/
@Component
public class PushU8CByApiCode {
private static String appId = "800037";
private static String publicKey = "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj";//用安中台
private static String secretKey = "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=";//用安中台
/**
* 发起post请求传递json类型
*
* @param apicode 地址
* @param data 请求参数
* @return 返回消息
*/
public ZTResult pushByPK(String apicode, String data) throws Exception {
Assert.notNull(apicode, "请求地址不能为空");
Assert.notNull(data, "请求参数不能为空(需要JSON格式)");
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(OverallConstant.getOverAllValue("u8cApiUrl"));
httpPost.setHeader("Content-Type", "application/json");
//u8c
httpPost.setHeader("usercode", OverallConstant.getOverAllValue("u8cApiUsercodePK"));
httpPost.setHeader("password", OverallConstant.getOverAllValue("u8cApiPasswordPK"));
httpPost.setHeader("trantype", OverallConstant.getOverAllValue("u8cApiTrantypePK"));
httpPost.setHeader("system", OverallConstant.getOverAllValue("u8cApiSystemPK"));
httpPost.setHeader("needStackTrace", OverallConstant.getOverAllValue("u8cApiNeedStackTracePK"));
//中台
httpPost.setHeader("publicKey", publicKey);
httpPost.setHeader("secretKey", secretKey);
//app
httpPost.setHeader("appId", appId);
httpPost.setHeader("apicode", apicode);
//data
httpPost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity);
EntityUtils.consume(entity);
ZTResult ztResult = JSON.parseObject(result).toJavaObject(ZTResult.class);
return ztResult;
}
/**
* 发起post请求传递json类型
* <p>
* u8c code模式
*
* @param apicode
* @param data 请求参数
* @return 返回消息
*/
public ZTResult pushByCode(String apicode, String data) throws Exception {
Assert.notNull(apicode, "请求地址不能为空");
Assert.notNull(data, "请求参数不能为空(需要JSON格式)");
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(ProfilesActiveConstant.U8C_URL);
httpPost.setHeader("Content-Type", "application/json");
//u8c
httpPost.setHeader("usercode", OverallConstant.getOverAllValue("u8cApiUsercodeCode"));
httpPost.setHeader("password", OverallConstant.getOverAllValue("u8cApiPasswordCode"));
httpPost.setHeader("trantype", OverallConstant.getOverAllValue("u8cApiTrantypeCode"));
httpPost.setHeader("system", OverallConstant.getOverAllValue("u8cApiSystemCode"));
httpPost.setHeader("needStackTrace", OverallConstant.getOverAllValue("u8cApiNeedStackTraceCode"));
//中台
httpPost.setHeader("publicKey", publicKey);
httpPost.setHeader("secretKey", secretKey);
//app
httpPost.setHeader("appId", appId);
httpPost.setHeader("apicode", apicode);
//data
httpPost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity);
EntityUtils.consume(entity);
ZTResult ztResult = JSON.parseObject(result).toJavaObject(ZTResult.class);
return ztResult;
}
}

View File

@ -0,0 +1,18 @@
package com.hzya.frame.plugin.lets.util.pushData;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ZTResult {
private String msg;
private String type;
private String flag;
private String status;
private Attribute attribute;
private String headMsg;
}