修改 map2xml 方法 传递参数中value为空时的bug
This commit is contained in:
parent
12fdf6065b
commit
94a9995b86
@ -1,142 +1,135 @@
|
|||||||
package com.foxinmy.weixin4j.model;
|
package com.foxinmy.weixin4j.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付账户
|
* 微信支付账户
|
||||||
*
|
*
|
||||||
* @className WeixinPayAccount
|
* @className WeixinPayAccount
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2015年6月26日
|
* @date 2015年6月26日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public class WeixinPayAccount extends WeixinAccount {
|
public class WeixinPayAccount extends WeixinAccount {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2791256176906048632L;
|
private static final long serialVersionUID = -2791256176906048632L;
|
||||||
/**
|
/**
|
||||||
* 公众号支付请求中用于加密的密钥 Key,可验证商户唯一身份,PaySignKey 对应于支付场景中的 appKey 值
|
* 公众号支付请求中用于加密的密钥 Key,可验证商户唯一身份,PaySignKey 对应于支付场景中的 appKey 值
|
||||||
*/
|
*/
|
||||||
private String paySignKey;
|
private String paySignKey;
|
||||||
/**
|
/**
|
||||||
* 财付通商户身份的标识
|
* 财付通商户身份的标识
|
||||||
*/
|
*/
|
||||||
private String partnerId;
|
private String partnerId;
|
||||||
/**
|
/**
|
||||||
* 财付通商户权限密钥Key
|
* 财付通商户权限密钥Key
|
||||||
*/
|
*/
|
||||||
private String partnerKey;
|
private String partnerKey;
|
||||||
/**
|
/**
|
||||||
* 微信支付分配的商户号(商户平台版)
|
* 微信支付分配的商户号(商户平台版)
|
||||||
*/
|
*/
|
||||||
private String mchId;
|
private String mchId;
|
||||||
/**
|
/**
|
||||||
* 微信支付分配的子商户号,受理模式下必填(商户平台版)
|
* 微信支付分配的子商户号,受理模式下必填(商户平台版)
|
||||||
*/
|
*/
|
||||||
private String subMchId;
|
private String subMchId;
|
||||||
/**
|
/**
|
||||||
* 微信支付分配的设备号(商户平台版)
|
* 微信支付分配的设备号(商户平台版)
|
||||||
*/
|
*/
|
||||||
private String deviceInfo;
|
private String deviceInfo;
|
||||||
/**
|
/**
|
||||||
* 微信支付版本号(如果无则按照mchId来做判断)
|
* 微信支付版本号(如果无则按照mchId来做判断)
|
||||||
*/
|
*/
|
||||||
private int version;
|
private int version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商户平台版本(V3)字段
|
* 商户平台版本(V3)字段
|
||||||
*
|
*
|
||||||
* @param appId
|
* @param appId
|
||||||
* 公众号唯一的身份ID
|
* 公众号唯一的身份ID
|
||||||
* @param appSecret
|
* @param appSecret
|
||||||
* 调用接口的凭证
|
* 调用接口的凭证
|
||||||
* @param paySignKey
|
* @param paySignKey
|
||||||
* 支付密钥字符串(必填)
|
* 支付密钥字符串(必填)
|
||||||
* @param mchId
|
* @param mchId
|
||||||
* 微信支付分配的商户号(必填)
|
* 微信支付分配的商户号(必填)
|
||||||
*/
|
*/
|
||||||
public WeixinPayAccount(String appId, String appSecret, String paySignKey,
|
public WeixinPayAccount(String appId, String appSecret, String paySignKey, String mchId) {
|
||||||
String mchId) {
|
this(appId, appSecret, paySignKey, mchId, null, null, null, null);
|
||||||
this(appId, appSecret, paySignKey, mchId, null, null, null, null);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 支付商户信息
|
||||||
* 支付商户信息
|
*
|
||||||
*
|
* @param appId
|
||||||
* @param appId
|
* 公众号唯一的身份ID(必填)
|
||||||
* 公众号唯一的身份ID
|
* @param appSecret
|
||||||
* @param appSecret
|
* 调用接口的凭证(必填)
|
||||||
* 调用接口的凭证
|
* @param paySignKey
|
||||||
* @param paySignKey
|
* 支付密钥字符串(必填)
|
||||||
* 支付密钥字符串(必填)
|
* @param mchId
|
||||||
* @param mchId
|
* 微信支付分配的商户号(V3商户平台版必填)
|
||||||
* 微信支付分配的商户号(V3版本必填)
|
* @param subMchId
|
||||||
* @param partnerId
|
* 微信支付分配的子商户号,受理模式下必填(V3商户平台版 非必须)
|
||||||
* 财付通的商户号(V2版本必填)
|
* @param deviceInfo
|
||||||
* @param partnerKey
|
* 微信支付分配的设备号(V3商户平台版 非必须)
|
||||||
* 财付通商户权限密钥Key(V2版本必填)
|
* @param partnerId
|
||||||
* @param subMchId
|
* 财付通的商户号(V2版本必填)
|
||||||
* 微信支付分配的子商户号,受理模式下必填(商户平台版)
|
* @param partnerKey
|
||||||
* @param deviceInfo
|
* 财付通商户权限密钥Key(V2版本必填)
|
||||||
* 微信支付分配的设备号(商户平台版)
|
*/
|
||||||
*/
|
@JSONCreator
|
||||||
@JSONCreator
|
public WeixinPayAccount(@JSONField(name = "id") String appId, @JSONField(name = "secret") String appSecret,
|
||||||
public WeixinPayAccount(@JSONField(name = "id") String appId,
|
@JSONField(name = "paySignKey") String paySignKey, @JSONField(name = "mchId") String mchId,
|
||||||
@JSONField(name = "secret") String appSecret,
|
@JSONField(name = "subMchId") String subMchId, @JSONField(name = "deviceInfo") String deviceInfo,
|
||||||
@JSONField(name = "paySignKey") String paySignKey,
|
@JSONField(name = "partnerId") String partnerId, @JSONField(name = "partnerKey") String partnerKey) {
|
||||||
@JSONField(name = "mchId") String mchId,
|
super(appId, appSecret);
|
||||||
@JSONField(name = "subMchId") String subMchId,
|
this.paySignKey = paySignKey;
|
||||||
@JSONField(name = "deviceInfo") String deviceInfo,
|
this.mchId = mchId;
|
||||||
@JSONField(name = "partnerId") String partnerId,
|
this.subMchId = subMchId;
|
||||||
@JSONField(name = "partnerKey") String partnerKey) {
|
this.deviceInfo = deviceInfo;
|
||||||
super(appId, appSecret);
|
this.partnerId = partnerId;
|
||||||
this.paySignKey = paySignKey;
|
this.partnerKey = partnerKey;
|
||||||
this.mchId = mchId;
|
}
|
||||||
this.subMchId = subMchId;
|
|
||||||
this.deviceInfo = deviceInfo;
|
public String getPaySignKey() {
|
||||||
this.partnerId = partnerId;
|
return paySignKey;
|
||||||
this.partnerKey = partnerKey;
|
}
|
||||||
}
|
|
||||||
|
public String getPartnerId() {
|
||||||
public String getPaySignKey() {
|
return partnerId;
|
||||||
return paySignKey;
|
}
|
||||||
}
|
|
||||||
|
public String getPartnerKey() {
|
||||||
public String getPartnerId() {
|
return partnerKey;
|
||||||
return partnerId;
|
}
|
||||||
}
|
|
||||||
|
public String getMchId() {
|
||||||
public String getPartnerKey() {
|
return mchId;
|
||||||
return partnerKey;
|
}
|
||||||
}
|
|
||||||
|
public String getSubMchId() {
|
||||||
public String getMchId() {
|
return subMchId;
|
||||||
return mchId;
|
}
|
||||||
}
|
|
||||||
|
public String getDeviceInfo() {
|
||||||
public String getSubMchId() {
|
return deviceInfo;
|
||||||
return subMchId;
|
}
|
||||||
}
|
|
||||||
|
public int getVersion() {
|
||||||
public String getDeviceInfo() {
|
if (version == 0) {
|
||||||
return deviceInfo;
|
return StringUtil.isNotBlank(mchId) ? 3 : 2;
|
||||||
}
|
}
|
||||||
|
return version;
|
||||||
public int getVersion() {
|
}
|
||||||
if (version == 0) {
|
|
||||||
return StringUtil.isNotBlank(mchId) ? 3 : 2;
|
@Override
|
||||||
}
|
public String toString() {
|
||||||
return version;
|
return "WeixinPayAccount [" + super.toString() + ", paySignKey=" + paySignKey + ", partnerId=" + partnerId
|
||||||
}
|
+ ", partnerKey=" + partnerKey + ", mchId=" + mchId + ", subMchId=" + subMchId + ", deviceInfo="
|
||||||
|
+ deviceInfo + ", version=" + getVersion() + "]";
|
||||||
@Override
|
}
|
||||||
public String toString() {
|
}
|
||||||
return "WeixinPayAccount [" + super.toString() + ", paySignKey="
|
|
||||||
+ paySignKey + ", partnerId=" + partnerId + ", partnerKey="
|
|
||||||
+ partnerKey + ", mchId=" + mchId + ", subMchId=" + subMchId
|
|
||||||
+ ", deviceInfo=" + deviceInfo + ", version=" + getVersion()
|
|
||||||
+ "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,280 +1,281 @@
|
|||||||
package com.foxinmy.weixin4j.xml;
|
package com.foxinmy.weixin4j.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBElement;
|
||||||
import javax.xml.bind.JAXBElement;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.namespace.QName;
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLOutputFactory;
|
||||||
import javax.xml.stream.XMLOutputFactory;
|
import javax.xml.stream.XMLStreamConstants;
|
||||||
import javax.xml.stream.XMLStreamConstants;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamReader;
|
||||||
import javax.xml.stream.XMLStreamReader;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.transform.Source;
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.stream.StreamSource;
|
||||||
import javax.xml.transform.stream.StreamSource;
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.foxinmy.weixin4j.model.Consts;
|
||||||
import com.foxinmy.weixin4j.model.Consts;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
|
||||||
|
/**
|
||||||
/**
|
* XML 处理
|
||||||
* XML 处理
|
*
|
||||||
*
|
* @className XmlStream
|
||||||
* @className XmlStream
|
* @author jy
|
||||||
* @author jy
|
* @date 2015年6月2日
|
||||||
* @date 2015年6月2日
|
* @since JDK 1.7
|
||||||
* @since JDK 1.7
|
* @see
|
||||||
* @see
|
*/
|
||||||
*/
|
public final class XmlStream {
|
||||||
public final class XmlStream {
|
private final static String ROOT_ELEMENT_XML = "xml";
|
||||||
private final static String ROOT_ELEMENT_XML = "xml";
|
private final static String XML_VERSION = "1.0";
|
||||||
private final static String XML_VERSION = "1.0";
|
private final static Map<Class<?>, Unmarshaller> messageUnmarshaller;
|
||||||
private final static Map<Class<?>, Unmarshaller> messageUnmarshaller;
|
private final static Map<Class<?>, Marshaller> messageMarshaller;
|
||||||
private final static Map<Class<?>, Marshaller> messageMarshaller;
|
|
||||||
static {
|
static {
|
||||||
messageUnmarshaller = new HashMap<Class<?>, Unmarshaller>();
|
messageUnmarshaller = new HashMap<Class<?>, Unmarshaller>();
|
||||||
messageMarshaller = new HashMap<Class<?>, Marshaller>();
|
messageMarshaller = new HashMap<Class<?>, Marshaller>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Xml2Bean
|
* Xml2Bean
|
||||||
*
|
*
|
||||||
* @param content
|
* @param content
|
||||||
* xml内容
|
* xml内容
|
||||||
* @param clazz
|
* @param clazz
|
||||||
* bean类型
|
* bean类型
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T fromXML(InputStream content, Class<T> clazz) {
|
public static <T> T fromXML(InputStream content, Class<T> clazz) {
|
||||||
Unmarshaller unmarshaller = messageUnmarshaller.get(clazz);
|
Unmarshaller unmarshaller = messageUnmarshaller.get(clazz);
|
||||||
if (unmarshaller == null) {
|
if (unmarshaller == null) {
|
||||||
try {
|
try {
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
|
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
|
||||||
unmarshaller = jaxbContext.createUnmarshaller();
|
unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
messageUnmarshaller.put(clazz, unmarshaller);
|
messageUnmarshaller.put(clazz, unmarshaller);
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Source source = new StreamSource(content);
|
Source source = new StreamSource(content);
|
||||||
XmlRootElement rootElement = clazz
|
XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class);
|
||||||
.getAnnotation(XmlRootElement.class);
|
if (rootElement == null
|
||||||
if (rootElement == null || rootElement.name().equals(
|
|| rootElement.name().equals(XmlRootElement.class.getMethod("name").getDefaultValue().toString())) {
|
||||||
XmlRootElement.class.getMethod("name")
|
JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source, clazz);
|
||||||
.getDefaultValue().toString())) {
|
return jaxbElement.getValue();
|
||||||
JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source,
|
} else {
|
||||||
clazz);
|
return (T) unmarshaller.unmarshal(source);
|
||||||
return jaxbElement.getValue();
|
}
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
return (T) unmarshaller.unmarshal(source);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
} finally {
|
||||||
} catch (Exception e) {
|
if (content != null) {
|
||||||
throw new IllegalArgumentException(e);
|
try {
|
||||||
} finally {
|
content.close();
|
||||||
if (content != null) {
|
} catch (IOException e) {
|
||||||
try {
|
;
|
||||||
content.close();
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
}
|
* Xml2Bean
|
||||||
|
*
|
||||||
/**
|
* @param content
|
||||||
* Xml2Bean
|
* xml内容
|
||||||
*
|
* @param clazz
|
||||||
* @param content
|
* bean类型
|
||||||
* xml内容
|
* @return
|
||||||
* @param clazz
|
*/
|
||||||
* bean类型
|
public static <T> T fromXML(String content, Class<T> clazz) {
|
||||||
* @return
|
return fromXML(new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz);
|
||||||
*/
|
}
|
||||||
public static <T> T fromXML(String content, Class<T> clazz) {
|
|
||||||
return fromXML(
|
/**
|
||||||
new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz);
|
* map2xml
|
||||||
}
|
*
|
||||||
|
* @param map
|
||||||
/**
|
* value无嵌套的map
|
||||||
* map2xml
|
* @return xml内容
|
||||||
*
|
*/
|
||||||
* @param map
|
public static String map2xml(Map<String, String> map) {
|
||||||
* value无嵌套的map
|
StringWriter sw = new StringWriter();
|
||||||
* @return xml内容
|
try {
|
||||||
*/
|
XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
|
||||||
public static String map2xml(Map<String, String> map) {
|
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
||||||
StringWriter sw = new StringWriter();
|
xw.writeStartElement(ROOT_ELEMENT_XML);
|
||||||
try {
|
for (Iterator<Entry<String, String>> it = map.entrySet().iterator(); it.hasNext();) {
|
||||||
XMLStreamWriter xw = XMLOutputFactory.newInstance()
|
Entry<String, String> entry = it.next();
|
||||||
.createXMLStreamWriter(sw);
|
if (StringUtil.isBlank(entry.getValue())) {
|
||||||
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
continue;
|
||||||
xw.writeStartElement(ROOT_ELEMENT_XML);
|
}
|
||||||
for (Iterator<Entry<String, String>> it = map.entrySet().iterator(); it
|
xw.writeStartElement(entry.getKey());
|
||||||
.hasNext();) {
|
xw.writeCData(entry.getValue());
|
||||||
Entry<String, String> entry = it.next();
|
xw.writeEndElement();
|
||||||
xw.writeStartElement(entry.getKey());
|
}
|
||||||
xw.writeCData(entry.getValue());
|
xw.writeEndDocument();
|
||||||
xw.writeEndElement();
|
xw.flush();
|
||||||
}
|
xw.close();
|
||||||
xw.writeEndDocument();
|
} catch (XMLStreamException e) {
|
||||||
xw.flush();
|
throw new IllegalArgumentException(e);
|
||||||
xw.close();
|
} finally {
|
||||||
} catch (XMLStreamException e) {
|
try {
|
||||||
throw new IllegalArgumentException(e);
|
sw.close();
|
||||||
} finally {
|
} catch (IOException e) {
|
||||||
try {
|
;
|
||||||
sw.close();
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
;
|
return sw.getBuffer().toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return sw.getBuffer().toString();
|
/**
|
||||||
}
|
* map2xml
|
||||||
|
*
|
||||||
public static String map2xml(JSONObject json) {
|
* @param json
|
||||||
StringWriter sw = new StringWriter();
|
* value无嵌套的json
|
||||||
try {
|
* @return xml内容
|
||||||
XMLStreamWriter xw = XMLOutputFactory.newInstance()
|
*/
|
||||||
.createXMLStreamWriter(sw);
|
public static String map2xml(JSONObject json) {
|
||||||
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
StringWriter sw = new StringWriter();
|
||||||
xw.writeStartElement(ROOT_ELEMENT_XML);
|
try {
|
||||||
Set<String> keys = json.keySet();
|
XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
|
||||||
for (String key : keys) {
|
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
||||||
xw.writeStartElement(key);
|
xw.writeStartElement(ROOT_ELEMENT_XML);
|
||||||
xw.writeCData(json.getString(key));
|
for (Iterator<Entry<String, Object>> it = json.entrySet().iterator(); it.hasNext();) {
|
||||||
xw.writeEndElement();
|
Entry<String, Object> entry = it.next();
|
||||||
}
|
if (StringUtil.isBlank(json.getString(entry.getKey()))) {
|
||||||
xw.writeEndDocument();
|
continue;
|
||||||
xw.flush();
|
}
|
||||||
xw.close();
|
xw.writeStartElement(entry.getKey());
|
||||||
} catch (XMLStreamException e) {
|
xw.writeCData(json.getString(entry.getKey()));
|
||||||
throw new IllegalArgumentException(e);
|
xw.writeEndElement();
|
||||||
} finally {
|
}
|
||||||
try {
|
xw.writeEndDocument();
|
||||||
sw.close();
|
xw.flush();
|
||||||
} catch (IOException e) {
|
xw.close();
|
||||||
;
|
} catch (XMLStreamException e) {
|
||||||
}
|
throw new IllegalArgumentException(e);
|
||||||
}
|
} finally {
|
||||||
return sw.getBuffer().toString();
|
try {
|
||||||
}
|
sw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
/**
|
;
|
||||||
* xml2map
|
}
|
||||||
*
|
}
|
||||||
* @param content
|
return sw.getBuffer().toString();
|
||||||
* 无嵌套节点的xml内容
|
}
|
||||||
* @return map对象
|
|
||||||
*/
|
/**
|
||||||
public static Map<String, String> xml2map(String content) {
|
* xml2map
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
*
|
||||||
StringReader sr = new StringReader(content);
|
* @param content
|
||||||
try {
|
* 无嵌套节点的xml内容
|
||||||
XMLStreamReader xr = XMLInputFactory.newInstance()
|
* @return map对象
|
||||||
.createXMLStreamReader(sr);
|
*/
|
||||||
while (true) {
|
public static Map<String, String> xml2map(String content) {
|
||||||
int event = xr.next();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
if (event == XMLStreamConstants.END_DOCUMENT) {
|
StringReader sr = new StringReader(content);
|
||||||
xr.close();
|
try {
|
||||||
break;
|
XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(sr);
|
||||||
} else if (event == XMLStreamConstants.START_ELEMENT) {
|
while (true) {
|
||||||
String name = xr.getLocalName();
|
int event = xr.next();
|
||||||
while (true) {
|
if (event == XMLStreamConstants.END_DOCUMENT) {
|
||||||
event = xr.next();
|
xr.close();
|
||||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
break;
|
||||||
name = xr.getLocalName();
|
} else if (event == XMLStreamConstants.START_ELEMENT) {
|
||||||
} else if (event == XMLStreamConstants.END_ELEMENT) {
|
String name = xr.getLocalName();
|
||||||
break;
|
while (true) {
|
||||||
} else if (event == XMLStreamConstants.CHARACTERS) {
|
event = xr.next();
|
||||||
String value = xr.getText();
|
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||||
map.put(name, value);
|
name = xr.getLocalName();
|
||||||
}
|
} else if (event == XMLStreamConstants.END_ELEMENT) {
|
||||||
}
|
break;
|
||||||
}
|
} else if (event == XMLStreamConstants.CHARACTERS) {
|
||||||
}
|
String value = xr.getText();
|
||||||
} catch (XMLStreamException e) {
|
map.put(name, value);
|
||||||
throw new IllegalArgumentException(e);
|
}
|
||||||
} finally {
|
}
|
||||||
sr.close();
|
}
|
||||||
}
|
}
|
||||||
return map;
|
} catch (XMLStreamException e) {
|
||||||
}
|
throw new IllegalArgumentException(e);
|
||||||
|
} finally {
|
||||||
/**
|
sr.close();
|
||||||
* Bean2Xml
|
}
|
||||||
*
|
return map;
|
||||||
* @param object
|
}
|
||||||
* bean对象
|
|
||||||
* @return xml内容
|
/**
|
||||||
*/
|
* Bean2Xml
|
||||||
public static String toXML(Object object) {
|
*
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
* @param object
|
||||||
toXML(object, os);
|
* bean对象
|
||||||
return StringUtil.newStringUtf8(os.toByteArray());
|
* @return xml内容
|
||||||
}
|
*/
|
||||||
|
public static String toXML(Object object) {
|
||||||
/**
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
* Bean2Xml
|
toXML(object, os);
|
||||||
*
|
return StringUtil.newStringUtf8(os.toByteArray());
|
||||||
* @param t
|
}
|
||||||
* bean对象
|
|
||||||
* @param os
|
/**
|
||||||
* 输出流
|
* Bean2Xml
|
||||||
*/
|
*
|
||||||
@SuppressWarnings("unchecked")
|
* @param t
|
||||||
public static <T> void toXML(T t, OutputStream os) {
|
* bean对象
|
||||||
Class<T> clazz = (Class<T>) t.getClass();
|
* @param os
|
||||||
Marshaller marshaller = messageMarshaller.get(clazz);
|
* 输出流
|
||||||
if (marshaller == null) {
|
*/
|
||||||
try {
|
@SuppressWarnings("unchecked")
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
|
public static <T> void toXML(T t, OutputStream os) {
|
||||||
marshaller = jaxbContext.createMarshaller();
|
Class<T> clazz = (Class<T>) t.getClass();
|
||||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, Consts.UTF_8.name());
|
Marshaller marshaller = messageMarshaller.get(clazz);
|
||||||
messageMarshaller.put(clazz, marshaller);
|
if (marshaller == null) {
|
||||||
} catch (JAXBException e) {
|
try {
|
||||||
throw new IllegalArgumentException(e);
|
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
|
||||||
}
|
marshaller = jaxbContext.createMarshaller();
|
||||||
}
|
marshaller.setProperty(Marshaller.JAXB_ENCODING, Consts.UTF_8.name());
|
||||||
try {
|
messageMarshaller.put(clazz, marshaller);
|
||||||
XmlRootElement rootElement = clazz
|
} catch (JAXBException e) {
|
||||||
.getAnnotation(XmlRootElement.class);
|
throw new IllegalArgumentException(e);
|
||||||
if (rootElement == null
|
}
|
||||||
|| rootElement.name().equals(
|
}
|
||||||
XmlRootElement.class.getMethod("name")
|
try {
|
||||||
.getDefaultValue().toString())) {
|
XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class);
|
||||||
marshaller.marshal(new JAXBElement<T>(new QName(
|
if (rootElement == null
|
||||||
ROOT_ELEMENT_XML), clazz, t), os);
|
|| rootElement.name().equals(XmlRootElement.class.getMethod("name").getDefaultValue().toString())) {
|
||||||
} else {
|
marshaller.marshal(new JAXBElement<T>(new QName(ROOT_ELEMENT_XML), clazz, t), os);
|
||||||
marshaller.marshal(t, os);
|
} else {
|
||||||
}
|
marshaller.marshal(t, os);
|
||||||
} catch (Exception e) {
|
}
|
||||||
throw new IllegalArgumentException(e);
|
} catch (Exception e) {
|
||||||
} finally {
|
throw new IllegalArgumentException(e);
|
||||||
if (os != null) {
|
} finally {
|
||||||
try {
|
if (os != null) {
|
||||||
os.close();
|
try {
|
||||||
} catch (IOException e) {
|
os.close();
|
||||||
;
|
} catch (IOException e) {
|
||||||
}
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,60 +1,60 @@
|
|||||||
package com.foxinmy.weixin4j.mp.test;
|
package com.foxinmy.weixin4j.mp.test;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.payment.mch.MPPayment;
|
import com.foxinmy.weixin4j.payment.mch.MPPayment;
|
||||||
import com.foxinmy.weixin4j.payment.mch.MPPaymentResult;
|
import com.foxinmy.weixin4j.payment.mch.MPPaymentResult;
|
||||||
import com.foxinmy.weixin4j.payment.mch.Redpacket;
|
import com.foxinmy.weixin4j.payment.mch.Redpacket;
|
||||||
import com.foxinmy.weixin4j.payment.mch.RedpacketRecord;
|
import com.foxinmy.weixin4j.payment.mch.RedpacketRecord;
|
||||||
import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult;
|
import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult;
|
||||||
import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
|
import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 现金发放测试
|
* 现金发放测试
|
||||||
*
|
*
|
||||||
* @className CashTest
|
* @className CashTest
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2015年4月1日
|
* @date 2015年4月1日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public class CashTest extends PayTest {
|
public class CashTest extends PayTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendRedpacket() throws WeixinException, IOException {
|
public void sendRedpacket() throws WeixinException, IOException {
|
||||||
Redpacket redpacket = new Redpacket("HB001", "无忧钱庄", "无忧钱庄",
|
Redpacket redpacket = new Redpacket("HB001", "无忧钱庄", "无忧钱庄",
|
||||||
"oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d);
|
"oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d);
|
||||||
redpacket.setActName("红包测试");
|
redpacket.setActName("红包测试");
|
||||||
redpacket.setClientIp("127.0.0.1");
|
redpacket.setClientIp("127.0.0.1");
|
||||||
redpacket.setMaxValue(1d);
|
redpacket.setMaxValue(1d);
|
||||||
redpacket.setMinValue(1d);
|
redpacket.setMinValue(1d);
|
||||||
redpacket.setRemark("快来领取红包吧!");
|
redpacket.setRemark("快来领取红包吧!");
|
||||||
redpacket.setTotalNum(1);
|
redpacket.setTotalNum(1);
|
||||||
redpacket.setWishing("来就送钱");
|
redpacket.setWishing("来就送钱");
|
||||||
RedpacketSendResult result = PAY3.sendRedpack(new FileInputStream(
|
RedpacketSendResult result = PAY3.sendRedpack(new FileInputStream(
|
||||||
caFile), redpacket);
|
caFile), redpacket);
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void queryRedpacket() throws WeixinException, IOException {
|
public void queryRedpacket() throws WeixinException, IOException {
|
||||||
String outTradeNo = "HB001";
|
String outTradeNo = "HB001";
|
||||||
RedpacketRecord record = PAY3.queryRedpack(new FileInputStream(
|
RedpacketRecord record = PAY3.queryRedpack(new FileInputStream(
|
||||||
caFile), outTradeNo);
|
caFile), outTradeNo);
|
||||||
System.err.println(record);
|
System.err.println(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mpPayment() throws WeixinException, IOException {
|
public void mpPayment() throws WeixinException, IOException {
|
||||||
MPPayment payment = new MPPayment("MP001",
|
MPPayment payment = new MPPayment("MP001",
|
||||||
"oyFLst1bqtuTcxK-ojF8hOGtLQao",
|
"oyFLst1bqtuTcxK-ojF8hOGtLQao",
|
||||||
MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1");
|
MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1");
|
||||||
MPPaymentResult result = PAY3.mpPayment(
|
MPPaymentResult result = PAY3.mpPayment(
|
||||||
new FileInputStream(caFile), payment);
|
new FileInputStream(caFile), payment);
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user