| | |
| | | import cc.mrbird.febs.pay.model.*; |
| | | import cc.mrbird.febs.pay.service.IXcxPayService; |
| | | import cc.mrbird.febs.pay.service.WxFaPiaoService; |
| | | import cc.mrbird.febs.pay.util.JCEUtil; |
| | | import cc.mrbird.febs.pay.util.WechatConfigure; |
| | | import cc.mrbird.febs.rabbit.consumer.AgentConsumer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | |
| | | import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner; |
| | | import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials; |
| | | import com.wechat.pay.contrib.apache.httpclient.notification.NotificationHandler; |
| | | import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; |
| | | import okhttp3.HttpUrl; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | |
| | | import java.net.URLConnection; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.KeyPair; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.PrivateKey; |
| | | import java.security.*; |
| | | import java.security.cert.CertificateFactory; |
| | | import java.security.cert.X509Certificate; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.InputStream; |
| | |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void rankProfit2_01() throws IOException, ParseException, GeneralSecurityException {//获取平台证书 |
| | | JCEUtil.removeCryptographyRestrictions(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
| | | PrivateKey privateKey = wxFaPiaoService.getPrivateKeyV3(); |
| | | String baseUrl = "https://api.mch.weixin.qq.com"; |
| | | String canonicalUrl = "/v3/certificates"; |
| | | String postStr = null; |
| | | try { |
| | | postStr = wxFaPiaoService.createAuthorization( |
| | | "GET", |
| | | baseUrl+canonicalUrl, |
| | | "", |
| | | privateKey |
| | | |
| | | ); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | HttpClient httpClient = new HttpClient(); |
| | | try { |
| | | 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 i = httpClient.executeMethod(method); |
| | | System.out.println(i); |
| | | System.out.println(method); |
| | | String responseBodyAsString = method.getResponseBodyAsString(); |
| | | cn.hutool.json.JSONObject maps = JSONUtil.parseObj(responseBodyAsString); |
| | | System.out.println(maps); |
| | | |
| | | 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())) { |
| | | FPEncryptCertificate encrypt_certificate = certificates.getEncrypt_certificate(); |
| | | //解密 |
| | | AesUtil aesUtil = new AesUtil("daL341aN5orDt13puXadsAf2rpuX12v3".getBytes("utf-8")); |
| | | String pulicKey = aesUtil.decryptToString( |
| | | encrypt_certificate.getAssociated_data().getBytes("utf-8"), |
| | | encrypt_certificate.getNonce().getBytes("utf-8"), |
| | | encrypt_certificate.getCiphertext()); |
| | | //获取平台证书 |
| | | final CertificateFactory cf = CertificateFactory.getInstance("X509"); |
| | | |
| | | ByteArrayInputStream inputStream = new ByteArrayInputStream(pulicKey.getBytes(StandardCharsets.UTF_8)); |
| | | |
| | | X509Certificate x509Certificate = (X509Certificate) cf.generateCertificate(inputStream); |
| | | System.out.println(x509Certificate); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Autowired |
| | | private MallOrderInfoMapper mallOrderInfoMapper; |