1
0
mirror of synced 2025-12-19 14:48:02 +08:00

优化部分代码

This commit is contained in:
Binary Wang
2018-01-27 18:39:37 +08:00
parent 5bd2d209db
commit 48d3163b33
13 changed files with 50 additions and 247 deletions

View File

@@ -13,8 +13,11 @@ import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.*; import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.mp.api.*; import me.chanjar.weixin.mp.api.*;
import me.chanjar.weixin.mp.bean.*; import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
import me.chanjar.weixin.mp.bean.result.*; import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -22,7 +25,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, RequestHttp<H, P> { public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestHttp<H, P> {
private static final JsonParser JSON_PARSER = new JsonParser(); private static final JsonParser JSON_PARSER = new JsonParser();
@@ -92,14 +95,14 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
@Override @Override
public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException { public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
long timestamp = System.currentTimeMillis() / 1000; long timestamp = System.currentTimeMillis() / 1000;
String noncestr = RandomUtils.getRandomStr(); String randomStr = RandomUtils.getRandomStr();
String jsapiTicket = getJsapiTicket(false); String jsapiTicket = getJsapiTicket(false);
String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket,
"noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url); "noncestr=" + randomStr, "timestamp=" + timestamp, "url=" + url);
WxJsapiSignature jsapiSignature = new WxJsapiSignature(); WxJsapiSignature jsapiSignature = new WxJsapiSignature();
jsapiSignature.setAppId(this.getWxMpConfigStorage().getAppId()); jsapiSignature.setAppId(this.getWxMpConfigStorage().getAppId());
jsapiSignature.setTimestamp(timestamp); jsapiSignature.setTimestamp(timestamp);
jsapiSignature.setNonceStr(noncestr); jsapiSignature.setNonceStr(randomStr);
jsapiSignature.setUrl(url); jsapiSignature.setUrl(url);
jsapiSignature.setSignature(signature); jsapiSignature.setSignature(signature);
return jsapiSignature; return jsapiSignature;
@@ -111,10 +114,10 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
} }
@Override @Override
public String shortUrl(String long_url) throws WxErrorException { public String shortUrl(String longUrl) throws WxErrorException {
JsonObject o = new JsonObject(); JsonObject o = new JsonObject();
o.addProperty("action", "long2short"); o.addProperty("action", "long2short");
o.addProperty("long_url", long_url); o.addProperty("long_url", longUrl);
String responseContent = this.post(WxMpService.SHORTURL_API_URL, o.toString()); String responseContent = this.post(WxMpService.SHORTURL_API_URL, o.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
@@ -161,12 +164,12 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
} }
@Override @Override
public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException { public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken token, String lang) throws WxErrorException {
if (lang == null) { if (lang == null) {
lang = "zh_CN"; lang = "zh_CN";
} }
String url = String.format(WxMpService.OAUTH2_USERINFO_URL, oAuth2AccessToken.getAccessToken(), oAuth2AccessToken.getOpenId(), lang); String url = String.format(WxMpService.OAUTH2_USERINFO_URL, token.getAccessToken(), token.getOpenId(), lang);
try { try {
RequestExecutor<String, String> executor = SimpleGetRequestExecutor.create(this); RequestExecutor<String, String> executor = SimpleGetRequestExecutor.create(this);
@@ -178,8 +181,8 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
} }
@Override @Override
public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken) { public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken token) {
String url = String.format(WxMpService.OAUTH2_VALIDATE_TOKEN_URL, oAuth2AccessToken.getAccessToken(), oAuth2AccessToken.getOpenId()); String url = String.format(WxMpService.OAUTH2_VALIDATE_TOKEN_URL, token.getAccessToken(), token.getOpenId());
try { try {
SimpleGetRequestExecutor.create(this).execute(url, null); SimpleGetRequestExecutor.create(this).execute(url, null);
@@ -226,7 +229,7 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
} }
/** /**
* 向微信端发送请求在这里执行的策略是当发生access_token过期时才去刷新然后重新执行请求而不是全局定时请求 * 向微信端发送请求在这里执行的策略是当发生access_token过期时才去刷新然后重新执行请求而不是全局定时请求.
*/ */
@Override @Override
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException { public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
@@ -265,6 +268,7 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
if (uri.contains("access_token=")) { if (uri.contains("access_token=")) {
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri); throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
} }
String accessToken = getAccessToken(false); String accessToken = getAccessToken(false);
String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken; String uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + accessToken;
@@ -296,7 +300,7 @@ public abstract class WxMpServiceAbstractImpl<H, P> implements WxMpService, Requ
return null; return null;
} catch (IOException e) { } catch (IOException e) {
this.log.error("\n【请求地址】: {}\n【请求参数】{}\n【异常信息】{}", uriWithAccessToken, data, e.getMessage()); this.log.error("\n【请求地址】: {}\n【请求参数】{}\n【异常信息】{}", uriWithAccessToken, data, e.getMessage());
throw new RuntimeException(e); throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
} }
} }

