2023-09-13 14:16:46 +08:00
|
|
|
|
package com.zhgd.xmgl.util;
|
|
|
|
|
|
|
|
|
|
|
|
import com.gexin.fastjson.JSON;
|
|
|
|
|
|
import com.zhgd.jeecg.common.util.pass.HttpUtils;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.ThirdPartRequestLog;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.mapper.ThirdPartRequestLogMapper;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
2023-12-02 11:10:52 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 请求第三方请求记录工具,记录日志到数据库
|
|
|
|
|
|
*/
|
2023-09-13 14:16:46 +08:00
|
|
|
|
@Component
|
|
|
|
|
|
public class ThirdPartRequestUtil {
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
ThirdPartRequestLogMapper thirdPartRequestLogMapper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发送http请求,json格式
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param url
|
|
|
|
|
|
* @param body
|
|
|
|
|
|
*/
|
2023-12-02 11:10:52 +08:00
|
|
|
|
public String postJson(String url, Object body) {
|
2023-09-13 14:16:46 +08:00
|
|
|
|
ThirdPartRequestLog log = new ThirdPartRequestLog();
|
|
|
|
|
|
log.setUrl(url);
|
|
|
|
|
|
log.setMethod(2);
|
|
|
|
|
|
log.setParam(JSON.toJSONString(body));
|
|
|
|
|
|
thirdPartRequestLogMapper.insert(log);
|
2023-12-02 11:10:52 +08:00
|
|
|
|
String rs = HttpUtils.postJson(url, body);
|
2023-09-13 14:16:46 +08:00
|
|
|
|
log.setResult(rs);
|
|
|
|
|
|
log.setStatus(1);
|
|
|
|
|
|
thirdPartRequestLogMapper.updateById(log);
|
|
|
|
|
|
return rs;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-02 11:10:52 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 发送get,http请求
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param url
|
|
|
|
|
|
*/
|
|
|
|
|
|
public String get(String url) {
|
|
|
|
|
|
ThirdPartRequestLog log = new ThirdPartRequestLog();
|
|
|
|
|
|
log.setUrl(url);
|
|
|
|
|
|
log.setMethod(1);
|
|
|
|
|
|
thirdPartRequestLogMapper.insert(log);
|
|
|
|
|
|
String rs = HttpUtils.get(url);
|
|
|
|
|
|
log.setResult(rs);
|
|
|
|
|
|
log.setStatus(1);
|
|
|
|
|
|
thirdPartRequestLogMapper.updateById(log);
|
|
|
|
|
|
return rs;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-13 14:16:46 +08:00
|
|
|
|
}
|