| | |
| | | package com.gkhy.exam.pay.utils; |
| | | |
| | | import cn.com.jit.mof.MOFClient; |
| | | import cn.com.jit.mof.bean.MOFSignResult; |
| | | import cn.com.jit.mof.bean.MOFVerifyResult; |
| | | import cn.com.jit.new_vstk.AdvanceSignClient; |
| | | import cn.com.jit.new_vstk.Bean.*; |
| | | import cn.com.jit.new_vstk.SignClient; |
| | |
| | | public ResultVo sendApiPost(PayReqData payReqData) throws IOException { |
| | | |
| | | Map<String, String> param = new HashMap<>(); |
| | | String appid = "A1749891493E4CDDBFE4506357B1F0AB"; |
| | | String orderUrl = "http://finpt.xjcz.gov.cn/fs-service/fs-pay/invoice.do"; |
| | | |
| | | HttpPost httpPost = new HttpPost("http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do"); |
| | | log.info("请求地址:"+"http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do"); |
| | | HttpPost httpPost = new HttpPost(orderUrl); |
| | | log.info("请求地址:"+orderUrl); |
| | | //请求参数转为json格式base64编码 |
| | | String reqData = Base64.getEncoder().encodeToString(JSONObject.toJSONString(payReqData).getBytes()); |
| | | String mac = "ED76A5F1703540BE977D34780B371FEB" + "||" + reqData; |
| | | String mac = appid + "||" + reqData; |
| | | mac = DigestUtils.md5Hex(mac.getBytes()); |
| | | param.put("appid", "ED76A5F1703540BE977D34780B371FEB"); |
| | | log.info("请求appid:"+"ED76A5F1703540BE977D34780B371FEB"); |
| | | param.put("appid", appid); |
| | | log.info("请求appid:"+appid); |
| | | param.put("reqdata", reqData); |
| | | param.put("mac", mac); |
| | | |
| | | httpPost.setEntity(assemblyFormEntity(param, "utf-8")); |
| | | HttpClient httpClient = getHttpClient("http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do"); |
| | | HttpClient httpClient = getHttpClient(orderUrl); |
| | | HttpResultVo execute = httpClient.execute(httpPost, getResponseHandler()); |
| | | String stringContent = execute.getStringContent(); |
| | | ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class); |
| | |
| | | } |
| | | |
| | | //上传财政电子票据签名文件 |
| | | public ResultVo uploadXml(String orderId, byte[] plain) throws IOException { |
| | | public ResultVo uploadXml(String orderId, String plain) throws IOException { |
| | | Map<String, String> params = new HashMap<>(); |
| | | |
| | | // Sign sign = new Sign(); |
| | |
| | | // SignDto signDto = new SignDto("SM3", "Base64", new Date(), verify.getReturnData(), verify.getSerialNumber(), verify.getIssure()); |
| | | // Element signature = sign.getSignature(signDto); |
| | | |
| | | String appid = "A1749891493E4CDDBFE4506357B1F0AB"; |
| | | String orderUrl = "http://finpt.xjcz.gov.cn/fs-service/fs-pay/uploadXml.do"; |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("orderNo",orderId); |
| | | jsonObject.put("fileData", Base64.getEncoder().encodeToString(plain)); |
| | | jsonObject.put("fileData", Base64.getEncoder().encodeToString(plain.getBytes())); |
| | | |
| | | String reqdata = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes()); |
| | | String mac = "ED76A5F1703540BE977D34780B371FEB"+"||" +reqdata; |
| | | String mac = appid+"||" +reqdata; |
| | | mac = DigestUtils.md5Hex(mac.getBytes()); |
| | | |
| | | params.put("appid","ED76A5F1703540BE977D34780B371FEB"); |
| | | params.put("appid",appid); |
| | | params.put("reqdata",reqdata); |
| | | params.put("mac",mac); |
| | | |
| | | HttpPost httpPost = new HttpPost("http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/uploadXml.do"); |
| | | HttpPost httpPost = new HttpPost(orderUrl); |
| | | httpPost.setEntity(assemblyFormEntity(params,"utf-8")); |
| | | HttpClient httpClient = getHttpClient("http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/uploadXml.do"); |
| | | HttpClient httpClient = getHttpClient(orderUrl); |
| | | HttpResultVo execute = httpClient.execute(httpPost, getResponseHandler()); |
| | | String stringContent = execute.getStringContent(); |
| | | ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class); |
| | |
| | | } |
| | | |
| | | |
| | | public JSONObject signFileV2(String fileData) throws Exception { |
| | | JSONObject xysfResult = new JSONObject(); |
| | | String certId = "11650000MB1957293J"; |
| | | MOFSignResult result = null; |
| | | // Map<String, Object> mmp = new HashMap<>(); |
| | | |
| | | try { |
| | | String filePath = "F:\\text\\cssconfig.properties"; |
| | | System.out.println("配置文件路径:" + filePath); |
| | | MOFClient client = new MOFClient(filePath); |
| | | System.out.println("证书标识为:" + certId); |
| | | System.out.println("待签名数据:" + fileData); |
| | | result = client.sign(certId, fileData.getBytes(StandardCharsets.UTF_8)); |
| | | System.out.println("签名返回结果:" + JSONObject.toJSONString(result)); |
| | | byte[] signData = result.getSignData(); |
| | | String base64Str = new String(Base64.getEncoder().encode(signData)); |
| | | // mmp.put("signResult", base64Str); |
| | | MOFVerifyResult resultVer = client.verifySign(signData, fileData.getBytes(StandardCharsets.UTF_8)); |
| | | System.out.println("验签结果为:" + JSONObject.toJSONString(resultVer)); |
| | | // mmp.put("issure", resultVer.getIssure()); |
| | | // mmp.put("sn", resultVer.getSn()); |
| | | // mmp.put("signTime", resultVer.getSignTime()); |
| | | SignDto signDto = new SignDto(resultVer.getSignTime(),base64Str,resultVer.getIssure(),resultVer.getSn()); |
| | | xysfResult.put("success", Boolean.valueOf(true)); |
| | | xysfResult.put("content", signDto); |
| | | return xysfResult; |
| | | } catch (NewCSSException e) { |
| | | System.out.println("****签名失败****"); |
| | | System.out.println("错误号为:" + e.getCode()); |
| | | System.out.println("错误描述为:" + e.getDescription()); |
| | | xysfResult.put("success", Boolean.valueOf(false)); |
| | | xysfResult.put("msg", "系统错误"); |
| | | return xysfResult; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //签名 |
| | | public SignResult sign(byte[] strData) { |
| | | public SignResult sign(String strData) { |
| | | SignResult result = null; |
| | | String certId = "11650000MB1957293J"; |
| | | try { |
| | | AdvanceSignClient client = new AdvanceSignClient("F:\\text\\cssconfig.properties"); |
| | | result = client.sign(certId,strData); |
| | | MOFClient client = new MOFClient("F:\\text\\cssconfig.properties"); |
| | | result = client.sign(certId,strData.getBytes(StandardCharsets.UTF_8)); |
| | | log.info("***签名成功***"); |
| | | log.info("签名返回结果为:"+result); |
| | | byte[] signData = result.getSignData(); |
| | | String s = new String(Base64.getEncoder().encode(signData)); |
| | | log.info("签名结果为:"+s); |
| | |
| | | /** |
| | | * 验签名 |
| | | */ |
| | | public VerifyResult verify(byte[] strData,byte[] signData){ |
| | | VerifyResult verify = null; |
| | | public MOFVerifyResult verify(byte[] strData,String signData){ |
| | | MOFVerifyResult verify = null; |
| | | try { |
| | | SignClient client = new SignClient("F:\\text\\cssconfig.properties"); |
| | | byte[] plain = strData; |
| | | byte[] sign = signData; |
| | | MOFClient client = new MOFClient("F:\\text\\cssconfig.properties"); |
| | | |
| | | verify = client.verify(sign, plain); |
| | | verify = client.verifySign(strData, signData.getBytes(StandardCharsets.UTF_8)); |
| | | log.info("验签成功"); |
| | | log.info(" 证书subjectdn: " + verify.getSubjectdn()); |
| | | log.info(" 证书issuer: " + verify.getIssure()); |