微信支付相关代码独立成一个子模块

This commit is contained in:
Binary Wang
2017-03-05 22:49:17 +08:00
parent 8a270c8f7e
commit eee954b736
49 changed files with 1596 additions and 1308 deletions

View File

@@ -0,0 +1,38 @@
package com.github.binarywang.wxpay.testbase;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.thoughtworks.xstream.XStream;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import java.io.IOException;
import java.io.InputStream;
public class ApiTestModule implements Module {
@Override
public void configure(Binder binder) {
try (InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml")) {
TestPayConfig config = this.fromXml(TestPayConfig.class, is1);
WxPayService wxService = new WxPayServiceImpl();
wxService.setConfig(config);
binder.bind(WxPayService.class).toInstance(wxService);
binder.bind(WxPayConfig.class).toInstance(config);
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
private <T> T fromXml(Class<T> clazz, InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", clazz);
xstream.processAnnotations(clazz);
return (T) xstream.fromXML(is);
}
}

View File

@@ -0,0 +1,31 @@
package com.github.binarywang.wxpay.testbase;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.http.ssl.SSLContexts;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
@XStreamAlias("xml")
public class TestPayConfig extends WxPayConfig {
private String openid;
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
@Override
public boolean useSandboxForWxPay() {
//沙箱环境不成熟,有问题无法使用,暂时屏蔽掉
// return true;
return false;
}
}