微信红包接口-CA证书
来源:互联网 发布:rlcf pic单片机指令 编辑:程序博客网 时间:2024/05/16 16:12
package com.kaipai.ck.common;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.security.KeyStore;
import java.util.Properties;
import javax.net.ssl.SSLContext;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import com.kaipai.ck.wx.configs.WxConfigs;
@SuppressWarnings(“deprecation”)
public class AiwHttpsCAUtils {
private static final String CHARSET = "UTF-8";//private static final String HTTP_POST = "POST";//private static final String HTTP_GET = "GET";/** * 方法 * @param url 微信接口url * @param data xml格式 * @return */static public String doHttpsPost(String url, String data) { String result = null; try { String path = Thread.currentThread().getContextClassLoader().getResource("/").getPath(); Properties props=System.getProperties(); //获得系统属性集 String osName = props.getProperty("os.name"); //操作系统名称 char oneChar = path.charAt(0); char twoChar = path.charAt(1); if (osName.startsWith("Win")) { if (oneChar=='/') { path = path.replaceFirst("/", ""); } }else { if (oneChar=='/') { path = path.replaceFirst("/", ""); }else if (twoChar=='/') { path = path.replaceFirst("/", ""); } } path = path+WxConfigs.WxPay.WX_APICLIENT_CERT; KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileInputStream instream = new FileInputStream(new File(path)); try { keyStore.load(instream, WxConfigs.WxPay.MCH_ID.toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom() .loadKeyMaterial(keyStore, WxConfigs.WxPay.MCH_ID.toCharArray()) .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom() .setSSLSocketFactory(sslsf) .build(); try { HttpPost httpPost = new HttpPost(url); System.out.println("executing request" + httpPost.getRequestLine()); httpPost.setEntity(new StringEntity(data, CHARSET)); CloseableHttpResponse response = httpclient.execute(httpPost); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); String text; while ((text = bufferedReader.readLine()) != null) { System.out.println(text); //连接成一个字符串 if (result != null) result += text; else result = text; } } EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } } catch (Exception e) { // TODO: handle exception } return result;}
}
- 微信红包接口-CA证书
- 微信红包CA证书出错
- 微信红包接口实现
- 微信现金红包高级红包接口开发注意事项
- 微信平台红包接口调用教程
- 微信红包高级接口JAVA实现
- 微信红包接口集成流程
- 微信支付现金红包接口
- 微信现金红包接口demo(java)
- 微信公众号 调用红包接口
- 接口发放微信企业号红包
- 接口发放微信企业号红包
- 微信红包调用获取不到证书路径问题
- CA证书出错,请登录微信支付商户平台下载证书
- 微信支付(红包)接口的测试
- Java微信开发之现金红包接口
- 微信商户发放红包接口调试经验总结
- 微信红包接口API实现(php版)
- php rsa加密解密使用详解
- 利用doker快速搭建node.js运行环境
- NGINX重启HTTPS站点要Enter PEM pass phrase输入密码
- 五子棋AI算法第七篇-Zobrist
- 程序员的十层楼
- 微信红包接口-CA证书
- 06.C++学习笔记------静态绑定动态绑定
- leetcode:Path Sum 【Java】
- 魔术方法__call 和__callStatic
- PAT (Basic Level)1031. 查验身份证
- hive left semi join
- linux下gettimeofday()的使用
- Python任务调度模块 – APScheduler
- dijit/Tree 部件美化