| | |
| | | package com.gkhy.exam.pay.utils; |
| | | |
| | | import cn.com.jit.new_vstk.AdvanceSignClient; |
| | | import cn.com.jit.new_vstk.Bean.*; |
| | | import cn.com.jit.new_vstk.SignClient; |
| | | import cn.com.jit.new_vstk.exception.NewCSSException; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.gkhy.exam.pay.entity.PayReqData; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | Map<String, String> param = new HashMap<>(); |
| | | |
| | | HttpPost httpPost = new HttpPost(orderUrl); |
| | | HttpPost httpPost = new HttpPost("http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do"); |
| | | |
| | | //请求参数转为json格式base64编码 |
| | | String reqData = Base64.getEncoder().encodeToString(JSONObject.toJSONString(payReqData).getBytes()); |
| | | String mac = appId + "||" + reqData; |
| | | String mac = "ED76A5F1703540BE977D34780B371FEB" + "||" + reqData; |
| | | mac = DigestUtils.md5Hex(mac.getBytes()); |
| | | param.put("appid", appId); |
| | | param.put("appid", "ED76A5F1703540BE977D34780B371FEB"); |
| | | param.put("reqdata", reqData); |
| | | param.put("mac", mac); |
| | | |
| | | httpPost.setEntity(assemblyFormEntity(param, "utf-8")); |
| | | HttpClient httpClient = getHttpClient(orderUrl); |
| | | HttpClient httpClient = getHttpClient("http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do"); |
| | | HttpResultVo execute = httpClient.execute(httpPost, getResponseHandler()); |
| | | String stringContent = execute.getStringContent(); |
| | | ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class); |
| | |
| | | Map<String, String> params = new HashMap<>(); |
| | | |
| | | Sign sign = new Sign(); |
| | | Element signature = sign.getSignature(plain); |
| | | SignResult sign1 = this.sign(plain); |
| | | log.info("签名结果为:"+ Arrays.toString(sign1.getSignData())); |
| | | VerifyResult verify = this.verify(plain, new String(sign1.getSignData())); |
| | | SignDto signDto = new SignDto("SM3", "Base64", new Date(), verify.getReturnData(), verify.getSerialNumber(), verify.getIssure()); |
| | | Element signature = sign.getSignature(signDto); |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("orderNo",orderId); |
| | |
| | | return byteArrayOutputStream.toByteArray(); |
| | | } |
| | | |
| | | |
| | | //签名 |
| | | public SignResult sign(String strData) { |
| | | SignResult result = null; |
| | | String certId = "rsa"; |
| | | try { |
| | | AdvanceSignClient client = new AdvanceSignClient("cssconfig.properties"); |
| | | result = client.sign(certId,strData.getBytes()); |
| | | log.info("***签名成功***"); |
| | | byte[] signData = result.getSignData(); |
| | | String s = new String(Base64.getEncoder().encode(signData)); |
| | | log.info("签名结果为:"+s); |
| | | } catch (NewCSSException e) { |
| | | log.info("签名失败"); |
| | | log.info("错误号为:" + e.getCode()); |
| | | log.info("错误描述为: " + e.getDescription()); |
| | | log.info("日志标识码: " + e.getSerialNumber()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 验签名 |
| | | */ |
| | | public VerifyResult verify(String strData,String signData){ |
| | | VerifyResult verify = null; |
| | | try { |
| | | AdvanceSignClient client = new AdvanceSignClient("cssconfig.properties"); |
| | | byte[] plain = strData.getBytes(); |
| | | byte[] sign = signData.getBytes(); |
| | | |
| | | verify = client.verify(sign, plain); |
| | | log.info("验签成功"); |
| | | log.info(" 证书subjectdn: " + verify.getSubjectdn()); |
| | | log.info(" 证书issuer: " + verify.getIssure()); |
| | | log.info(" 证书SN: " + verify.getSn()); |
| | | log.info(" 证书实体base64: " + verify.getDsCert()); |
| | | |
| | | } catch (NewCSSException e) { |
| | | log.info("****操作失败****"); |
| | | log.info("错误号为:" + e.getCode()); |
| | | log.info("错误描述为: " + e.getDescription()); |
| | | log.info("日志标识码: " + e.getSerialNumber()); |
| | | } |
| | | return verify; |
| | | } |
| | | |
| | | /** |
| | | * 制作数字信封 |
| | | */ |
| | | public EnvelopResult encryptEnvelop(String plain){ |
| | | EnvelopResult envelopResult = null; |
| | | try { |
| | | AdvanceSignClient client = new AdvanceSignClient("cssconfig.properties"); |
| | | String certId = "rsa"; |
| | | CertIdParams certIdParams = new CertIdParams(certId); |
| | | //将封装好的加密证书参数对象放入 数组中 |
| | | CertParams[] envelopCerts = new CertIdParams[]{certIdParams}; |
| | | byte[] bytes = plain.getBytes(); |
| | | /* 制作信封 */ |
| | | envelopResult = client.encryptEnvelop(envelopCerts, bytes); |
| | | byte[] envelopData = envelopResult.getEnvelopData(); |
| | | log.info("信封结果:["+envelopData+"]"); |
| | | } catch (NewCSSException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return envelopResult; |
| | | } |
| | | |
| | | /** |
| | | * 解密数字信封 |
| | | */ |
| | | public DecryptResult decryptEnvelop(String signData){ |
| | | DecryptResult result = null; |
| | | try { |
| | | AdvanceSignClient client = new AdvanceSignClient("cssconfig.properties"); |
| | | byte[] enc_data = signData.getBytes(); |
| | | result = client.decryptEnvelop(enc_data); |
| | | log.info("解密数字信封结果成功"); |
| | | String plainData = new String(result.getPlainData()); |
| | | log.info("原文:"+plainData); |
| | | log.info(" 证书subjectdn: " + result.getSubjectdn()); |
| | | log.info(" 证书issuer: " + result.getIssure()); |
| | | log.info(" 证书SN: " + result.getSn()); |
| | | log.info(" 证书实体base64: " + result.getDsCert()); |
| | | |
| | | } catch (NewCSSException e) { |
| | | log.info("****操作失败****"); |
| | | log.info("错误号为:" + e.getCode()); |
| | | log.info("错误描述为: " + e.getDescription()); |
| | | log.info("日志标识码: " + e.getSerialNumber()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |