微信支付---申请退款的https双向认证demo
来源:互联网 发布:自然语言和c语言 编辑:程序博客网 时间:2024/05/15 20:59
/**
* https双向签名认证,用于支付申请退款
*
* */
public static String payHttps(String url,String data) throws Exception {
//商户id
String MCH_ID = PropUtil.getPropertyValue("wx.sz.mchid", "").replace("\"","");
//指定读取证书格式为PKCS12
KeyStore keyStore = KeyStore.getInstance("PKCS12");
String path =PropUtil.getPropertyValue("wx.sz.certificate.path", "D:/apiclient_cert.p12").replace("\"","");
//读取本机存放的PKCS12证书文件
FileInputStream instream = new FileInputStream(new File(path));
try {
//指定PKCS12的密码(商户ID)
keyStore.load(instream, MCH_ID.toCharArray());
} finally {
instream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, MCH_ID.toCharArray()).build();
//指定TLS版本
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,new String[] { "TLSv1" },null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
//设置httpclient的SSLSocketFactory
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
try {
HttpPost httpost = new HttpPost(url); // 设置响应头信息
httpost.addHeader("Connection", "keep-alive");
httpost.addHeader("Accept", "*/*");
httpost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
httpost.addHeader("Host", "api.mch.weixin.qq.com");
httpost.addHeader("X-Requested-With", "XMLHttpRequest");
httpost.addHeader("Cache-Control", "max-age=0");
httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = httpclient.execute(httpost);
try {
HttpEntity entity = response.getEntity();
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
return jsonStr;
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
* https双向签名认证,用于支付申请退款
*
* */
public static String payHttps(String url,String data) throws Exception {
//商户id
String MCH_ID = PropUtil.getPropertyValue("wx.sz.mchid", "").replace("\"","");
//指定读取证书格式为PKCS12
KeyStore keyStore = KeyStore.getInstance("PKCS12");
String path =PropUtil.getPropertyValue("wx.sz.certificate.path", "D:/apiclient_cert.p12").replace("\"","");
//读取本机存放的PKCS12证书文件
FileInputStream instream = new FileInputStream(new File(path));
try {
//指定PKCS12的密码(商户ID)
keyStore.load(instream, MCH_ID.toCharArray());
} finally {
instream.close();
}
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, MCH_ID.toCharArray()).build();
//指定TLS版本
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,new String[] { "TLSv1" },null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
//设置httpclient的SSLSocketFactory
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
try {
HttpPost httpost = new HttpPost(url); // 设置响应头信息
httpost.addHeader("Connection", "keep-alive");
httpost.addHeader("Accept", "*/*");
httpost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
httpost.addHeader("Host", "api.mch.weixin.qq.com");
httpost.addHeader("X-Requested-With", "XMLHttpRequest");
httpost.addHeader("Cache-Control", "max-age=0");
httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = httpclient.execute(httpost);
try {
HttpEntity entity = response.getEntity();
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
return jsonStr;
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
0 0
- 微信支付---申请退款的https双向认证demo
- 微信支付一 :公众号支付3 申请退款
- 微信支付java版本之退款申请
- 微信支付java版本之退款申请
- 微信支付,退款
- 微信支付认证和ssl-https
- 微信支付退款接口
- 微信支付之退款
- 微信支付退款接口
- 微信退款demo--Java
- 微信开放支付接口申请,所有认证过的服务号均可申请
- 微信支付-退款(v3版微信支付)
- java-微信支付-微信退款
- 微信开发申请退款-公众号支付开发-视频教程10
- 微信支付后退款遇到的问题
- https的双向认证
- PHP实现微信申请退款
- 微信申请退款报“签名错误”
- WCF
- 冒泡法排序
- 沙盒存储机制
- 解决跨域问题,聊聊JSONP
- 【directX 3D游戏开发】DirectX 中的空间坐标和灵活顶点格式使用
- 微信支付---申请退款的https双向认证demo
- 函数指针与指针函数
- 关于list集合
- 测试某个类运行是否正常的方法
- Android Fragment 真正的完全解析(下)
- eclipse 设置 自动格式化代码 formatter cleanup
- Objective-C 【从文件中读写字符串(直接读写/通过NSURL读写)】
- 统计_z值
- linux device 与driver prove 过程