parent
a6ec644596
commit
b2ca23721e
@ -810,4 +810,13 @@
|
|||||||
|
|
||||||
* 2018-06-14
|
* 2018-06-14
|
||||||
+ version upgrade to 1.8.0
|
+ version upgrade to 1.8.0
|
||||||
|
|
||||||
+ 新增了微信小程序相关的支持 API 实现
|
+ 新增了微信小程序相关的支持 API 实现
|
||||||
|
|
||||||
|
* 2018-07-08
|
||||||
|
|
||||||
|
+ [XEE](https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet)bug修复
|
||||||
|
|
||||||
|
+ 上传媒体文件content-length为-1导致503问题修复
|
||||||
|
|
||||||
|
+ release1.8.2版本
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>weixin4j</name>
|
<name>weixin4j</name>
|
||||||
<url>https://github.com/foxinmy/weixin4j</url>
|
<url>https://github.com/foxinmy/weixin4j</url>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-base</artifactId>
|
<artifactId>weixin4j-base</artifactId>
|
||||||
<name>weixin4j-base</name>
|
<name>weixin4j-base</name>
|
||||||
@ -71,11 +71,5 @@
|
|||||||
<version>3.0.2</version>
|
<version>3.0.2</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>1.7.19</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -43,68 +43,74 @@ import com.foxinmy.weixin4j.http.apache.mime.MIME;
|
|||||||
*/
|
*/
|
||||||
public class InputStreamBody extends AbstractContentBody {
|
public class InputStreamBody extends AbstractContentBody {
|
||||||
|
|
||||||
private final InputStream in;
|
private final InputStream in;
|
||||||
private final String filename;
|
private final String filename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public InputStreamBody(final InputStream in, final String mimeType, final String filename) {
|
public InputStreamBody(final InputStream in, final String mimeType,
|
||||||
this(in, ContentType.create(mimeType), filename);
|
final String filename) {
|
||||||
}
|
this(in, ContentType.create(mimeType), filename);
|
||||||
|
}
|
||||||
|
|
||||||
public InputStreamBody(final InputStream in, final String filename) {
|
public InputStreamBody(final InputStream in, final String filename) {
|
||||||
this(in, ContentType.DEFAULT_BINARY, filename);
|
this(in, ContentType.DEFAULT_BINARY, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
public InputStreamBody(final InputStream in, final ContentType contentType, final String filename) {
|
public InputStreamBody(final InputStream in, final ContentType contentType,
|
||||||
super(contentType);
|
final String filename) {
|
||||||
this.in = in;
|
super(contentType);
|
||||||
this.filename = filename;
|
this.in = in;
|
||||||
}
|
this.filename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
public InputStreamBody(final InputStream in, final ContentType contentType) {
|
public InputStreamBody(final InputStream in, final ContentType contentType) {
|
||||||
this(in, contentType, null);
|
this(in, contentType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
return this.in;
|
return this.in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(final OutputStream out) throws IOException {
|
public void writeTo(final OutputStream out) throws IOException {
|
||||||
try {
|
try {
|
||||||
final byte[] tmp = new byte[4096];
|
final byte[] tmp = new byte[4096];
|
||||||
int l;
|
int l;
|
||||||
while ((l = this.in.read(tmp)) != -1) {
|
while ((l = this.in.read(tmp)) != -1) {
|
||||||
out.write(tmp, 0, l);
|
out.write(tmp, 0, l);
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
} finally {
|
} finally {
|
||||||
this.in.close();
|
this.in.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransferEncoding() {
|
public String getTransferEncoding() {
|
||||||
return MIME.ENC_BINARY;
|
return MIME.ENC_BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentLength() {
|
public long getContentLength() {
|
||||||
return -1;
|
try {
|
||||||
}
|
return in.available();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
return this.filename;
|
return this.filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,60 +38,59 @@ import com.foxinmy.weixin4j.http.entity.HttpEntity;
|
|||||||
|
|
||||||
class MultipartFormEntity implements HttpEntity {
|
class MultipartFormEntity implements HttpEntity {
|
||||||
|
|
||||||
private final AbstractMultipartForm multipart;
|
private final AbstractMultipartForm multipart;
|
||||||
private final ContentType contentType;
|
private final ContentType contentType;
|
||||||
private final long contentLength;
|
private final long contentLength;
|
||||||
|
|
||||||
MultipartFormEntity(
|
MultipartFormEntity(final AbstractMultipartForm multipart,
|
||||||
final AbstractMultipartForm multipart,
|
final ContentType contentType, final long contentLength) {
|
||||||
final ContentType contentType,
|
super();
|
||||||
final long contentLength) {
|
this.multipart = multipart;
|
||||||
super();
|
this.contentType = contentType;
|
||||||
this.multipart = multipart;
|
this.contentLength = contentLength;
|
||||||
this.contentType = contentType;
|
}
|
||||||
this.contentLength = contentLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractMultipartForm getMultipart() {
|
AbstractMultipartForm getMultipart() {
|
||||||
return this.multipart;
|
return this.multipart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRepeatable() {
|
public boolean isRepeatable() {
|
||||||
return this.contentLength != -1;
|
return this.contentLength != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChunked() {
|
public boolean isChunked() {
|
||||||
return !isRepeatable();
|
return !isRepeatable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStreaming() {
|
public boolean isStreaming() {
|
||||||
return !isRepeatable();
|
return !isRepeatable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentLength() {
|
public long getContentLength() {
|
||||||
return this.contentLength;
|
return this.contentLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentType getContentType() {
|
public ContentType getContentType() {
|
||||||
return this.contentType;
|
return this.contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getContent() throws IOException {
|
public InputStream getContent() throws IOException {
|
||||||
if (this.contentLength < 0) {
|
if (this.contentLength < 0) {
|
||||||
throw new IllegalArgumentException("Content length is unknown");
|
throw new IllegalArgumentException("Content length is unknown");
|
||||||
} else if (this.contentLength > 25 * 1024) {
|
} else if (this.contentLength > 5 * 1024 * 1024) {
|
||||||
throw new IllegalArgumentException("Content length is too long: " + this.contentLength);
|
throw new IllegalArgumentException("Content length is too long: "
|
||||||
}
|
+ this.contentLength);
|
||||||
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
}
|
||||||
writeTo(outstream);
|
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
||||||
outstream.flush();
|
writeTo(outstream);
|
||||||
return new ByteArrayInputStream(outstream.toByteArray());
|
outstream.flush();
|
||||||
}
|
return new ByteArrayInputStream(outstream.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(final OutputStream outstream) throws IOException {
|
public void writeTo(final OutputStream outstream) throws IOException {
|
||||||
this.multipart.writeTo(outstream);
|
this.multipart.writeTo(outstream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import org.apache.http.client.methods.HttpRequestBase;
|
|||||||
import org.apache.http.client.methods.HttpTrace;
|
import org.apache.http.client.methods.HttpTrace;
|
||||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||||
import org.apache.http.entity.AbstractHttpEntity;
|
import org.apache.http.entity.AbstractHttpEntity;
|
||||||
import org.apache.http.entity.InputStreamEntity;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.http.AbstractHttpClient;
|
import com.foxinmy.weixin4j.http.AbstractHttpClient;
|
||||||
@ -31,7 +30,6 @@ import com.foxinmy.weixin4j.http.HttpClientException;
|
|||||||
import com.foxinmy.weixin4j.http.HttpHeaders;
|
import com.foxinmy.weixin4j.http.HttpHeaders;
|
||||||
import com.foxinmy.weixin4j.http.HttpMethod;
|
import com.foxinmy.weixin4j.http.HttpMethod;
|
||||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||||
import com.foxinmy.weixin4j.http.apache.mime.MultipartEntity;
|
|
||||||
import com.foxinmy.weixin4j.http.entity.HttpEntity;
|
import com.foxinmy.weixin4j.http.entity.HttpEntity;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
|
|
||||||
@ -119,18 +117,12 @@ public abstract class HttpComponent4 extends AbstractHttpClient {
|
|||||||
protected void resolveContent(HttpEntity entity, HttpRequestBase httpRequest)
|
protected void resolveContent(HttpEntity entity, HttpRequestBase httpRequest)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
AbstractHttpEntity httpEntity = null;
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
if (entity instanceof MultipartEntity) {
|
entity.writeTo(os);
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
os.flush();
|
||||||
entity.writeTo(os);
|
AbstractHttpEntity httpEntity = new org.apache.http.entity.ByteArrayEntity(
|
||||||
os.flush();
|
os.toByteArray());
|
||||||
httpEntity = new org.apache.http.entity.ByteArrayEntity(
|
os.close();
|
||||||
os.toByteArray());
|
|
||||||
os.close();
|
|
||||||
} else {
|
|
||||||
httpEntity = new InputStreamEntity(entity.getContent(),
|
|
||||||
entity.getContentLength());
|
|
||||||
}
|
|
||||||
httpEntity.setContentType(entity.getContentType().toString());
|
httpEntity.setContentType(entity.getContentType().toString());
|
||||||
((HttpEntityEnclosingRequestBase) httpRequest)
|
((HttpEntityEnclosingRequestBase) httpRequest)
|
||||||
.setEntity(httpEntity);
|
.setEntity(httpEntity);
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import java.util.List;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
|
import okio.Okio;
|
||||||
|
import okio.Source;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.http.AbstractHttpClient;
|
import com.foxinmy.weixin4j.http.AbstractHttpClient;
|
||||||
import com.foxinmy.weixin4j.http.HttpClientException;
|
import com.foxinmy.weixin4j.http.HttpClientException;
|
||||||
@ -20,6 +22,7 @@ import com.squareup.okhttp.OkHttpClient;
|
|||||||
import com.squareup.okhttp.Request;
|
import com.squareup.okhttp.Request;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import com.squareup.okhttp.RequestBody;
|
||||||
import com.squareup.okhttp.Response;
|
import com.squareup.okhttp.Response;
|
||||||
|
import com.squareup.okhttp.internal.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OkHttp2
|
* OkHttp2
|
||||||
@ -130,7 +133,13 @@ public class OkHttpClient2 extends AbstractHttpClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(BufferedSink sink) throws IOException {
|
public void writeTo(BufferedSink sink) throws IOException {
|
||||||
entity.writeTo(sink.outputStream());
|
Source source = null;
|
||||||
|
try {
|
||||||
|
source = Okio.source(entity.getContent());
|
||||||
|
sink.writeAll(source);
|
||||||
|
} finally {
|
||||||
|
Util.closeQuietly(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -28,7 +28,6 @@ public class OkHttpClient2Factory extends HttpClientFactory {
|
|||||||
okClient.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
|
okClient.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
|
||||||
okClient.setSslSocketFactory(HttpClientFactory.allowSSLContext()
|
okClient.setSslSocketFactory(HttpClientFactory.allowSSLContext()
|
||||||
.getSocketFactory());
|
.getSocketFactory());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OkHttpClient2Factory(OkHttpClient okClient) {
|
public OkHttpClient2Factory(OkHttpClient okClient) {
|
||||||
|
|||||||
@ -71,7 +71,7 @@ public class SceneInfoApp {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static SceneInfoApp createAndroidAPP(String appName, String packageName) {
|
public static SceneInfoApp createAndroidAPP(String appName, String packageName) {
|
||||||
SceneInfoApp app = new SceneInfoApp("IOS", appName, packageName);
|
SceneInfoApp app = new SceneInfoApp("Android", appName, packageName);
|
||||||
String sceneInfo = String
|
String sceneInfo = String
|
||||||
.format("{\"type\": \"%s\",\"app_name\": \"%s\",\"package_name\": \"%s\"}",
|
.format("{\"type\": \"%s\",\"app_name\": \"%s\",\"package_name\": \"%s\"}",
|
||||||
app.getType(), app.getName(), app.getPath());
|
app.getType(), app.getName(), app.getPath());
|
||||||
|
|||||||
@ -19,6 +19,7 @@ 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.parsers.SAXParserFactory;
|
||||||
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;
|
||||||
@ -26,7 +27,9 @@ 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.sax.SAXSource;
|
||||||
|
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.foxinmy.weixin4j.util.Consts;
|
import com.foxinmy.weixin4j.util.Consts;
|
||||||
@ -45,6 +48,16 @@ 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 ConcurrentHashMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class<?>, JAXBContext>();
|
private final static ConcurrentHashMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<Class<?>, JAXBContext>();
|
||||||
|
private final static SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
|
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
|
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Xml2Bean
|
* Xml2Bean
|
||||||
@ -60,25 +73,17 @@ public final class XmlStream {
|
|||||||
JAXBContext jaxbContext = getJaxbContext(clazz);
|
JAXBContext jaxbContext = getJaxbContext(clazz);
|
||||||
try {
|
try {
|
||||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
Source source = new StreamSource(content);
|
Source source = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(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())) {
|
|
||||||
JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source,
|
|
||||||
clazz);
|
|
||||||
return jaxbElement.getValue();
|
return jaxbElement.getValue();
|
||||||
} else {
|
} else {
|
||||||
return (T) unmarshaller.unmarshal(source);
|
return (T) unmarshaller.unmarshal(source);
|
||||||
}
|
}
|
||||||
} catch (JAXBException ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException("Could not unmarshaller class [" + clazz
|
throw new RuntimeException("Could not unmarshaller class [" + clazz + "]", ex);
|
||||||
+ "]: " + ex.getMessage(), ex);
|
|
||||||
} catch (NoSuchMethodException ex) {
|
|
||||||
throw new RuntimeException("Could not unmarshaller class [" + clazz
|
|
||||||
+ "]: " + ex.getMessage(), ex);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
try {
|
try {
|
||||||
@ -100,8 +105,7 @@ public final class XmlStream {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static <T> T fromXML(String content, Class<T> clazz) {
|
public static <T> T fromXML(String content, Class<T> clazz) {
|
||||||
return fromXML(
|
return fromXML(new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz);
|
||||||
new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,8 +118,7 @@ public final class XmlStream {
|
|||||||
public static String map2xml(Map<String, String> map) {
|
public static String map2xml(Map<String, String> map) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
try {
|
try {
|
||||||
XMLStreamWriter xw = XMLOutputFactory.newInstance()
|
XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
|
||||||
.createXMLStreamWriter(sw);
|
|
||||||
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
||||||
xw.writeStartElement(ROOT_ELEMENT_XML);
|
xw.writeStartElement(ROOT_ELEMENT_XML);
|
||||||
for (Entry<String, String> entry : map.entrySet()) {
|
for (Entry<String, String> entry : map.entrySet()) {
|
||||||
@ -151,8 +154,7 @@ public final class XmlStream {
|
|||||||
public static String map2xml(JSONObject json) {
|
public static String map2xml(JSONObject json) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
try {
|
try {
|
||||||
XMLStreamWriter xw = XMLOutputFactory.newInstance()
|
XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
|
||||||
.createXMLStreamWriter(sw);
|
|
||||||
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
||||||
xw.writeStartElement(ROOT_ELEMENT_XML);
|
xw.writeStartElement(ROOT_ELEMENT_XML);
|
||||||
for (Entry<String, Object> entry : json.entrySet()) {
|
for (Entry<String, Object> entry : json.entrySet()) {
|
||||||
@ -189,8 +191,7 @@ public final class XmlStream {
|
|||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
StringReader sr = new StringReader(content);
|
StringReader sr = new StringReader(content);
|
||||||
try {
|
try {
|
||||||
XMLStreamReader xr = XMLInputFactory.newInstance()
|
XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(sr);
|
||||||
.createXMLStreamReader(sr);
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int event = xr.next();
|
int event = xr.next();
|
||||||
if (event == XMLStreamConstants.END_DOCUMENT) {
|
if (event == XMLStreamConstants.END_DOCUMENT) {
|
||||||
@ -246,25 +247,16 @@ public final class XmlStream {
|
|||||||
JAXBContext jaxbContext = getJaxbContext(clazz);
|
JAXBContext jaxbContext = getJaxbContext(clazz);
|
||||||
try {
|
try {
|
||||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||||
marshaller.setProperty(Marshaller.JAXB_ENCODING,
|
marshaller.setProperty(Marshaller.JAXB_ENCODING, Consts.UTF_8.name());
|
||||||
Consts.UTF_8.name());
|
XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class);
|
||||||
XmlRootElement rootElement = clazz
|
|
||||||
.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")
|
marshaller.marshal(new JAXBElement<T>(new QName(ROOT_ELEMENT_XML), clazz, t), os);
|
||||||
.getDefaultValue().toString())) {
|
|
||||||
marshaller.marshal(new JAXBElement<T>(new QName(
|
|
||||||
ROOT_ELEMENT_XML), clazz, t), os);
|
|
||||||
} else {
|
} else {
|
||||||
marshaller.marshal(t, os);
|
marshaller.marshal(t, os);
|
||||||
}
|
}
|
||||||
} catch (JAXBException ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException("Could not marshal class [" + clazz
|
throw new RuntimeException("Could not marshal class [" + clazz + "] ", ex);
|
||||||
+ "]: " + ex.getMessage(), ex);
|
|
||||||
} catch (NoSuchMethodException ex) {
|
|
||||||
throw new RuntimeException("Could not marshaller class [" + clazz
|
|
||||||
+ "]: " + ex.getMessage(), ex);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (os != null) {
|
if (os != null) {
|
||||||
try {
|
try {
|
||||||
@ -283,9 +275,7 @@ public final class XmlStream {
|
|||||||
jaxbContext = JAXBContext.newInstance(clazz);
|
jaxbContext = JAXBContext.newInstance(clazz);
|
||||||
jaxbContexts.putIfAbsent(clazz, jaxbContext);
|
jaxbContexts.putIfAbsent(clazz, jaxbContext);
|
||||||
} catch (JAXBException ex) {
|
} catch (JAXBException ex) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException("Could not instantiate JAXBContext for class [" + clazz + "] ", ex);
|
||||||
"Could not instantiate JAXBContext for class [" + clazz
|
|
||||||
+ "]: " + ex.getMessage(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jaxbContext;
|
return jaxbContext;
|
||||||
|
|||||||
1
weixin4j-example/.gitignore
vendored
1
weixin4j-example/.gitignore
vendored
@ -33,3 +33,4 @@ Thumbs.db
|
|||||||
bin
|
bin
|
||||||
/target/
|
/target/
|
||||||
/target/
|
/target/
|
||||||
|
/target/
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<artifactId>weixin4j-example</artifactId>
|
<artifactId>weixin4j-example</artifactId>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-mp</artifactId>
|
<artifactId>weixin4j-mp</artifactId>
|
||||||
<name>weixin4j-mp</name>
|
<name>weixin4j-mp</name>
|
||||||
@ -29,11 +29,5 @@
|
|||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-core</artifactId>
|
|
||||||
<version>1.1.8</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -2,6 +2,7 @@ package com.foxinmy.weixin4j.mp.test;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -82,6 +83,18 @@ public class MediaTest extends TokenTest {
|
|||||||
System.err.println(mediaId);
|
System.err.println(mediaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void uploadVideo() throws WeixinException, FileNotFoundException {
|
||||||
|
InputStream is = new FileInputStream("/Users/jy/Downloads/test.mp4");
|
||||||
|
String fileName = "视频文件名";
|
||||||
|
String title = "视频标题";
|
||||||
|
String description = "视频描述";
|
||||||
|
MpVideo mpVideo = mediaApi
|
||||||
|
.uploadVideo(is, fileName, title, description);
|
||||||
|
Assert.assertTrue(mpVideo.getMediaId() != null);
|
||||||
|
System.err.println(mpVideo.getMediaId());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uploadMaterialArticle() throws WeixinException {
|
public void uploadMaterialArticle() throws WeixinException {
|
||||||
List<MpArticle> articles = new ArrayList<MpArticle>();
|
List<MpArticle> articles = new ArrayList<MpArticle>();
|
||||||
@ -94,7 +107,8 @@ public class MediaTest extends TokenTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downloadArticle() throws WeixinException {
|
public void downloadArticle() throws WeixinException {
|
||||||
List<MpArticle> articles = mediaApi.downloadArticle("DVWwU0u9ommOTPgyJszpK943IWCCVAcFGNmiIBObf5E");
|
List<MpArticle> articles = mediaApi
|
||||||
|
.downloadArticle("DVWwU0u9ommOTPgyJszpK943IWCCVAcFGNmiIBObf5E");
|
||||||
Assert.assertTrue(articles != null && !articles.isEmpty());
|
Assert.assertTrue(articles != null && !articles.isEmpty());
|
||||||
System.err.println(articles);
|
System.err.println(articles);
|
||||||
}
|
}
|
||||||
@ -138,15 +152,4 @@ public class MediaTest extends TokenTest {
|
|||||||
.listAllMaterialMedia(MediaType.image);
|
.listAllMaterialMedia(MediaType.image);
|
||||||
System.err.println(mediaList);
|
System.err.println(mediaList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void uploadVideo() throws WeixinException {
|
|
||||||
InputStream is = null;
|
|
||||||
String fileName = "视频文件名";
|
|
||||||
String title = "视频标题";
|
|
||||||
String description = "视频描述";
|
|
||||||
MpVideo mpVideo = mediaApi
|
|
||||||
.uploadVideo(is, fileName, title, description);
|
|
||||||
Assert.assertTrue(mpVideo.getMediaId() != null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,4 +95,12 @@ public class XmlstreamTest {
|
|||||||
sb.toString(),
|
sb.toString(),
|
||||||
com.foxinmy.weixin4j.payment.mch.RefundRecord.class));
|
com.foxinmy.weixin4j.payment.mch.RefundRecord.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception{
|
||||||
|
XmlstreamTest.xml2order();
|
||||||
|
XmlstreamTest.xml2refundRecordV2();
|
||||||
|
XmlstreamTest.xml2refundRecordV3();
|
||||||
|
XmlstreamTest.map2xml();
|
||||||
|
XmlstreamTest.object2xmlWithRootElement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-qy</artifactId>
|
<artifactId>weixin4j-qy</artifactId>
|
||||||
<name>weixin4j-qy</name>
|
<name>weixin4j-qy</name>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-server</artifactId>
|
<artifactId>weixin4j-server</artifactId>
|
||||||
<version>1.1.9</version>
|
<version>1.1.9</version>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-serverX</artifactId>
|
<artifactId>weixin4j-serverX</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.1</version>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.foxinmy</groupId>
|
<groupId>com.foxinmy</groupId>
|
||||||
<artifactId>weixin4j</artifactId>
|
<artifactId>weixin4j</artifactId>
|
||||||
<version>1.8.1</version>
|
<version>1.8.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>weixin4j-wxa</artifactId>
|
<artifactId>weixin4j-wxa</artifactId>
|
||||||
<name>weixin4j-wxa</name>
|
<name>weixin4j-wxa</name>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user