use of com.thoughtworks.xstream.XStream in project weixin-java-tools by chanjarster.
the class XStreamTransformer method config_WxMpXmlOutTextMessage.
private static XStream config_WxMpXmlOutTextMessage() {
XStream xstream = XStreamInitializer.getInstance();
xstream.processAnnotations(WxMpXmlOutMessage.class);
xstream.processAnnotations(WxMpXmlOutTextMessage.class);
return xstream;
}
use of com.thoughtworks.xstream.XStream in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method getJSSDKCallbackData.
@Override
public WxMpPayCallback getJSSDKCallbackData(String xmlData) {
try {
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", WxMpPayCallback.class);
WxMpPayCallback wxMpCallback = (WxMpPayCallback) xstream.fromXML(xmlData);
return wxMpCallback;
} catch (Exception e) {
e.printStackTrace();
}
return new WxMpPayCallback();
}
use of com.thoughtworks.xstream.XStream in project weixin-java-tools by chanjarster.
the class ApiTestModule method fromXml.
public static <T> T fromXml(Class<T> clazz, InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", clazz);
xstream.processAnnotations(clazz);
return (T) xstream.fromXML(is);
}
use of com.thoughtworks.xstream.XStream in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method sendRedpack.
@Override
public WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErrorException {
String nonce_str = System.currentTimeMillis() + "";
SortedMap<String, String> packageParams = new TreeMap<String, String>(parameters);
packageParams.put("wxappid", wxMpConfigStorage.getAppId());
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
packageParams.put("nonce_str", nonce_str);
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
packageParams.put("sign", sign);
StringBuilder request = new StringBuilder("<xml>");
for (Entry<String, String> para : packageParams.entrySet()) {
request.append(String.format("<%s>%s</%s>", para.getKey(), para.getValue(), para.getKey()));
}
request.append("</xml>");
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack");
if (httpProxy != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
httpPost.setConfig(config);
}
StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8);
httpPost.setEntity(entity);
try {
CloseableHttpResponse response = getHttpclient().execute(httpPost);
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
XStream xstream = XStreamInitializer.getInstance();
xstream.processAnnotations(WxRedpackResult.class);
WxRedpackResult wxMpRedpackResult = (WxRedpackResult) xstream.fromXML(responseContent);
return wxMpRedpackResult;
} catch (IOException e) {
log.error(MessageFormatter.format("The exception was happened when sending redpack '{}'.", request.toString()).getMessage(), e);
WxError error = new WxError();
error.setErrorCode(-1);
throw new WxErrorException(error);
}
}
use of com.thoughtworks.xstream.XStream in project weixin-java-tools by chanjarster.
the class WxCpDemoInMemoryConfigStorage method fromXml.
public static WxCpDemoInMemoryConfigStorage fromXml(InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
xstream.processAnnotations(WxCpDemoInMemoryConfigStorage.class);
return (WxCpDemoInMemoryConfigStorage) xstream.fromXML(is);
}
Aggregations