| | |
| | | import cc.mrbird.febs.pay.model.FPEncryptCertificate; |
| | | import cc.mrbird.febs.pay.model.HeaderDto; |
| | | import cc.mrbird.febs.pay.service.WxFaPiaoService; |
| | | import cc.mrbird.febs.pay.util.JCEUtil; |
| | | import cc.mrbird.febs.pay.util.RandomStringGenerator; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.json.JSONObject; |
| | |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import okhttp3.HttpUrl; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | | import org.apache.commons.httpclient.methods.GetMethod; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | |
| | | log.info("微信电子发票回调接口....resource解密:"+decryptToString); |
| | | |
| | | JSONObject parseObj = JSONUtil.parseObj(decryptToString); |
| | | |
| | | log.info("微信电子发票回调接口....resource解密-JSONObject:"+parseObj); |
| | | |
| | | String mchid = String.valueOf(parseObj.get("mchid")); |
| | | String fapiao_apply_id = String.valueOf(parseObj.get("fapiao_apply_id")); |
| | | String apply_time = String.valueOf(parseObj.get("apply_time")); |
| | | MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectByOrderNo(fapiao_apply_id); |
| | | if(ObjectUtil.isNotEmpty(mallOrderInfo)){ |
| | | //省略查询订单 |
| | |
| | | * 获取平台证书 |
| | | */ |
| | | public X509Certificate getCertificates() throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException, ParseException { |
| | | JCEUtil.removeCryptographyRestrictions(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | |
| | | PrivateKey privateKey = this.getPrivateKeyV3(); |
| | | String baseUrl = "https://api.mch.weixin.qq.com"; |
| | |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | HttpClient httpClient = new HttpClient(); |
| | | //请求URL |
| | | HttpGet httpGet = new HttpGet(baseUrl+canonicalUrl); |
| | | httpGet.setHeader("Accept", "application/json"); |
| | | //生成签名 |
| | | httpGet.setHeader("Authorization ", "WECHATPAY2-SHA256-RSA2048"+postStr); |
| | | httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"); |
| | | GetMethod method = new GetMethod(baseUrl+canonicalUrl); |
| | | method.setRequestHeader("Accept", "application/json"); |
| | | method.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"); |
| | | method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); |
| | | // method.setRequestHeader("Connection", "keep-alive"); |
| | | method.setRequestHeader("Authorization", "WECHATPAY2-SHA256-RSA2048 "+postStr); |
| | | int statusCode = httpClient.executeMethod(method); |
| | | //完成签名并执行请求 |
| | | CloseableHttpResponse response = httpClient.execute(httpGet); |
| | | X509Certificate x509Certificate = null; |
| | | try { |
| | | int statusCode = response.getStatusLine().getStatusCode(); |
| | | if (statusCode == 200) { //处理成功 |
| | | // System.out.println("success,return body = " + EntityUtils.toString(response.getEntity())); |
| | | FPCertificateVo certificateVo = com.alibaba.fastjson.JSONObject.parseObject(EntityUtils.toString(response.getEntity()), FPCertificateVo.class); |
| | | |
| | | String responseBodyAsString = method.getResponseBodyAsString(); |
| | | FPCertificateVo certificateVo = com.alibaba.fastjson.JSONObject.parseObject(responseBodyAsString, FPCertificateVo.class); |
| | | for (FPCertificates certificates : certificateVo.getData()) { |
| | | if (format.parse(certificates.getEffective_time()).before(new Date()) |
| | | && format.parse(certificates.getExpire_time()).after(new Date())) { |
| | |
| | | } |
| | | return x509Certificate; |
| | | } else if (statusCode == 204) { //处理成功,无返回Body |
| | | System.out.println("success"); |
| | | return x509Certificate; |
| | | } else { |
| | | System.out.println("failed,resp code = " + statusCode + ",return body = " + EntityUtils.toString(response.getEntity())); |
| | | return x509Certificate; |
| | | } |
| | | } catch (GeneralSecurityException | ParseException e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } finally { |
| | | response.close(); |
| | | httpClient.close(); |
| | | } |
| | | } |
| | | |