| | |
| | | import com.fzzy.api.service.ApiCommonService; |
| | | import com.fzzy.api.service.ApiRemoteService; |
| | | import com.fzzy.api.service.ApiTriggerService; |
| | | import com.fzzy.api.utils.AESUtils; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.utils.MyMD5Util; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | | import com.fzzy.api.view.repository.*; |
| | | import com.fzzy.push.whhpjl.dto.WhjlReqDto; |
| | | import com.fzzy.push.whhpjl.dto.WhjlRespDto; |
| | | import com.fzzy.whjl.WhjlConstant; |
| | | import lombok.Data; |
| | |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 武汉军粮省平台-上传数据服务类 |
| | |
| | | public ResponseDto pushData(ApiParam param, ApiConfs conf, Object data) { |
| | | String inteId = param.getInteId(); |
| | | String kqdm = param.getKqdm(); |
| | | String bizId = param.getBizId(); |
| | | |
| | | try { |
| | | if (null == conf) { |
| | | conf = apiCommonService.getConf(kqdm); |
| | | } |
| | | |
| | | //添加LOGO |
| | | //添加日志 |
| | | ApiLog apiLog = new ApiLog(); |
| | | apiLog.setId(ContextUtil.getUUID()); |
| | | apiLog.setInteId(inteId); |
| | | String jsonData = getJsonData(inteId, data, conf.getApiUrl()); |
| | | log.info("报文信息=" + jsonData); |
| | | String jsonData = getJsonData(inteId, data); |
| | | log.info("数据报文信息=" + jsonData); |
| | | inteId = getInteId(inteId); |
| | | if (StringUtils.isEmpty(inteId)) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到接口", bizId); |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到接口"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到接口"); |
| | | apiLogRep.save(apiLog); |
| | |
| | | apiLog.setUploadTime(new Date()); |
| | | |
| | | if (conf == null) { |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置", bizId); |
| | | ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置"); |
| | | apiLog.setStatus(99); |
| | | apiLog.setResult("没有获取到上传配置"); |
| | | apiLogRep.save(apiLog); |
| | | return responseDto; |
| | | } |
| | | //封装推送数据 |
| | | WhjlReqDto reqData = new WhjlReqDto(); |
| | | reqData.setId(ContextUtil.getUUID()); |
| | | reqData.setUid(conf.getKqdm()); |
| | | //TODO 指令id待确认 |
| | | reqData.setOrderid(""); |
| | | reqData.setAppcode(conf.getUserName()); |
| | | reqData.setTimestamp(ContextUtil.getCurTimeMillis()); |
| | | List<Object> list = (List<Object>)data; |
| | | reqData.setDatalength(list.size()); |
| | | //数据进行SM4加密 |
| | | reqData.setData(AESUtils.encrypt(jsonData, conf.getPublicKey())); |
| | | reqData.setOperator("insert"); |
| | | //摘要,数据主体的MD5值 |
| | | reqData.setDigst(MyMD5Util.encrypt(jsonData)); |
| | | //身份签名,对应用码_授权码_站点编码_报文ID_时间戳进行MD5算法签名 |
| | | StringBuffer buffer = new StringBuffer(); |
| | | buffer.append(reqData.getAppcode()).append("_"); |
| | | buffer.append(conf.getPublicKey()).append("_"); |
| | | buffer.append(conf.getKqmc()).append("_"); |
| | | buffer.append(reqData.getId()).append("_"); |
| | | buffer.append(reqData.getTimestamp()); |
| | | reqData.setDigst(MyMD5Util.encrypt(buffer.toString())); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | WhjlRespDto responseDto = Whjl2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, jsonData, conf, null); |
| | | WhjlRespDto responseDto = Whjl2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, reqData, conf); |
| | | apiLog.setStatus(responseDto.getCode() == 200 ? 0 : responseDto.getCode()); |
| | | apiLog.setResult(responseDto.getResult()); |
| | | apiLogRep.save(apiLog); |
| | | ResponseDto resd = new ResponseDto(); |
| | | resd.setSuccess(responseDto.getCode() == 200 ? 0 : responseDto.getCode()); |
| | | resd.setMsg(responseDto.getResult()); |
| | | //updateGD2022AuthToken(responseDto,conf, token); |
| | | |
| | | return resd; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String getJsonData(String inteId, Object data, String url) { |
| | | private String getJsonData(String inteId, Object data) { |
| | | return JSON.toJSONString(data); |
| | | } |
| | | |