资源简介
网银支付试例代码,官网下的 没找到的同学可以下载
代码片段和文件信息
package com.unionpay.acp.sdk;
import java.net.URL;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.SimpleHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.protocol.Protocol;
/**
* 基于apache httpclient 组件实现的通信类
*
* @author cm.he
*
*/
public class ApacheHttpClient {
/**
* 目标地址
*/
private String url;
/**
* 通信连接超时时间
*/
private int connectionTimeout = 15000;
/**
* 通信读超时时间
*/
private int readTimeOut = 30000;
/**
* 通信结果
*/
private String result;
public ApacheHttpClient(String url int connectionTimeout
int readTimeOut) {
this.url = url;
this.connectionTimeout = connectionTimeout;
this.readTimeOut = readTimeOut;
}
public int send(Map data String encoding) {
PostMethod post = new PostMethod(url);
HttpClient httpclient = null;
try {
post.addRequestHeader(“Content-Type““application/x-www-form-urlencoded;charset=“+encoding);
post.addRequestHeader(“cache-control“ “no-cache“);
post.addRequestHeader(“pragma“ “no-cache“);
post.addRequestHeader(“connection“ “keep-alive“);
if (null != data && 0 != data.size()) {
for (Entry en : data.entrySet()) {
post.addParameter(en.getKey() en.getValue());
}
}
URL uRL = new URL(url);
//测试环境配置不验证SSL证书(如果接银联生产环境需要验证SSL证书,可以注释以下两行代码)
Protocol myhttps = new Protocol(uRL.getProtocol() new MySSLSocketFactory()-1 == uRL.getPort()?443:uRL.getPort());
Protocol.registerProtocol(“https“ myhttps);
httpclient = new HttpClient();
httpclient.getHostConfiguration().setHost(uRL.getHost()uRL.getPort() uRL.getProtocol());
httpclient.setTimeout(readTimeOut);
httpclient.setConnectionTimeout(connectionTimeout);
int result = httpclient.executeMethod(post);
LogUtil.writeLog(“HTTP Return Status-Code:[“ + result + “]“);
/**
* 获取返回值
*/
if (result == HttpStatus.SC_OK) {
// 读取内容
byte[] responseBody = post.getResponseBody();
setResult(new String(responseBody encoding));
}
LogUtil.writeLog(“返回报文:[“ + getResult() + “]“);
return result;
} catch (Exception ex) {
ex.printStackTrace();
return -1;
} finally {
post.releaseConnection();
if (httpclient != null) {
((SimpleHttpConnectionManager) httpclient.getHttpConnectionManager()).shutdown();
}
}
}
public int sendGet(String encoding) {
GetMethod get = new GetMethod(url);
HttpClient httpclient = null;
try {
get.addRequestHeader(“Content-Type““application/x-www-form-urlencoded;charset=“+encoding);
get.addRequestHeader(“cache-control“ “no-cache“);
get.addRequestHeader(“pragma“ “no-cache“);
get.addRequestHeader(“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 865 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\.classpath
I.A.... 1046 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.project
I.A.... 503 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\.jsdtscope
I.A.... 88 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\org.eclipse.core.resources.prefs
I.A.... 629 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\org.eclipse.jdt.core.prefs
I.A.... 469 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\org.eclipse.wst.common.component
I.A.... 345 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\org.eclipse.wst.common.project.facet.core.xm
I.A.... 49 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\org.eclipse.wst.jsdt.ui.superType.container
I.A.... 6 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 3797 2017-07-13 14:53 Java Version SDK (通用版)\ACPSample_B2B\build\classes\acp_sdk.properties
文件 4509 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\BackRcvResponse.class
文件 9347 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\Demoba
文件 2677 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\EncryptCerUpdateQuery.class
文件 3347 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\Form02_6_2_FrontConsume.class
文件 3725 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\Form02_6_3_Refund.class
文件 3593 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\Form02_6_4_Query.class
文件 4845 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\Form02_7_FileTransfer.class
文件 6441 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\FrontRcvResponse.class
文件 693 2016-12-12 13:08 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\demo\多个商户号各自使用自己的私钥证书(多证书)或密钥(多密钥)使用方法.txt
文件 17777 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\AcpService.class
文件 1084 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\ba
文件 744 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\ba
文件 2861 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\ba
文件 856 2017-07-27 10:24 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\CertUtil$CerFilter.class
文件 19943 2017-07-27 10:24 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\CertUtil.class
文件 8449 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\HttpClient.class
文件 3171 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\LogUtil.class
文件 15813 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\SDKConfig.class
文件 7986 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\SDKConstants.class
文件 18988 2017-07-15 15:02 Java Version SDK (通用版)\ACPSample_B2B\build\classes\com\unionpay\acp\sdk\SDKUtil.class
............此处省略333个文件信息
评论
共有 条评论