cbs8接口
This commit is contained in:
parent
e4d0f19e02
commit
442fbb602e
|
@ -8,7 +8,6 @@ import com.hzya.frame.cbs8.dto.req.*;
|
|||
import com.hzya.frame.cbs8.service.ICbs8ExtService;
|
||||
import com.hzya.frame.cbs8.util.CBSUtil;
|
||||
import com.hzya.frame.cbs8.util.CbsAccessToken;
|
||||
import com.hzya.frame.cbs8.util.SM2Util;
|
||||
import com.hzya.frame.seeyon.cbs8.entity.PaymentEntity;
|
||||
import com.hzya.frame.stringutil.StringUtil;
|
||||
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
|
||||
|
@ -62,21 +61,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
payRequestDTO.setPayAccount(null);
|
||||
}
|
||||
String requestData = JSONObject.toJSONString(payRequestDTO);
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = new HashMap();
|
||||
header.put(CBSUtil.SIGN_HEADER_NAME,sign);
|
||||
header.put(CBSUtil.TIMESTAMP_HEADER,Long.toString(timestamp));
|
||||
header.put(HTTP.CONTENT_TYPE,CBSUtil.TARGET_CONTENT_TYPE);
|
||||
header.put(CBSUtil.AUTHORIZATION,CBSUtil.BEARER+ CbsAccessToken.getToken());
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setHeaders(header);
|
||||
|
||||
String body = HttpRequest.post("https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/payment/openapi/v1/payment-apply-common").addHeaders(header).body(encryptedData).execute().body();
|
||||
System.out.println(body);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
|
@ -94,14 +80,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
if (StrUtil.isNotEmpty(boyds)){
|
||||
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(boyds,AgentPayRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(agentPayRequest);
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = getHeaders(sign,timestamp);
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setHeaders(header);
|
||||
//加密签名
|
||||
encrypAndsign(entity, requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
@ -119,17 +99,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
PayResultRequestDTO payResultRequest = JSONObject.parseObject(bodys,PayResultRequestDTO.class);
|
||||
if (null != payResultRequest && StrUtil.isNotEmpty(payResultRequest.getReferenceNum())){
|
||||
String requestData = JSONObject.toJSONString(payResultRequest);
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = getHeaders(sign,timestamp);
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setHeaders(header);
|
||||
byte[] bodyBytes = HttpRequest.post("https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/payment/openapi/v2/detail").addHeaders(header).body(encryptedData).execute().bodyBytes();
|
||||
//解密报文
|
||||
String decrypt = CBSUtil.decrypt(bodyBytes);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
}else {
|
||||
throw new BaseSystemException("业务参考号不能为空!!!!");
|
||||
}
|
||||
|
@ -149,14 +120,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
if (StrUtil.isEmpty(bodys)){
|
||||
TransactionDetailReqDTO transactionDetailReqDTO = JSONObject.parseObject(bodys,TransactionDetailReqDTO.class);
|
||||
String requestData = JSONObject.toJSONString(transactionDetailReqDTO);
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = getHeaders(sign,timestamp);
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setHeaders(header);
|
||||
////加密签名
|
||||
encrypAndsign(entity, requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
@ -169,9 +134,18 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
*/
|
||||
@Override
|
||||
public SysExtensionApiEntity payApplyAgent(SysExtensionApiEntity entity) {
|
||||
return null;
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(bodys,AgentPayRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(agentPayRequest);
|
||||
////加密签名
|
||||
encrypAndsign(entity, requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 代发代扣结果查询
|
||||
*
|
||||
|
@ -180,7 +154,13 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
*/
|
||||
@Override
|
||||
public SysExtensionApiEntity payApplyAgentResult(SysExtensionApiEntity entity) {
|
||||
return null;
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
AgentPayResultRequestDTO agentPayResultRequestDTO = JSONObject.parseObject(bodys,AgentPayResultRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(agentPayResultRequestDTO);
|
||||
encrypAndsign(entity,requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,25 +175,20 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
if (StrUtil.isNotEmpty(bodys)){
|
||||
ElecRequestDTO elecRequestDTO = JSONObject.parseObject(bodys,ElecRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(elecRequestDTO);
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = getHeaders(sign,timestamp);
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setHeaders(header);
|
||||
byte[] bodyBytes = HttpRequest.post("https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/account/openapi/v1/electronic-bill/query").addHeaders(header).body(encryptedData).execute().bodyBytes();
|
||||
//解密报文
|
||||
String decrypt = CBSUtil.decrypt(bodyBytes);
|
||||
System.out.println(decrypt);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Map<String,String> getHeaders(String sign,long timestamp){
|
||||
/**
|
||||
* 请求头
|
||||
* @param sign
|
||||
* @param timestamp
|
||||
* @return
|
||||
*/
|
||||
private Map<String,String> headersValueOf(String sign, long timestamp){
|
||||
Map<String,String> header = new HashMap();
|
||||
header.put(CBSUtil.SIGN_HEADER_NAME,sign);
|
||||
header.put(CBSUtil.TIMESTAMP_HEADER,Long.toString(timestamp));
|
||||
|
@ -221,4 +196,20 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
header.put(CBSUtil.AUTHORIZATION,CBSUtil.BEARER+ CbsAccessToken.getToken());
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密 签名
|
||||
* @param entity 接口转发参数对象
|
||||
* @param requestData 请求参数json字符串
|
||||
*/
|
||||
private void encrypAndsign(SysExtensionApiEntity entity, String requestData) {
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = headersValueOf(sign,timestamp);
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setHeaders(header);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,13 @@ import com.hzya.frame.cbs8.service.ICbs8Service;
|
|||
import com.hzya.frame.cbs8.util.CBSUtil;
|
||||
import com.hzya.frame.seeyon.cbs8.entity.PaymentEntity;
|
||||
import com.hzya.frame.seeyon.cbs8.service.IPaymentService;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -39,8 +41,10 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
.put("secretKey","7Gp6OjHrIaQ6R3tXGPrI4morjQyWL+qu4JJschQnkBRtv26VDgGFVYKOy5kMZfd/j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800026")
|
||||
.build();
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(JSONObject.toJSONString(paymentEntity)).timeout(60000).execute().body();
|
||||
PayResponseDTO payResponseDTO = JSONObject.parseObject(body,PayResponseDTO.class);
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(JSONObject.toJSONString(paymentEntity)).timeout(60000).execute().body();
|
||||
//解密响应报文
|
||||
String result = decryptResBody(body);
|
||||
PayResponseDTO payResponseDTO = JSONObject.parseObject(result,PayResponseDTO.class);
|
||||
return payResponseDTO;
|
||||
}
|
||||
|
||||
|
@ -59,14 +63,13 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
.put("secretKey","7Gp6OjHrIaQ6R3tXGPrI4morjQyWL+qu4JJschQnkBRtv26VDgGFVYKOy5kMZfd/j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800026")
|
||||
.build();
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(JSONObject.toJSONString(resultRequestDTO)).timeout(60000).execute().body();
|
||||
if (StrUtil.isEmpty(body)){
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(body, CbsResponseDTO.class);
|
||||
if (CollectionUtils.isNotEmpty(cbsResponseDTO.getData())){
|
||||
List<JSONObject> dataList = cbsResponseDTO.getData();
|
||||
List<PayResultResDTO> payResultList = CBSUtil.convertJsonArrayToList(dataList, PayResultResDTO.class);
|
||||
return payResultList;
|
||||
}
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(JSONObject.toJSONString(resultRequestDTO)).timeout(60000).execute().body();
|
||||
String result = decryptResBody(body);
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
|
||||
if (CollectionUtils.isNotEmpty(cbsResponseDTO.getData())){
|
||||
List<JSONObject> dataList = cbsResponseDTO.getData();
|
||||
List<PayResultResDTO> payResultList = CBSUtil.convertJsonArrayToList(dataList, PayResultResDTO.class);
|
||||
return payResultList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -102,7 +105,8 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
.put("secretKey","7Gp6OjHrIaQ6R3tXGPrI4morjQyWL+qu4JJschQnkBRtv26VDgGFVYKOy5kMZfd/j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800026")
|
||||
.build();
|
||||
String result = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
String result = decryptResBody(body);
|
||||
if (StrUtil.isNotEmpty(result)){
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
|
||||
if (null != cbsResponseDTO){
|
||||
|
@ -146,7 +150,8 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
.put("secretKey","7Gp6OjHrIaQ6R3tXGPrI4morjQyWL+qu4JJschQnkBRtv26VDgGFVYKOy5kMZfd/j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800026")
|
||||
.build();
|
||||
String result = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
String result = decryptResBody(body);
|
||||
if (StrUtil.isNotEmpty(result)){
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
|
||||
if (null != cbsResponseDTO){
|
||||
|
@ -180,7 +185,8 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
.put("secretKey","7Gp6OjHrIaQ6R3tXGPrI4morjQyWL+qu4JJschQnkBRtv26VDgGFVYKOy5kMZfd/j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800026")
|
||||
.build();
|
||||
String result = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
String result = decryptResBody(body);
|
||||
if (StrUtil.isNotEmpty(result)){
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
|
||||
List<JSONObject> dataList = cbsResponseDTO.getData();
|
||||
|
@ -201,6 +207,42 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
*/
|
||||
@Override
|
||||
public AgentPayResultResDTO agentPayResult(AgentPayResultRequestDTO agentPayResultRequestDTO) {
|
||||
Map<String, String> headerMap = MapBuilder.<String, String>create(true)
|
||||
.put("apiCode", "8000260004")
|
||||
.put("publicKey","ZJYA1vBeY1ai53iNmbAEsw6DImjkXGBkdMailxcBdliFC85Ce7eDIk+3zDUT+v578prj")
|
||||
.put("secretKey","7Gp6OjHrIaQ6R3tXGPrI4morjQyWL+qu4JJschQnkBRtv26VDgGFVYKOy5kMZfd/j3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800026")
|
||||
.build();
|
||||
String params = JSON.toJSONString(agentPayResultRequestDTO);
|
||||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(params).timeout(60000).execute().body();
|
||||
//解密报文
|
||||
String result = decryptResBody(body);
|
||||
if (StrUtil.isNotEmpty(result)){
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
|
||||
List<JSONObject> dataList = cbsResponseDTO.getData();
|
||||
if (CollectionUtils.isNotEmpty(dataList)){
|
||||
JSONObject o = dataList.get(0);
|
||||
AgentPayResultResDTO agentPayResultResDTO = JSON.toJavaObject(o, AgentPayResultResDTO.class);
|
||||
return agentPayResultResDTO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密响应报文
|
||||
* @param body
|
||||
* @return
|
||||
*/
|
||||
private String decryptResBody(String body){
|
||||
if (StrUtil.isNotEmpty(body)){
|
||||
JsonResultEntity resultEntity = JSONObject.parseObject(body,JsonResultEntity.class);
|
||||
String bodyBase64 = String.valueOf(resultEntity.getAttribute());
|
||||
byte[] bodyBytes = Base64.getDecoder().decode(bodyBase64);
|
||||
//解密报文
|
||||
String result = CBSUtil.decrypt(bodyBytes);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue