config moved
为避免冲突讲config.propertiese移入src/main/java/com/foxinmy/weixin4j目录并更新其它相关
This commit is contained in:
parent
0e60f200af
commit
a1a5cd59b3
7
pom.xml
7
pom.xml
@ -35,6 +35,13 @@
|
|||||||
<exclude>logback.xml</exclude>
|
<exclude>logback.xml</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/config.properties</include>
|
||||||
|
<include>**/error.xml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<finalName>weixin4j-sdk</finalName>
|
<finalName>weixin4j-sdk</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import org.dom4j.io.SAXReader;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.foxinmy.weixin4j.WeixinProxy;
|
||||||
import com.foxinmy.weixin4j.msg.ErrorMessage;
|
import com.foxinmy.weixin4j.msg.ErrorMessage;
|
||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
|
|
||||||
@ -59,12 +60,17 @@ public class Response {
|
|||||||
JSONObject jsonObj = getAsJson();
|
JSONObject jsonObj = getAsJson();
|
||||||
if (jsonObj.containsKey(ERROR_CODE_KEY)) {
|
if (jsonObj.containsKey(ERROR_CODE_KEY)) {
|
||||||
SAXReader reader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
Document doc = reader.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("error_code.xml"));
|
Document doc = reader.read(WeixinProxy.class
|
||||||
Node node = doc.getRootElement().selectSingleNode(String.format("error[@code='%d']", jsonObj.getInteger(ERROR_CODE_KEY)));
|
.getResourceAsStream("error.xml"));
|
||||||
|
Node node = doc.getRootElement().selectSingleNode(
|
||||||
|
String.format("error[@code='%d']",
|
||||||
|
jsonObj.getInteger(ERROR_CODE_KEY)));
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
return new ErrorMessage(jsonObj.getInteger(ERROR_CODE_KEY), jsonObj.getString(ERROR_MSG_KEY), node.getStringValue());
|
return new ErrorMessage(jsonObj.getInteger(ERROR_CODE_KEY),
|
||||||
|
jsonObj.getString(ERROR_MSG_KEY), node.getStringValue());
|
||||||
}
|
}
|
||||||
return new ErrorMessage(jsonObj.getInteger(ERROR_CODE_KEY), "unknown error", "未知错误");
|
return new ErrorMessage(jsonObj.getInteger(ERROR_CODE_KEY),
|
||||||
|
"unknown error", "未知错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ErrorMessage(0, "request success", "");
|
return new ErrorMessage(0, "request success", "");
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import java.util.Properties;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.WeixinProxy;
|
||||||
|
|
||||||
public class WeixinConfig {
|
public class WeixinConfig {
|
||||||
public WeixinConfig() {
|
public WeixinConfig() {
|
||||||
}
|
}
|
||||||
@ -13,7 +15,8 @@ public class WeixinConfig {
|
|||||||
private static Properties props = new Properties();
|
private static Properties props = new Properties();
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
|
props.load(WeixinProxy.class
|
||||||
|
.getResourceAsStream("config.properties"));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -29,7 +32,8 @@ public class WeixinConfig {
|
|||||||
String sub = null;
|
String sub = null;
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
sub = m.group();
|
sub = m.group();
|
||||||
m.appendReplacement(sb, getValue(sub.substring(1, sub.length() - 1)));
|
m.appendReplacement(sb,
|
||||||
|
getValue(sub.substring(1, sub.length() - 1)));
|
||||||
}
|
}
|
||||||
m.appendTail(sb);
|
m.appendTail(sb);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user