View File

@@ -19,9 +19,9 @@ import java.io.IOException;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
/** /**
* apache-http方式实现 * apache http client方式实现.
*/ */
public class WxMpServiceApacheHttpClientImpl extends WxMpServiceAbstractImpl<CloseableHttpClient, HttpHost> { public class WxMpServiceHttpClientImpl extends WxMpServiceBaseImpl<CloseableHttpClient, HttpHost> {
private CloseableHttpClient httpClient; private CloseableHttpClient httpClient;
private HttpHost httpProxy; private HttpHost httpProxy;

View File

@@ -8,5 +8,5 @@ package me.chanjar.weixin.mp.api.impl;
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
public class WxMpServiceImpl extends WxMpServiceApacheHttpClientImpl { public class WxMpServiceImpl extends WxMpServiceHttpClientImpl {
} }

View File

@@ -14,7 +14,7 @@ import java.util.concurrent.locks.Lock;
/** /**
* jodd-http方式实现 * jodd-http方式实现
*/ */
public class WxMpServiceJoddHttpImpl extends WxMpServiceAbstractImpl<HttpConnectionProvider, ProxyInfo> { public class WxMpServiceJoddHttpImpl extends WxMpServiceBaseImpl<HttpConnectionProvider, ProxyInfo> {
private HttpConnectionProvider httpClient; private HttpConnectionProvider httpClient;
private ProxyInfo httpProxy; private ProxyInfo httpProxy;

View File

@@ -11,7 +11,10 @@ import okhttp3.*;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
public class WxMpServiceOkHttpImpl extends WxMpServiceAbstractImpl<OkHttpClient, OkHttpProxyInfo> { /**
* okhttp实现
*/
public class WxMpServiceOkHttpImpl extends WxMpServiceBaseImpl<OkHttpClient, OkHttpProxyInfo> {
private OkHttpClient httpClient; private OkHttpClient httpClient;
private OkHttpProxyInfo httpProxy; private OkHttpProxyInfo httpProxy;

View File

@@ -3,7 +3,7 @@ package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.mp.api.impl.WxMpServiceApacheHttpClientImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import org.testng.annotations.*; import org.testng.annotations.*;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@@ -16,7 +16,7 @@ public class WxMpBusyRetryTest {
@DataProvider(name = "getService") @DataProvider(name = "getService")
public Object[][] getService() { public Object[][] getService() {
WxMpService service = new WxMpServiceApacheHttpClientImpl() { WxMpService service = new WxMpServiceHttpClientImpl() {
@Override @Override
public synchronized <T, E> T executeInternal( public synchronized <T, E> T executeInternal(

View File

@@ -5,7 +5,7 @@ import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpMessageHandler; import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpMessageRouter; import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceApacheHttpClientImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
@@ -47,7 +47,7 @@ public class WxMpDemoServer {
.fromXml(is1); .fromXml(is1);
wxMpConfigStorage = config; wxMpConfigStorage = config;
wxMpService = new WxMpServiceApacheHttpClientImpl(); wxMpService = new WxMpServiceHttpClientImpl();
wxMpService.setWxMpConfigStorage(config); wxMpService.setWxMpConfigStorage(config);
WxMpMessageHandler logHandler = new DemoLogHandler(); WxMpMessageHandler logHandler = new DemoLogHandler();

View File

@@ -24,7 +24,7 @@ import me.chanjar.weixin.common.util.ToStringUtils;
public class EntPayRequest extends BaseWxPayRequest { public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名公众账号appid * 字段名公众账号appid.
* 变量名mch_appid * 变量名mch_appid
* 是否必填:是 * 是否必填:是
* 示例值wx8888888888888888 * 示例值wx8888888888888888
@@ -37,7 +37,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:商户号 * 字段名:商户号.
* 变量名mchid * 变量名mchid
* 是否必填:是 * 是否必填:是
* 示例值1900000109 * 示例值1900000109
@@ -50,7 +50,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:设备号 * 字段名:设备号.
* 变量名device_info * 变量名device_info
* 是否必填:否 * 是否必填:否
* 示例值13467007045764 * 示例值13467007045764
@@ -63,7 +63,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:商户订单号 * 字段名:商户订单号.
* 变量名partner_trade_no * 变量名partner_trade_no
* 是否必填:是 * 是否必填:是
* 示例值10000098201411111234567890 * 示例值10000098201411111234567890
@@ -77,7 +77,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:需保持唯一性 用户openid * 字段名:需保持唯一性 用户openid.
* 变量名openid * 变量名openid
* 是否必填:是 * 是否必填:是
* 示例值oxTWIuGaIt6gTKsQRLau2M0yL16E * 示例值oxTWIuGaIt6gTKsQRLau2M0yL16E
@@ -91,7 +91,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:校验用户姓名选项 * 字段名:校验用户姓名选项.
* 变量名check_name * 变量名check_name
* 是否必填:是 * 是否必填:是
* 示例值OPTION_CHECK * 示例值OPTION_CHECK
@@ -107,7 +107,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:收款用户姓名 * 字段名:收款用户姓名.
* 变量名re_user_name * 变量名re_user_name
* 是否必填:可选 * 是否必填:可选
* 示例值:马花花 * 示例值:马花花
@@ -121,7 +121,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:金额 * 字段名:金额.
* 变量名amount * 变量名amount
* 是否必填:是 * 是否必填:是
* 示例值10099 * 示例值10099
@@ -135,7 +135,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名:企业付款描述信息 * 字段名:企业付款描述信息.
* 变量名desc * 变量名desc
* 是否必填:是 * 是否必填:是
* 示例值:理赔 * 示例值:理赔
@@ -149,7 +149,7 @@ public class EntPayRequest extends BaseWxPayRequest {
/** /**
* <pre> * <pre>
* 字段名Ip地址 * 字段名Ip地址.
* 变量名spbill_create_ip * 变量名spbill_create_ip
* 是否必填:是 * 是否必填:是
* 示例值192.168.0.1 * 示例值192.168.0.1
@@ -191,4 +191,8 @@ public class EntPayRequest extends BaseWxPayRequest {
return ToStringUtils.toSimpleString(this); return ToStringUtils.toSimpleString(this);
} }
@Override
protected boolean ignoreSignType() {
return true;
}
} }

View File

@@ -1,15 +0,0 @@
package com.github.binarywang.wxpay.bean.request;
import com.github.binarywang.wxpay.bean.entpay.EntPayQueryRequest;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.util.ToStringUtils;
/**
* 请使用 {@link EntPayQueryRequest}
*/
@XStreamAlias("xml")
@Deprecated
public class WxEntPayQueryRequest extends EntPayQueryRequest {
}

View File

@@ -1,149 +0,0 @@
package com.github.binarywang.wxpay.bean.request;
import com.github.binarywang.wxpay.bean.entpay.EntPayQueryRequest;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.util.ToStringUtils;
/**
* <pre>
* 企业付款请求对象
* 请使用 {@link EntPayRequest}
* </pre>
*/
@XStreamAlias("xml")
@Deprecated
public class WxEntPayRequest extends EntPayRequest {
private WxEntPayRequest(Builder builder) {
setAppid(builder.appid);
setMchId(builder.mchId);
setSubAppId(builder.subAppId);
setSubMchId(builder.subMchId);
setNonceStr(builder.nonceStr);
setSign(builder.sign);
setSignType(builder.signType);
setMchAppid(builder.mchAppid);
setMchId(builder.mchId);
setDeviceInfo(builder.deviceInfo);
setPartnerTradeNo(builder.partnerTradeNo);
setOpenid(builder.openid);
setCheckName(builder.checkName);
setReUserName(builder.reUserName);
setAmount(builder.amount);
setDescription(builder.description);
setSpbillCreateIp(builder.spbillCreateIp);
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
private String appid;
private String mchId;
private String deviceInfo;
private String partnerTradeNo;
private String openid;
private String checkName;
private String reUserName;
private Integer amount;
private String description;
private String spbillCreateIp;
private String subAppId;
private String subMchId;
private String nonceStr;
private String sign;
private String signType;
private String mchAppid;
private Builder() {
}
public Builder appid(String appid) {
this.appid = appid;
return this;
}
public Builder mchId(String mchId) {
this.mchId = mchId;
return this;
}
public Builder deviceInfo(String deviceInfo) {
this.deviceInfo = deviceInfo;
return this;
}
public Builder partnerTradeNo(String partnerTradeNo) {
this.partnerTradeNo = partnerTradeNo;
return this;
}
public Builder openid(String openid) {
this.openid = openid;
return this;
}
public Builder checkName(String checkName) {
this.checkName = checkName;
return this;
}
public Builder reUserName(String reUserName) {
this.reUserName = reUserName;
return this;
}
public Builder amount(Integer amount) {
this.amount = amount;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder spbillCreateIp(String spbillCreateIp) {
this.spbillCreateIp = spbillCreateIp;
return this;
}
public WxEntPayRequest build() {
return new WxEntPayRequest(this);
}
public Builder subAppId(String subAppId) {
this.subAppId = subAppId;
return this;
}
public Builder subMchId(String subMchId) {
this.subMchId = subMchId;
return this;
}
public Builder nonceStr(String nonceStr) {
this.nonceStr = nonceStr;
return this;
}
public Builder sign(String sign) {
this.sign = sign;
return this;
}
public Builder signType(String signType) {
this.signType = signType;
return this;
}
public Builder mchAppid(String mchAppid) {
this.mchAppid = mchAppid;
return this;
}
}
}

View File

@@ -2,7 +2,6 @@ package com.github.binarywang.wxpay.service;
import com.github.binarywang.wxpay.bean.WxPayApiData; import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.bean.coupon.*; import com.github.binarywang.wxpay.bean.coupon.*;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.request.*;
@@ -208,18 +207,6 @@ public interface WxPayService {
*/ */
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException; WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
/**
* 请使用this.getEntPayService().entPay()方法{@link EntPayService#entPay(EntPayRequest)}
*/
@Deprecated
WxEntPayResult entPay(WxEntPayRequest request) throws WxPayException;
/**
* 请使用this.getEntPayService().queryEntPay()方法 {@link EntPayService#queryEntPay(String)}
*/
@Deprecated
WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException;
/** /**
* <pre> * <pre>
* 扫码支付模式一生成二维码的方法 * 扫码支付模式一生成二维码的方法

View File

@@ -345,18 +345,6 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
return payInfo; return payInfo;
} }
@Override
@Deprecated
public WxEntPayResult entPay(WxEntPayRequest request) throws WxPayException {
return WxEntPayResult.createFrom(this.getEntPayService().entPay(request));
}
@Override
@Deprecated
public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException {
return WxEntPayQueryResult.createFrom(this.getEntPayService().queryEntPay(partnerTradeNo));
}
@Override @Override
public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) { public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) {
String content = this.createScanPayQrcodeMode1(productId); String content = this.createScanPayQrcodeMode1(productId);

View File

@@ -1,18 +1,16 @@
package com.github.binarywang.wxpay.service.impl; package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.github.binarywang.wxpay.bean.entpay.EntPayBankRequest; import com.github.binarywang.wxpay.bean.entpay.EntPayBankRequest;
import com.github.binarywang.wxpay.bean.entpay.EntPayBankResult; import com.github.binarywang.wxpay.bean.entpay.EntPayBankResult;
import com.github.binarywang.wxpay.bean.request.WxEntPayRequest; import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.constant.WxPayConstants.CheckNameOption;
import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.github.binarywang.wxpay.testbase.ApiTestModule;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.annotations.Guice; import org.testng.annotations.*;
import org.testng.annotations.Test;
/** /**
* <pre> * <pre>
@@ -30,37 +28,20 @@ public class EntPayServiceImplTest {
@Inject @Inject
private WxPayService payService; private WxPayService payService;
@Test
public void testEntPay_old() throws WxPayException {
this.logger.info(this.payService.entPay(WxEntPayRequest.builder()
.partnerTradeNo("Eb6Aep7uVTdbkJqrP4")
.openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4")
.amount(1)
.spbillCreateIp("10.10.10.10")
.checkName(WxPayConstants.CheckNameOption.NO_CHECK)
.description("描述信息")
.build()).toString());
}
@Test @Test
public void testEntPay() throws WxPayException { public void testEntPay() throws WxPayException {
EntPayRequest request = EntPayRequest.newBuilder() EntPayRequest request = EntPayRequest.newBuilder()
.partnerTradeNo("Eb6Aep7uVTdbkJqrP4") .partnerTradeNo("Eb6Aep7uVTdbkJqrP4")
.openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4") .openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP5")
.amount(1) .amount(100)
.spbillCreateIp("10.10.10.10") .spbillCreateIp("10.10.10.10")
.checkName(WxPayConstants.CheckNameOption.NO_CHECK) .checkName(CheckNameOption.NO_CHECK)
.description("描述信息") .description("描述信息")
.build(); .build();
this.logger.info(this.payService.getEntPayService().entPay(request).toString()); this.logger.info(this.payService.getEntPayService().entPay(request).toString());
} }
@Test
public void testQueryEntPay_old() throws WxPayException {
this.logger.info(this.payService.queryEntPay("11212121").toString());
}
@Test @Test
public void testQueryEntPay() throws WxPayException { public void testQueryEntPay() throws WxPayException {
this.logger.info(this.payService.getEntPayService().queryEntPay("11212121").toString()); this.logger.info(this.payService.getEntPayService().queryEntPay("11212121").toString());