大象V6升级

beta-enc
dongxiaoke 2 years ago
parent 760c669452
commit d140bd2061
  1. 1891
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java
  2. 102
      jianshui-invoice/src/main/java/com/jianshui/invoice/utils/elephant/ElephantUtils.java

@ -25,6 +25,7 @@ import com.jianshui.common.utils.http.HttpUtils;
import com.jianshui.common.utils.jianshui.CommonUtils;
import com.jianshui.common.utils.spring.SpringUtils;
import com.jianshui.invoice.constant.elephant.ElephantConstants;
import com.jianshui.invoice.domain.dto.HXResponse;
import com.jianshui.system.domain.CompanyserviceProp;
import com.jianshui.system.service.ICompanyservicePropService;
import com.jianshui.system.service.ISysConfigService;
@ -622,4 +623,105 @@ public class ElephantUtils {
}
throw new JianshuiParamErrorException("暂不支持的开票类型,请联系管理员!", null, "invoice");
}
/**
* @Author: kk
* @Description: 大象接口V6调用工具类 对应销项-大象-V6实例
*/
public static AjaxResult sendRequestWithoutTokenV6New(String uri, String methodName, JSON data, Companyservice companyservice) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_secret_id");
if (secretIdProp == null) {
throw new JianshuiServiceException("企业未配置属性,请联系管理员!");
}
String secretId = secretIdProp.getValue();
CompanyserviceProp sercretKeyProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_secret_key");
if (sercretKeyProp == null) {
throw new JianshuiServiceException("企业未配置属性,请联系管理员!");
}
String sercretKey = sercretKeyProp.getValue();
// 调用v6请求内容(content字段)
String str = JSONUtil.toJsonStr(data);
boolean isDevMode = CommonUtils.isDevMode();
// 主机名(京东云地址)
String host = ElephantConstants.PROD_HOST_LOCAL_V6_JingDongYun;
if (isDevMode) {
host = ElephantConstants.DEV_HOST_LOCAL_V6_JingDongYun;
}
// 最终接口地址
String url = host + uri;
// 封装大象v6调用类
DxhyInterfaceRequest dxhyInterfaceRequest = new DxhyInterfaceRequest();
// 地址
dxhyInterfaceRequest.setRequestUrl(url);
// 请求方式
dxhyInterfaceRequest.setRequestType("POST");
// 超时时间(毫秒值)
dxhyInterfaceRequest.setHttpTimeOut("100000");
// 流水号(拷贝的接口文档的)
// dxhyInterfaceRequest.setDataExchangeId("1617954341800234234234552");
// 生成流水号
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
long snowflakeId = snowflake.nextId();
String snowflakeIdStr = String.valueOf(snowflakeId);
dxhyInterfaceRequest.setDataExchangeId(snowflakeIdStr);
// appid
dxhyInterfaceRequest.setSecretId(secretId);
// appkey
dxhyInterfaceRequest.setSecretKey(sercretKey);
// 内容字段(content请求体)
dxhyInterfaceRequest.setContent(str);
// 不打包
dxhyInterfaceRequest.setZipCode("0");
// 不加密
dxhyInterfaceRequest.setEncryptCode("0");
try {
DxhyInterfaceResponse dxhyInterfaceResponse = null;
// 大象v6调用方法(获取结果处理)
log.info("【销项】【大象工具类】调用V6接口,入参{}",JSONUtil.toJsonStr(dxhyInterfaceRequest));
dxhyInterfaceResponse = InvokeDxhyApi.dxhyInterfaceInvoke(dxhyInterfaceRequest);
log.info("【销项】【大象工具类】请求成功,结果{}",JSONUtil.toJsonStr(dxhyInterfaceResponse));
// 返回报文处理为简税报文
String dataDxhy = dxhyInterfaceResponse.getData();
String codeDxhy = dxhyInterfaceResponse.getCode();
String messageDxhy = dxhyInterfaceResponse.getMessage();
if("0000".equals(codeDxhy)){
return AjaxResult.success("0000",dataDxhy);
}else{
return AjaxResult.error(codeDxhy,messageDxhy);
}
} catch (Exception e) {
log.error("【销项】【大象接口】调用HttpsUtilV6.Exception, url=" + url + ",request=" + JSONUtil.toJsonStr(dxhyInterfaceRequest), e);
}
return AjaxResult.error("9999","请求失败!");
}
}

Loading…
Cancel
Save