Commit 7b2af1cc authored by 胡建龙's avatar 胡建龙

20220415 未整理接口

parent 95a9ed4a
......@@ -264,6 +264,7 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.65.01</version>
<!-- <version>1.47</version>-->
<scope>system</scope>
<systemPath>
${project.basedir}/src/main/webapp/WEB-INF/lib/bcprov-jdk15on-1.65.01.jar
......
......@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/*
* 〈〉
......@@ -53,4 +54,40 @@ public class HclcCmbPolyController extends BaseController {
return jsonResult;
}
/**
* 主动请求订单状态结果
* @param request
* @param params
* @return
*/
@ResponseBody
@RequestMapping("/cmb/poly/query/order/status")
public JSONObject queryOrderStatus(HttpServletRequest request,
@RequestBody(required = true) JSONObject params) {
JSONObject jsonResult = new JSONObject();
IRequest iRequest = createRequestContext(request);
jsonResult = hclcCmbPolyService.queryOrderStatus(iRequest, params);
return jsonResult;
}
/**
* 暴露出去的回调地址,被动获取订单状态结果
* @param request
* @param params
* @return
*/
@ResponseBody
@RequestMapping("/cmb/poly/order/notify")
public Map<String, String> orderStatusNotify(HttpServletRequest request,
@RequestBody(required = true) JSONObject params) {
IRequest iRequest = createRequestContext(request);
return hclcCmbPolyService.orderNotify(iRequest, params);
}
//订单关闭 4.7.1
}
\ No newline at end of file
......@@ -3,9 +3,14 @@ package com.cmb.service;
import com.alibaba.fastjson.JSONObject;
import com.hand.hap.core.IRequest;
import java.util.Map;
public interface HclcCmbPolyService {
JSONObject getQrcode(IRequest iRequest, JSONObject params);
JSONObject queryOrderStatus(IRequest iRequest, JSONObject params);
Map orderNotify(IRequest iRequest, JSONObject params);
}
package com.cmb.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import java.util.HashMap;
import java.util.Map;
//构造请求报文工具类
public class GenerateUtil {
private static final Logger LOGGER = Logger.getLogger(GenerateUtil.class);
@Value("${cmb.version}")
private static String version;
@Value("${cmb.encoding}")
private static String encoding;
@Value("${cmb.signMethod}")
private static String signMethod;
public static final String privateKey = "D5F2AFA24E6BA9071B54A8C9AD735F9A1DE9C4657FA386C09B592694BC118B38";
public static final String publicKey = "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE6Q+fktsnY9OFP+LpSR5Udbxf5zHCFO0PmOKlFNTxDIGl8jsPbbB/9ET23NV+acSz4FEkzD74sW2iiNVHRLiKHg==";
public static String initRequestParam(Pojo pojo){
//设置公共请求参数
Map<String,String> resultPublicParam = new HashMap<>();
resultPublicParam.put("version",version);
resultPublicParam.put("encoding",encoding);
resultPublicParam.put("sign_method", signMethod);
//初始化业务请求参数
try {
ObjectMapper objectMapper = new ObjectMapper();
String bizContent = objectMapper.writeValueAsString(pojo);
System.out.println(bizContent);
resultPublicParam.put("biz_content",bizContent);
//对待加签内容进行排序拼接
String signStr = SignatureUtil.getSignContent(resultPublicParam);
//加签
String sign = SM2Util.sm2Sign(signStr, privateKey);
resultPublicParam.put("sign",sign);
String requestStr = objectMapper.writeValueAsString(resultPublicParam);
LOGGER.info("加签后的报文内容:" + requestStr);
return requestStr;
}catch (Exception ex){
ex.printStackTrace();
return null;
}
}
/**
* 处理响应报文
* @param responseMap
* @return
*/
public static void handleResponse(Map<String,String> responseMap){
if( null == responseMap){
LOGGER.equals("响应的内容为空");
return ;
}
try {
ObjectMapper objectMapper = new ObjectMapper();
LOGGER.info("收到响应的内容为:" + objectMapper.writeValueAsString(responseMap));
//验签
String sign = responseMap.remove("sign");
//生成验签字符串
String signStr = SignatureUtil.getSignContent(responseMap);
boolean flag = SM2Util.sm2Check(signStr,sign, publicKey);
if( flag ){
LOGGER.info("验签成功!");
} else {
LOGGER.error("验签失败!");
}
return;
}catch (Exception ex){
LOGGER.equals("系统异常");
return;
}
}
}
package com.cmb.util;
public class Pojo {
public Pojo(){}
}
......@@ -5,10 +5,8 @@ package com.cmb.util;
import org.apache.commons.codec.binary.Base64;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.security.KeyFactory;
import java.security.PrivateKey;
......@@ -87,6 +85,18 @@ public class SignatureUtil {
return content.toString();
}
public static String decode(String str) {
String result = null;
if (str != null) {
try {
result = URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException var4) {
throw new RuntimeException(var4);
}
}
return result;
}
public static boolean rsaCheck(String content, String sign, String publicKey, String charset) throws Exception {
try {
PublicKey pubKey = getPublicKeyFromX509("RSA", new ByteArrayInputStream(publicKey.getBytes()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment