优化了代码
This commit is contained in:
@@ -582,7 +582,7 @@ public class PayApi extends MpApi {
|
||||
String param = map2xml(map);
|
||||
response = request.post(refundquery_uri, param);
|
||||
}
|
||||
return new RefundConverter().fromXML(response.getAsString());
|
||||
return RefundConverter.fromXML(response.getAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TmplApi extends MpApi {
|
||||
/**
|
||||
* 发送模板消息
|
||||
*
|
||||
* @param message
|
||||
* @param message 消息对象
|
||||
* @return 发送结果
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
@@ -40,9 +40,8 @@ public class TmplApi extends MpApi {
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
String para = JSON.toJSONString(tplMessage);
|
||||
Response response = request.post(
|
||||
String.format(template_send_uri, token.getAccessToken()), para);
|
||||
String.format(template_send_uri, token.getAccessToken()), JSON.toJSONString(tplMessage));
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class PayUtil {
|
||||
return createPayJsRequestJsonV3((PayPackageV3) payPackage,
|
||||
weixinAccount);
|
||||
}
|
||||
throw new PayException("-1", "unknown pay");
|
||||
throw new PayException("unknown pay");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-13
@@ -31,25 +31,26 @@ import com.thoughtworks.xstream.mapper.Mapper;
|
||||
*/
|
||||
public class RefundConverter {
|
||||
private final static XStream xStream = XStream.get();
|
||||
private final Mapper mapper;
|
||||
private final ReflectionProvider reflectionProvider;
|
||||
|
||||
public RefundConverter() {
|
||||
private final static Mapper mapper;
|
||||
private final static ReflectionProvider reflectionProvider;
|
||||
private final static Pattern pattern = Pattern.compile("(_\\d)$");
|
||||
static {
|
||||
xStream.processAnnotations(Refund.class);
|
||||
xStream.registerConverter(new RefundConverter.$());
|
||||
this.mapper = xStream.getMapper();
|
||||
this.reflectionProvider = xStream.getReflectionProvider();
|
||||
xStream.processAnnotations(RefundDetail.class);
|
||||
xStream.registerConverter(new $());
|
||||
mapper = xStream.getMapper();
|
||||
reflectionProvider = xStream.getReflectionProvider();
|
||||
}
|
||||
|
||||
public String toXML(Refund refund) {
|
||||
public static String toXML(Refund refund) {
|
||||
return xStream.toXML(refund);
|
||||
}
|
||||
|
||||
public Refund fromXML(String xml) {
|
||||
public static Refund fromXML(String xml) {
|
||||
return xStream.fromXML(xml, Refund.class);
|
||||
}
|
||||
|
||||
private class $ implements Converter {
|
||||
private static class $ implements Converter {
|
||||
@Override
|
||||
public boolean canConvert(@SuppressWarnings("rawtypes") Class clazz) {
|
||||
return clazz.equals(Refund.class);
|
||||
@@ -67,7 +68,6 @@ public class RefundConverter {
|
||||
public Object unmarshal(HierarchicalStreamReader reader,
|
||||
UnmarshallingContext context) {
|
||||
Refund refund = new Refund();
|
||||
Pattern pattern = Pattern.compile("(_\\d)$");
|
||||
Matcher matcher = null;
|
||||
Map<String, Map<String, String>> outMap = new HashMap<String, Map<String, String>>();
|
||||
while (reader.hasMoreChildren()) {
|
||||
@@ -108,9 +108,8 @@ public class RefundConverter {
|
||||
detailXml.append("</").append(detailCanonicalName).append(">");
|
||||
}
|
||||
detailXml.append("</list>");
|
||||
xStream.processAnnotations(RefundDetail.class);
|
||||
refund.setDetails(xStream.fromXML(detailXml.toString(), List.class));
|
||||
return refund;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user