重构Weixin4jSettings...

This commit is contained in:
jinyu
2016-02-02 19:48:30 +08:00
parent baff97e9db
commit 8a9f93e54e
39 changed files with 636 additions and 1020 deletions
@@ -12,6 +12,7 @@ import java.nio.charset.Charset;
* @see
*/
public final class Consts {
public static final String WEIXIN4J = "weixin4j";
public static final Charset UTF_8 = Charset.forName("UTF-8");
public static final Charset GBK = Charset.forName("GBK");
public static final String SUCCESS = "SUCCESS";
@@ -49,9 +49,9 @@ public class WeixinPayAccount extends WeixinAccount {
* 商户平台版本(V3)字段
*
* @param appId
* 公众号唯一的身份ID
* 公众号唯一的身份ID(必填)
* @param appSecret
* 调用接口的凭证
* 调用接口的凭证(最好填写)
* @param paySignKey
* 支付密钥字符串(必填)
* @param mchId
@@ -68,7 +68,7 @@ public class WeixinPayAccount extends WeixinAccount {
* @param appId
* 公众号唯一的身份ID(必填)
* @param appSecret
* 调用接口的凭证(必填)
* 调用接口的凭证(最好填写)
* @param paySignKey
* 支付密钥字符串(必填)
* @param mchId
@@ -30,11 +30,11 @@ import com.foxinmy.weixin4j.payment.mch.Redpacket;
import com.foxinmy.weixin4j.payment.mch.RedpacketRecord;
import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult;
import com.foxinmy.weixin4j.payment.mch.RefundRecord;
import com.foxinmy.weixin4j.settings.Weixin4jPaySettings;
import com.foxinmy.weixin4j.type.BillType;
import com.foxinmy.weixin4j.type.CurrencyType;
import com.foxinmy.weixin4j.type.IdQuery;
import com.foxinmy.weixin4j.type.TradeType;
import com.foxinmy.weixin4j.util.Weixin4jSettings;
/**
* 微信支付接口实现
@@ -52,26 +52,26 @@ public class WeixinPayProxy {
private final CouponApi couponApi;
private final CashApi cashApi;
private final Weixin4jPaySettings settings;
private final Weixin4jSettings settings;
/**
* 使用weixin4j.properties配置的支付账号信息
*/
public WeixinPayProxy() {
this(new Weixin4jPaySettings());
this(new Weixin4jSettings());
}
/**
*
* @param settings
* 支付相关配置信息
* @see com.foxinmy.weixin4j.settings.Weixin4jPaySettings
* @see com.foxinmy.weixin4j.util.Weixin4jSettings
*/
public WeixinPayProxy(Weixin4jPaySettings settings) {
public WeixinPayProxy(Weixin4jSettings settings) {
this.settings = settings;
this.pay3Api = new Pay3Api(settings.getPayAccount());
this.couponApi = new CouponApi(settings.getPayAccount());
this.cashApi = new CashApi(settings.getPayAccount());
this.pay3Api = new Pay3Api(settings.getWeixinPayAccount());
this.couponApi = new CouponApi(settings.getWeixinPayAccount());
this.cashApi = new CashApi(settings.getWeixinPayAccount());
}
/**
@@ -80,7 +80,7 @@ public class WeixinPayProxy {
* @return
*/
public WeixinPayAccount getPayAccount() {
return this.settings.getPayAccount();
return this.settings.getWeixinPayAccount();
}
/**
@@ -467,7 +467,7 @@ public class WeixinPayProxy {
IdQuery idQuery, String outRefundNo, double totalFee)
throws WeixinException, IOException {
return pay3Api.refundApply(
new FileInputStream(settings.getCertificatePath()), idQuery,
new FileInputStream(settings.getCertificateFile0()), idQuery,
outRefundNo, totalFee);
}
@@ -514,7 +514,7 @@ public class WeixinPayProxy {
*/
public File downloadBill(Date billDate, BillType billType)
throws WeixinException {
return pay3Api.downloadBill(billDate, billType, settings.getBillPath());
return pay3Api.downloadBill(billDate, billType, settings.getTmpdir0());
}
/**
@@ -551,7 +551,7 @@ public class WeixinPayProxy {
public ApiResult reverseOrder(IdQuery idQuery) throws WeixinException,
IOException {
return pay3Api.reverseOrder(
new FileInputStream(settings.getCertificatePath()), idQuery);
new FileInputStream(settings.getCertificateFile0()), idQuery);
}
/**
@@ -655,7 +655,7 @@ public class WeixinPayProxy {
public CouponResult sendCoupon(String couponStockId, String partnerTradeNo,
String openId) throws WeixinException, IOException {
return couponApi.sendCoupon(
new FileInputStream(settings.getCertificatePath()),
new FileInputStream(settings.getCertificateFile0()),
couponStockId, partnerTradeNo, openId, null);
}
@@ -721,7 +721,7 @@ public class WeixinPayProxy {
public RedpacketSendResult sendRedpack(Redpacket redpacket)
throws WeixinException, IOException {
return cashApi.sendRedpack(
new FileInputStream(settings.getCertificatePath()), redpacket);
new FileInputStream(settings.getCertificateFile0()), redpacket);
}
/**
@@ -750,8 +750,10 @@ public class WeixinPayProxy {
*/
public RedpacketRecord queryRedpack(String outTradeNo)
throws WeixinException, IOException {
return cashApi.queryRedpack(
new FileInputStream(settings.getCertificatePath()), outTradeNo);
return cashApi
.queryRedpack(
new FileInputStream(settings.getCertificateFile0()),
outTradeNo);
}
/**
@@ -782,7 +784,7 @@ public class WeixinPayProxy {
public MPPaymentResult mpPayment(MPPayment mpPayment)
throws WeixinException, IOException {
return cashApi.mchPayment(
new FileInputStream(settings.getCertificatePath()), mpPayment);
new FileInputStream(settings.getCertificateFile0()), mpPayment);
}
/**
@@ -811,8 +813,10 @@ public class WeixinPayProxy {
*/
public MPPaymentRecord mpPaymentQuery(String outTradeNo)
throws WeixinException, IOException {
return cashApi.mchPaymentQuery(
new FileInputStream(settings.getCertificatePath()), outTradeNo);
return cashApi
.mchPaymentQuery(
new FileInputStream(settings.getCertificateFile0()),
outTradeNo);
}
/**
@@ -1,14 +0,0 @@
package com.foxinmy.weixin4j.settings;
/**
* 微信请求配置相关(待实现
*
* @className Weixin4jHttpSettings
* @author jy
* @date 2016年1月28日
* @since JDK 1.6
* @see
*/
public class Weixin4jHttpSettings {
}
@@ -1,108 +0,0 @@
package com.foxinmy.weixin4j.settings;
import com.alibaba.fastjson.JSON;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.util.StringUtil;
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
/**
* 微信支付配置相关
*
* @className Weixin4jPaySettings
* @author jy
* @date 2016年1月28日
* @since JDK 1.6
* @see
*/
public class Weixin4jPaySettings {
private final WeixinPayAccount payAccount;
public Weixin4jPaySettings() {
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
WeixinPayAccount.class));
}
public Weixin4jPaySettings(WeixinPayAccount payAccount) {
this.payAccount = payAccount;
}
/**
* 支付账号信息
*
* @return
*/
public WeixinPayAccount getPayAccount() {
return this.payAccount;
}
private String billPath;
/**
* 对账单保存路径
*
* @param billPath
* 硬盘目录
*/
public Weixin4jPaySettings billPath(String billPath) {
this.billPath = billPath;
return this;
}
/**
* 默认对账单保存路径
*/
public static final String DEFAULT_BILL_PATH = "/tmp/weixin4j/bill";
/**
* 对账单保存路径,默认值为{@link #DEFAULT_BILL_PATH}
*
* @return
*/
public String getBillPath() {
if (StringUtil.isBlank(billPath)) {
this.billPath = Weixin4jConfigUtil.getClassPathValue("bill.path",
DEFAULT_BILL_PATH);
}
return this.billPath;
}
private String certificatePath;
/**
* ca证书存放路径
*
* @param certificatePath
* 硬盘目录
* @return
*/
public Weixin4jPaySettings certificatePath(String certificatePath) {
this.certificatePath = certificatePath;
return this;
}
/**
* 默认ca证书存放路径
*/
public static final String DEFAULT_CAFILE_PATH = "classpath:ca.p12";
/**
* ca证书存放路径,默认值为{@link #DEFAULT_CAFILE_PATH}
*
* @return
*/
public String getCertificatePath() {
if (StringUtil.isBlank(certificatePath)) {
this.certificatePath = Weixin4jConfigUtil.getClassPathValue(
"certificate.path", DEFAULT_CAFILE_PATH);
}
return this.certificatePath;
}
@Override
public String toString() {
return "Weixin4jPaySettings [payAccount=" + payAccount + ", billPath="
+ getBillPath() + ", certificatePath=" + getCertificatePath()
+ "]";
}
}
@@ -1,168 +0,0 @@
package com.foxinmy.weixin4j.settings;
import com.foxinmy.weixin4j.model.WeixinAccount;
import com.foxinmy.weixin4j.token.FileTokenStorager;
import com.foxinmy.weixin4j.token.TokenStorager;
import com.foxinmy.weixin4j.util.StringUtil;
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
/**
* 微信基础配置相关
*
* @className Weixin4jSettings
* @author jy
* @date 2016年1月28日
* @since JDK 1.6
* @see
*/
public class Weixin4jSettings {
private final WeixinAccount account;
public Weixin4jSettings() {
this(Weixin4jConfigUtil.getWeixinAccount());
}
/**
*
* @param id
* 应用唯一标识 appid/corpid
* @param secret
* 应用接口密钥
*/
public Weixin4jSettings(String id, String secret) {
this(new WeixinAccount(id, secret));
}
public Weixin4jSettings(WeixinAccount account) {
this.account = account;
}
/**
* 微信账号信息
*/
public WeixinAccount getAccount() {
return this.account;
}
private String tokenPath;
/**
* 使用FileTokenStorager时token的存放路径
*
* @param tokenPath
* 硬盘目录
* @return
*/
public Weixin4jSettings setTokenPath(String tokenPath) {
this.tokenPath = tokenPath;
return this;
}
/**
* 默认token的存放路径
*/
public static final String DEFAULT_TOKEN_PATH = "/tmp/weixin4j/token";
/**
* 使用FileTokenStorager时token的存放路径,默认值为{@link #DEFAULT_TOKEN_PATH}
*/
public String getTokenPath() {
if (StringUtil.isBlank(tokenPath)) {
tokenPath = Weixin4jConfigUtil.getClassPathValue("token.path",
DEFAULT_TOKEN_PATH);
}
return tokenPath;
}
private String qrcodePath;
/**
* 二维码保存路径
*
* @param qrcodePath
* 硬盘目录
*/
public Weixin4jSettings setQrcodePath(String qrcodePath) {
this.qrcodePath = qrcodePath;
return this;
}
/**
* 默认二维码保存路径
*/
public static final String DEFAULT_QRCODE_PATH = "/tmp/weixin4j/qrcode";
/**
* 二维码保存路径,默认值为{@link #DEFAULT_QRCODE_PATH}
*/
public String getQrcodePath() {
if (StringUtil.isBlank(qrcodePath)) {
this.qrcodePath = Weixin4jConfigUtil.getClassPathValue(
"qrcode.path", DEFAULT_QRCODE_PATH);
}
return this.qrcodePath;
}
private String mediaPath;
/**
* 媒体文件保存路径
*
* @param mediaPath
* 硬盘目录
*/
public Weixin4jSettings setMediaPath(String mediaPath) {
this.mediaPath = mediaPath;
return this;
}
/**
* 默认媒体文件保存路径
*/
public static final String DEFAULT_MEDIA_PATH = "/tmp/weixin4j/media";
/**
* 媒体文件保存路径,默认值为{@link #DEFAULT_MEDIA_PATH}
*/
public String getMediaPath() {
if (StringUtil.isBlank(mediaPath)) {
this.mediaPath = Weixin4jConfigUtil.getClassPathValue("media.path",
DEFAULT_MEDIA_PATH);
}
return this.mediaPath;
}
private TokenStorager tokenStorager;
/**
* token存储
*
* @param tokenStorager
* @return
*/
public Weixin4jSettings setTokenStorager(TokenStorager tokenStorager) {
this.tokenStorager = tokenStorager;
return this;
}
/**
* 获取token存储方式 默认为FileTokenStorager
*
* @return
*/
public TokenStorager getTokenStorager() {
if (tokenStorager == null) {
this.tokenStorager = new FileTokenStorager(getTokenPath());
}
return this.tokenStorager;
}
@Override
public String toString() {
return "Weixin4jSettings [account=" + account + ", tokenPath="
+ getTokenPath() + ", qrcodePath=" + getQrcodePath()
+ ", mediaPath=" + getMediaPath() + ", tokenStorager="
+ getTokenStorager() + "]";
}
}
@@ -1,6 +1,5 @@
package com.foxinmy.weixin4j.util;
import java.io.File;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@@ -25,18 +24,6 @@ public class Weixin4jConfigUtil {
.getResource("").getPath();
try {
weixinBundle = ResourceBundle.getBundle("weixin4j");
File file = null;
for (String key : weixinBundle.keySet()) {
if (!key.endsWith(".path")) {
continue;
}
file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX,
CLASSPATH_VALUE));
if (!file.exists() && !file.mkdirs()) {
System.err.append(String.format("%s create fail.%n",
file.getAbsolutePath()));
}
}
} catch (MissingResourceException e) {
;
}
@@ -0,0 +1,155 @@
package com.foxinmy.weixin4j.util;
import com.alibaba.fastjson.JSON;
import com.foxinmy.weixin4j.http.HttpParams;
import com.foxinmy.weixin4j.model.WeixinAccount;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.token.FileTokenStorager;
import com.foxinmy.weixin4j.token.TokenStorager;
/**
* 微信配置相关
*
* @className Weixin4jSettings
* @author jy
* @date 2016年1月28日
* @since JDK 1.6
* @see
*/
public class Weixin4jSettings {
/**
* 微信支付账号信息
*/
private WeixinPayAccount weixinPayAccount;
/**
* 微信账号信息
*/
private WeixinAccount weixinAccount;
/**
* Http参数
*/
private HttpParams httpParams;
/**
* token存储方式 默认为FileTokenStorager
*/
private TokenStorager tokenStorager;
/**
* 系统临时目录
*/
private String tmpdir;
/**
* 支付接口需要的证书文件(*.p12)
*/
private String certificateFile;
/**
* 默认使用weixin4j.properties配置的信息
*/
public Weixin4jSettings() {
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
WeixinPayAccount.class));
}
/**
* 支付代理接口
*
* @param weixinPayAccount
* 商户信息
* @param certificateFile
* 支付接口需要的证书文件(*.p12),比如退款接口
*/
public Weixin4jSettings(WeixinPayAccount weixinPayAccount,
String certificateFile) {
this.weixinPayAccount = weixinPayAccount;
this.certificateFile = certificateFile;
this.weixinAccount = new WeixinAccount(weixinPayAccount.getId(),
weixinPayAccount.getSecret());
}
/**
* 普通代理接口
*
* @param weixinAccount
*/
public Weixin4jSettings(WeixinAccount weixinAccount) {
this.weixinAccount = weixinAccount;
}
public WeixinPayAccount getWeixinPayAccount() {
return weixinPayAccount;
}
public WeixinAccount getWeixinAccount() {
return weixinAccount;
}
public HttpParams getHttpParams() {
return httpParams;
}
public HttpParams getHttpParams0() {
if (httpParams == null) {
return new HttpParams();
}
return httpParams;
}
public String getTmpdir() {
return tmpdir;
}
public String getTmpdir0() {
if (StringUtil.isBlank(tmpdir)) {
return Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
System.getProperty("java.io.tmpdir"));
}
return tmpdir;
}
public TokenStorager getTokenStorager() {
return tokenStorager;
}
public TokenStorager getTokenStorager0() {
if (tokenStorager == null) {
return new FileTokenStorager(getTmpdir0());
}
return tokenStorager;
}
public String getCertificateFile() {
return certificateFile;
}
public String getCertificateFile0() {
if (StringUtil.isBlank(certificateFile)) {
return Weixin4jConfigUtil.getClassPathValue(
"weixin4j.certificate.file", "classpath:ca.p12");
}
return certificateFile;
}
public void setHttpParams(HttpParams httpParams) {
this.httpParams = httpParams;
}
public void setTmpdir(String tmpdir) {
this.tmpdir = tmpdir;
}
public void setTokenStorager(TokenStorager tokenStorager) {
this.tokenStorager = tokenStorager;
}
public void setCertificateFile(String certificateFile) {
this.certificateFile = certificateFile;
}
@Override
public String toString() {
return "Weixin4jSettings [weixinAccount=" + weixinAccount
+ ", httpParams=" + httpParams + ",tokenStorager="
+ tokenStorager + ", tmpdir=" + tmpdir + ", certificateFile= "
+ certificateFile + "]";
}
}
@@ -0,0 +1,57 @@
package com.foxinmy.weixin4j.base.test;
import java.io.FileInputStream;
import java.io.IOException;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.payment.mch.MPPayment;
import com.foxinmy.weixin4j.payment.mch.MPPaymentResult;
import com.foxinmy.weixin4j.payment.mch.Redpacket;
import com.foxinmy.weixin4j.payment.mch.RedpacketRecord;
import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult;
import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
/**
* 现金发放测试
*
* @className CashTest
* @author jy
* @date 2015年4月1日
* @since JDK 1.6
* @see
*/
public class CashTest extends PayTest {
@Test
public void sendRedpacket() throws WeixinException, IOException {
Redpacket redpacket = new Redpacket("HB001", "无忧钱庄",
"oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d, 1);
redpacket.setActName("红包测试");
redpacket.setClientIp("127.0.0.1");
redpacket.setRemark("快来领取红包吧!");
redpacket.setWishing("来就送钱");
RedpacketSendResult result = PAY3.sendRedpack(new FileInputStream(
caFile), redpacket);
System.err.println(result);
}
@Test
public void queryRedpacket() throws WeixinException, IOException {
String outTradeNo = "HB001";
RedpacketRecord record = PAY3.queryRedpack(new FileInputStream(caFile),
outTradeNo);
System.err.println(record);
}
@Test
public void mpPayment() throws WeixinException, IOException {
MPPayment payment = new MPPayment("MP001",
"oyFLst1bqtuTcxK-ojF8hOGtLQao",
MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 0.01d, "127.0.0.1");
MPPaymentResult result = PAY3.mpPayment(new FileInputStream(caFile),
payment);
System.err.println(result);
}
}
@@ -0,0 +1,48 @@
package com.foxinmy.weixin4j.base.test;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.model.Consts;
import com.foxinmy.weixin4j.payment.coupon.CouponDetail;
import com.foxinmy.weixin4j.payment.coupon.CouponResult;
import com.foxinmy.weixin4j.payment.coupon.CouponStock;
import com.foxinmy.weixin4j.util.DateUtil;
/**
* 代金券测试
*
* @className CouponTest
* @author jy
* @date 2015年3月25日
* @since JDK 1.6
* @see
*/
public class CouponTest extends PayTest {
@Test
public void sendCoupon() throws WeixinException, IOException {
String partnerTradeNo = String.format("%s%s%s", ACCOUNT3.getMchId(),
DateUtil.fortmat2yyyyMMdd(new Date()), "1");
CouponResult result = PAY3.sendCoupon(new FileInputStream(caFile),
"123", partnerTradeNo, "oyFLst1bqtuTcxK-ojF8hOGtLQao", null);
Assert.assertTrue(result.getRetCode().equalsIgnoreCase(Consts.SUCCESS));
}
@Test
public void queryCouponStock() throws WeixinException {
CouponStock couponStock = PAY3.queryCouponStock("couponStockId");
System.err.println(couponStock);
}
@Test
public void queryCouponDetail() throws WeixinException {
CouponDetail couponDetail = PAY3.queryCouponDetail("couponId");
System.err.println(couponDetail);
}
}
@@ -0,0 +1,156 @@
package com.foxinmy.weixin4j.base.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.exception.WeixinPayException;
import com.foxinmy.weixin4j.http.weixin.XmlResult;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.WeixinPayProxy;
import com.foxinmy.weixin4j.payment.mch.ApiResult;
import com.foxinmy.weixin4j.payment.mch.MchPayPackage;
import com.foxinmy.weixin4j.payment.mch.Order;
import com.foxinmy.weixin4j.payment.mch.PrePay;
import com.foxinmy.weixin4j.type.IdQuery;
import com.foxinmy.weixin4j.type.IdType;
import com.foxinmy.weixin4j.type.TradeType;
import com.foxinmy.weixin4j.util.DigestUtil;
import com.foxinmy.weixin4j.util.Weixin4jSettings;
/**
* 支付测试(商户平台)
*
* @className PayTest
* @author jy
* @date 2016年1月30日
* @since JDK 1.7
* @see
*/
public class PayTest {
protected final static WeixinPayProxy PAY3;
protected final static WeixinPayAccount ACCOUNT3;
static {
ACCOUNT3 = new WeixinPayAccount("wx5518c745065b1f95",
"请填入v3版本的appSecret", "DTYUNJKL1234fghjkRTGHJNM345678fc",
"1298173301", null, null, null, null, null);
PAY3 = new WeixinPayProxy(new Weixin4jSettings(ACCOUNT3));
}
/**
* 商户证书文件
*/
protected File caFile = new File("证书文件,如12333.p12");
@Test
public void orderQueryV3() throws WeixinException {
Order order = PAY3.orderQuery(new IdQuery("BY2016010800025",
IdType.TRADENO));
System.err.println(order);
String sign = order.getSign();
order.setSign(null);
String valiSign = DigestUtil
.paysignMd5(order, ACCOUNT3.getPaySignKey());
System.err
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
Assert.assertEquals(valiSign, sign);
}
@Test
public void refundQueryV3() throws WeixinException {
com.foxinmy.weixin4j.payment.mch.RefundRecord record = PAY3
.refundQuery(new IdQuery("TT_1427183696238", IdType.TRADENO));
System.err.println(record);
// 这里的验证签名需要把details循环拼接
String sign = record.getSign();
record.setSign(null);
String valiSign = DigestUtil.paysignMd5(record,
ACCOUNT3.getPaySignKey());
System.err
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
Assert.assertEquals(valiSign, sign);
}
@Test
public void downbillV3() throws WeixinException {
Calendar c = Calendar.getInstance();
System.err.println(c.getTime());
c.set(Calendar.YEAR, 2015);
c.set(Calendar.MONTH, 2);
c.set(Calendar.DAY_OF_MONTH, 24);
System.err.println(c.getTime());
File file = PAY3.downloadBill(c.getTime(), null);
System.err.println(file);
}
@Test
public void refundV3() throws WeixinException, IOException {
IdQuery idQuery = new IdQuery("TT_1427183696238", IdType.TRADENO);
com.foxinmy.weixin4j.payment.mch.RefundResult result = PAY3
.refundApply(new FileInputStream(caFile), idQuery, "TT_R"
+ System.currentTimeMillis(), 0.01d, 0.01d, null,
"10020674");
System.err.println(result);
String sign = result.getSign();
result.setSign(null);
String valiSign = DigestUtil.paysignMd5(result,
ACCOUNT3.getPaySignKey());
System.err
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
Assert.assertEquals(valiSign, sign);
}
@Test
public void nativeV3() throws WeixinException {
MchPayPackage payPackageV3 = new MchPayPackage(ACCOUNT3,
"oyFLst1bqtuTcxK-ojF8hOGtLQao", "native测试", "T0001", 0.1d,
"notify_url", "127.0.0.1", TradeType.NATIVE);
payPackageV3.setProductId("0001");
PrePay prePay = null;
try {
prePay = PAY3.createPrePay(payPackageV3);
} catch (WeixinPayException e) {
e.printStackTrace();
}
System.err.println(prePay);
}
@Test
public void closeOrder() throws WeixinException {
ApiResult result = PAY3.closeOrder("D111");
System.err.println(result);
String sign = result.getSign();
result.setSign(null);
String valiSign = DigestUtil.paysignMd5(result,
ACCOUNT3.getPaySignKey());
System.err
.println(String.format("sign=%s,valiSign=%s", sign, valiSign));
Assert.assertEquals(valiSign, sign);
}
@Test
public void shortUrl() throws WeixinException {
String url = "weixin://wxpay/bizpayurl?xxxxxx";
String shortUrl = PAY3.getPayShorturl(url);
System.err.println(shortUrl);
}
@Test
public void interfaceReport() throws WeixinException {
String interfaceUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
int executeTime = 2500;
String outTradeNo = null;
String ip = "127.0.0.1";
Date time = new Date();
XmlResult returnXml = new XmlResult("SUCCESS", "");
returnXml.setResultCode("SUCCESS");
returnXml = PAY3.interfaceReport(interfaceUrl, executeTime, outTradeNo,
ip, time, returnXml);
System.err.println(returnXml);
}
}