資源簡介
java版微信jsapi支付 配置后可用 如有問題請添加, 這個分有點高。
代碼片段和文件信息
package?com.github.wxpay.sdk;
//import?com.sunyard.constans.Constants;
import?java.io.IOException;
import?java.net.URL;
import?org.apache.commons.httpclient.HttpClient;
import?org.apache.commons.httpclient.HttpConnectionManager;
import?org.apache.commons.httpclient.HttpException;
import?org.apache.commons.httpclient.HttpMethod;
import?org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import?org.apache.commons.httpclient.methods.GetMethod;
import?org.apache.commons.httpclient.methods.PostMethod;
import?org.apache.commons.httpclient.methods.RequestEntity;
import?org.apache.commons.httpclient.methods.StringRequestEntity;
import?org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import?org.apache.commons.lang3.StringUtils;
import?org.apache.log4j.LogManager;
import?org.apache.log4j.Logger;
public?class?HTTPUtils?{
????private?final?static?Logger?logger?=?LogManager.getLogger(HTTPUtils.class);
????private?final?static?String?OPERATER_NAME?=?“【HTTP操作】“;
????private?final?static?int?SUCCESS?=?200;
????private?final?static?String?UTF8?=?“UTF-8“;
????private?HttpClient?client;
????private?static?HTTPUtils?instance?=?new?HTTPUtils();
????/**
?????*?私有化構造器
?????*/
????private?HTTPUtils()?{
????????HttpConnectionManager?httpConnectionManager?=?new?MultiThreadedHttpConnectionManager();
????????HttpConnectionManagerParams?params?=?httpConnectionManager.getParams();
????????params.setConnectionTimeout(5000);
????????params.setSoTimeout(20000);
????????params.setDefaultMaxConnectionsPerHost(1000);
????????params.setMaxTotalConnections(1000);
????????client?=?new?HttpClient(httpConnectionManager);
????????client.getParams().setContentCharset(UTF8);
????????client.getParams().setHttpElementCharset(UTF8);
????}
????/**
?????*?get請求
?????*/
????public?static?String?get(URL?url)?{
????????return?instance.doGet(url);
????}
????private?String?doGet(URL?url)?{
????????long?beginTime?=?System.currentTimeMillis();
????????String?respStr?=?StringUtils.EMPTY;
????????try?{
????????????//?System.out.println(OPERATER_NAME?+?“開始get通信,目標host:“?+?url);
????????????HttpMethod?method?=?new?GetMethod(url.toString());
????????????//?中文轉碼
????????????method.getParams().setContentCharset(UTF8);
????????????try?{
????????????????client.executeMethod(method);
????????????}?catch?(HttpException?e)?{
//????????????????logger.error(new?StringBuffer(“發送HTTP?GET給\r\n“).append(url)
//????????????????????????.append(“\r\nHTTP異常\r\n“)?e);
????????????}?catch?(IOException?e)?{
//????????????????logger.error(new?StringBuffer(“發送HTTP?GET給\r\n“).append(url)
//????????????????????????.append(“\r\nIO異常\r\n“)?e);
????????????}
????????????if?(method.getStatusCode()?==?SUCCESS)?{
????????????????respStr?=?method.getResponseBodyAsString();
????????????}
????????????//?釋放連接
????????????method.releaseConnection();
????????????//?System.out.println(OPERATER_NAME?+?“通訊完成,返回碼
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-22?17:20??wechat\
?????文件?????????680??2018-06-20?11:41??wechat\.classpath
?????目錄???????????0??2018-06-22?17:20??wechat\.myeclipse\
?????文件?????????291??2018-06-20?11:39??wechat\.myme
?????文件????????1749??2018-06-15?17:15??wechat\.project
?????目錄???????????0??2018-06-22?17:20??wechat\.settings\
?????文件?????????500??2018-06-15?16:06??wechat\.settings\.jsdtscope
?????文件?????????106??2018-06-22?16:27??wechat\.settings\com.genuitec.eclipse.core.prefs
?????文件??????????89??2018-06-22?17:19??wechat\.settings\org.eclipse.core.resources.prefs
?????文件?????????364??2018-06-20?11:41??wechat\.settings\org.eclipse.jdt.core.prefs
?????文件?????????456??2018-06-15?16:06??wechat\.settings\org.eclipse.wst.common.component
?????文件?????????252??2018-06-15?16:06??wechat\.settings\org.eclipse.wst.common.project.facet.core.xm
?????文件??????????49??2018-06-15?16:06??wechat\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2018-06-15?16:06??wechat\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\
?????文件?????????742??2018-06-22?17:19??wechat\WebRoot\Auto.jsp
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\me
?????文件??????????36??2018-06-15?16:06??wechat\WebRoot\me
?????文件????????3334??2018-06-22?17:15??wechat\WebRoot\Pay.jsp
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\WEB-INF\
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\WEB-INF\classes\
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\WEB-INF\classes\com\
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\WEB-INF\classes\com\github\
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\
?????目錄???????????0??2018-06-22?17:20??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\
?????文件????????4529??2018-06-22?16:27??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\HTTPUtils.class
?????文件?????????978??2018-06-22?11:05??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\IWXPayDomain$DomainInfo.class
?????文件?????????388??2018-06-22?11:05??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\IWXPayDomain.class
?????文件????????7353??2018-06-22?11:40??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\WXPay.class
?????文件????????1018??2018-06-22?16:22??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\WXPayConfig.class
?????文件????????2536??2018-06-22?17:16??wechat\WebRoot\WEB-INF\classes\com\github\wxpay\sdk\WXPayConfigImpl.class
............此處省略98個文件信息
評論
共有 條評論