clear code with findbugs plugin and change the version to 1.1
This commit is contained in:
parent
54963b283c
commit
5b8666d2f0
@ -191,6 +191,12 @@ netty的代码没有放到maven中心仓库,也没什么意义,因为最终需
|
||||
+ **weixin4j-mp**: 新增群发消息预览、状态查询接口
|
||||
|
||||
+ **weixin4j-mp**: 新增多客服添加账号、更新账号、上传头像、删除账号接口
|
||||
|
||||
* 2014-12-18
|
||||
|
||||
+ clear code with findbugs plugin
|
||||
|
||||
+ change the version to 1.1
|
||||
|
||||
接下来
|
||||
------
|
||||
|
||||
14
pom.xml
14
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>weixin4j</name>
|
||||
<url>https://github.com/foxinmy/weixin4j</url>
|
||||
@ -71,6 +71,7 @@
|
||||
<maven.javadoc.plugin.version>2.10.1</maven.javadoc.plugin.version>
|
||||
<maven.deploy.plugin.version>2.8.2</maven.deploy.plugin.version>
|
||||
<maven.gpg.plugin.version>1.5</maven.gpg.plugin.version>
|
||||
<maven.surefire.plugin.version>2.18</maven.surefire.plugin.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@ -192,6 +193,14 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven.surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<resources>
|
||||
@ -241,9 +250,6 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<distributionManagement>
|
||||
|
||||
@ -5,10 +5,11 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<name>weixin4j-base</name>
|
||||
<description>微信开发基础工程</description>
|
||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-base</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -8,7 +8,7 @@ import org.dom4j.DocumentException;
|
||||
import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.response.ResponseMessage;
|
||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 继承的类需实现execute(M inMessage)
|
||||
@ -28,7 +28,7 @@ public abstract class AbstractAction<M extends BaseMsg> implements WeixinAction
|
||||
public ResponseMessage execute(String msg) throws DocumentException {
|
||||
BaseMsg message = MessageUtil.xml2msg(msg);
|
||||
if (message == null) {
|
||||
return execute(XStream.get(msg, getGenericType()));
|
||||
return execute(XmlStream.get(msg, getGenericType()));
|
||||
}
|
||||
return execute((M) message);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.xml.Map2ObjectConverter;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
import com.thoughtworks.xstream.core.ClassLoaderReference;
|
||||
import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
|
||||
@ -20,14 +20,13 @@ import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/index.php">微信公众平台API文档</a>
|
||||
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php">微信企业号API文档</a>
|
||||
*/
|
||||
public class BaseApi {
|
||||
public abstract class BaseApi {
|
||||
protected final HttpRequest request = new HttpRequest();
|
||||
protected final static XStream mapXstream = XStream.get();
|
||||
protected static ResourceBundle weixinBundle;
|
||||
protected final static XmlStream mapXstream = XmlStream.get();
|
||||
static {
|
||||
mapXstream.alias("xml", Map.class);
|
||||
mapXstream.registerConverter(new Map2ObjectConverter(new DefaultMapper(
|
||||
new ClassLoaderReference(XStream.class.getClassLoader()))));
|
||||
new ClassLoaderReference(XmlStream.class.getClassLoader()))));
|
||||
}
|
||||
|
||||
protected String map2xml(Map<?, ?> map) {
|
||||
@ -38,9 +37,9 @@ public 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 = weixinBundle.getString(key);
|
||||
String url = getWeixinBundle().getString(key);
|
||||
Pattern p = Pattern.compile("(\\{[^\\}]*\\})");
|
||||
Matcher m = p.matcher(url);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -11,7 +12,7 @@ import org.dom4j.io.SAXReader;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
public class Response {
|
||||
|
||||
@ -57,13 +58,13 @@ public class Response {
|
||||
if (isXmlResult) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<T> clazz = (Class<T>) typeReference.getType();
|
||||
return XStream.get(text, clazz);
|
||||
return XmlStream.get(text, clazz);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public XmlResult getAsXmlResult() {
|
||||
return XStream.get(text, XmlResult.class);
|
||||
return XmlStream.get(text, XmlResult.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,36 +80,48 @@ public class Response {
|
||||
result.setCode(code);
|
||||
SAXReader reader = new SAXReader();
|
||||
Document doc = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
doc = reader.read(Response.class.getResourceAsStream("error.xml"));
|
||||
is = Response.class.getResourceAsStream("error.xml");
|
||||
doc = reader.read(is);
|
||||
Node node = doc.getRootElement().selectSingleNode(
|
||||
String.format("error/code[text()=%d]", code));
|
||||
if (node != null) {
|
||||
node = node.getParent();
|
||||
String desc = null;
|
||||
Node _node = node.selectSingleNode("desc");
|
||||
if (_node != null) {
|
||||
desc = _node.getStringValue();
|
||||
}
|
||||
String text = null;
|
||||
_node = node.selectSingleNode("text");
|
||||
if (_node != null) {
|
||||
text = _node.getStringValue();
|
||||
}
|
||||
if (StringUtils.isBlank(desc) && StringUtils.isNotBlank(text)) {
|
||||
desc = text;
|
||||
}
|
||||
if (StringUtils.isBlank(text) && StringUtils.isNotBlank(desc)) {
|
||||
text = desc;
|
||||
}
|
||||
result.setDesc(desc);
|
||||
result.setText(text);
|
||||
} else {
|
||||
result.setDesc("unknown error");
|
||||
result.setText("未知错误");
|
||||
}
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Node node = doc.getRootElement().selectSingleNode(
|
||||
String.format("error/code[text()=%d]", code));
|
||||
if (node != null) {
|
||||
node = node.getParent();
|
||||
String desc = null;
|
||||
Node _node = node.selectSingleNode("desc");
|
||||
if (_node != null) {
|
||||
desc = _node.getStringValue();
|
||||
}
|
||||
String text = null;
|
||||
_node = node.selectSingleNode("text");
|
||||
if (_node != null) {
|
||||
text = _node.getStringValue();
|
||||
}
|
||||
if (StringUtils.isBlank(desc) && StringUtils.isNotBlank(text)) {
|
||||
desc = text;
|
||||
}
|
||||
if (StringUtils.isBlank(text) && StringUtils.isNotBlank(desc)) {
|
||||
text = desc;
|
||||
}
|
||||
result.setDesc(desc);
|
||||
result.setText(text);
|
||||
} else {
|
||||
result.setDesc("unknown error");
|
||||
result.setText("未知错误");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -134,11 +147,15 @@ public class Response {
|
||||
}
|
||||
|
||||
public byte[] getBody() {
|
||||
return body;
|
||||
return (byte[]) body.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* May expose internal representation by incorporating reference to mutable
|
||||
* object
|
||||
*/
|
||||
public void setBody(byte[] body) {
|
||||
this.body = body;
|
||||
this.body = (byte[]) body.clone();
|
||||
}
|
||||
|
||||
public InputStream getStream() {
|
||||
|
||||
@ -87,6 +87,21 @@ public class BaseMsg implements Serializable {
|
||||
return agentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((agentId == null) ? 0 : agentId.hashCode());
|
||||
result = prime * result + (int) (createTime ^ (createTime >>> 32));
|
||||
result = prime * result
|
||||
+ ((fromUserName == null) ? 0 : fromUserName.hashCode());
|
||||
result = prime * result + (int) (msgId ^ (msgId >>> 32));
|
||||
result = prime * result + ((msgType == null) ? 0 : msgType.hashCode());
|
||||
result = prime * result
|
||||
+ ((toUserName == null) ? 0 : toUserName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof BaseMsg) {
|
||||
|
||||
@ -19,8 +19,9 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
*/
|
||||
@XStreamAlias("app-token")
|
||||
public class Token implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final long serialVersionUID = -7564855472419104084L;
|
||||
|
||||
@JSONField(name = "access_token")
|
||||
private String accessToken;
|
||||
@JSONField(name = "expires_in")
|
||||
@ -51,14 +52,6 @@ public class Token implements Serializable {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Token) {
|
||||
return accessToken.equals(((Token) obj).getAccessToken());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Token [accessToken=" + accessToken + ", expiresIn=" + expiresIn
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.foxinmy.weixin4j.msg.event.menu;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.foxinmy.weixin4j.type.EventType;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@ -30,7 +32,10 @@ public class MenuLocationEventMessage extends MenuEventMessage {
|
||||
return locationInfo;
|
||||
}
|
||||
|
||||
public static class LocationInfo {
|
||||
public static class LocationInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4904181780216819965L;
|
||||
|
||||
@XStreamAlias("Location_X")
|
||||
private double x; // 地理位置维度
|
||||
@XStreamAlias("Location_Y")
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.msg.event.menu;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
@ -27,7 +28,10 @@ public class MenuPhotoEventMessage extends MenuEventMessage {
|
||||
return pictureInfo;
|
||||
}
|
||||
|
||||
public static class PictureInfo {
|
||||
public static class PictureInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3361375879168233258L;
|
||||
|
||||
@XStreamAlias("Count")
|
||||
private int count;
|
||||
@XStreamAlias("PicList")
|
||||
@ -48,7 +52,10 @@ public class MenuPhotoEventMessage extends MenuEventMessage {
|
||||
}
|
||||
|
||||
@XStreamAlias("item")
|
||||
public static class PictureItem {
|
||||
public static class PictureItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7636697449096645590L;
|
||||
|
||||
@XStreamAlias("PicMd5Sum")
|
||||
private String md5;
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.foxinmy.weixin4j.msg.event.menu;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@ -25,7 +27,10 @@ public class MenuScanEventMessage extends MenuEventMessage {
|
||||
return scanInfo;
|
||||
}
|
||||
|
||||
public static class ScanInfo {
|
||||
public static class ScanInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2237570238164900421L;
|
||||
|
||||
@XStreamAlias("ScanType")
|
||||
private String type;
|
||||
@XStreamAlias("ScanResult")
|
||||
|
||||
@ -8,7 +8,7 @@ import com.foxinmy.weixin4j.msg.model.Base;
|
||||
import com.foxinmy.weixin4j.msg.model.News;
|
||||
import com.foxinmy.weixin4j.msg.model.Responseable;
|
||||
import com.foxinmy.weixin4j.util.ClassUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
/**
|
||||
@ -40,7 +40,7 @@ public class ResponseMessage extends BaseMsg {
|
||||
|
||||
private static final long serialVersionUID = 7761192742840031607L;
|
||||
|
||||
protected final static XStream xmlStream = XStream.get();
|
||||
protected final static XmlStream xmlStream = XmlStream.get();
|
||||
static {
|
||||
Class<?>[] classes = ClassUtil.getClasses(Base.class.getPackage())
|
||||
.toArray(new Class[0]);
|
||||
@ -58,7 +58,8 @@ public class ResponseMessage extends BaseMsg {
|
||||
private final Base box;
|
||||
|
||||
public ResponseMessage(Base box) {
|
||||
this(box, null);
|
||||
super(box.getMediaType().name());
|
||||
this.box = box;
|
||||
}
|
||||
|
||||
public ResponseMessage(Base box, BaseMsg inMessage) {
|
||||
|
||||
@ -15,7 +15,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.type.AccountType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 基于文件保存的Token获取类
|
||||
@ -66,7 +66,7 @@ public class FileTokenHolder extends AbstractTokenHolder {
|
||||
long now_time = ca.getTimeInMillis();
|
||||
try {
|
||||
if (token_file.exists()) {
|
||||
token = XStream.get(new FileInputStream(token_file),
|
||||
token = XmlStream.get(new FileInputStream(token_file),
|
||||
Token.class);
|
||||
long expire_time = token.getTime()
|
||||
+ (token.getExpiresIn() * 1000) - 2;
|
||||
@ -78,7 +78,7 @@ public class FileTokenHolder extends AbstractTokenHolder {
|
||||
token = response.getAsObject(new TypeReference<Token>() {
|
||||
});
|
||||
token.setTime(now_time);
|
||||
XStream.to(token, new FileOutputStream(token_file));
|
||||
XmlStream.to(token, new FileOutputStream(token_file));
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException(e.getMessage());
|
||||
}
|
||||
|
||||
@ -23,11 +23,16 @@ public class ConfigUtil {
|
||||
static {
|
||||
weixinBundle = ResourceBundle.getBundle("weixin");
|
||||
Set<String> keySet = weixinBundle.keySet();
|
||||
File file = null;
|
||||
for (String key : keySet) {
|
||||
if (!key.endsWith("_path")) {
|
||||
continue;
|
||||
}
|
||||
new File(getValue(key)).mkdirs();
|
||||
file = new File(getValue(key));
|
||||
if (!file.exists() && !file.mkdirs()) {
|
||||
System.err.append(String.format("%s create fail.%n",
|
||||
file.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -92,6 +92,7 @@ public class FileUtil {
|
||||
|
||||
/**
|
||||
* 获取文件类型
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@ -101,14 +102,16 @@ public class FileUtil {
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
byte[] b = new byte[10];
|
||||
fis.read(b, 0, b.length);
|
||||
String fileCode = bytesToHexString(b).toLowerCase();
|
||||
Iterator<String> keyIter = FILE_TYPE_MAP.keySet().iterator();
|
||||
while (keyIter.hasNext()) {
|
||||
String key = keyIter.next().toLowerCase();
|
||||
if (key.startsWith(fileCode) || fileCode.startsWith(key)) {
|
||||
fileType = FILE_TYPE_MAP.get(key);
|
||||
break;
|
||||
int t = fis.read(b, 0, b.length);
|
||||
if (t > 0) {
|
||||
String fileCode = bytesToHexString(b).toLowerCase();
|
||||
Iterator<String> keyIter = FILE_TYPE_MAP.keySet().iterator();
|
||||
while (keyIter.hasNext()) {
|
||||
String key = keyIter.next().toLowerCase();
|
||||
if (key.startsWith(fileCode) || fileCode.startsWith(key)) {
|
||||
fileType = FILE_TYPE_MAP.get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -20,7 +20,7 @@ import com.foxinmy.weixin4j.model.BaseMsg;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.type.EventType;
|
||||
import com.foxinmy.weixin4j.type.MessageType;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 消息工具类
|
||||
@ -205,7 +205,7 @@ public class MessageUtil {
|
||||
messageClass = EventType.valueOf(type.toLowerCase())
|
||||
.getEventClass();
|
||||
}
|
||||
return XStream.get(xmlMsg, messageClass);
|
||||
return XmlStream.get(xmlMsg, messageClass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -48,11 +48,11 @@ public class PKCS7Encoder {
|
||||
// 获得补位所用的字符
|
||||
byte target = (byte) (amountToPad & 0xFF);
|
||||
char padChr = (char) target;
|
||||
String tmp = new String();
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
for (int index = 0; index < amountToPad; index++) {
|
||||
tmp += padChr;
|
||||
tmp.append(padChr);
|
||||
}
|
||||
return tmp.getBytes(Consts.UTF_8);
|
||||
return tmp.toString().getBytes(Consts.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -10,9 +10,9 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
||||
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
|
||||
|
||||
public class XStream extends com.thoughtworks.xstream.XStream {
|
||||
public class XmlStream extends com.thoughtworks.xstream.XStream {
|
||||
|
||||
public XStream() {
|
||||
public XmlStream() {
|
||||
|
||||
super(new Xpp3Driver() {
|
||||
|
||||
@ -31,7 +31,7 @@ public class XStream extends com.thoughtworks.xstream.XStream {
|
||||
});
|
||||
}
|
||||
|
||||
public XStream(HierarchicalStreamDriver hierarchicalStreamDriver) {
|
||||
public XmlStream(HierarchicalStreamDriver hierarchicalStreamDriver) {
|
||||
super(hierarchicalStreamDriver);
|
||||
}
|
||||
|
||||
@ -45,29 +45,29 @@ public class XStream extends com.thoughtworks.xstream.XStream {
|
||||
return (T) super.fromXML(inputStream);
|
||||
}
|
||||
|
||||
public static XStream get() {
|
||||
XStream xstream = new XStream();
|
||||
public static XmlStream get() {
|
||||
XmlStream xstream = new XmlStream();
|
||||
xstream.ignoreUnknownElements();
|
||||
xstream.autodetectAnnotations(true);
|
||||
return xstream;
|
||||
}
|
||||
|
||||
public static <T> T get(InputStream inputStream, Class<T> clazz) {
|
||||
XStream xStream = get();
|
||||
XmlStream xStream = get();
|
||||
xStream.alias("xml", clazz);
|
||||
xStream.processAnnotations(clazz);
|
||||
return xStream.fromXML(inputStream, clazz);
|
||||
}
|
||||
|
||||
public static <T> T get(String xml, Class<T> clazz) {
|
||||
XStream xStream = get();
|
||||
XmlStream xStream = get();
|
||||
xStream.alias("xml", clazz);
|
||||
xStream.processAnnotations(clazz);
|
||||
return xStream.fromXML(xml, clazz);
|
||||
}
|
||||
|
||||
public static String to(Object obj) {
|
||||
XStream xStream = get();
|
||||
XmlStream xStream = get();
|
||||
Class<?> clazz = obj.getClass();
|
||||
xStream.alias("xml", clazz);
|
||||
xStream.processAnnotations(clazz);
|
||||
@ -75,7 +75,7 @@ public class XStream extends com.thoughtworks.xstream.XStream {
|
||||
}
|
||||
|
||||
public static void to(Object obj, OutputStream out) {
|
||||
XStream xStream = get();
|
||||
XmlStream xStream = get();
|
||||
Class<?> clazz = obj.getClass();
|
||||
xStream.alias("xml", clazz);
|
||||
xStream.processAnnotations(clazz);
|
||||
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-mp</artifactId>
|
||||
<name>weixin4j-mp</name>
|
||||
@ -15,11 +15,4 @@
|
||||
<module>weixin4j-mp-api</module>
|
||||
<module>weixin4j-mp-server</module>
|
||||
</modules>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,15 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-mp</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-mp-api</artifactId>
|
||||
<name>weixin4j-mp-api</name>
|
||||
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-mp/weixin4j-mp-api</url>
|
||||
<description>微信公众号API</description>
|
||||
<description>微信公众平台API</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -22,6 +23,11 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
|
||||
@ -187,7 +187,6 @@ public class WeixinProxy {
|
||||
* 媒体类型
|
||||
* @return 写入硬盘后的文件对象
|
||||
* @throws WeixinException
|
||||
* @throws IOException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/10/78b15308b053286e2a66b33f0f0f5fb6.html">上传下载说明</a>
|
||||
* @see com.foxinmy.weixin4j.type.MediaType
|
||||
@ -195,7 +194,7 @@ public class WeixinProxy {
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#downloadMedia(String)}
|
||||
*/
|
||||
public File downloadMedia(String mediaId, MediaType mediaType)
|
||||
throws WeixinException, IOException {
|
||||
throws WeixinException {
|
||||
return mediaApi.downloadMedia(mediaId, mediaType);
|
||||
}
|
||||
|
||||
@ -503,7 +502,8 @@ public class WeixinProxy {
|
||||
* href="http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html#.E5.88.A0.E9.99.A4.E7.BE.A4.E5.8F.91.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91">删除群发</a>
|
||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByGroupId(Base, int)}
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(Base, String...)
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#massByOpenIds(Base, String...)
|
||||
|
||||
*/
|
||||
public JsonResult deleteMassNews(String msgid) throws WeixinException {
|
||||
return massApi.deleteMassNews(msgid);
|
||||
@ -756,7 +756,7 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 自定义菜单
|
||||
*
|
||||
* @param btnList
|
||||
* @param btnList 菜单列表
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html">创建自定义菜单</a>
|
||||
@ -798,7 +798,7 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 生成带参数的二维码
|
||||
*
|
||||
* @param parameter
|
||||
* @param parameter 二维码参数
|
||||
* @return byte数据包
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.api.QrApi
|
||||
@ -838,14 +838,12 @@ public class WeixinProxy {
|
||||
* 二维码参数
|
||||
* @return 硬盘存储的文件对象
|
||||
* @throws WeixinException
|
||||
* @throws IOException
|
||||
* @see <a
|
||||
* href="mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html">二维码</a>
|
||||
* @see com.foxinmy.weixin4j.mp.model.QRParameter
|
||||
* @see com.foxinmy.weixin4j.mp.api.QrApi
|
||||
*/
|
||||
public File getQR(QRParameter parameter) throws WeixinException,
|
||||
IOException {
|
||||
public File getQR(QRParameter parameter) throws WeixinException {
|
||||
return qrApi.getQR(parameter);
|
||||
}
|
||||
|
||||
@ -902,7 +900,7 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 长链接转短链接
|
||||
*
|
||||
* @param url
|
||||
* @param url 待转换的链接
|
||||
* @return 短链接
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
|
||||
@ -33,7 +33,7 @@ public class HelperApi extends MpApi {
|
||||
/**
|
||||
* 长链接转短链接
|
||||
*
|
||||
* @param url
|
||||
* @param url 待转换的链接
|
||||
* @return 短链接
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
|
||||
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.entity.mime.content.ByteArrayBody;
|
||||
@ -65,7 +66,6 @@ public class MediaApi extends MpApi {
|
||||
* 媒体类型
|
||||
* @return 上传到微信服务器返回的媒体标识
|
||||
* @throws WeixinException
|
||||
* @throws IOException
|
||||
* @see com.foxinmy.weixin4j.type.MediaType
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#uploadMedia(String, byte[],String)}
|
||||
*/
|
||||
@ -116,14 +116,13 @@ public class MediaApi extends MpApi {
|
||||
* 媒体类型
|
||||
* @return 写入硬盘后的文件对象
|
||||
* @throws WeixinException
|
||||
* @throws IOException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/10/78b15308b053286e2a66b33f0f0f5fb6.html">上传下载说明</a>
|
||||
* @see com.foxinmy.weixin4j.type.MediaType
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.MediaApi#downloadMedia(String)}
|
||||
*/
|
||||
public File downloadMedia(String mediaId, MediaType mediaType)
|
||||
throws WeixinException, IOException {
|
||||
throws WeixinException {
|
||||
String media_path = ConfigUtil.getValue("media_path");
|
||||
File file = new File(media_path + File.separator + mediaId + "."
|
||||
+ mediaType.getFormatName());
|
||||
@ -131,10 +130,27 @@ public class MediaApi extends MpApi {
|
||||
return file;
|
||||
}
|
||||
byte[] datas = downloadMedia(mediaId);
|
||||
file.createNewFile();
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(datas);
|
||||
out.close();
|
||||
OutputStream os = null;
|
||||
try {
|
||||
boolean flag = file.createNewFile();
|
||||
if (flag) {
|
||||
os = new FileOutputStream(file);
|
||||
os.write(datas);
|
||||
} else {
|
||||
throw new WeixinException("-1", String.format(
|
||||
"create file fail:%s", file.getAbsolutePath()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException("-1", e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ public class MenuApi extends MpApi {
|
||||
/**
|
||||
* 自定义菜单
|
||||
*
|
||||
* @param btnList
|
||||
* @param btnList 菜单列表
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html">创建自定义菜单</a>
|
||||
|
||||
@ -15,8 +15,14 @@ import com.foxinmy.weixin4j.api.BaseApi;
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/index.php">api文档</a>
|
||||
*/
|
||||
public class MpApi extends BaseApi {
|
||||
private final static ResourceBundle weixinBundle;
|
||||
static {
|
||||
weixinBundle = ResourceBundle
|
||||
.getBundle("com/foxinmy/weixin4j/mp/api/weixin");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceBundle getWeixinBundle() {
|
||||
return weixinBundle;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
@ -246,8 +247,7 @@ public class PayApi extends MpApi {
|
||||
*/
|
||||
public RefundResult refund(InputStream ca, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, String opUserPasswd) throws WeixinException,
|
||||
IOException {
|
||||
String opUserId, String opUserPasswd) throws WeixinException{
|
||||
int version = weixinAccount.getVersion();
|
||||
String refund_uri = getRequestUri(String.format("refund_v%d_uri",
|
||||
version));
|
||||
@ -355,6 +355,9 @@ public class PayApi extends MpApi {
|
||||
SSLHttpRequest request = new SSLHttpRequest(
|
||||
weixinAccount.getMchId(), ca);
|
||||
response = request.post(refund_uri, param);
|
||||
} else {
|
||||
throw new WeixinException("-1", String.format("unknown version:%d",
|
||||
version));
|
||||
}
|
||||
return response.getAsObject(new TypeReference<RefundResult>() {
|
||||
});
|
||||
@ -482,7 +485,7 @@ public class PayApi extends MpApi {
|
||||
* @throws IOException
|
||||
*/
|
||||
public File downloadbill(Date billDate, BillType billType)
|
||||
throws WeixinException, IOException {
|
||||
throws WeixinException {
|
||||
if (billDate == null) {
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.add(Calendar.DAY_OF_MONTH, -1);
|
||||
@ -526,25 +529,46 @@ public class PayApi extends MpApi {
|
||||
map.put("sign", sign);
|
||||
String param = map2xml(map);
|
||||
response = request.post(downloadbill_uri, param);
|
||||
} else {
|
||||
throw new WeixinException("-1", String.format("unknown version:%d",
|
||||
version));
|
||||
}
|
||||
BufferedReader reader = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
response.getStream(), charset));
|
||||
String line = null;
|
||||
List<String[]> bills = new LinkedList<String[]>();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
bills.add(line.replaceAll("`", "").split(","));
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
response.getStream(), charset));
|
||||
String line = null;
|
||||
List<String[]> bills = new LinkedList<String[]>();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
bills.add(line.replaceAll("`", "").split(","));
|
||||
List<String> headers = Arrays.asList(bills.remove(0));
|
||||
List<String> totalDatas = Arrays
|
||||
.asList(bills.remove(bills.size() - 1));
|
||||
List<String> totalHeaders = Arrays
|
||||
.asList(bills.remove(bills.size() - 1));
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
wb.createSheet(_billDate + "对账单");
|
||||
ExcelUtil.list2excel(wb, headers, bills);
|
||||
ExcelUtil.list2excel(wb, totalHeaders, totalDatas);
|
||||
os = new FileOutputStream(file);
|
||||
wb.write(os);
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException("-1", e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
List<String> headers = Arrays.asList(bills.remove(0));
|
||||
List<String> totalDatas = Arrays.asList(bills.remove(bills.size() - 1));
|
||||
List<String> totalHeaders = Arrays
|
||||
.asList(bills.remove(bills.size() - 1));
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
wb.createSheet(_billDate + "对账单");
|
||||
ExcelUtil.list2excel(wb, headers, bills);
|
||||
ExcelUtil.list2excel(wb, totalHeaders, totalDatas);
|
||||
wb.write(new FileOutputStream(file));
|
||||
return file;
|
||||
}
|
||||
|
||||
@ -581,6 +605,9 @@ public class PayApi extends MpApi {
|
||||
map.put("sign", sign);
|
||||
String param = map2xml(map);
|
||||
response = request.post(refundquery_uri, param);
|
||||
} else {
|
||||
throw new WeixinException("-1", String.format("unknown version:%d",
|
||||
version));
|
||||
}
|
||||
return RefundConverter.fromXML(response.getAsString());
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.foxinmy.weixin4j.mp.api;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
@ -82,13 +83,11 @@ public class QrApi extends MpApi {
|
||||
* 二维码参数
|
||||
* @return 硬盘存储的文件对象
|
||||
* @throws WeixinException
|
||||
* @throws IOException
|
||||
* @see <a
|
||||
* href="mp.weixin.qq.com/wiki/18/28fc21e7ed87bec960651f0ce873ef8a.html">二维码</a>
|
||||
* @see com.foxinmy.weixin4j.mp.model.QRParameter
|
||||
*/
|
||||
public File getQR(QRParameter parameter) throws WeixinException,
|
||||
IOException {
|
||||
public File getQR(QRParameter parameter) throws WeixinException {
|
||||
String qr_path = ConfigUtil.getValue("qr_path");
|
||||
String filename = String.format("%s_%d_%d.jpg", parameter.getQrType()
|
||||
.name(), parameter.getSceneId(), parameter.getExpireSeconds());
|
||||
@ -97,10 +96,27 @@ public class QrApi extends MpApi {
|
||||
return file;
|
||||
}
|
||||
byte[] datas = getQRData(parameter);
|
||||
file.createNewFile();
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(datas);
|
||||
out.close();
|
||||
OutputStream os = null;
|
||||
try {
|
||||
boolean flag = file.createNewFile();
|
||||
if (flag) {
|
||||
os = new FileOutputStream(file);
|
||||
os.write(datas);
|
||||
} else {
|
||||
throw new WeixinException("-1", String.format(
|
||||
"create file fail:%s", file.getAbsolutePath()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException("-1", e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ public class CustomRecord implements Serializable {
|
||||
}
|
||||
|
||||
public Date getTime() {
|
||||
return time;
|
||||
return (Date) time.clone();
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
|
||||
@ -77,6 +77,16 @@ public class Group implements Serializable {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + count;
|
||||
result = prime * result + id;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[Group id=%d ,name=%s ,count=%d]", id, name,
|
||||
|
||||
@ -33,16 +33,16 @@ public class SemQuery implements Serializable {
|
||||
|
||||
// 需要使用的服务类别,多个用,隔开,不能为空
|
||||
public SemQuery category(SemCategory... categorys) {
|
||||
String category = "";
|
||||
StringBuilder category = new StringBuilder();
|
||||
if (categorys.length == 1) {
|
||||
category = categorys[0].name();
|
||||
category.append(categorys[0].name());
|
||||
} else {
|
||||
for (int i = 0; i < categorys.length - 1; i++) {
|
||||
category += categorys[i].name() + ",";
|
||||
category.append(categorys[i].name()).append(",");
|
||||
}
|
||||
category += categorys[categorys.length - 1].name();
|
||||
category.append(categorys[categorys.length - 1].name());
|
||||
}
|
||||
jsonObj.put("category", category);
|
||||
jsonObj.put("category", category.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -163,6 +163,31 @@ public class User implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((city == null) ? 0 : city.hashCode());
|
||||
result = prime * result + ((country == null) ? 0 : country.hashCode());
|
||||
result = prime * result
|
||||
+ ((headimgurl == null) ? 0 : headimgurl.hashCode());
|
||||
result = prime * result
|
||||
+ ((language == null) ? 0 : language.hashCode());
|
||||
result = prime * result
|
||||
+ ((nickname == null) ? 0 : nickname.hashCode());
|
||||
result = prime * result + ((openid == null) ? 0 : openid.hashCode());
|
||||
result = prime * result
|
||||
+ ((privilege == null) ? 0 : privilege.hashCode());
|
||||
result = prime * result
|
||||
+ ((province == null) ? 0 : province.hashCode());
|
||||
result = prime * result + sex;
|
||||
result = prime * result + subscribe;
|
||||
result = prime * result
|
||||
+ (int) (subscribe_time ^ (subscribe_time >>> 32));
|
||||
result = prime * result + ((unionid == null) ? 0 : unionid.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -26,7 +26,7 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 支付工具类(JSAPI,NATIVE,MicroPay)
|
||||
@ -166,10 +166,10 @@ public class PayUtil {
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param ip
|
||||
* ip地址
|
||||
* @param notifyUrl
|
||||
* 支付通知地址
|
||||
* @param ip
|
||||
* ip地址
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
@ -221,7 +221,7 @@ public class PayUtil {
|
||||
if (StringUtils.isBlank(payPackage.getSign())) {
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
}
|
||||
String payJsRequestXml = XStream.to(payPackage).replaceAll("__", "_");
|
||||
String payJsRequestXml = XmlStream.to(payPackage).replaceAll("__", "_");
|
||||
HttpRequest request = new HttpRequest();
|
||||
try {
|
||||
Response response = request.post(Consts.UNIFIEDORDER,
|
||||
@ -351,7 +351,7 @@ public class PayUtil {
|
||||
map.put("retcode", payRequest.getRetCode());
|
||||
map.put("reterrmsg", payRequest.getRetMsg());
|
||||
payRequest.setPaySign(paysignSha(map));
|
||||
return XStream.to(payRequest);
|
||||
return XmlStream.to(payRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,7 +399,7 @@ public class PayUtil {
|
||||
throws WeixinException {
|
||||
String sign = paysignMd5(payPackage, weixinAccount.getPaySignKey());
|
||||
payPackage.setSign(sign);
|
||||
String para = XStream.to(payPackage).replaceAll("__", "_");
|
||||
String para = XmlStream.to(payPackage).replaceAll("__", "_");
|
||||
HttpRequest request = new HttpRequest();
|
||||
Response response = request.post(Consts.MICROPAYURL, para);
|
||||
return response
|
||||
|
||||
@ -9,7 +9,7 @@ import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
@ -30,7 +30,7 @@ import com.thoughtworks.xstream.mapper.Mapper;
|
||||
* @see com.foxinmy.weixin4j.mp.payment.RefundDetail
|
||||
*/
|
||||
public class RefundConverter {
|
||||
private final static XStream xStream = XStream.get();
|
||||
private final static XmlStream xStream = XmlStream.get();
|
||||
private final static Mapper mapper;
|
||||
private final static ReflectionProvider reflectionProvider;
|
||||
private final static Pattern pattern = Pattern.compile("(_\\d)$");
|
||||
|
||||
@ -31,6 +31,7 @@ public class Order extends ApiResult {
|
||||
@XStreamAlias("openid")
|
||||
private String openId;
|
||||
// 用户是否关注公众账号,Y- 关注,N-未关注,仅在公众 账号类型支付有效
|
||||
@XStreamAlias("is_subscribe")
|
||||
private String isSubscribe;
|
||||
// 交易类型
|
||||
@XStreamAlias("trade_type")
|
||||
@ -54,6 +55,7 @@ public class Order extends ApiResult {
|
||||
@XStreamAlias("out_rade_no")
|
||||
private String outTradeNo;
|
||||
// 商家数据包
|
||||
@XStreamAlias("attach")
|
||||
private String attach;
|
||||
// 支付完成时间,格式为 yyyyMMddhhmmss
|
||||
@XStreamAlias("time_end")
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.foxinmy.weixin4j.mp.spider;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -52,9 +51,8 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class WeixinExecutor implements Serializable {
|
||||
public class WeixinExecutor {
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static final long serialVersionUID = 4253859892138066462L;
|
||||
|
||||
private final static Map<String, String> accountMap = new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -175,7 +173,7 @@ public class WeixinExecutor implements Serializable {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("username", uname));
|
||||
parameters.add(new BasicNameValuePair("pwd", DigestUtils.md5Hex(pwd
|
||||
.getBytes())));
|
||||
.getBytes(Consts.UTF_8))));
|
||||
parameters.add(new BasicNameValuePair("f", "json"));
|
||||
parameters.add(new BasicNameValuePair("imgcode", imgcode));
|
||||
if (!StringUtils.isBlank(imgcode)) {
|
||||
@ -387,7 +385,6 @@ public class WeixinExecutor implements Serializable {
|
||||
.getString("bedeveloper")));
|
||||
post.addHeader("Referer", url);
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("token",
|
||||
weixin.getString("urlToken")));
|
||||
parameters.add(new BasicNameValuePair("f", "json"));
|
||||
@ -527,6 +524,7 @@ public class WeixinExecutor implements Serializable {
|
||||
case -205:
|
||||
msg = "该URL可能存在安全风险,请检查";
|
||||
code = 207;
|
||||
break;
|
||||
case -301:
|
||||
msg = "请求URL超时";
|
||||
code = 204;
|
||||
|
||||
@ -11,6 +11,7 @@ import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFFont;
|
||||
@ -34,6 +35,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* excel工具类
|
||||
*
|
||||
* @className ExcelUtil
|
||||
* @author jy
|
||||
* @date 2014年11月1日
|
||||
@ -53,18 +55,19 @@ public class ExcelUtil {
|
||||
*/
|
||||
public static String[][] read(File file) throws Exception {
|
||||
String fileExt = getExtension(file.getName());
|
||||
|
||||
if (null != fileExt && fileExt.toLowerCase().equals("xls")) {// 2003
|
||||
BufferedInputStream in = new BufferedInputStream(
|
||||
new FileInputStream(file));
|
||||
// 打开HSSFWorkbook
|
||||
POIFSFileSystem fs = new POIFSFileSystem(in);
|
||||
Workbook wb = new HSSFWorkbook(fs);
|
||||
in.close();
|
||||
return readExcel(wb);
|
||||
} else if (null != fileExt && fileExt.toLowerCase().equals("xlsx")) {// 2007
|
||||
Workbook wb = new XSSFWorkbook(new FileInputStream(file));
|
||||
return readExcel(wb);
|
||||
if (StringUtils.isNotBlank(fileExt)) {
|
||||
if (fileExt.toLowerCase().equals("xls")) {// 2003
|
||||
BufferedInputStream in = new BufferedInputStream(
|
||||
new FileInputStream(file));
|
||||
// 打开HSSFWorkbook
|
||||
POIFSFileSystem fs = new POIFSFileSystem(in);
|
||||
Workbook wb = new HSSFWorkbook(fs);
|
||||
in.close();
|
||||
return readExcel(wb);
|
||||
} else if (fileExt.toLowerCase().equals("xlsx")) {// 2007
|
||||
Workbook wb = new XSSFWorkbook(new FileInputStream(file));
|
||||
return readExcel(wb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -72,18 +75,19 @@ public class ExcelUtil {
|
||||
public static String[][] read4Special(File file, String fileName,
|
||||
int columnSize) throws Exception {
|
||||
String fileExt = getExtension(fileName);
|
||||
|
||||
if (null != fileExt && fileExt.toLowerCase().equals("xls")) {// 2003
|
||||
BufferedInputStream in = new BufferedInputStream(
|
||||
new FileInputStream(file));
|
||||
// 打开HSSFWorkbook
|
||||
POIFSFileSystem fs = new POIFSFileSystem(in);
|
||||
Workbook wb = new HSSFWorkbook(fs);
|
||||
in.close();
|
||||
return readExcel4Special(wb, columnSize);
|
||||
} else if (null != fileExt && fileExt.toLowerCase().equals("xlsx")) {// 2007
|
||||
Workbook wb = new XSSFWorkbook(new FileInputStream(file));
|
||||
return readExcel4Special(wb, columnSize);
|
||||
if (StringUtils.isNotBlank(fileExt)) {
|
||||
if (fileExt.toLowerCase().equals("xls")) {// 2003
|
||||
BufferedInputStream in = new BufferedInputStream(
|
||||
new FileInputStream(file));
|
||||
// 打开HSSFWorkbook
|
||||
POIFSFileSystem fs = new POIFSFileSystem(in);
|
||||
Workbook wb = new HSSFWorkbook(fs);
|
||||
in.close();
|
||||
return readExcel4Special(wb, columnSize);
|
||||
} else if (fileExt.toLowerCase().equals("xlsx")) {// 2007
|
||||
Workbook wb = new XSSFWorkbook(new FileInputStream(file));
|
||||
return readExcel4Special(wb, columnSize);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-mp</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-mp-server</artifactId>
|
||||
<name>weixin4j-mp-server</name>
|
||||
|
||||
@ -26,7 +26,7 @@ import com.foxinmy.weixin4j.mp.payment.v3.NativePayResponseV3;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.PayPackageV3;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 支付示例
|
||||
@ -48,10 +48,9 @@ public class PayAction {
|
||||
*/
|
||||
public JSONObject jsPay() {
|
||||
JSONObject obj = new JSONObject();
|
||||
PayPackage payPackage = null;
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
// V3 支付
|
||||
payPackage = new PayPackageV3(weixinAccount, "用户openid", "商品描述",
|
||||
PayPackage payPackage = new PayPackageV3(weixinAccount, "用户openid", "商品描述",
|
||||
"系统内部订单号", 1d, "IP地址", TradeType.JSAPI);
|
||||
// V2 支付
|
||||
payPackage = new PayPackageV2("商品描述", weixinAccount.getPartnerId(),
|
||||
@ -113,7 +112,7 @@ public class PayAction {
|
||||
* transaction_id=1221928801201410296039230054&transport_fee=0
|
||||
*/
|
||||
log.info("jspay_notify_orderinfo,{}", objMap);
|
||||
JsPayNotify payNotify = XStream.get(inputStream, JsPayNotify.class);
|
||||
JsPayNotify payNotify = XmlStream.get(inputStream, JsPayNotify.class);
|
||||
log.info("jspay_notify_userinfo,{}", payNotify);
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
// 验证财付通签名
|
||||
@ -152,7 +151,7 @@ public class PayAction {
|
||||
* </xml>
|
||||
*/
|
||||
public String jsNotifyV3(InputStream inputStream) {
|
||||
com.foxinmy.weixin4j.mp.payment.v3.Order order = XStream.get(
|
||||
com.foxinmy.weixin4j.mp.payment.v3.Order order = XmlStream.get(
|
||||
inputStream, com.foxinmy.weixin4j.mp.payment.v3.Order.class);
|
||||
log.info("jaapi_notify_order_info:", order);
|
||||
String sign = order.getSign();
|
||||
@ -162,9 +161,9 @@ public class PayAction {
|
||||
weixinAccount.getPaySignKey());
|
||||
log.info("微信签名----->sign={},vaild_sign={}", sign, valid_sign);
|
||||
if (!sign.equals(valid_sign)) {
|
||||
return XStream.to(new XmlResult(Consts.FAIL, "签名错误"));
|
||||
return XmlStream.to(new XmlResult(Consts.FAIL, "签名错误"));
|
||||
}
|
||||
return XStream.to(new XmlResult());
|
||||
return XmlStream.to(new XmlResult());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,7 +185,7 @@ public class PayAction {
|
||||
*/
|
||||
public String nativeNotifyV2(InputStream inputStream) {
|
||||
// V2.x版本
|
||||
NativePayNotifyV2 payNotify = XStream.get(inputStream,
|
||||
NativePayNotifyV2 payNotify = XmlStream.get(inputStream,
|
||||
NativePayNotifyV2.class);
|
||||
log.info("native_pay_notify,{}", payNotify);
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
@ -205,7 +204,7 @@ public class PayAction {
|
||||
weixinAccount.getPartnerId(), "系统内部订单号", 1d, "回调地址", "IP地址");
|
||||
NativePayResponseV2 payResponse = new NativePayResponseV2(
|
||||
weixinAccount, payPackage);
|
||||
return XStream.to(payResponse);
|
||||
return XmlStream.to(payResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,7 +222,7 @@ public class PayAction {
|
||||
* @throws PayException
|
||||
*/
|
||||
public String nativeNotifyV3(InputStream inputStream) throws PayException {
|
||||
NativePayNotifyV3 payNotify = XStream.get(inputStream,
|
||||
NativePayNotifyV3 payNotify = XmlStream.get(inputStream,
|
||||
NativePayNotifyV3.class);
|
||||
String sign = payNotify.getSign();
|
||||
payNotify.setSign(null);
|
||||
@ -241,7 +240,7 @@ public class PayAction {
|
||||
null);
|
||||
payReponse.setSign(PayUtil.paysignMd5(payReponse,
|
||||
weixinAccount.getPaySignKey()));
|
||||
return XStream.to(payReponse);
|
||||
return XmlStream.to(payReponse);
|
||||
|
||||
}
|
||||
// 成功返回
|
||||
@ -249,7 +248,7 @@ public class PayAction {
|
||||
weixinAccount.getPaySignKey());
|
||||
payReponse.setSign(PayUtil.paysignMd5(payReponse,
|
||||
weixinAccount.getPaySignKey()));
|
||||
return XStream.to(payReponse);
|
||||
return XmlStream.to(payReponse);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +270,7 @@ public class PayAction {
|
||||
* @return
|
||||
*/
|
||||
public String warning(InputStream inputStream) {
|
||||
PayWarn payWarn = XStream.get(inputStream, PayWarn.class);
|
||||
PayWarn payWarn = XmlStream.get(inputStream, PayWarn.class);
|
||||
log.info("pay_warning,{}", payWarn);
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
String sign = payWarn.getPaySign();
|
||||
@ -292,7 +291,7 @@ public class PayAction {
|
||||
* @return
|
||||
*/
|
||||
public String feedback(InputStream inputStream) {
|
||||
PayFeedback feedback = XStream.get(inputStream, PayFeedback.class);
|
||||
PayFeedback feedback = XmlStream.get(inputStream, PayFeedback.class);
|
||||
log.info("pay_feedback_info:{}", feedback);
|
||||
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
|
||||
// 验证微信签名
|
||||
|
||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.response.HttpWeixinMessage;
|
||||
import com.foxinmy.weixin4j.type.EncryptType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 微信消息解码类
|
||||
@ -41,7 +41,7 @@ public class WeixinMessageDecoder extends
|
||||
String xmlContent = req.content().toString(Consts.UTF_8);
|
||||
HttpWeixinMessage message = new HttpWeixinMessage();
|
||||
if (StringUtils.isNotBlank(xmlContent)) {
|
||||
message = XStream.get(xmlContent, HttpWeixinMessage.class);
|
||||
message = XmlStream.get(xmlContent, HttpWeixinMessage.class);
|
||||
}
|
||||
message.setMethod(req.getMethod().name());
|
||||
QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri(),
|
||||
|
||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.xml.Map2ObjectConverter;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
import com.thoughtworks.xstream.core.ClassLoaderReference;
|
||||
import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
|
||||
@ -35,11 +35,11 @@ import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
public class WeixinMessageEncoder extends
|
||||
MessageToMessageEncoder<ResponseMessage> {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final static XStream mapXstream = XStream.get();
|
||||
private final static XmlStream mapXstream = XmlStream.get();
|
||||
static {
|
||||
mapXstream.alias("xml", Map.class);
|
||||
mapXstream.registerConverter(new Map2ObjectConverter(new DefaultMapper(
|
||||
new ClassLoaderReference(XStream.class.getClassLoader()))));
|
||||
new ClassLoaderReference(XmlStream.class.getClassLoader()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -36,9 +36,11 @@ public class HttpUtil {
|
||||
}
|
||||
FullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1,
|
||||
OK, Unpooled.copiedBuffer(content, Consts.UTF_8));
|
||||
httpResponse.headers().set(CONTENT_TYPE,
|
||||
"application/xml;encoding=utf-8");
|
||||
httpResponse.headers().set(CONTENT_LENGTH, content.getBytes().length);
|
||||
httpResponse.headers().set(
|
||||
CONTENT_TYPE,
|
||||
String.format("%s;encoding=%s", contentType.getMimeType(),
|
||||
Consts.UTF_8.displayName()));
|
||||
httpResponse.headers().set(CONTENT_LENGTH, content.getBytes(Consts.UTF_8).length);
|
||||
httpResponse.headers().set(CONNECTION, Values.KEEP_ALIVE);
|
||||
httpResponse.headers().set(DATE, new Date());
|
||||
httpResponse.headers().set(SERVER, "netty4");
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-qy</artifactId>
|
||||
<name>weixin4j-qy</name>
|
||||
@ -15,11 +15,4 @@
|
||||
<module>weixin4j-qy-api</module>
|
||||
<module>weixin4j-qy-server</module>
|
||||
</modules>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,10 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-qy</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-qy-api</artifactId>
|
||||
<name>weixin4j-qy-api</name>
|
||||
@ -22,6 +23,11 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
|
||||
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.entity.mime.content.ByteArrayBody;
|
||||
@ -121,7 +122,7 @@ public class MediaApi extends QyApi {
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#downloadMedia(String)}
|
||||
*/
|
||||
public File downloadMedia(String mediaId, String extension)
|
||||
throws WeixinException, IOException {
|
||||
throws WeixinException {
|
||||
String media_path = ConfigUtil.getValue("media_path");
|
||||
File file = new File(media_path + File.separator + mediaId + "."
|
||||
+ extension);
|
||||
@ -129,10 +130,27 @@ public class MediaApi extends QyApi {
|
||||
return file;
|
||||
}
|
||||
byte[] datas = downloadMedia(mediaId);
|
||||
file.createNewFile();
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(datas);
|
||||
out.close();
|
||||
OutputStream os = null;
|
||||
try {
|
||||
boolean flag = file.createNewFile();
|
||||
if (flag) {
|
||||
os = new FileOutputStream(file);
|
||||
os.write(datas);
|
||||
} else {
|
||||
throw new WeixinException("-1", String.format(
|
||||
"create file fail:%s", file.getAbsolutePath()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException("-1", e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
@ -15,8 +15,14 @@ import com.foxinmy.weixin4j.api.BaseApi;
|
||||
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php">api文档</a>
|
||||
*/
|
||||
public class QyApi extends BaseApi {
|
||||
private final static ResourceBundle weixinBundle;
|
||||
static {
|
||||
weixinBundle = ResourceBundle
|
||||
.getBundle("com/foxinmy/weixin4j/qy/api/weixin");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceBundle getWeixinBundle() {
|
||||
return weixinBundle;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j-qy</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-qy-server</artifactId>
|
||||
<name>weixin4j-qy-server</name>
|
||||
|
||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.response.HttpWeixinMessage;
|
||||
import com.foxinmy.weixin4j.type.EncryptType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 微信消息解码类
|
||||
@ -42,7 +42,7 @@ public class WeixinMessageDecoder extends
|
||||
HttpWeixinMessage message = new HttpWeixinMessage();
|
||||
message.setXmlContent(xmlContent);
|
||||
if (StringUtils.isNotBlank(xmlContent)) {
|
||||
message = XStream.get(xmlContent, HttpWeixinMessage.class);
|
||||
message = XmlStream.get(xmlContent, HttpWeixinMessage.class);
|
||||
message.setXmlContent(MessageUtil.aesDecrypt(qyAccount.getId(),
|
||||
qyAccount.getEncodingAesKey(), message.getEncryptContent()));
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.xml.Map2ObjectConverter;
|
||||
import com.foxinmy.weixin4j.xml.XStream;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
import com.thoughtworks.xstream.core.ClassLoaderReference;
|
||||
import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
|
||||
@ -35,11 +35,11 @@ import com.thoughtworks.xstream.mapper.DefaultMapper;
|
||||
public class WeixinMessageEncoder extends
|
||||
MessageToMessageEncoder<ResponseMessage> {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final static XStream mapXstream = XStream.get();
|
||||
private final static XmlStream mapXstream = XmlStream.get();
|
||||
static {
|
||||
mapXstream.alias("xml", Map.class);
|
||||
mapXstream.registerConverter(new Map2ObjectConverter(new DefaultMapper(
|
||||
new ClassLoaderReference(XStream.class.getClassLoader()))));
|
||||
new ClassLoaderReference(XmlStream.class.getClassLoader()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -41,7 +41,7 @@ public class HttpUtil {
|
||||
String.format("%s;encoding=%s", contentType.getMimeType(),
|
||||
Consts.UTF_8.displayName()));
|
||||
|
||||
httpResponse.headers().set(CONTENT_LENGTH, content.getBytes().length);
|
||||
httpResponse.headers().set(CONTENT_LENGTH, content.getBytes(Consts.UTF_8).length);
|
||||
httpResponse.headers().set(CONNECTION, Values.KEEP_ALIVE);
|
||||
httpResponse.headers().set(DATE, new Date());
|
||||
httpResponse.headers().set(SERVER, "netty4");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user