From 94a9995b86910f59cebc818bbd3b7505922dc438 Mon Sep 17 00:00:00 2001 From: jinyu Date: Tue, 13 Oct 2015 16:17:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20map2xml=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E4=BC=A0=E9=80=92=E5=8F=82=E6=95=B0=E4=B8=ADvalue?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin4j/model/WeixinPayAccount.java | 277 +++++---- .../com/foxinmy/weixin4j/xml/XmlStream.java | 561 +++++++++--------- .../foxinmy/weixin4j/mp/test/CashTest.java | 120 ++-- 3 files changed, 476 insertions(+), 482 deletions(-) diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/WeixinPayAccount.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/WeixinPayAccount.java index 57e63837..7aa6d2f8 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/WeixinPayAccount.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/WeixinPayAccount.java @@ -1,142 +1,135 @@ -package com.foxinmy.weixin4j.model; - -import com.alibaba.fastjson.annotation.JSONCreator; -import com.alibaba.fastjson.annotation.JSONField; -import com.foxinmy.weixin4j.util.StringUtil; - -/** - * 微信支付账户 - * - * @className WeixinPayAccount - * @author jy - * @date 2015年6月26日 - * @since JDK 1.7 - * @see - */ -public class WeixinPayAccount extends WeixinAccount { - - private static final long serialVersionUID = -2791256176906048632L; - /** - * 公众号支付请求中用于加密的密钥 Key,可验证商户唯一身份,PaySignKey 对应于支付场景中的 appKey 值 - */ - private String paySignKey; - /** - * 财付通商户身份的标识 - */ - private String partnerId; - /** - * 财付通商户权限密钥Key - */ - private String partnerKey; - /** - * 微信支付分配的商户号(商户平台版) - */ - private String mchId; - /** - * 微信支付分配的子商户号,受理模式下必填(商户平台版) - */ - private String subMchId; - /** - * 微信支付分配的设备号(商户平台版) - */ - private String deviceInfo; - /** - * 微信支付版本号(如果无则按照mchId来做判断) - */ - private int version; - - /** - * 商户平台版本(V3)字段 - * - * @param appId - * 公众号唯一的身份ID - * @param appSecret - * 调用接口的凭证 - * @param paySignKey - * 支付密钥字符串(必填) - * @param mchId - * 微信支付分配的商户号(必填) - */ - public WeixinPayAccount(String appId, String appSecret, String paySignKey, - String mchId) { - this(appId, appSecret, paySignKey, mchId, null, null, null, null); - } - - /** - * 支付商户信息 - * - * @param appId - * 公众号唯一的身份ID - * @param appSecret - * 调用接口的凭证 - * @param paySignKey - * 支付密钥字符串(必填) - * @param mchId - * 微信支付分配的商户号(V3版本必填) - * @param partnerId - * 财付通的商户号(V2版本必填) - * @param partnerKey - * 财付通商户权限密钥Key(V2版本必填) - * @param subMchId - * 微信支付分配的子商户号,受理模式下必填(商户平台版) - * @param deviceInfo - * 微信支付分配的设备号(商户平台版) - */ - @JSONCreator - public WeixinPayAccount(@JSONField(name = "id") String appId, - @JSONField(name = "secret") String appSecret, - @JSONField(name = "paySignKey") String paySignKey, - @JSONField(name = "mchId") String mchId, - @JSONField(name = "subMchId") String subMchId, - @JSONField(name = "deviceInfo") String deviceInfo, - @JSONField(name = "partnerId") String partnerId, - @JSONField(name = "partnerKey") String partnerKey) { - super(appId, appSecret); - this.paySignKey = paySignKey; - this.mchId = mchId; - this.subMchId = subMchId; - this.deviceInfo = deviceInfo; - this.partnerId = partnerId; - this.partnerKey = partnerKey; - } - - public String getPaySignKey() { - return paySignKey; - } - - public String getPartnerId() { - return partnerId; - } - - public String getPartnerKey() { - return partnerKey; - } - - public String getMchId() { - return mchId; - } - - public String getSubMchId() { - return subMchId; - } - - public String getDeviceInfo() { - return deviceInfo; - } - - public int getVersion() { - if (version == 0) { - return StringUtil.isNotBlank(mchId) ? 3 : 2; - } - return version; - } - - @Override - public String toString() { - return "WeixinPayAccount [" + super.toString() + ", paySignKey=" - + paySignKey + ", partnerId=" + partnerId + ", partnerKey=" - + partnerKey + ", mchId=" + mchId + ", subMchId=" + subMchId - + ", deviceInfo=" + deviceInfo + ", version=" + getVersion() - + "]"; - } -} +package com.foxinmy.weixin4j.model; + +import com.alibaba.fastjson.annotation.JSONCreator; +import com.alibaba.fastjson.annotation.JSONField; +import com.foxinmy.weixin4j.util.StringUtil; + +/** + * 微信支付账户 + * + * @className WeixinPayAccount + * @author jy + * @date 2015年6月26日 + * @since JDK 1.7 + * @see + */ +public class WeixinPayAccount extends WeixinAccount { + + private static final long serialVersionUID = -2791256176906048632L; + /** + * 公众号支付请求中用于加密的密钥 Key,可验证商户唯一身份,PaySignKey 对应于支付场景中的 appKey 值 + */ + private String paySignKey; + /** + * 财付通商户身份的标识 + */ + private String partnerId; + /** + * 财付通商户权限密钥Key + */ + private String partnerKey; + /** + * 微信支付分配的商户号(商户平台版) + */ + private String mchId; + /** + * 微信支付分配的子商户号,受理模式下必填(商户平台版) + */ + private String subMchId; + /** + * 微信支付分配的设备号(商户平台版) + */ + private String deviceInfo; + /** + * 微信支付版本号(如果无则按照mchId来做判断) + */ + private int version; + + /** + * 商户平台版本(V3)字段 + * + * @param appId + * 公众号唯一的身份ID + * @param appSecret + * 调用接口的凭证 + * @param paySignKey + * 支付密钥字符串(必填) + * @param mchId + * 微信支付分配的商户号(必填) + */ + public WeixinPayAccount(String appId, String appSecret, String paySignKey, String mchId) { + this(appId, appSecret, paySignKey, mchId, null, null, null, null); + } + + /** + * 支付商户信息 + * + * @param appId + * 公众号唯一的身份ID(必填) + * @param appSecret + * 调用接口的凭证(必填) + * @param paySignKey + * 支付密钥字符串(必填) + * @param mchId + * 微信支付分配的商户号(V3商户平台版必填) + * @param subMchId + * 微信支付分配的子商户号,受理模式下必填(V3商户平台版 非必须) + * @param deviceInfo + * 微信支付分配的设备号(V3商户平台版 非必须) + * @param partnerId + * 财付通的商户号(V2版本必填) + * @param partnerKey + * 财付通商户权限密钥Key(V2版本必填) + */ + @JSONCreator + public WeixinPayAccount(@JSONField(name = "id") String appId, @JSONField(name = "secret") String appSecret, + @JSONField(name = "paySignKey") String paySignKey, @JSONField(name = "mchId") String mchId, + @JSONField(name = "subMchId") String subMchId, @JSONField(name = "deviceInfo") String deviceInfo, + @JSONField(name = "partnerId") String partnerId, @JSONField(name = "partnerKey") String partnerKey) { + super(appId, appSecret); + this.paySignKey = paySignKey; + this.mchId = mchId; + this.subMchId = subMchId; + this.deviceInfo = deviceInfo; + this.partnerId = partnerId; + this.partnerKey = partnerKey; + } + + public String getPaySignKey() { + return paySignKey; + } + + public String getPartnerId() { + return partnerId; + } + + public String getPartnerKey() { + return partnerKey; + } + + public String getMchId() { + return mchId; + } + + public String getSubMchId() { + return subMchId; + } + + public String getDeviceInfo() { + return deviceInfo; + } + + public int getVersion() { + if (version == 0) { + return StringUtil.isNotBlank(mchId) ? 3 : 2; + } + return version; + } + + @Override + public String toString() { + return "WeixinPayAccount [" + super.toString() + ", paySignKey=" + paySignKey + ", partnerId=" + partnerId + + ", partnerKey=" + partnerKey + ", mchId=" + mchId + ", subMchId=" + subMchId + ", deviceInfo=" + + deviceInfo + ", version=" + getVersion() + "]"; + } +} diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/xml/XmlStream.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/xml/XmlStream.java index 462e0100..1c07af6d 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/xml/XmlStream.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/xml/XmlStream.java @@ -1,280 +1,281 @@ -package com.foxinmy.weixin4j.xml; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; - -import com.alibaba.fastjson.JSONObject; -import com.foxinmy.weixin4j.model.Consts; -import com.foxinmy.weixin4j.util.StringUtil; - -/** - * XML 处理 - * - * @className XmlStream - * @author jy - * @date 2015年6月2日 - * @since JDK 1.7 - * @see - */ -public final class XmlStream { - private final static String ROOT_ELEMENT_XML = "xml"; - private final static String XML_VERSION = "1.0"; - private final static Map, Unmarshaller> messageUnmarshaller; - private final static Map, Marshaller> messageMarshaller; - static { - messageUnmarshaller = new HashMap, Unmarshaller>(); - messageMarshaller = new HashMap, Marshaller>(); - } - - /** - * Xml2Bean - * - * @param content - * xml内容 - * @param clazz - * bean类型 - * @return - */ - @SuppressWarnings("unchecked") - public static T fromXML(InputStream content, Class clazz) { - Unmarshaller unmarshaller = messageUnmarshaller.get(clazz); - if (unmarshaller == null) { - try { - JAXBContext jaxbContext = JAXBContext.newInstance(clazz); - unmarshaller = jaxbContext.createUnmarshaller(); - messageUnmarshaller.put(clazz, unmarshaller); - } catch (JAXBException e) { - throw new IllegalArgumentException(e); - } - } - try { - Source source = new StreamSource(content); - XmlRootElement rootElement = clazz - .getAnnotation(XmlRootElement.class); - if (rootElement == null || rootElement.name().equals( - XmlRootElement.class.getMethod("name") - .getDefaultValue().toString())) { - JAXBElement jaxbElement = unmarshaller.unmarshal(source, - clazz); - return jaxbElement.getValue(); - } else { - return (T) unmarshaller.unmarshal(source); - } - } catch (Exception e) { - throw new IllegalArgumentException(e); - } finally { - if (content != null) { - try { - content.close(); - } catch (IOException e) { - ; - } - } - } - } - - /** - * Xml2Bean - * - * @param content - * xml内容 - * @param clazz - * bean类型 - * @return - */ - public static T fromXML(String content, Class clazz) { - return fromXML( - new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz); - } - - /** - * map2xml - * - * @param map - * value无嵌套的map - * @return xml内容 - */ - public static String map2xml(Map map) { - StringWriter sw = new StringWriter(); - try { - XMLStreamWriter xw = XMLOutputFactory.newInstance() - .createXMLStreamWriter(sw); - xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION); - xw.writeStartElement(ROOT_ELEMENT_XML); - for (Iterator> it = map.entrySet().iterator(); it - .hasNext();) { - Entry entry = it.next(); - xw.writeStartElement(entry.getKey()); - xw.writeCData(entry.getValue()); - xw.writeEndElement(); - } - xw.writeEndDocument(); - xw.flush(); - xw.close(); - } catch (XMLStreamException e) { - throw new IllegalArgumentException(e); - } finally { - try { - sw.close(); - } catch (IOException e) { - ; - } - } - return sw.getBuffer().toString(); - } - - public static String map2xml(JSONObject json) { - StringWriter sw = new StringWriter(); - try { - XMLStreamWriter xw = XMLOutputFactory.newInstance() - .createXMLStreamWriter(sw); - xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION); - xw.writeStartElement(ROOT_ELEMENT_XML); - Set keys = json.keySet(); - for (String key : keys) { - xw.writeStartElement(key); - xw.writeCData(json.getString(key)); - xw.writeEndElement(); - } - xw.writeEndDocument(); - xw.flush(); - xw.close(); - } catch (XMLStreamException e) { - throw new IllegalArgumentException(e); - } finally { - try { - sw.close(); - } catch (IOException e) { - ; - } - } - return sw.getBuffer().toString(); - } - - /** - * xml2map - * - * @param content - * 无嵌套节点的xml内容 - * @return map对象 - */ - public static Map xml2map(String content) { - Map map = new HashMap(); - StringReader sr = new StringReader(content); - try { - XMLStreamReader xr = XMLInputFactory.newInstance() - .createXMLStreamReader(sr); - while (true) { - int event = xr.next(); - if (event == XMLStreamConstants.END_DOCUMENT) { - xr.close(); - break; - } else if (event == XMLStreamConstants.START_ELEMENT) { - String name = xr.getLocalName(); - while (true) { - event = xr.next(); - if (event == XMLStreamConstants.START_ELEMENT) { - name = xr.getLocalName(); - } else if (event == XMLStreamConstants.END_ELEMENT) { - break; - } else if (event == XMLStreamConstants.CHARACTERS) { - String value = xr.getText(); - map.put(name, value); - } - } - } - } - } catch (XMLStreamException e) { - throw new IllegalArgumentException(e); - } finally { - sr.close(); - } - return map; - } - - /** - * Bean2Xml - * - * @param object - * bean对象 - * @return xml内容 - */ - public static String toXML(Object object) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - toXML(object, os); - return StringUtil.newStringUtf8(os.toByteArray()); - } - - /** - * Bean2Xml - * - * @param t - * bean对象 - * @param os - * 输出流 - */ - @SuppressWarnings("unchecked") - public static void toXML(T t, OutputStream os) { - Class clazz = (Class) t.getClass(); - Marshaller marshaller = messageMarshaller.get(clazz); - if (marshaller == null) { - try { - JAXBContext jaxbContext = JAXBContext.newInstance(clazz); - marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_ENCODING, Consts.UTF_8.name()); - messageMarshaller.put(clazz, marshaller); - } catch (JAXBException e) { - throw new IllegalArgumentException(e); - } - } - try { - XmlRootElement rootElement = clazz - .getAnnotation(XmlRootElement.class); - if (rootElement == null - || rootElement.name().equals( - XmlRootElement.class.getMethod("name") - .getDefaultValue().toString())) { - marshaller.marshal(new JAXBElement(new QName( - ROOT_ELEMENT_XML), clazz, t), os); - } else { - marshaller.marshal(t, os); - } - } catch (Exception e) { - throw new IllegalArgumentException(e); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - ; - } - } - } - } -} +package com.foxinmy.weixin4j.xml; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; + +import com.alibaba.fastjson.JSONObject; +import com.foxinmy.weixin4j.model.Consts; +import com.foxinmy.weixin4j.util.StringUtil; + +/** + * XML 处理 + * + * @className XmlStream + * @author jy + * @date 2015年6月2日 + * @since JDK 1.7 + * @see + */ +public final class XmlStream { + private final static String ROOT_ELEMENT_XML = "xml"; + private final static String XML_VERSION = "1.0"; + private final static Map, Unmarshaller> messageUnmarshaller; + private final static Map, Marshaller> messageMarshaller; + + static { + messageUnmarshaller = new HashMap, Unmarshaller>(); + messageMarshaller = new HashMap, Marshaller>(); + } + + /** + * Xml2Bean + * + * @param content + * xml内容 + * @param clazz + * bean类型 + * @return + */ + @SuppressWarnings("unchecked") + public static T fromXML(InputStream content, Class clazz) { + Unmarshaller unmarshaller = messageUnmarshaller.get(clazz); + if (unmarshaller == null) { + try { + JAXBContext jaxbContext = JAXBContext.newInstance(clazz); + unmarshaller = jaxbContext.createUnmarshaller(); + messageUnmarshaller.put(clazz, unmarshaller); + } catch (JAXBException e) { + throw new IllegalArgumentException(e); + } + } + try { + Source source = new StreamSource(content); + XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class); + if (rootElement == null + || rootElement.name().equals(XmlRootElement.class.getMethod("name").getDefaultValue().toString())) { + JAXBElement jaxbElement = unmarshaller.unmarshal(source, clazz); + return jaxbElement.getValue(); + } else { + return (T) unmarshaller.unmarshal(source); + } + } catch (Exception e) { + throw new IllegalArgumentException(e); + } finally { + if (content != null) { + try { + content.close(); + } catch (IOException e) { + ; + } + } + } + } + + /** + * Xml2Bean + * + * @param content + * xml内容 + * @param clazz + * bean类型 + * @return + */ + public static T fromXML(String content, Class clazz) { + return fromXML(new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz); + } + + /** + * map2xml + * + * @param map + * value无嵌套的map + * @return xml内容 + */ + public static String map2xml(Map map) { + StringWriter sw = new StringWriter(); + try { + XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); + xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION); + xw.writeStartElement(ROOT_ELEMENT_XML); + for (Iterator> it = map.entrySet().iterator(); it.hasNext();) { + Entry entry = it.next(); + if (StringUtil.isBlank(entry.getValue())) { + continue; + } + xw.writeStartElement(entry.getKey()); + xw.writeCData(entry.getValue()); + xw.writeEndElement(); + } + xw.writeEndDocument(); + xw.flush(); + xw.close(); + } catch (XMLStreamException e) { + throw new IllegalArgumentException(e); + } finally { + try { + sw.close(); + } catch (IOException e) { + ; + } + } + return sw.getBuffer().toString(); + } + + /** + * map2xml + * + * @param json + * value无嵌套的json + * @return xml内容 + */ + public static String map2xml(JSONObject json) { + StringWriter sw = new StringWriter(); + try { + XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); + xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION); + xw.writeStartElement(ROOT_ELEMENT_XML); + for (Iterator> it = json.entrySet().iterator(); it.hasNext();) { + Entry entry = it.next(); + if (StringUtil.isBlank(json.getString(entry.getKey()))) { + continue; + } + xw.writeStartElement(entry.getKey()); + xw.writeCData(json.getString(entry.getKey())); + xw.writeEndElement(); + } + xw.writeEndDocument(); + xw.flush(); + xw.close(); + } catch (XMLStreamException e) { + throw new IllegalArgumentException(e); + } finally { + try { + sw.close(); + } catch (IOException e) { + ; + } + } + return sw.getBuffer().toString(); + } + + /** + * xml2map + * + * @param content + * 无嵌套节点的xml内容 + * @return map对象 + */ + public static Map xml2map(String content) { + Map map = new HashMap(); + StringReader sr = new StringReader(content); + try { + XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(sr); + while (true) { + int event = xr.next(); + if (event == XMLStreamConstants.END_DOCUMENT) { + xr.close(); + break; + } else if (event == XMLStreamConstants.START_ELEMENT) { + String name = xr.getLocalName(); + while (true) { + event = xr.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + name = xr.getLocalName(); + } else if (event == XMLStreamConstants.END_ELEMENT) { + break; + } else if (event == XMLStreamConstants.CHARACTERS) { + String value = xr.getText(); + map.put(name, value); + } + } + } + } + } catch (XMLStreamException e) { + throw new IllegalArgumentException(e); + } finally { + sr.close(); + } + return map; + } + + /** + * Bean2Xml + * + * @param object + * bean对象 + * @return xml内容 + */ + public static String toXML(Object object) { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + toXML(object, os); + return StringUtil.newStringUtf8(os.toByteArray()); + } + + /** + * Bean2Xml + * + * @param t + * bean对象 + * @param os + * 输出流 + */ + @SuppressWarnings("unchecked") + public static void toXML(T t, OutputStream os) { + Class clazz = (Class) t.getClass(); + Marshaller marshaller = messageMarshaller.get(clazz); + if (marshaller == null) { + try { + JAXBContext jaxbContext = JAXBContext.newInstance(clazz); + marshaller = jaxbContext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_ENCODING, Consts.UTF_8.name()); + messageMarshaller.put(clazz, marshaller); + } catch (JAXBException e) { + throw new IllegalArgumentException(e); + } + } + try { + XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class); + if (rootElement == null + || rootElement.name().equals(XmlRootElement.class.getMethod("name").getDefaultValue().toString())) { + marshaller.marshal(new JAXBElement(new QName(ROOT_ELEMENT_XML), clazz, t), os); + } else { + marshaller.marshal(t, os); + } + } catch (Exception e) { + throw new IllegalArgumentException(e); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + ; + } + } + } + } +} diff --git a/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/CashTest.java b/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/CashTest.java index 8e61e51f..a97effd5 100644 --- a/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/CashTest.java +++ b/weixin4j-mp/src/test/java/com/foxinmy/weixin4j/mp/test/CashTest.java @@ -1,60 +1,60 @@ -package com.foxinmy.weixin4j.mp.test; - -import java.io.FileInputStream; -import java.io.IOException; - -import org.junit.Test; - -import com.foxinmy.weixin4j.exception.WeixinException; -import com.foxinmy.weixin4j.payment.mch.MPPayment; -import com.foxinmy.weixin4j.payment.mch.MPPaymentResult; -import com.foxinmy.weixin4j.payment.mch.Redpacket; -import com.foxinmy.weixin4j.payment.mch.RedpacketRecord; -import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult; -import com.foxinmy.weixin4j.type.MPPaymentCheckNameType; - -/** - * 现金发放测试 - * - * @className CashTest - * @author jy - * @date 2015年4月1日 - * @since JDK 1.7 - * @see - */ -public class CashTest extends PayTest { - - @Test - public void sendRedpacket() throws WeixinException, IOException { - Redpacket redpacket = new Redpacket("HB001", "无忧钱庄", "无忧钱庄", - "oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d); - redpacket.setActName("红包测试"); - redpacket.setClientIp("127.0.0.1"); - redpacket.setMaxValue(1d); - redpacket.setMinValue(1d); - redpacket.setRemark("快来领取红包吧!"); - redpacket.setTotalNum(1); - redpacket.setWishing("来就送钱"); - RedpacketSendResult result = PAY3.sendRedpack(new FileInputStream( - caFile), redpacket); - System.err.println(result); - } - - @Test - public void queryRedpacket() throws WeixinException, IOException { - String outTradeNo = "HB001"; - RedpacketRecord record = PAY3.queryRedpack(new FileInputStream( - caFile), outTradeNo); - System.err.println(record); - } - - @Test - public void mpPayment() throws WeixinException, IOException { - MPPayment payment = new MPPayment("MP001", - "oyFLst1bqtuTcxK-ojF8hOGtLQao", - MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1"); - MPPaymentResult result = PAY3.mpPayment( - new FileInputStream(caFile), payment); - System.err.println(result); - } -} +package com.foxinmy.weixin4j.mp.test; + +import java.io.FileInputStream; +import java.io.IOException; + +import org.junit.Test; + +import com.foxinmy.weixin4j.exception.WeixinException; +import com.foxinmy.weixin4j.payment.mch.MPPayment; +import com.foxinmy.weixin4j.payment.mch.MPPaymentResult; +import com.foxinmy.weixin4j.payment.mch.Redpacket; +import com.foxinmy.weixin4j.payment.mch.RedpacketRecord; +import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult; +import com.foxinmy.weixin4j.type.MPPaymentCheckNameType; + +/** + * 现金发放测试 + * + * @className CashTest + * @author jy + * @date 2015年4月1日 + * @since JDK 1.7 + * @see + */ +public class CashTest extends PayTest { + + @Test + public void sendRedpacket() throws WeixinException, IOException { + Redpacket redpacket = new Redpacket("HB001", "无忧钱庄", "无忧钱庄", + "oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d); + redpacket.setActName("红包测试"); + redpacket.setClientIp("127.0.0.1"); + redpacket.setMaxValue(1d); + redpacket.setMinValue(1d); + redpacket.setRemark("快来领取红包吧!"); + redpacket.setTotalNum(1); + redpacket.setWishing("来就送钱"); + RedpacketSendResult result = PAY3.sendRedpack(new FileInputStream( + caFile), redpacket); + System.err.println(result); + } + + @Test + public void queryRedpacket() throws WeixinException, IOException { + String outTradeNo = "HB001"; + RedpacketRecord record = PAY3.queryRedpack(new FileInputStream( + caFile), outTradeNo); + System.err.println(record); + } + + @Test + public void mpPayment() throws WeixinException, IOException { + MPPayment payment = new MPPayment("MP001", + "oyFLst1bqtuTcxK-ojF8hOGtLQao", + MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1"); + MPPaymentResult result = PAY3.mpPayment( + new FileInputStream(caFile), payment); + System.err.println(result); + } +}