支付模块拆分为V2跟V3
This commit is contained in:
@@ -37,4 +37,8 @@ weixin4j-base
|
||||
|
||||
* 2014-11-24
|
||||
|
||||
+ 将Action跟Mapping基础类并入到项目
|
||||
+ 将Action跟Mapping基础类并入到项目
|
||||
|
||||
* 2015-01-04
|
||||
|
||||
+ ConfigUtil类新增获取classpath目录下的资源路径的方法
|
||||
@@ -13,6 +13,7 @@ import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
|
||||
/**
|
||||
* API基础
|
||||
*
|
||||
* @className BaseApi
|
||||
* @author jy.hu
|
||||
* @date 2014年9月26日
|
||||
@@ -37,7 +38,9 @@ public abstract class BaseApi {
|
||||
protected Map<String, String> xml2map(String xml) {
|
||||
return mapXstream.fromXML(xml, Map.class);
|
||||
}
|
||||
|
||||
protected abstract ResourceBundle getWeixinBundle();
|
||||
|
||||
protected String getRequestUri(String key) {
|
||||
String url = getWeixinBundle().getString(key);
|
||||
Pattern p = Pattern.compile("(\\{[^\\}]*\\})");
|
||||
|
||||
@@ -188,7 +188,6 @@ public class HttpRequest {
|
||||
response.setStatusText(statusLine.getReasonPhrase());
|
||||
response.setStream(new ByteArrayInputStream(data));
|
||||
response.setText(new String(data, Consts.UTF_8));
|
||||
|
||||
EntityUtils.consume(httpEntity);
|
||||
Header contentType = httpResponse
|
||||
.getFirstHeader(HttpHeaders.CONTENT_TYPE);
|
||||
|
||||
@@ -168,10 +168,9 @@ public class Response {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[Response text=").append(text);
|
||||
sb.append(", statusCode=").append(statusCode);
|
||||
sb.append(", statusText=").append(statusText).append("]");
|
||||
return sb.toString();
|
||||
return "Response [text=" + text + ", statusCode=" + statusCode
|
||||
+ ", statusText=" + statusText + ", stream=" + stream
|
||||
+ ", isJsonResult=" + isJsonResult + ", isXmlResult="
|
||||
+ isXmlResult + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.foxinmy.weixin4j.http;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
|
||||
@@ -23,10 +20,6 @@ import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
*/
|
||||
public class SSLHttpRequest extends HttpRequest {
|
||||
|
||||
public SSLHttpRequest(String password, File file) throws IOException {
|
||||
this(password, new FileInputStream(file));
|
||||
}
|
||||
|
||||
public SSLHttpRequest(String password, InputStream inputStream) {
|
||||
super();
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.foxinmy.weixin4j.http;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@@ -19,16 +21,29 @@ public class XmlResult implements Serializable {
|
||||
private static final long serialVersionUID = -6185313616955051150L;
|
||||
|
||||
@XStreamAlias("return_code")
|
||||
@JSONField(name = "return_code")
|
||||
private String returnCode;// 此字段是通信标识,非交易 标识,交易是否成功需要查 看 result_code 来判断 非空
|
||||
@XStreamAlias("return_msg")
|
||||
@JSONField(name = "return_msg")
|
||||
private String returnMsg;// 返回信息,如非 空,为错误原因 可能为空
|
||||
@XStreamAlias("result_code")
|
||||
@JSONField(name = "result_code")
|
||||
private String resultCode;// 业务结果SUCCESS/FAIL 非空
|
||||
@XStreamAlias("err_code")
|
||||
@JSONField(name = "err_code")
|
||||
private String errCode;// 错误代码 可为空
|
||||
@XStreamAlias("err_code_des")
|
||||
@JSONField(name = "err_code_des")
|
||||
private String errCodeDes;// 结果信息描述 可为空
|
||||
|
||||
public XmlResult() {
|
||||
}
|
||||
|
||||
public XmlResult(String returnCode, String returnMsg) {
|
||||
this.returnCode = returnCode;
|
||||
this.returnMsg = returnMsg;
|
||||
}
|
||||
|
||||
public String getReturnCode() {
|
||||
return returnCode;
|
||||
}
|
||||
@@ -38,7 +53,7 @@ public class XmlResult implements Serializable {
|
||||
}
|
||||
|
||||
public String getReturnMsg() {
|
||||
return returnMsg;
|
||||
return StringUtils.isNotBlank(returnMsg) ? returnMsg : null;
|
||||
}
|
||||
|
||||
public void setReturnMsg(String returnMsg) {
|
||||
@@ -62,27 +77,13 @@ public class XmlResult implements Serializable {
|
||||
}
|
||||
|
||||
public String getErrCodeDes() {
|
||||
return errCodeDes;
|
||||
return StringUtils.isNotBlank(errCodeDes) ? errCodeDes : null;
|
||||
}
|
||||
|
||||
public void setErrCodeDes(String errCodeDes) {
|
||||
this.errCodeDes = errCodeDes;
|
||||
}
|
||||
|
||||
public XmlResult() {
|
||||
this(Consts.SUCCESS.toLowerCase(), "");
|
||||
}
|
||||
|
||||
public XmlResult(String returnCode, String returnMsg) {
|
||||
this.returnCode = returnCode;
|
||||
this.returnMsg = returnMsg;
|
||||
if (returnCode.equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
this.resultCode = Consts.SUCCESS.toLowerCase();
|
||||
this.errCode = Consts.SUCCESS.toLowerCase();
|
||||
this.errCodeDes = "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "returnCode=" + returnCode + ", returnMsg=" + returnMsg
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* 常量类
|
||||
* @className Consts
|
||||
@@ -8,6 +11,8 @@ package com.foxinmy.weixin4j.model;
|
||||
* @see
|
||||
*/
|
||||
public final class Consts {
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
public static final Charset GBK = Charset.forName("GBK");
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
public static final String FAIL = "FAIL";
|
||||
public static final String SunX509 = "SunX509";
|
||||
|
||||
@@ -19,16 +19,21 @@ import com.foxinmy.weixin4j.model.WeixinQyAccount;
|
||||
* @see
|
||||
*/
|
||||
public class ConfigUtil {
|
||||
private final static String CLASSPATH_PREFIX = "classpath:";
|
||||
private final static String CLASSPATH_VALUE;
|
||||
private final static ResourceBundle weixinBundle;
|
||||
static {
|
||||
weixinBundle = ResourceBundle.getBundle("weixin");
|
||||
Set<String> keySet = weixinBundle.keySet();
|
||||
File file = null;
|
||||
CLASSPATH_VALUE = Thread.currentThread().getContextClassLoader()
|
||||
.getResource("").getPath();
|
||||
for (String key : keySet) {
|
||||
if (!key.endsWith("_path")) {
|
||||
continue;
|
||||
}
|
||||
file = new File(getValue(key));
|
||||
file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX,
|
||||
CLASSPATH_VALUE));
|
||||
if (!file.exists() && !file.mkdirs()) {
|
||||
System.err.append(String.format("%s create fail.%n",
|
||||
file.getAbsolutePath()));
|
||||
@@ -36,10 +41,27 @@ public class ConfigUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取weixin.properties文件中的key值
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getValue(String key) {
|
||||
return weixinBundle.getString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断属性是否存在[classpath:]如果存在则拼接项目路径后返回 一般用于文件的绝对路径获取
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getClassPathValue(String key) {
|
||||
return new File(getValue(key).replaceFirst(CLASSPATH_PREFIX,
|
||||
CLASSPATH_VALUE)).getPath();
|
||||
}
|
||||
|
||||
public static <T extends WeixinAccount> T getWeixinAccount(Class<T> clazz) {
|
||||
String text = getValue("account");
|
||||
return JSON.parseObject(text, clazz);
|
||||
|
||||
Reference in New Issue
Block a user