将微信支付模块移到base工程
This commit is contained in:
parent
663cba9677
commit
5ee2755a16
@ -351,4 +351,8 @@
|
||||
|
||||
* 2015-06-24
|
||||
|
||||
+ **weixin4j-qy**: 新增userid与openid互换接口
|
||||
+ **weixin4j-qy**: 新增userid与openid互换接口
|
||||
|
||||
* 2015-06-26
|
||||
|
||||
+ 将微信支付模块移到base工程
|
||||
@ -56,4 +56,8 @@
|
||||
|
||||
* 2015-06-08
|
||||
|
||||
+ 新增群发卡券消息类型
|
||||
+ 新增群发卡券消息类型
|
||||
|
||||
* 2015-06-26
|
||||
|
||||
+ 移入微信支付模块
|
||||
@ -3,9 +3,12 @@ package com.foxinmy.weixin4j.api;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
|
||||
/**
|
||||
* API基础
|
||||
@ -38,8 +41,19 @@ public abstract class BaseApi {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties文件中的公众号信息
|
||||
*/
|
||||
public final static WeixinAccount DEFAULT_WEIXIN_ACCOUNT;
|
||||
|
||||
/**
|
||||
* 默认token使用File的方式存储
|
||||
*/
|
||||
public final static TokenStorager DEFAULT_TOKEN_STORAGER = new FileTokenStorager();
|
||||
public final static TokenStorager DEFAULT_TOKEN_STORAGER;
|
||||
|
||||
static {
|
||||
DEFAULT_WEIXIN_ACCOUNT = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinAccount.class);
|
||||
DEFAULT_TOKEN_STORAGER = new FileTokenStorager();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
package com.foxinmy.weixin4j.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -13,14 +13,15 @@ import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.SSLHttpClinet;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPayment;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.Redpacket;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.PayURLConsts;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.payment.mch.MPPayment;
|
||||
import com.foxinmy.weixin4j.payment.mch.MPPaymentRecord;
|
||||
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.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
@ -36,11 +37,11 @@ import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_1">企业付款</a>
|
||||
*/
|
||||
public class CashApi extends MpApi {
|
||||
public class CashApi {
|
||||
|
||||
private final WeixinMpAccount weixinAccount;
|
||||
private final WeixinPayAccount weixinAccount;
|
||||
|
||||
public CashApi(WeixinMpAccount weixinAccount) {
|
||||
public CashApi(WeixinPayAccount weixinAccount) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
}
|
||||
|
||||
@ -52,8 +53,8 @@ public class CashApi extends MpApi {
|
||||
* @param redpacket
|
||||
* 红包信息
|
||||
* @return 发放结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.Redpacket
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Redpacket
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RedpacketSendResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5">发放红包接口说明</a>
|
||||
* @throws WeixinException
|
||||
@ -68,14 +69,13 @@ public class CashApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(obj, weixinAccount.getPaySignKey());
|
||||
obj.put("sign", sign);
|
||||
String param = XmlStream.map2xml(obj);
|
||||
String redpack_send_uri = getRequestUri("redpack_send_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
response = request.post(redpack_send_uri, param);
|
||||
response = request.post(PayURLConsts.MCH_REDPACKSEND_URL, param);
|
||||
} catch (WeixinException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -101,7 +101,7 @@ public class CashApi extends MpApi {
|
||||
* @param outTradeNo
|
||||
* 商户发放红包的商户订单号
|
||||
* @return 红包记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RedpacketRecord
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RedpacketRecord
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_6">查询红包接口说明</a>
|
||||
* @throws WeixinException
|
||||
@ -117,14 +117,13 @@ public class CashApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(para, weixinAccount.getPaySignKey());
|
||||
para.put("sign", sign);
|
||||
String param = XmlStream.map2xml(para);
|
||||
String redpack_query_uri = getRequestUri("redpack_query_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
response = request.post(redpack_query_uri, param);
|
||||
response = request.post(PayURLConsts.MCH_REDPACKQUERY_URL, param);
|
||||
} catch (WeixinException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -150,8 +149,8 @@ public class CashApi extends MpApi {
|
||||
* @param mpPayment
|
||||
* 付款信息
|
||||
* @return 付款结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPayment
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MPPayment
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MPPaymentResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_1">企业付款</a>
|
||||
* @throws WeixinException
|
||||
@ -167,14 +166,13 @@ public class CashApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(obj, weixinAccount.getPaySignKey());
|
||||
obj.put("sign", sign);
|
||||
String param = XmlStream.map2xml(obj);
|
||||
String mp_payment_uri = getRequestUri("mp_payment_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
response = request.post(mp_payment_uri, param);
|
||||
response = request.post(PayURLConsts.MCH_ENPAYMENT_URL, param);
|
||||
} catch (WeixinException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -204,7 +202,7 @@ public class CashApi extends MpApi {
|
||||
* @param outTradeNo
|
||||
* 商户调用企业付款API时使用的商户订单号
|
||||
* @return 付款记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPaymentRecord
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MPPaymentRecord
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_3">企业付款查询</a>
|
||||
* @throws WeixinException
|
||||
@ -219,14 +217,13 @@ public class CashApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(obj, weixinAccount.getPaySignKey());
|
||||
obj.put("sign", sign);
|
||||
String param = XmlStream.map2xml(obj);
|
||||
String mp_payquery_uri = getRequestUri("mp_payquery_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
response = request.post(mp_payquery_uri, param);
|
||||
response = request.post(PayURLConsts.MCH_ENPAYQUERY_URL, param);
|
||||
} catch (WeixinException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
package com.foxinmy.weixin4j.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -10,12 +10,14 @@ import java.util.Map;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.SSLHttpClinet;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponDetail;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponStock;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.PayURLConsts;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
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.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
@ -29,12 +31,15 @@ import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
* @since JDK 1.7
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php">代金券文档</a>
|
||||
*/
|
||||
public class CouponApi extends MpApi {
|
||||
public class CouponApi {
|
||||
|
||||
private final WeixinMpAccount weixinAccount;
|
||||
private final WeixinHttpClient weixinClient;
|
||||
|
||||
public CouponApi(WeixinMpAccount weixinAccount) {
|
||||
private final WeixinPayAccount weixinAccount;
|
||||
|
||||
public CouponApi(WeixinPayAccount weixinAccount) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.weixinClient = new WeixinHttpClient();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,7 +56,7 @@ public class CouponApi extends MpApi {
|
||||
* @param opUserId
|
||||
* 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限 可为空
|
||||
* @return 发放结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponResult
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php?chapter=12_3">发放代金券接口</a>
|
||||
* @throws WeixinException
|
||||
@ -75,14 +80,13 @@ public class CouponApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
String coupon_send_uri = getRequestUri("coupon_send_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
response = request.post(coupon_send_uri, param);
|
||||
response = request.post(PayURLConsts.MCH_COUPONSEND_URL, param);
|
||||
} catch (WeixinException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -106,7 +110,7 @@ public class CouponApi extends MpApi {
|
||||
* @param couponStockId
|
||||
* 代金券批次ID
|
||||
* @return 代金券批次信息
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponStock
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponStock
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php?chapter=12_4">查询代金券批次信息</a>
|
||||
* @throws WeixinException
|
||||
@ -118,9 +122,8 @@ public class CouponApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
String couponstock_query_uri = getRequestUri("couponstock_query_uri");
|
||||
WeixinResponse response = weixinClient.post(couponstock_query_uri,
|
||||
param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_COUPONSTOCKQUERY_URL, param);
|
||||
return response.getAsObject(new TypeReference<CouponStock>() {
|
||||
});
|
||||
}
|
||||
@ -131,7 +134,7 @@ public class CouponApi extends MpApi {
|
||||
* @param couponId
|
||||
* 代金券ID
|
||||
* @return 代金券详细信息
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponDetail
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponDetail
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php?chapter=12_5">查询代金券详细信息</a>
|
||||
* @throws WeixinException
|
||||
@ -143,9 +146,8 @@ public class CouponApi extends MpApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
String coupondetail_query_uri = getRequestUri("coupondetail_query_uri");
|
||||
WeixinResponse response = weixinClient.post(coupondetail_query_uri,
|
||||
param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_COUPONDETAILQUERY_URL, param);
|
||||
return response.getAsObject(new TypeReference<CouponDetail>() {
|
||||
});
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
package com.foxinmy.weixin4j.api;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@ -20,20 +20,21 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.SSLHttpClinet;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.http.weixin.XmlResult;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.Order;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RefundRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RefundResult;
|
||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.mp.type.IdType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.PayURLConsts;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.payment.mch.ApiResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundRecord;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundResult;
|
||||
import com.foxinmy.weixin4j.type.BillType;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.IdType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
@ -42,7 +43,7 @@ import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* V3(商户平台版)支付API
|
||||
* (商户平台版)支付API
|
||||
*
|
||||
* @className Pay3Api
|
||||
* @author jy
|
||||
@ -50,10 +51,15 @@ import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
* @since JDK 1.7
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/index.html">商户平台API</a>
|
||||
*/
|
||||
public class Pay3Api extends PayApi {
|
||||
public class Pay3Api {
|
||||
|
||||
private final WeixinHttpClient weixinClient;
|
||||
|
||||
public Pay3Api(WeixinMpAccount weixinAccount, TokenHolder tokenHolder) {
|
||||
super(weixinAccount, tokenHolder);
|
||||
private final WeixinPayAccount weixinAccount;
|
||||
|
||||
public Pay3Api(WeixinPayAccount weixinAccount) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.weixinClient = new WeixinHttpClient();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +73,7 @@ public class Pay3Api extends PayApi {
|
||||
* 商户系统内部的订单号, transaction_id、out_trade_no 二 选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @return 订单信息
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.Order
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Order
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2">订单查询API</a>
|
||||
* @since V3
|
||||
@ -78,8 +84,8 @@ public class Pay3Api extends PayApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
String orderquery_uri = getRequestUri("orderquery_v3_uri");
|
||||
WeixinResponse response = weixinClient.post(orderquery_uri, param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_ORDERQUERY_URL, param);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
Order.class);
|
||||
}
|
||||
@ -111,16 +117,15 @@ public class Pay3Api extends PayApi {
|
||||
* 操作员帐号, 默认为商户号
|
||||
*
|
||||
* @return 退款申请结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundResult
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RefundResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4">申请退款API</a>
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
protected RefundResult refund(File caFile, IdQuery idQuery,
|
||||
protected RefundResult refundApply(File caFile, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, Map<String, String> mopara) throws WeixinException {
|
||||
String refund_uri = getRequestUri("refund_v3_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
@ -143,7 +148,7 @@ public class Pay3Api extends PayApi {
|
||||
String param = XmlStream.map2xml(map);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
response = request.post(refund_uri, param);
|
||||
response = request.post(PayURLConsts.MCH_REFUNDAPPLY_URL, param);
|
||||
} catch (WeixinException e) {
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
@ -179,9 +184,9 @@ public class Pay3Api extends PayApi {
|
||||
* 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
|
||||
* @param opUserId
|
||||
* 操作员帐号, 默认为商户号
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.Pay3Api#refund(File, IdQuery, String, double, double, String, Map)}
|
||||
* @see {@link com.foxinmy.weixin4j.api.Pay3Api#refundApply(File, IdQuery, String, double, double, String, Map)}
|
||||
*/
|
||||
public RefundResult refund(File caFile, IdQuery idQuery,
|
||||
public RefundResult refundApply(File caFile, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
CurrencyType refundFeeType, String opUserId) throws WeixinException {
|
||||
Map<String, String> mopara = new HashMap<String, String>();
|
||||
@ -189,7 +194,7 @@ public class Pay3Api extends PayApi {
|
||||
refundFeeType = CurrencyType.CNY;
|
||||
}
|
||||
mopara.put("refund_fee_type", refundFeeType.name());
|
||||
return refund(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
return refundApply(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
opUserId, mopara);
|
||||
}
|
||||
|
||||
@ -208,20 +213,20 @@ public class Pay3Api extends PayApi {
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult reverse(File caFile, IdQuery idQuery)
|
||||
public ApiResult reverseOrder(File caFile, IdQuery idQuery)
|
||||
throws WeixinException {
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
SSLHttpClinet request = new SSLHttpClinet(weixinAccount.getMchId(),
|
||||
ca);
|
||||
String reverse_uri = getRequestUri("reverse_uri");
|
||||
Map<String, String> map = baseMap(idQuery);
|
||||
String sign = PayUtil
|
||||
.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
WeixinResponse response = request.post(reverse_uri, param);
|
||||
WeixinResponse response = request.post(
|
||||
PayURLConsts.MCH_ORDERREVERSE_URL, param);
|
||||
return response.getAsObject(new TypeReference<ApiResult>() {
|
||||
});
|
||||
} catch (IOException e) {
|
||||
@ -258,8 +263,8 @@ public class Pay3Api extends PayApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
String shorturl_uri = getRequestUri("p_shorturl_uri");
|
||||
WeixinResponse response = weixinClient.post(shorturl_uri, param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_SHORTURL_URL, param);
|
||||
map = XmlStream.xml2map(response.getAsString());
|
||||
return map.get("short_url");
|
||||
}
|
||||
@ -285,8 +290,8 @@ public class Pay3Api extends PayApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
String closeorder_uri = getRequestUri("closeorder_uri");
|
||||
WeixinResponse response = weixinClient.post(closeorder_uri, param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_CLOSEORDER_URL, param);
|
||||
return response.getAsObject(new TypeReference<ApiResult>() {
|
||||
});
|
||||
}
|
||||
@ -327,14 +332,14 @@ public class Pay3Api extends PayApi {
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
String downloadbill_uri = getRequestUri("downloadbill_v3_uri");
|
||||
Map<String, String> map = baseMap(null);
|
||||
map.put("bill_date", formatBillDate);
|
||||
map.put("bill_type", billType.name());
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
WeixinResponse response = weixinClient.post(downloadbill_uri, param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_DOWNLOADBILL_URL, param);
|
||||
|
||||
BufferedReader reader = null;
|
||||
BufferedWriter writer = null;
|
||||
@ -380,22 +385,22 @@ public class Pay3Api extends PayApi {
|
||||
* 四个参数必填一个,优先级为:
|
||||
* refund_id>out_refund_no>transaction_id>out_trade_no
|
||||
* @return 退款记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundRecord
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RefundRecord
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RefundDetail
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5">退款查询API</a>
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public RefundRecord refundQuery(IdQuery idQuery) throws WeixinException {
|
||||
String refundquery_uri = getRequestUri("refundquery_v3_uri");
|
||||
Map<String, String> map = baseMap(idQuery);
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
WeixinResponse response = weixinClient.post(refundquery_uri, param);
|
||||
return ListsuffixResultDeserializer.deserialize(
|
||||
response.getAsString(), RefundRecord.class);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_REFUNDQUERY_URL, param);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
RefundRecord.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -423,7 +428,6 @@ public class Pay3Api extends PayApi {
|
||||
public XmlResult interfaceReport(String interfaceUrl, int executeTime,
|
||||
String outTradeNo, String ip, Date time, XmlResult returnXml)
|
||||
throws WeixinException {
|
||||
String pay_report_uri = getRequestUri("pay_report_uri");
|
||||
Map<String, String> map = baseMap(null);
|
||||
map.put("interface_url", interfaceUrl);
|
||||
map.put("execute_time_", Integer.toString(executeTime));
|
||||
@ -434,7 +438,8 @@ public class Pay3Api extends PayApi {
|
||||
String sign = PayUtil.paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
WeixinResponse response = weixinClient.post(pay_report_uri, param);
|
||||
WeixinResponse response = weixinClient.post(
|
||||
PayURLConsts.MCH_PAYREPORT_URL, param);
|
||||
return response.getAsXmlResult();
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
package com.foxinmy.weixin4j.page;
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.foxinmy.weixin4j.page.Sort.Direction;
|
||||
import com.foxinmy.weixin4j.model.Sort.Direction;
|
||||
|
||||
/**
|
||||
* @className Pageable
|
||||
* @author jy
|
||||
* @date 2014年12月27日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.page.springframework.data.domain.Pageable
|
||||
* @see com.foxinmy.weixin4j.model.springframework.data.domain.Pageable
|
||||
*/
|
||||
public class Pageable implements Serializable {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.page;
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.page;
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -29,6 +29,7 @@ public class WeixinAccount implements Serializable {
|
||||
private String encodingAesKey;
|
||||
|
||||
public WeixinAccount() {
|
||||
|
||||
}
|
||||
|
||||
public WeixinAccount(String id, String secret) {
|
||||
|
||||
@ -1,26 +1,21 @@
|
||||
package com.foxinmy.weixin4j.mp.model;
|
||||
package com.foxinmy.weixin4j.model;
|
||||
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 微信公众平台信息
|
||||
* 微信支付账户
|
||||
*
|
||||
* @className WeixinMpAccount
|
||||
* @className WeixinPayAccount
|
||||
* @author jy
|
||||
* @date 2014年8月17日
|
||||
* @date 2015年6月26日
|
||||
* @since JDK 1.7
|
||||
* @see <a href=
|
||||
* "https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=836970804&lang=zh_CN"
|
||||
* >开发者模式</a>
|
||||
* @see
|
||||
*/
|
||||
public class WeixinMpAccount extends WeixinAccount {
|
||||
private static final long serialVersionUID = 3689999353867189585L;
|
||||
public class WeixinPayAccount extends WeixinAccount {
|
||||
|
||||
/**
|
||||
* 支付场景下为用户的openid 其余情况可能是公众号的原始ID
|
||||
*/
|
||||
private String openId;
|
||||
private static final long serialVersionUID = -2791256176906048632L;
|
||||
/**
|
||||
* 公众号支付请求中用于加密的密钥 Key,可验证商户唯一身份,PaySignKey 对应于支付场景中的 appKey 值
|
||||
*/
|
||||
@ -50,81 +45,6 @@ public class WeixinMpAccount extends WeixinAccount {
|
||||
*/
|
||||
private int version;
|
||||
|
||||
public String getOpenId() {
|
||||
return openId;
|
||||
}
|
||||
|
||||
public void setOpenId(String openId) {
|
||||
this.openId = openId;
|
||||
}
|
||||
|
||||
public String getPaySignKey() {
|
||||
return paySignKey;
|
||||
}
|
||||
|
||||
public void setPaySignKey(String paySignKey) {
|
||||
this.paySignKey = paySignKey;
|
||||
}
|
||||
|
||||
public String getPartnerId() {
|
||||
return partnerId;
|
||||
}
|
||||
|
||||
public void setPartnerId(String partnerId) {
|
||||
this.partnerId = partnerId;
|
||||
}
|
||||
|
||||
public String getPartnerKey() {
|
||||
return partnerKey;
|
||||
}
|
||||
|
||||
public void setPartnerKey(String partnerKey) {
|
||||
this.partnerKey = partnerKey;
|
||||
}
|
||||
|
||||
public String getMchId() {
|
||||
return mchId;
|
||||
}
|
||||
|
||||
public void setMchId(String mchId) {
|
||||
this.mchId = mchId;
|
||||
}
|
||||
|
||||
public String getDeviceInfo() {
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
public void setDeviceInfo(String deviceInfo) {
|
||||
this.deviceInfo = deviceInfo;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
if (version == 0) {
|
||||
return StringUtil.isNotBlank(mchId) ? 3 : 2;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getSubMchId() {
|
||||
return subMchId;
|
||||
}
|
||||
|
||||
public void setSubMchId(String subMchId) {
|
||||
this.subMchId = subMchId;
|
||||
}
|
||||
|
||||
public WeixinMpAccount() {
|
||||
|
||||
}
|
||||
|
||||
public WeixinMpAccount(String appId, String appSecret) {
|
||||
super(appId, appSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户平台版本(V3)字段
|
||||
*
|
||||
@ -137,9 +57,12 @@ public class WeixinMpAccount extends WeixinAccount {
|
||||
* @param mchId
|
||||
* 微信支付分配的商户号
|
||||
*/
|
||||
public WeixinMpAccount(String appId, String appSecret, String paySignKey,
|
||||
String mchId) {
|
||||
this(appId, appSecret);
|
||||
@JSONCreator
|
||||
public WeixinPayAccount(@JSONField(name = "appId") String appId,
|
||||
@JSONField(name = "appSecret") String appSecret,
|
||||
@JSONField(name = "paySignKey") String paySignKey,
|
||||
@JSONField(name = "mchId") String mchId) {
|
||||
super(appId, appSecret);
|
||||
this.paySignKey = paySignKey;
|
||||
this.mchId = mchId;
|
||||
}
|
||||
@ -158,20 +81,54 @@ public class WeixinMpAccount extends WeixinAccount {
|
||||
* @param partnerKey
|
||||
* 财付通账号的key
|
||||
*/
|
||||
public WeixinMpAccount(String appId, String appSecret, String paySignKey,
|
||||
String partnerId, String partnerKey) {
|
||||
this(appId, appSecret);
|
||||
@JSONCreator
|
||||
public WeixinPayAccount(@JSONField(name = "appId") String appId,
|
||||
@JSONField(name = "appSecret") String appSecret,
|
||||
@JSONField(name = "paySignKey") String paySignKey,
|
||||
@JSONField(name = "partnerId") String partnerId,
|
||||
@JSONField(name = "partnerKey") String partnerKey) {
|
||||
super(appId, appSecret);
|
||||
this.paySignKey = paySignKey;
|
||||
this.partnerId = partnerId;
|
||||
this.partnerKey = partnerKey;
|
||||
}
|
||||
|
||||
public String getPaySignKey() {
|
||||
return paySignKey;
|
||||
}
|
||||
|
||||
public String getPartnerId() {
|
||||
return partnerId;
|
||||
}
|
||||
|
||||
public String getPartnerKey() {
|
||||
return partnerKey;
|
||||
}
|
||||
|
||||
public String getMchId() {
|
||||
return mchId;
|
||||
}
|
||||
|
||||
public String getSubMchId() {
|
||||
return subMchId;
|
||||
}
|
||||
|
||||
public String getDeviceInfo() {
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
if (version == 0) {
|
||||
return StringUtil.isNotBlank(mchId) ? 3 : 2;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WeixinMpAccount [openId=" + openId + ", paySignKey="
|
||||
+ paySignKey + ", partnerId=" + partnerId + ", partnerKey="
|
||||
+ partnerKey + ", mchId=" + mchId + ", deviceInfo="
|
||||
+ deviceInfo + ", version=" + version + ", " + super.toString()
|
||||
+ "]";
|
||||
return "WeixinPayAccount [paySignKey=" + paySignKey + ", partnerId="
|
||||
+ partnerId + ", partnerKey=" + partnerKey + ", mchId=" + mchId
|
||||
+ ", subMchId=" + subMchId + ", deviceInfo=" + deviceInfo
|
||||
+ ", version=" + version + "]";
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment;
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment;
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
|
||||
/**
|
||||
@ -62,7 +62,7 @@ public class MicroPayPackage extends PayPackage {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public MicroPayPackage(WeixinMpAccount weixinAccount, String body,
|
||||
public MicroPayPackage(WeixinPayAccount weixinAccount, String body,
|
||||
String attach, String outTradeNo, double totalFee,
|
||||
String spbillCreateIp, String authCode) {
|
||||
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment;
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
|
||||
/**
|
||||
* 基本信息
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment;
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment;
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -0,0 +1,105 @@
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
/**
|
||||
* 支付URL常量类
|
||||
*
|
||||
* @className PayURLConsts
|
||||
* @author jy
|
||||
* @date 2014年12月3日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public final class PayURLConsts {
|
||||
|
||||
private static final String MCH_BASE_URL = "https://api.mch.weixin.qq.com";
|
||||
|
||||
/**
|
||||
* 商户平台下统一订单生成的url
|
||||
*/
|
||||
public static final String MCH_UNIFIEDORDER_URL = MCH_BASE_URL
|
||||
+ "/pay/unifiedorder";
|
||||
/**
|
||||
* 订单查询(商户平台)
|
||||
*/
|
||||
public static final String MCH_ORDERQUERY_URL = MCH_BASE_URL
|
||||
+ "/pay/orderquery";
|
||||
/**
|
||||
* 关闭订单(商户平台)
|
||||
*/
|
||||
public static final String MCH_CLOSEORDER_URL = MCH_BASE_URL
|
||||
+ "/pay/closeorder";
|
||||
/**
|
||||
* 对账单下载(商户平台)
|
||||
*/
|
||||
public static final String MCH_DOWNLOADBILL_URL = MCH_BASE_URL
|
||||
+ "/pay/downloadbill";
|
||||
/**
|
||||
* 退款查询(商户平台)
|
||||
*/
|
||||
public static final String MCH_REFUNDQUERY_URL = MCH_BASE_URL
|
||||
+ "/pay/refundquery";
|
||||
/**
|
||||
* 退款申请(商户平台)
|
||||
*/
|
||||
public static final String MCH_REFUNDAPPLY_URL = MCH_BASE_URL
|
||||
+ "/secapi/pay/refund";
|
||||
/**
|
||||
* 冲正撤销(商户平台)
|
||||
*/
|
||||
public static final String MCH_ORDERREVERSE_URL = MCH_BASE_URL
|
||||
+ "/secapi/pay/reverse";
|
||||
/**
|
||||
* 被扫支付&刷卡支付(商户平台)
|
||||
*/
|
||||
public static final String MCH_MICROPAY_URL = MCH_BASE_URL
|
||||
+ "/pay/micropay";
|
||||
/**
|
||||
* 接口上报(商户平台)
|
||||
*/
|
||||
public static final String MCH_PAYREPORT_URL = MCH_BASE_URL
|
||||
+ "/payitil/report";
|
||||
/**
|
||||
* 发送现金红包(商户平台)
|
||||
*/
|
||||
public static final String MCH_REDPACKSEND_URL = MCH_BASE_URL
|
||||
+ "/mmpaymkttransfers/sendredpack";
|
||||
/**
|
||||
* 查询现金红包(商户平台)
|
||||
*/
|
||||
public static final String MCH_REDPACKQUERY_URL = MCH_BASE_URL
|
||||
+ "/mmpaymkttransfers/gethbinfo";
|
||||
/**
|
||||
* 企业向个人付款(商户平台)
|
||||
*/
|
||||
public static final String MCH_ENPAYMENT_URL = MCH_BASE_URL
|
||||
+ "/mmpaymkttransfers/promotion/transfers";
|
||||
/**
|
||||
* 企业付款查询(商户平台)
|
||||
*/
|
||||
public static final String MCH_ENPAYQUERY_URL = MCH_BASE_URL
|
||||
+ "/mmpaymkttransfers/gettransferinfo";
|
||||
/**
|
||||
* 发放代金券(商户平台)
|
||||
*/
|
||||
public static final String MCH_COUPONSEND_URL = MCH_BASE_URL
|
||||
+ "/mmpaymkttransfers/send_coupon";
|
||||
/**
|
||||
* 查询代金券批次信息(商户平台)
|
||||
*/
|
||||
public static final String MCH_COUPONSTOCKQUERY_URL = MCH_BASE_URL
|
||||
+ "/mmpaymkttransfers/query_coupon_stock";
|
||||
/**
|
||||
* 查询代金券详细信息(商户平台)
|
||||
*/
|
||||
public static final String MCH_COUPONDETAILQUERY_URL = MCH_BASE_URL
|
||||
+ "/promotion/query_coupon";
|
||||
/**
|
||||
* 长链接转换(商户平台)
|
||||
*/
|
||||
public static final String MCH_SHORTURL_URL = MCH_BASE_URL
|
||||
+ "/tools/shorturl";
|
||||
/**
|
||||
* 商户平台下native支付的url
|
||||
*/
|
||||
public static final String MCH_NATIVE_URL = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
|
||||
}
|
||||
@ -0,0 +1,290 @@
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.mch.MchPayPackage;
|
||||
import com.foxinmy.weixin4j.payment.mch.MchPayRequest;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.payment.mch.PrePay;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 支付工具类(JSAPI,NATIVE,MicroPay)
|
||||
*
|
||||
* @className PayUtil
|
||||
* @author jy
|
||||
* @date 2014年10月28日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class PayUtil {
|
||||
|
||||
/**
|
||||
* md5签名(一般用于V3.x支付接口)
|
||||
*
|
||||
* @param obj
|
||||
* 签名对象
|
||||
* @param paySignKey
|
||||
* 支付API的密钥
|
||||
* @return
|
||||
*/
|
||||
public static String paysignMd5(Object obj, String paySignKey) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// a--->string1
|
||||
sb.append(MapUtil.toJoinString(obj, false, false, null));
|
||||
// b--->
|
||||
// 在 string1 最后拼接上 key=paternerKey 得到 stringSignTemp 字符串,并 对
|
||||
// stringSignTemp 进行 md5 运算
|
||||
// 再将得到的 字符串所有字符转换为大写 ,得到 sign 值 signValue。
|
||||
sb.append("&key=").append(paySignKey);
|
||||
return DigestUtil.MD5(sb.toString()).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V3.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param body
|
||||
* 订单描述
|
||||
* @param orderNo
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param notifyUrl
|
||||
* 支付通知地址
|
||||
* @param ip
|
||||
* ip地址
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJson(String openId, String body,
|
||||
String orderNo, double orderFee, String notifyUrl, String ip,
|
||||
WeixinPayAccount weixinAccount) throws PayException {
|
||||
MchPayPackage payPackage = new MchPayPackage(weixinAccount, openId,
|
||||
body, orderNo, orderFee, ip, TradeType.JSAPI);
|
||||
payPackage.setNotifyUrl(notifyUrl);
|
||||
return createPayJsRequestJson(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V3.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJson(MchPayPackage payPackage,
|
||||
WeixinPayAccount weixinAccount) throws PayException {
|
||||
String paySignKey = weixinAccount.getPaySignKey();
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
PrePay prePay = createPrePay(payPackage, paySignKey);
|
||||
MchPayRequest jsPayRequest = new MchPayRequest(prePay);
|
||||
jsPayRequest.setSignType(SignType.MD5);
|
||||
jsPayRequest.setPaySign(paysignMd5(jsPayRequest, paySignKey));
|
||||
return JSON.toJSONString(jsPayRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一下单接口</br>
|
||||
* 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI
|
||||
* 、APP等不同场景生成交易串调起支付。
|
||||
*
|
||||
* @param payPackage
|
||||
* 包含订单信息的对象
|
||||
* @param paySignKey
|
||||
* <font color="red">如果sign为空 则拿paysignkey进行签名</font>
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MchPayPackage
|
||||
* @see com.foxinmy.weixin4j.payment.mch.PrePay
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1">统一下单接口</a>
|
||||
* @return 预支付对象
|
||||
*/
|
||||
private final static WeixinHttpClient httpClient = new WeixinHttpClient();
|
||||
|
||||
public static PrePay createPrePay(MchPayPackage payPackage,
|
||||
String paySignKey) throws PayException {
|
||||
if (StringUtil.isBlank(payPackage.getSign())) {
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
}
|
||||
String payJsRequestXml = XmlStream.toXML(payPackage);
|
||||
try {
|
||||
WeixinResponse response = httpClient.post(
|
||||
PayURLConsts.MCH_UNIFIEDORDER_URL, payJsRequestXml);
|
||||
PrePay prePay = response.getAsObject(new TypeReference<PrePay>() {
|
||||
});
|
||||
if (!prePay.getReturnCode().equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
throw new PayException(prePay.getReturnMsg(),
|
||||
prePay.getReturnCode());
|
||||
}
|
||||
if (!prePay.getResultCode().equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
throw new PayException(prePay.getResultCode(),
|
||||
prePay.getErrCodeDes());
|
||||
}
|
||||
return prePay;
|
||||
} catch (WeixinException e) {
|
||||
throw new PayException(e.getErrorCode(), e.getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 生成编辑地址请求
|
||||
* </p>
|
||||
*
|
||||
* err_msg edit_address:ok获取编辑收货地址成功</br> edit_address:fail获取编辑收货地址失败</br>
|
||||
* userName 收货人姓名</br> telNumber 收货人电话</br> addressPostalCode 邮编</br>
|
||||
* proviceFirstStageName 国标收货地址第一级地址</br> addressCitySecondStageName
|
||||
* 国标收货地址第二级地址</br> addressCountiesThirdStageName 国标收货地址第三级地址</br>
|
||||
* addressDetailInfo 详细收货地址信息</br> nationalCode 收货地址国家码</br>
|
||||
*
|
||||
* @param appId
|
||||
* 公众号的ID
|
||||
* @param url
|
||||
* 当前访问页的URL
|
||||
* @param accessToken
|
||||
* snsapi_base授权时产生的token
|
||||
* @return
|
||||
*/
|
||||
public static String createAddressRequestJson(String appId, String url,
|
||||
String accessToken) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appId", appId);
|
||||
map.put("timeStamp", DateUtil.timestamp2string());
|
||||
map.put("nonceStr", RandomUtil.generateString(16));
|
||||
map.put("url", url);
|
||||
map.put("accessToken", accessToken);
|
||||
String sign = DigestUtil.SHA1(MapUtil.toJoinString(map, false, true,
|
||||
null));
|
||||
map.remove("url");
|
||||
map.remove("accessToken");
|
||||
map.put("scope", "jsapi_address");
|
||||
map.put("signType", SignType.SHA1.name().toLowerCase());
|
||||
map.put("addrSign", sign);
|
||||
|
||||
return JSON.toJSONString(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V3.x NativePay支付(扫码支付)链接
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 支付配置信息
|
||||
* @param productId
|
||||
* 与订单ID等价
|
||||
* @return 支付链接
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
|
||||
*/
|
||||
public static String createNativePayRequestURL(
|
||||
WeixinPayAccount weixinAccount, String productId) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("mch_id", weixinAccount.getMchId());
|
||||
map.put("time_stamp", timestamp);
|
||||
map.put("nonce_str", noncestr);
|
||||
map.put("product_id", productId);
|
||||
String sign = paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
return String.format(PayURLConsts.MCH_NATIVE_URL, sign,
|
||||
weixinAccount.getId(), weixinAccount.getMchId(), productId,
|
||||
timestamp, noncestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交被扫支付
|
||||
*
|
||||
* @param authCode
|
||||
* 扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param attach
|
||||
* 附加数据
|
||||
* @param orderNo
|
||||
* 商户内部唯一订单号
|
||||
* @param orderFee
|
||||
* 商品总额 单位元
|
||||
* @param ip
|
||||
* 订单生成的机器 IP
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付的订单信息
|
||||
* @see {@link com.foxinmy.weixin4j.payment.PayUtil#createMicroPay(MicroPayPackage, WeixinPayAccount)}
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static Order createMicroPay(String authCode, String body,
|
||||
String attach, String orderNo, double orderFee, String ip,
|
||||
WeixinPayAccount weixinAccount) throws WeixinException {
|
||||
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body,
|
||||
attach, orderNo, orderFee, ip, authCode);
|
||||
return createMicroPay(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交被扫支付:收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,由商户收银台或者商户后台调用该接口发起支付.
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付的订单信息
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Order
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10">提交被扫支付API</a>
|
||||
*/
|
||||
public static Order createMicroPay(MicroPayPackage payPackage,
|
||||
WeixinPayAccount weixinAccount) throws WeixinException {
|
||||
String sign = paysignMd5(payPackage, weixinAccount.getPaySignKey());
|
||||
payPackage.setSign(sign);
|
||||
String para = XmlStream.toXML(payPackage);
|
||||
WeixinResponse response = httpClient.post(
|
||||
PayURLConsts.MCH_MICROPAY_URL, para);
|
||||
return response
|
||||
.getAsObject(new TypeReference<com.foxinmy.weixin4j.payment.mch.Order>() {
|
||||
});
|
||||
}
|
||||
|
||||
private static String JSAPI() throws PayException {
|
||||
WeixinPayAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinPayAccount.class);
|
||||
return createPayJsRequestJson("oyFLst1bqtuTcxK-ojF8hOGtLQao", "支付测试",
|
||||
"JSAPI01", 0.01d, "http://127.0.0.1/jsapi/notify", "127.0.0.0",
|
||||
weixinAccount);
|
||||
}
|
||||
|
||||
private static String NATIVE() {
|
||||
WeixinPayAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinPayAccount.class);
|
||||
return createNativePayRequestURL(weixinAccount, "P1");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws PayException {
|
||||
// V3版本下的JS支付
|
||||
System.out.println(JSAPI());
|
||||
// V3版本下的原生支付
|
||||
System.out.println(NATIVE());
|
||||
}
|
||||
}
|
||||
@ -4,20 +4,14 @@
|
||||
|
||||
微信公众平台[V3版本支付](https://mp.weixin.qq.com/paymch/readtemplate?t=mp/business/course3_tmpl&lang=zh_CN)文档
|
||||
|
||||
**在`2014年10月9号`之前申请并审核通过的支付接口应该属于`V2版本`支付,而之后申请的接口则为`V3版本`支付**
|
||||
**在`2014年10月9号`之前申请并审核通过的支付接口应该属于`V2版本`支付,而之后申请的接口则为`V3版本(商户平台)`支付**
|
||||
|
||||
[PayUtil](./PayUtil.java)
|
||||
-------------------------
|
||||
|
||||
* createPayJsRequestJson: 创建JSAPI支付串
|
||||
* createPayJsRequestJson: 创建V3版本(商户平台)的JSAPI支付串
|
||||
|
||||
* createPayJsRequestJsonV2: 创建V2版本的JSAPI支付串
|
||||
|
||||
* createNativePayRequestURLV2: 创建V2版本的扫码支付链接
|
||||
|
||||
* createPayJsRequestJsonV3: 创建V3版本(商户平台)的JSAPI支付串
|
||||
|
||||
* createNativePayRequestURLV3: 创建V3版本(商户平台)的扫码支付链接
|
||||
* createNativePayRequestURL: 创建V3版本(商户平台)的扫码支付链接
|
||||
|
||||
* createPrePay: 调用V3版本(商户平台)的统一订单接口生成预订单数据
|
||||
|
||||
@ -26,14 +20,14 @@
|
||||
* createAddressRequestJson: 生成编辑收货地址请求串
|
||||
|
||||
|
||||
[Pay3Api](./Pay3Api.java)
|
||||
[Pay3Api](../api/Pay3Api.java)
|
||||
-------------------------
|
||||
|
||||
* orderQuery: 订单查询接口
|
||||
|
||||
* refund: 退款申请接口
|
||||
* refundOrder: 退款申请接口
|
||||
|
||||
* reverse: 冲正订单接口
|
||||
* reverseOrder: 冲正订单接口
|
||||
|
||||
* closeOrder: 关闭订单接口
|
||||
|
||||
@ -42,12 +36,12 @@
|
||||
* refundQuery: 退款查询接口
|
||||
|
||||
|
||||
[Pay2Api](./Pay2Api.java)
|
||||
[Pay2Api](../api/Pay2Api.java)
|
||||
-------------------------
|
||||
|
||||
* orderQuery: 订单查询接口
|
||||
|
||||
* refund: 退款申请接口
|
||||
* refundOrder: 退款申请接口
|
||||
|
||||
* downloadbill: 下载对账单接口
|
||||
|
||||
@ -1,36 +1,31 @@
|
||||
package com.foxinmy.weixin4j.mp;
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.api.CashApi;
|
||||
import com.foxinmy.weixin4j.api.CouponApi;
|
||||
import com.foxinmy.weixin4j.api.Pay3Api;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.XmlResult;
|
||||
import com.foxinmy.weixin4j.mp.api.CashApi;
|
||||
import com.foxinmy.weixin4j.mp.api.CouponApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MpApi;
|
||||
import com.foxinmy.weixin4j.mp.api.Pay2Api;
|
||||
import com.foxinmy.weixin4j.mp.api.Pay3Api;
|
||||
import com.foxinmy.weixin4j.mp.api.PayApi;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponDetail;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponStock;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPayment;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.Redpacket;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.mp.type.IdType;
|
||||
import com.foxinmy.weixin4j.mp.type.RefundType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
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.payment.mch.ApiResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.MPPayment;
|
||||
import com.foxinmy.weixin4j.payment.mch.MPPaymentRecord;
|
||||
import com.foxinmy.weixin4j.payment.mch.MPPaymentResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
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.type.BillType;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信支付接口实现
|
||||
@ -39,42 +34,24 @@ import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
* @author jy
|
||||
* @date 2015年1月3日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/index.html">商户平台支付API</a>
|
||||
*/
|
||||
public class WeixinPayProxy {
|
||||
|
||||
private final PayApi payApi;
|
||||
private final Pay2Api pay2Api;
|
||||
private final Pay3Api pay3Api;
|
||||
private final CouponApi couponApi;
|
||||
private final CashApi cashApi;
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
|
||||
/**
|
||||
* 默认使用文件保存token、使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinPayProxy() {
|
||||
this(MpApi.DEFAULT_TOKEN_STORAGER);
|
||||
}
|
||||
private final File DEFAULT_CA_FILE;
|
||||
|
||||
/**
|
||||
* 使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinPayProxy(TokenStorager tokenStorager) {
|
||||
this(MpApi.DEFAULT_WEIXIN_ACCOUNT, tokenStorager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用文件保存token
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 支付相关的公众号账号信息
|
||||
*/
|
||||
public WeixinPayProxy(WeixinMpAccount weixinAccount) {
|
||||
this(weixinAccount, MpApi.DEFAULT_TOKEN_STORAGER);
|
||||
public WeixinPayProxy() {
|
||||
this(JSON.parseObject(ConfigUtil.getValue("account"),
|
||||
WeixinPayAccount.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,94 +59,16 @@ public class WeixinPayProxy {
|
||||
* @param weixinAccount
|
||||
* 支付相关的公众号账号信息
|
||||
*
|
||||
* @param tokenStorager
|
||||
* token的存储策略
|
||||
*/
|
||||
public WeixinPayProxy(WeixinMpAccount weixinAccount,
|
||||
TokenStorager tokenStorager) {
|
||||
this.tokenHolder = new TokenHolder(new WeixinTokenCreator(
|
||||
weixinAccount.getId(), weixinAccount.getSecret()),
|
||||
tokenStorager);
|
||||
this.pay2Api = new Pay2Api(weixinAccount, tokenHolder);
|
||||
this.pay3Api = new Pay3Api(weixinAccount, tokenHolder);
|
||||
int version = weixinAccount.getVersion();
|
||||
if (version == 2) {
|
||||
this.payApi = this.pay2Api;
|
||||
} else if (version == 3) {
|
||||
this.payApi = this.pay3Api;
|
||||
} else {
|
||||
this.payApi = this.pay3Api;
|
||||
}
|
||||
public WeixinPayProxy(WeixinPayAccount weixinAccount) {
|
||||
this.pay3Api = new Pay3Api(weixinAccount);
|
||||
this.couponApi = new CouponApi(weixinAccount);
|
||||
this.cashApi = new CashApi(weixinAccount);
|
||||
}
|
||||
|
||||
public TokenHolder getTokenHolder() {
|
||||
return this.tokenHolder;
|
||||
this.DEFAULT_CA_FILE = new File(ConfigUtil.getClassPathValue("ca_file"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货通知
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param transid
|
||||
* 交易单号
|
||||
* @param outTradeNo
|
||||
* 订单号
|
||||
* @param status
|
||||
* 成功|失败
|
||||
* @param statusMsg
|
||||
* status为失败时携带的信息
|
||||
* @return 发货处理结果
|
||||
* @since V2 & V3
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult deliverNotify(String openId, String transid,
|
||||
String outTradeNo, boolean status, String statusMsg)
|
||||
throws WeixinException {
|
||||
return payApi.deliverNotify(openId, transid, outTradeNo, status,
|
||||
statusMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 维权处理
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param feedbackId
|
||||
* 维权单号
|
||||
* @return 调用结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @since V2 & V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult updateFeedback(String openId, String feedbackId)
|
||||
throws WeixinException {
|
||||
return payApi.updateFeedback(openId, feedbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* V2订单查询
|
||||
*
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id、out_trade_no 二 选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @since V2
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.Order
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @return 订单详情
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v2.Order orderQueryV2(
|
||||
String outTradeNo) throws WeixinException {
|
||||
return pay2Api.orderQuery(new IdQuery(outTradeNo, IdType.TRADENO));
|
||||
}
|
||||
|
||||
/**
|
||||
* V3订单查询
|
||||
* 订单查询
|
||||
* <p>
|
||||
* 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;</br> 调用支付接口后,返回系统错误或未知交易状态情况;</br>
|
||||
* 调用被扫支付API,返回USERPAYING的状态;</br> 调用关单或撤销接口API之前,需确认支付状态;
|
||||
@ -179,133 +78,20 @@ public class WeixinPayProxy {
|
||||
* 商户系统内部的订单号, transaction_id、out_trade_no 二 选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @since V3
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.Order
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Order
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2">订单查询API</a>
|
||||
* @return 订单详情
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v3.Order orderQueryV3(IdQuery idQuery)
|
||||
throws WeixinException {
|
||||
public Order orderQuery(IdQuery idQuery) throws WeixinException {
|
||||
return pay3Api.orderQuery(idQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* V2申请退款(请求需要双向证书)</br>
|
||||
* <p style="color:red">
|
||||
* 交易时间超过 1 年的订单无法提交退款; </br> 支持部分退款,部分退需要设置相同的订单号和不同的 out_refund_no。一笔退款失
|
||||
* 败后重新提交,要采用原来的 out_refund_no。总退款金额不能超过用户实际支付金额。</br>
|
||||
* </p>
|
||||
*
|
||||
* @param caFile
|
||||
* 证书文件(后缀为*.pfx)
|
||||
* @param idQuery
|
||||
* ) 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @param outRefundNo
|
||||
* 商户系统内部的退款单号,商 户系统内部唯一,同一退款单号多次请求只退一笔
|
||||
* @param totalFee
|
||||
* 订单总金额,单位为元
|
||||
* @param refundFee
|
||||
* 退款总金额,单位为元,可以做部分退款
|
||||
* @param opUserId
|
||||
* 操作员帐号, 默认为商户号
|
||||
* @param opUserPasswd
|
||||
* 操作员密码
|
||||
*
|
||||
* @return 退款申请结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundResult
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v2.RefundResult refundV2(
|
||||
File caFile, IdQuery idQuery, String outRefundNo, double totalFee,
|
||||
double refundFee, String opUserId, String opUserPasswd)
|
||||
throws WeixinException {
|
||||
return pay2Api.refund(caFile, idQuery, outRefundNo, totalFee,
|
||||
refundFee, opUserId, opUserPasswd);
|
||||
}
|
||||
|
||||
/**
|
||||
* V2退款申请采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#refundV2(File, IdQuery, String, double, double, String,String)}
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v2.RefundResult refundV2(
|
||||
IdQuery idQuery, String outRefundNo, double totalFee,
|
||||
double refundFee, String opUserId, String opUserPasswd)
|
||||
throws WeixinException {
|
||||
return refundV2(PayApi.DEFAULT_CA_FILE, idQuery, outRefundNo, totalFee,
|
||||
refundFee, opUserId, opUserPasswd);
|
||||
}
|
||||
|
||||
/**
|
||||
* V2退款申请
|
||||
*
|
||||
* @param caFile
|
||||
* 证书文件(V2版本后缀为*.pfx)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @param outRefundNo
|
||||
* 商户系统内部的退款单号,商 户系统内部唯一,同一退款单号多次请求只退一笔
|
||||
* @param totalFee
|
||||
* 订单总金额,单位为元
|
||||
* @param refundFee
|
||||
* 退款总金额,单位为元,可以做部分退款
|
||||
* @param opUserId
|
||||
* 操作员帐号, 默认为商户号
|
||||
* @param opUserPasswd
|
||||
* 操作员密码,默认为商户后台登录密码
|
||||
* @param recvUserId
|
||||
* 转账退款接收退款的财付通帐号。 一般无需填写,只有退银行失败,资金转入商 户号现金账号时(即状态为转入代发,查询返 回的
|
||||
* refund_status 是 7 或 11),填写原退款 单号并填写此字段,资金才会退到指定财付通
|
||||
* 账号。其他情况此字段忽略
|
||||
* @param reccvUserName
|
||||
* 转账退款接收退款的姓名(需与接收退款的财 付通帐号绑定的姓名一致)
|
||||
* @param refundType
|
||||
* 为空或者填 1:商户号余额退款;2:现金帐号 退款;3:优先商户号退款,若商户号余额不足, 再做现金帐号退款。使用 2 或
|
||||
* 3 时,需联系财 付通开通此功能
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundResult
|
||||
* @return 退款结果
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v2.RefundResult refundV2(
|
||||
File caFile, IdQuery idQuery, String outRefundNo, double totalFee,
|
||||
double refundFee, String opUserId, String opUserPasswd,
|
||||
String recvUserId, String reccvUserName, RefundType refundType)
|
||||
throws WeixinException {
|
||||
return pay2Api.refund(caFile, idQuery, outRefundNo, totalFee,
|
||||
refundFee, opUserId, opUserPasswd, recvUserId, reccvUserName,
|
||||
refundType);
|
||||
}
|
||||
|
||||
/**
|
||||
* V2退款查询</br> 退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款 3 个工作日后重新查询退款状态
|
||||
*
|
||||
* @param idQuery
|
||||
* 单号 refund_id、out_refund_no、 out_trade_no 、 transaction_id
|
||||
* 四个参数必填一个,优先级为:
|
||||
* refund_id>out_refund_no>transaction_id>out_trade_no
|
||||
* @return 退款记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundRecord
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v2.RefundRecord refundQueryV2(
|
||||
IdQuery idQuery) throws WeixinException {
|
||||
return pay2Api.refundQuery(idQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* V3申请退款(请求需要双向证书)</br>
|
||||
* 申请退款(请求需要双向证书)</br>
|
||||
* <p>
|
||||
* 当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后,
|
||||
* 按照退款规则将支付款按原路退到买家帐号上。
|
||||
@ -333,36 +119,36 @@ public class WeixinPayProxy {
|
||||
* 操作员帐号, 默认为商户号
|
||||
*
|
||||
* @return 退款申请结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundResult
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RefundResult
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4">申请退款API</a>
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v3.RefundResult refundV3(
|
||||
public com.foxinmy.weixin4j.payment.mch.RefundResult refundApply(
|
||||
File caFile, IdQuery idQuery, String outRefundNo, double totalFee,
|
||||
double refundFee, CurrencyType refundFeeType, String opUserId)
|
||||
throws WeixinException {
|
||||
return pay3Api.refund(caFile, idQuery, outRefundNo, totalFee,
|
||||
return pay3Api.refundApply(caFile, idQuery, outRefundNo, totalFee,
|
||||
refundFee, refundFeeType, opUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* V3退款申请采用properties中配置的ca文件
|
||||
* 退款申请采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#refundV3(File, IdQuery, String, double, double,CurrencyType, String)}
|
||||
* @see {@link com.foxinmy.weixin4j.payment.WeixinPayProxy#refundV3(File, IdQuery, String, double, double,CurrencyType, String)}
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v3.RefundResult refundV3(
|
||||
public com.foxinmy.weixin4j.payment.mch.RefundResult refundApply(
|
||||
IdQuery idQuery, String outRefundNo, double totalFee,
|
||||
double refundFee, String opUserId) throws WeixinException {
|
||||
return pay3Api.refund(PayApi.DEFAULT_CA_FILE, idQuery, outRefundNo,
|
||||
return pay3Api.refundApply(DEFAULT_CA_FILE, idQuery, outRefundNo,
|
||||
totalFee, refundFee, CurrencyType.CNY, opUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* V3退款查询
|
||||
* 退款查询
|
||||
* <p>
|
||||
* 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
|
||||
* </p>
|
||||
@ -372,16 +158,15 @@ public class WeixinPayProxy {
|
||||
* 四个参数必填一个,优先级为:
|
||||
* refund_id>out_refund_no>transaction_id>out_trade_no
|
||||
* @return 退款记录
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundRecord
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RefundRecord
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5">退款查询API</a>
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public com.foxinmy.weixin4j.mp.payment.v3.RefundRecord refundQueryV3(
|
||||
IdQuery idQuery) throws WeixinException {
|
||||
public RefundRecord refundQueryV3(IdQuery idQuery) throws WeixinException {
|
||||
return pay3Api.refundQuery(idQuery);
|
||||
}
|
||||
|
||||
@ -399,14 +184,14 @@ public class WeixinPayProxy {
|
||||
* REFUND,返回当日退款订单
|
||||
* @return excel表格
|
||||
* @since V2 & V3
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">下载对账单API</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public File downloadbill(Date billDate, BillType billType)
|
||||
throws WeixinException {
|
||||
return payApi.downloadbill(billDate, billType);
|
||||
return pay3Api.downloadbill(billDate, billType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,15 +206,15 @@ public class WeixinPayProxy {
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @return 撤销结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult reverse(File caFile, IdQuery idQuery)
|
||||
public ApiResult reverseOrder(File caFile, IdQuery idQuery)
|
||||
throws WeixinException {
|
||||
return payApi.reverse(caFile, idQuery);
|
||||
return pay3Api.reverseOrder(caFile, idQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,8 +226,8 @@ public class WeixinPayProxy {
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinProxy#reverse(File, IdQuery)}
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult reverse(IdQuery idQuery) throws WeixinException {
|
||||
return payApi.reverse(PayApi.DEFAULT_CA_FILE, idQuery);
|
||||
public ApiResult reverseOrder(IdQuery idQuery) throws WeixinException {
|
||||
return pay3Api.reverseOrder(DEFAULT_CA_FILE, idQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -455,15 +240,15 @@ public class WeixinPayProxy {
|
||||
* @param outTradeNo
|
||||
* 商户系统内部的订单号
|
||||
* @return 执行结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3">关闭订单API</a>
|
||||
*/
|
||||
public ApiResult closeOrder(String outTradeNo) throws WeixinException {
|
||||
return payApi.closeOrder(outTradeNo);
|
||||
return pay3Api.closeOrder(outTradeNo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -473,16 +258,16 @@ public class WeixinPayProxy {
|
||||
* @param url
|
||||
* 具有native标识的支付URL
|
||||
* @return 转换后的短链接
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_9">转换短链接API</a>
|
||||
* @since V2 & V3
|
||||
* @since V3
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getPayShorturl(String url) throws WeixinException {
|
||||
return payApi.getShorturl(url);
|
||||
return pay3Api.getShorturl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,8 +287,8 @@ public class WeixinPayProxy {
|
||||
* @param returnXml
|
||||
* 调用接口返回的基本数据
|
||||
* @return 处理结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.api.PayApi
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_8">接口测试上报API</a>
|
||||
* @throws WeixinException
|
||||
@ -529,8 +314,8 @@ public class WeixinPayProxy {
|
||||
* @param opUserId
|
||||
* 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限 可为空
|
||||
* @return 发放结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.CouponApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponResult
|
||||
* @see com.foxinmy.weixin4j.api.CouponApi
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php?chapter=12_3">发放代金券接口</a>
|
||||
* @throws WeixinException
|
||||
@ -545,11 +330,11 @@ public class WeixinPayProxy {
|
||||
/**
|
||||
* 发放代金券采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#sendCoupon(File, String, String, String, String)}
|
||||
* @see {@link com.foxinmy.weixin4j.payment.WeixinPayProxy#sendCoupon(File, String, String, String, String)}
|
||||
*/
|
||||
public CouponResult sendCoupon(String couponStockId, String partnerTradeNo,
|
||||
String openId) throws WeixinException {
|
||||
return couponApi.sendCoupon(PayApi.DEFAULT_CA_FILE, couponStockId,
|
||||
return couponApi.sendCoupon(DEFAULT_CA_FILE, couponStockId,
|
||||
partnerTradeNo, openId, null);
|
||||
}
|
||||
|
||||
@ -559,8 +344,8 @@ public class WeixinPayProxy {
|
||||
* @param couponStockId
|
||||
* 代金券批次ID
|
||||
* @return 代金券批次信息
|
||||
* @see com.foxinmy.weixin4j.mp.api.CouponApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponStock
|
||||
* @see com.foxinmy.weixin4j.api.CouponApi
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponStock
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php?chapter=12_4">查询代金券信息</a>
|
||||
* @throws WeixinException
|
||||
@ -576,8 +361,8 @@ public class WeixinPayProxy {
|
||||
* @param couponId
|
||||
* 代金券ID
|
||||
* @return 代金券详细信息
|
||||
* @see com.foxinmy.weixin4j.mp.api.CouponApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponDetail
|
||||
* @see com.foxinmy.weixin4j.api.CouponApi
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponDetail
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/sp_coupon.php?chapter=12_5">查询代金券详细信息</a>
|
||||
* @throws WeixinException
|
||||
@ -595,9 +380,9 @@ public class WeixinPayProxy {
|
||||
* @param redpacket
|
||||
* 红包信息
|
||||
* @return 发放结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.Redpacket
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult
|
||||
* @see com.foxinmy.weixin4j.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.payment.mch.Redpacket
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RedpacketSendResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5">红包接口说明</a>
|
||||
* @throws WeixinException
|
||||
@ -610,11 +395,11 @@ public class WeixinPayProxy {
|
||||
/**
|
||||
* 发放红包采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#sendRedpack(File, Redpacket)}
|
||||
* @see {@link com.foxinmy.weixin4j.payment.WeixinPayProxy#sendRedpack(File, Redpacket)}
|
||||
*/
|
||||
public RedpacketSendResult sendRedpack(Redpacket redpacket)
|
||||
throws WeixinException {
|
||||
return cashApi.sendRedpack(PayApi.DEFAULT_CA_FILE, redpacket);
|
||||
return cashApi.sendRedpack(DEFAULT_CA_FILE, redpacket);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -625,8 +410,8 @@ public class WeixinPayProxy {
|
||||
* @param outTradeNo
|
||||
* 商户发放红包的商户订单号
|
||||
* @return 红包记录
|
||||
* @see com.foxinmy.weixin4j.mp.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RedpacketRecord
|
||||
* @see com.foxinmy.weixin4j.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RedpacketRecord
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_6">查询红包接口说明</a>
|
||||
* @throws WeixinException
|
||||
@ -639,11 +424,11 @@ public class WeixinPayProxy {
|
||||
/**
|
||||
* 查询红包采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#queryRedpack(File,String)}
|
||||
* @see {@link com.foxinmy.weixin4j.payment.WeixinPayProxy#queryRedpack(File,String)}
|
||||
*/
|
||||
public RedpacketRecord queryRedpack(String outTradeNo)
|
||||
throws WeixinException {
|
||||
return cashApi.queryRedpack(PayApi.DEFAULT_CA_FILE, outTradeNo);
|
||||
return cashApi.queryRedpack(DEFAULT_CA_FILE, outTradeNo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -654,9 +439,9 @@ public class WeixinPayProxy {
|
||||
* @param mpPayment
|
||||
* 付款信息
|
||||
* @return 付款结果
|
||||
* @see com.foxinmy.weixin4j.mp.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPayment
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult
|
||||
* @see com.foxinmy.weixin4j.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MPPayment
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MPPaymentResult
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_1">企业付款</a>
|
||||
* @throws WeixinException
|
||||
@ -669,11 +454,11 @@ public class WeixinPayProxy {
|
||||
/**
|
||||
* 企业付款采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#mpPayment(File, MPPayment)}
|
||||
* @see {@link com.foxinmy.weixin4j.payment.WeixinPayProxy#mpPayment(File, MPPayment)}
|
||||
*/
|
||||
public MPPaymentResult mpPayment(MPPayment mpPayment)
|
||||
throws WeixinException {
|
||||
return cashApi.mpPayment(PayApi.DEFAULT_CA_FILE, mpPayment);
|
||||
return cashApi.mpPayment(DEFAULT_CA_FILE, mpPayment);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -684,8 +469,8 @@ public class WeixinPayProxy {
|
||||
* @param outTradeNo
|
||||
* 商户调用企业付款API时使用的商户订单号
|
||||
* @return 付款记录
|
||||
* @see com.foxinmy.weixin4j.mp.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.MPPaymentRecord
|
||||
* @see com.foxinmy.weixin4j.api.CashApi
|
||||
* @see com.foxinmy.weixin4j.payment.mch.MPPaymentRecord
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/mch_pay.php?chapter=14_3">企业付款查询</a>
|
||||
* @throws WeixinException
|
||||
@ -698,10 +483,10 @@ public class WeixinPayProxy {
|
||||
/**
|
||||
* 企业付款查询采用properties中配置的ca文件
|
||||
*
|
||||
* @see {@link com.foxinmy.weixin4j.mp.WeixinPayProxy#mpPaymentQuery(File, String)}
|
||||
* @see {@link com.foxinmy.weixin4j.payment.WeixinPayProxy#mpPaymentQuery(File, String)}
|
||||
*/
|
||||
public MPPaymentRecord mpPaymentQuery(String outTradeNo)
|
||||
throws WeixinException {
|
||||
return cashApi.mpPaymentQuery(PayApi.DEFAULT_CA_FILE, outTradeNo);
|
||||
return cashApi.mpPaymentQuery(DEFAULT_CA_FILE, outTradeNo);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.coupon;
|
||||
package com.foxinmy.weixin4j.payment.coupon;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -8,10 +8,10 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.type.CouponStatus;
|
||||
import com.foxinmy.weixin4j.mp.type.CouponStockType;
|
||||
import com.foxinmy.weixin4j.mp.type.CouponType;
|
||||
import com.foxinmy.weixin4j.payment.mch.ApiResult;
|
||||
import com.foxinmy.weixin4j.type.CouponStatus;
|
||||
import com.foxinmy.weixin4j.type.CouponStockType;
|
||||
import com.foxinmy.weixin4j.type.CouponType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.coupon;
|
||||
package com.foxinmy.weixin4j.payment.coupon;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.coupon;
|
||||
package com.foxinmy.weixin4j.payment.coupon;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.ApiResult;
|
||||
|
||||
/**
|
||||
* 代金券发放结果
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.coupon;
|
||||
package com.foxinmy.weixin4j.payment.coupon;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -8,9 +8,9 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.type.CouponStockStatus;
|
||||
import com.foxinmy.weixin4j.mp.type.CouponType;
|
||||
import com.foxinmy.weixin4j.payment.mch.ApiResult;
|
||||
import com.foxinmy.weixin4j.type.CouponStockStatus;
|
||||
import com.foxinmy.weixin4j.type.CouponType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.MPPaymentCheckNameType;
|
||||
import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.MPPaymentCheckNameType;
|
||||
import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -8,15 +8,15 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayPackage;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.PayPackage;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
|
||||
/**
|
||||
* V3支付的订单详情
|
||||
* 支付的订单详情
|
||||
*
|
||||
* @className PayPackageV3
|
||||
* @className MchPayPackage
|
||||
* @author jy
|
||||
* @date 2014年10月21日
|
||||
* @since JDK 1.7
|
||||
@ -24,7 +24,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class PayPackageV3 extends PayPackage {
|
||||
public class MchPayPackage extends PayPackage {
|
||||
|
||||
private static final long serialVersionUID = 8944928173669656177L;
|
||||
|
||||
@ -71,18 +71,18 @@ public class PayPackageV3 extends PayPackage {
|
||||
@JSONField(name = "product_id")
|
||||
private String productId;
|
||||
|
||||
protected PayPackageV3() {
|
||||
protected MchPayPackage() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public PayPackageV3(WeixinMpAccount weixinAccount, String openId,
|
||||
|
||||
public MchPayPackage(WeixinPayAccount weixinAccount, String openId,
|
||||
String body, String outTradeNo, double totalFee,
|
||||
String spbillCreateIp, TradeType tradeType) {
|
||||
this(weixinAccount, openId, body, null, outTradeNo, totalFee, null,
|
||||
spbillCreateIp, tradeType);
|
||||
}
|
||||
|
||||
public PayPackageV3(WeixinMpAccount weixinAccount, String openId,
|
||||
public MchPayPackage(WeixinPayAccount weixinAccount, String openId,
|
||||
String body, String attach, String outTradeNo, double totalFee,
|
||||
String notifyUrl, String spbillCreateIp, TradeType tradeType) {
|
||||
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
|
||||
@ -91,7 +91,7 @@ public class PayPackageV3 extends PayPackage {
|
||||
notifyUrl, tradeType, openId, null);
|
||||
}
|
||||
|
||||
public PayPackageV3(String appid, String mchId, String deviceInfo,
|
||||
public MchPayPackage(String appid, String mchId, String deviceInfo,
|
||||
String nonceStr, String body, String attach, String outTradeNo,
|
||||
double totalFee, String spbillCreateIp, Date timeStart,
|
||||
Date timeExpire, String goodsTag, String notifyUrl,
|
||||
@ -149,7 +149,7 @@ public class PayPackageV3 extends PayPackage {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PayPackageV3 [appid=" + appid + ", mchId=" + mchId
|
||||
return "MchPayPackage [appid=" + appid + ", mchId=" + mchId
|
||||
+ ", deviceInfo=" + deviceInfo + ", nonceStr=" + nonceStr
|
||||
+ ", sign=" + sign + ", tradeType=" + tradeType + ", openid="
|
||||
+ openid + ", productId=" + productId + ", " + super.toString()
|
||||
@ -1,14 +1,14 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
|
||||
/**
|
||||
* V3 JS支付:get_brand_wcpay_request</br>
|
||||
* JS支付:get_brand_wcpay_request</br>
|
||||
* <p>
|
||||
* get_brand_wcpay_request:ok 支付成功<br>
|
||||
* get_brand_wcpay_request:cancel 支付过程中用户取消<br>
|
||||
@ -18,29 +18,29 @@ import com.foxinmy.weixin4j.mp.payment.PayRequest;
|
||||
* NATIVE支付:PayRequest.TradeType=NATIVE
|
||||
* </p>
|
||||
*
|
||||
* @className PayRequestV3
|
||||
* @className PayRequest
|
||||
* @author jy
|
||||
* @date 2014年8月17日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.PrePay
|
||||
* @see com.foxinmy.weixin4j.payment.mch.PrePay
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class PayRequestV3 extends PayRequest {
|
||||
public class MchPayRequest extends PayRequest {
|
||||
|
||||
private static final long serialVersionUID = -5972173459255255197L;
|
||||
|
||||
protected PayRequestV3() {
|
||||
protected MchPayRequest() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public PayRequestV3(PrePay prePay) throws PayException {
|
||||
public MchPayRequest(PrePay prePay) throws PayException {
|
||||
this.setAppId(prePay.getAppId());
|
||||
this.setPackageInfo("prepay_id=" + prePay.getPrepayId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JsPayRequestV3 [" + super.toString() + "]";
|
||||
return "MchPayRequest [" + super.toString() + "]";
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -6,9 +6,9 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* V3 Native支付回调时POST的信息
|
||||
* Native支付回调时POST的信息
|
||||
*
|
||||
* @className PayNativeNotifyV3
|
||||
* @className PayNativeNotify
|
||||
* @author jy
|
||||
* @date 2014年10月30日
|
||||
* @since JDK 1.7
|
||||
@ -16,7 +16,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class NativePayNotifyV3 extends ApiResult {
|
||||
public class NativePayNotify extends ApiResult {
|
||||
|
||||
private static final long serialVersionUID = 4515471400239795492L;
|
||||
|
||||
@ -26,7 +26,7 @@ public class NativePayNotifyV3 extends ApiResult {
|
||||
@XmlElement(name = "product_id")
|
||||
private String productId;
|
||||
|
||||
protected NativePayNotifyV3() {
|
||||
protected NativePayNotify() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class NativePayNotifyV3 extends ApiResult {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NativePayNotifyV3 [productId=" + productId + ", "
|
||||
return "NativePayNotify [productId=" + productId + ", "
|
||||
+ super.toString() + "]";
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -8,11 +8,11 @@ import javax.xml.bind.annotation.XmlTransient;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
|
||||
/**
|
||||
* V3 Native支付时的回调响应
|
||||
* Native支付时的回调响应
|
||||
*
|
||||
* @className NativePayResponseV3
|
||||
* @author jy
|
||||
@ -22,7 +22,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class NativePayResponseV3 extends ApiResult {
|
||||
public class NativePayResponse extends ApiResult {
|
||||
|
||||
private static final long serialVersionUID = 6119895998783333012L;
|
||||
|
||||
@ -32,10 +32,10 @@ public class NativePayResponseV3 extends ApiResult {
|
||||
|
||||
private String prepay_id;
|
||||
|
||||
protected NativePayResponseV3() {
|
||||
protected NativePayResponse() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 一般作为校验失败时返回
|
||||
*
|
||||
@ -45,7 +45,7 @@ public class NativePayResponseV3 extends ApiResult {
|
||||
* 结果消息
|
||||
* @throws PayException
|
||||
*/
|
||||
public NativePayResponseV3(String returnMsg, String resultMsg) {
|
||||
public NativePayResponse(String returnMsg, String resultMsg) {
|
||||
super.setReturnMsg(returnMsg);
|
||||
super.setReturnCode(Consts.FAIL);
|
||||
super.setErrCodeDes(resultMsg);
|
||||
@ -59,7 +59,7 @@ public class NativePayResponseV3 extends ApiResult {
|
||||
* 订单信息
|
||||
* @throws PayException
|
||||
*/
|
||||
public NativePayResponseV3(PayPackageV3 payPackage, String paysignKey)
|
||||
public NativePayResponse(MchPayPackage payPackage, String paysignKey)
|
||||
throws PayException {
|
||||
super.setReturnCode(Consts.SUCCESS);
|
||||
this.setResultCode(Consts.SUCCESS);
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -9,10 +9,10 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeState;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.payment.coupon.CouponInfo;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.TradeState;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResult;
|
||||
@ -1,11 +1,11 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
|
||||
/**
|
||||
* V3预订单信息
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -11,9 +11,9 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.http.weixin.XmlResult;
|
||||
import com.foxinmy.weixin4j.mp.type.RedpacketSendType;
|
||||
import com.foxinmy.weixin4j.mp.type.RedpacketStatus;
|
||||
import com.foxinmy.weixin4j.mp.type.RedpacketType;
|
||||
import com.foxinmy.weixin4j.type.RedpacketSendType;
|
||||
import com.foxinmy.weixin4j.type.RedpacketStatus;
|
||||
import com.foxinmy.weixin4j.type.RedpacketType;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -8,10 +8,10 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.mp.type.RefundChannel;
|
||||
import com.foxinmy.weixin4j.mp.type.RefundStatus;
|
||||
import com.foxinmy.weixin4j.payment.coupon.CouponInfo;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.RefundChannel;
|
||||
import com.foxinmy.weixin4j.type.RefundStatus;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResult;
|
||||
|
||||
@ -127,7 +127,7 @@ public class RefundDetail extends ApiResult {
|
||||
/**
|
||||
* 代金券信息
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo
|
||||
* @see com.foxinmy.weixin4j.payment.coupon.CouponInfo
|
||||
*/
|
||||
@ListsuffixResult
|
||||
private List<CouponInfo> couponList;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResult;
|
||||
|
||||
/**
|
||||
@ -86,7 +86,7 @@ public class RefundRecord extends ApiResult {
|
||||
/**
|
||||
* 退款详情
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail
|
||||
* @see com.foxinmy.weixin4j.payment.mch.RefundDetail
|
||||
*/
|
||||
@ListsuffixResult({ "^out_refund_no(_\\d)$", "^refund_.*(_\\d)$" })
|
||||
private List<RefundDetail> refundList;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v3;
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 对账单类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 代金券状态
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 代金券批次状态
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 代金券批次类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 代金券类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 币种
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* ID类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 企业付款检查收款人姓名的策略
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 二维码类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 红包发放类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 红包状态
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 红包类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 退款渠道
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 退款类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 签名类型
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 交易状态
|
||||
@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
package com.foxinmy.weixin4j.type;
|
||||
|
||||
/**
|
||||
* 微信支付类型
|
||||
@ -29,7 +29,7 @@ weixin4j-mp
|
||||
|
||||
* Pay2Api `V2支付API`
|
||||
|
||||
* Pay3Api `V3支付API`
|
||||
* Pay3Api `V3(商户平台)支付API`
|
||||
|
||||
* CouponApi `代金券API`
|
||||
|
||||
@ -39,7 +39,7 @@ weixin4j-mp
|
||||
|
||||
* CashApi `现金API`
|
||||
|
||||
* PayUtil [微信支付工具类](./src/main/java/com/foxinmy/weixin4j/mp/payment/PayUtil.java)
|
||||
* PayUtil [微信支付工具类](https://github.com/foxinmy/weixin4j/tree/master/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayUtil.java)
|
||||
|
||||
如何使用
|
||||
--------
|
||||
|
||||
@ -2,10 +2,7 @@ package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.api.BaseApi;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信公众平台API
|
||||
@ -20,16 +17,10 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
public class MpApi extends BaseApi {
|
||||
|
||||
private final static ResourceBundle WEIXIN_BUNDLE;
|
||||
/**
|
||||
* 默认使用weixin4j.properties文件中的公众号信息
|
||||
*/
|
||||
public final static WeixinMpAccount DEFAULT_WEIXIN_ACCOUNT;
|
||||
|
||||
static {
|
||||
WEIXIN_BUNDLE = ResourceBundle
|
||||
.getBundle("com/foxinmy/weixin4j/mp/api/weixin");
|
||||
DEFAULT_WEIXIN_ACCOUNT = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinMpAccount.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -28,21 +28,24 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.SSLHttpClinet;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.mp.type.RefundType;
|
||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.OrderV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.PayUtil2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundResultV2;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.type.BillType;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.RefundType;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
@ -59,13 +62,25 @@ import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Pay2Api extends PayApi {
|
||||
public class Pay2Api extends MpApi {
|
||||
|
||||
private final HelperApi helperApi;
|
||||
private final WeixinPayAccount weixinAccount;
|
||||
private final TokenHolder tokenHolder;
|
||||
|
||||
public Pay2Api(WeixinMpAccount weixinAccount, TokenHolder tokenHolder) {
|
||||
super(weixinAccount, tokenHolder);
|
||||
this.helperApi = new HelperApi(tokenHolder);
|
||||
public Pay2Api() {
|
||||
this(JSON.parseObject(ConfigUtil.getValue("account"),
|
||||
WeixinPayAccount.class));
|
||||
}
|
||||
|
||||
public Pay2Api(WeixinPayAccount weixinAccount) {
|
||||
this(weixinAccount, DEFAULT_TOKEN_STORAGER);
|
||||
}
|
||||
|
||||
public Pay2Api(WeixinPayAccount weixinAccount, TokenStorager tokenStorager) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.tokenHolder = new TokenHolder(new WeixinTokenCreator(
|
||||
weixinAccount.getId(), weixinAccount.getSecret()),
|
||||
tokenStorager);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,12 +89,12 @@ public class Pay2Api extends PayApi {
|
||||
* @param idQuery
|
||||
* 订单号
|
||||
* @return 订单信息
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.Order
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.OrderV2
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public Order orderQuery(IdQuery idQuery) throws WeixinException {
|
||||
String orderquery_uri = getRequestUri("orderquery_uri");
|
||||
public OrderV2 orderQuery(IdQuery idQuery) throws WeixinException {
|
||||
String orderquery_uri = getRequestUri("orderquery_v2_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(idQuery.getType().getName()).append("=")
|
||||
@ -97,7 +112,7 @@ public class Pay2Api extends PayApi {
|
||||
obj.put("appkey", weixinAccount.getPaySignKey());
|
||||
obj.put("package", sb.toString());
|
||||
obj.put("timestamp", timestamp);
|
||||
String signature = PayUtil.paysignSha(obj);
|
||||
String signature = PayUtil2.paysignSha(obj);
|
||||
|
||||
obj.clear();
|
||||
obj.put("appid", weixinAccount.getId());
|
||||
@ -111,7 +126,7 @@ public class Pay2Api extends PayApi {
|
||||
obj.toJSONString());
|
||||
|
||||
String order_info = response.getAsJson().getString("order_info");
|
||||
Order order = JSON.parseObject(order_info, Order.class,
|
||||
OrderV2 order = JSON.parseObject(order_info, OrderV2.class,
|
||||
Feature.IgnoreNotMatch);
|
||||
if (order.getRetCode() != 0) {
|
||||
throw new WeixinException(Integer.toString(order.getRetCode()),
|
||||
@ -144,15 +159,14 @@ public class Pay2Api extends PayApi {
|
||||
* 如 opUserPasswd
|
||||
*
|
||||
* @return 退款申请结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundResult
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundResultV2
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
@Override
|
||||
protected RefundResult refund(File caFile, IdQuery idQuery,
|
||||
protected RefundResultV2 refundApply(File caFile, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, Map<String, String> mopara) throws WeixinException {
|
||||
String refund_uri = getRequestUri("refund_v2_uri");
|
||||
String refund_uri = getRequestUri("refundapply_v2_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
@ -189,7 +203,7 @@ public class Pay2Api extends PayApi {
|
||||
CertificateFactory cf = CertificateFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.X509);
|
||||
java.security.cert.Certificate cert = cf
|
||||
.generateCertificate(PayUtil.class
|
||||
.generateCertificate(Pay2Api.class
|
||||
.getResourceAsStream("cacert.pem"));
|
||||
ks = KeyStore
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.JKS);
|
||||
@ -229,7 +243,7 @@ public class Pay2Api extends PayApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
return response.getAsObject(new TypeReference<RefundResult>() {
|
||||
return response.getAsObject(new TypeReference<RefundResultV2>() {
|
||||
});
|
||||
}
|
||||
|
||||
@ -251,14 +265,14 @@ public class Pay2Api extends PayApi {
|
||||
* 操作员帐号, 默认为商户号
|
||||
* @param opUserPasswd
|
||||
* 操作员密码,默认为商户后台登录密码
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.Pay2Api#refund(File, IdQuery, String, double, double, String, Map)}
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.Pay2Api#refundApply(File, IdQuery, String, double, double, String, Map)}
|
||||
*/
|
||||
public RefundResult refund(File caFile, IdQuery idQuery,
|
||||
public RefundResultV2 refundApply(File caFile, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, String opUserPasswd) throws WeixinException {
|
||||
Map<String, String> mopara = new HashMap<String, String>();
|
||||
mopara.put("op_user_passwd", DigestUtil.MD5(opUserPasswd));
|
||||
return refund(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
return refundApply(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
opUserId, mopara);
|
||||
}
|
||||
|
||||
@ -289,10 +303,10 @@ public class Pay2Api extends PayApi {
|
||||
* @param refundType
|
||||
* 为空或者填 1:商户号余额退款;2:现金帐号 退款;3:优先商户号退款,若商户号余额不足, 再做现金帐号退款。使用 2 或
|
||||
* 3 时,需联系财 付通开通此功能
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.Pay2Api#refund(File, IdQuery, String, double, double, String, Map)}
|
||||
* @see {@link com.foxinmy.weixin4j.mp.api.Pay2Api#refundApply(File, IdQuery, String, double, double, String, Map)}
|
||||
* @return 退款结果
|
||||
*/
|
||||
public RefundResult refund(File caFile, IdQuery idQuery,
|
||||
public RefundResultV2 refundApply(File caFile, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, String opUserPasswd, String recvUserId,
|
||||
String reccvUserName, RefundType refundType) throws WeixinException {
|
||||
@ -307,41 +321,10 @@ public class Pay2Api extends PayApi {
|
||||
if (refundType != null) {
|
||||
mopara.put("refund_type", Integer.toString(refundType.getVal()));
|
||||
}
|
||||
return refund(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
return refundApply(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
opUserId, mopara);
|
||||
}
|
||||
|
||||
/**
|
||||
* 冲正订单(需要证书)</br><font color="red">V2暂不支持</font>
|
||||
*
|
||||
* @param caFile
|
||||
* 证书文件(V2版本后缀为*.pfx)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @since V2
|
||||
* @return 撤销结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult reverse(File caFile, IdQuery idQuery)
|
||||
throws WeixinException {
|
||||
throw new WeixinException("V2 unsupport reverse api");
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单</br> 当订单支付失败,调用关单接口后用新订单号重新发起支付,如果关单失败,返回已完
|
||||
* 成支付请按正常支付处理。如果出现银行掉单,调用关单成功后,微信后台会主动发起退款。
|
||||
*
|
||||
* @param outTradeNo
|
||||
* 商户系统内部的订单号
|
||||
* @return 处理结果
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult closeOrder(String outTradeNo) throws WeixinException {
|
||||
throw new WeixinException("V2 unsupport closeOrder api");
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载对账单<br>
|
||||
* 1.微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账 单中,跟原支付单订单号一致,bill_type 为
|
||||
@ -428,12 +411,12 @@ public class Pay2Api extends PayApi {
|
||||
* 四个参数必填一个,优先级为:
|
||||
* refund_id>out_refund_no>transaction_id>out_trade_no
|
||||
* @return 退款记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundRecord
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundDetail
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundDetailV2
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public RefundRecord refundQuery(IdQuery idQuery) throws WeixinException {
|
||||
public RefundRecordV2 refundQuery(IdQuery idQuery) throws WeixinException {
|
||||
String refundquery_uri = getRequestUri("refundquery_v2_uri");
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("input_charset", Consts.UTF_8.name());
|
||||
@ -443,11 +426,66 @@ public class Pay2Api extends PayApi {
|
||||
map.put("sign", sign.toLowerCase());
|
||||
WeixinResponse response = weixinClient.get(refundquery_uri, map);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
RefundRecord.class);
|
||||
RefundRecordV2.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShorturl(String url) throws WeixinException {
|
||||
return helperApi.getShorturl(url);
|
||||
/**
|
||||
* 发货通知
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param transid
|
||||
* 交易单号
|
||||
* @param outTradeNo
|
||||
* 订单号
|
||||
* @param status
|
||||
* 成功|失败
|
||||
* @param statusMsg
|
||||
* status为失败时携带的信息
|
||||
* @return 发货处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult deliverNotify(String openId, String transid,
|
||||
String outTradeNo, boolean status, String statusMsg)
|
||||
throws WeixinException {
|
||||
String delivernotify_uri = getRequestUri("delivernotify_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
map.put("openid", openId);
|
||||
map.put("transid", transid);
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
map.put("deliver_timestamp", DateUtil.timestamp2string());
|
||||
map.put("deliver_status", status ? "1" : "0");
|
||||
map.put("deliver_msg", statusMsg);
|
||||
map.put("app_signature", PayUtil2.paysignSha(map));
|
||||
map.put("sign_method", SignType.SHA1.name().toLowerCase());
|
||||
|
||||
WeixinResponse response = weixinClient.post(
|
||||
String.format(delivernotify_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(map));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 维权处理
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param feedbackId
|
||||
* 维权单号
|
||||
* @return 维权处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult updateFeedback(String openId, String feedbackId)
|
||||
throws WeixinException {
|
||||
String payfeedback_update_uri = getRequestUri("payfeedback_update_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinClient.get(String.format(
|
||||
payfeedback_update_uri, token.getAccessToken(), openId,
|
||||
feedbackId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,221 +0,0 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
* 支付API
|
||||
*
|
||||
* @className PayApi
|
||||
* @author jy
|
||||
* @date 2014年10月28日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay2Api
|
||||
* @see com.foxinmy.weixin4j.mp.api.Pay3Api
|
||||
*/
|
||||
public abstract class PayApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 默认的证书文件
|
||||
*/
|
||||
public final static File DEFAULT_CA_FILE = new File(
|
||||
ConfigUtil.getClassPathValue("ca_file"));
|
||||
|
||||
protected final WeixinMpAccount weixinAccount;
|
||||
protected final TokenHolder tokenHolder;
|
||||
|
||||
public PayApi(WeixinMpAccount weixinAccount, TokenHolder tokenHolder) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.tokenHolder = tokenHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货通知
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param transid
|
||||
* 交易单号
|
||||
* @param outTradeNo
|
||||
* 订单号
|
||||
* @param status
|
||||
* 成功|失败
|
||||
* @param statusMsg
|
||||
* status为失败时携带的信息
|
||||
* @return 发货处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult deliverNotify(String openId, String transid,
|
||||
String outTradeNo, boolean status, String statusMsg)
|
||||
throws WeixinException {
|
||||
String delivernotify_uri = getRequestUri("delivernotify_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
map.put("openid", openId);
|
||||
map.put("transid", transid);
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
map.put("deliver_timestamp", DateUtil.timestamp2string());
|
||||
map.put("deliver_status", status ? "1" : "0");
|
||||
map.put("deliver_msg", statusMsg);
|
||||
map.put("app_signature", PayUtil.paysignSha(map));
|
||||
map.put("sign_method", SignType.SHA1.name().toLowerCase());
|
||||
|
||||
WeixinResponse response = weixinClient.post(
|
||||
String.format(delivernotify_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(map));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 维权处理
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param feedbackId
|
||||
* 维权单号
|
||||
* @return 维权处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult updateFeedback(String openId, String feedbackId)
|
||||
throws WeixinException {
|
||||
String payfeedback_update_uri = getRequestUri("payfeedback_update_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinClient.get(String.format(
|
||||
payfeedback_update_uri, token.getAccessToken(), openId,
|
||||
feedbackId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单查询
|
||||
*
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id、out_trade_no 二 选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @return 订单信息
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.Order
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.Order
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public abstract Object orderQuery(IdQuery idQuery) throws WeixinException;
|
||||
|
||||
/**
|
||||
* 申请退款(请求需要双向证书)</br>
|
||||
* <p style="color:red">
|
||||
* 交易时间超过 1 年的订单无法提交退款; </br> 支持部分退款,部分退需要设置相同的订单号和不同的 out_refund_no。一笔退款失
|
||||
* 败后重新提交,要采用原来的 out_refund_no。总退款金额不能超过用户实际支付金额。</br>
|
||||
* </p>
|
||||
*
|
||||
* @param caFile
|
||||
* 证书文件(V2版本后缀为*.pfx,V3版本后缀为*.p12)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @param outRefundNo
|
||||
* 商户系统内部的退款单号,商 户系统内部唯一,同一退款单号多次请求只退一笔
|
||||
* @param totalFee
|
||||
* 订单总金额,单位为元
|
||||
* @param refundFee
|
||||
* 退款总金额,单位为元,可以做部分退款
|
||||
* @param opUserId
|
||||
* 操作员帐号, 默认为商户号
|
||||
* @param mopara
|
||||
* 更多参数 如V2版本的opUserPasswd
|
||||
*
|
||||
* @return 退款申请结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundResult
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundResult
|
||||
* @throws WeixinException
|
||||
*/
|
||||
protected abstract Object refund(File caFile, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, Map<String, String> mopara) throws WeixinException;
|
||||
|
||||
/**
|
||||
* 退款查询</br> 退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款 3 个工作日后重新查询退款状态
|
||||
*
|
||||
* @param idQuery
|
||||
* 单号 refund_id、out_refund_no、 out_trade_no 、 transaction_id
|
||||
* 四个参数必填一个,优先级为:
|
||||
* refund_id>out_refund_no>transaction_id>out_trade_no
|
||||
* @return 退款记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundRecord
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundRecord
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public abstract Object refundQuery(IdQuery idQuery) throws WeixinException;
|
||||
|
||||
/**
|
||||
* 冲正订单(需要证书)
|
||||
*
|
||||
* @param caFile
|
||||
* 证书文件 (V2版本后缀为*.pfx,V3版本后缀为*.p12)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
* transaction_id> out_trade_no
|
||||
* @return 撤销结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public abstract ApiResult reverse(File caFile, IdQuery idQuery)
|
||||
throws WeixinException;
|
||||
|
||||
/**
|
||||
* 下载对账单<br>
|
||||
* 1.微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账 单中,跟原支付单订单号一致,bill_type 为
|
||||
* REVOKED;<br>
|
||||
* 2.微信在次日 9 点启动生成前一天的对账单,建议商户 9 点半后再获取;<br>
|
||||
* 3.对账单中涉及金额的字段单位为“元”。<br>
|
||||
*
|
||||
* @param billDate
|
||||
* 下载对账单的日期
|
||||
* @param billType
|
||||
* 下载对账单的类型 ALL,返回当日所有订单信息, 默认值 SUCCESS,返回当日成功支付的订单
|
||||
* REFUND,返回当日退款订单
|
||||
* @return excel表格
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public abstract File downloadbill(Date billDate, BillType billType)
|
||||
throws WeixinException;
|
||||
|
||||
/**
|
||||
* 关闭订单</br> 当订单支付失败,调用关单接口后用新订单号重新发起支付,如果关单失败,返回已完
|
||||
* 成支付请按正常支付处理。如果出现银行掉单,调用关单成功后,微信后台会主动发起退款。
|
||||
*
|
||||
* @param outTradeNo
|
||||
* 商户系统内部的订单号
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public abstract ApiResult closeOrder(String outTradeNo)
|
||||
throws WeixinException;
|
||||
|
||||
/**
|
||||
* native支付URL转短链接
|
||||
*
|
||||
* @param url
|
||||
* 具有native标识的支付URL
|
||||
* @return 转换后的短链接
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public abstract String getShorturl(String url) throws WeixinException;
|
||||
}
|
||||
@ -113,18 +113,18 @@ semantic_uri={api_base_url}/semantic/semproxy/search?access_token=%s
|
||||
# \u5fae\u4fe1\u670d\u52a1\u5730\u5740
|
||||
getcallbackip_uri={api_cgi_url}/getcallbackip?access_token=%s
|
||||
|
||||
# \u8ba2\u5355\u67e5\u8be2
|
||||
orderquery_uri={api_base_url}/pay/orderquery?access_token=%s
|
||||
# v2\u8ba2\u5355\u67e5\u8be2
|
||||
orderquery_v2_uri={api_base_url}/pay/orderquery?access_token=%s
|
||||
# \u53d1\u8d27\u901a\u77e5
|
||||
delivernotify_uri={api_base_url}/pay/delivernotify?access_token=%s
|
||||
# \u7ef4\u6743\u5904\u7406
|
||||
payfeedback_update_uri={api_base_url}/payfeedback/update?access_token=%s&openid=%s&feedbackid=%s
|
||||
# \u5bf9\u8d26\u5355\u4e0b\u8f7d
|
||||
# v2\u5bf9\u8d26\u5355\u4e0b\u8f7d
|
||||
downloadbill_v2_uri={tenpay_base_url}/cgi-bin/mchdown_real_new.cgi
|
||||
# \u9000\u6b3e\u67e5\u8be2
|
||||
# v2\u9000\u6b3e\u67e5\u8be2
|
||||
refundquery_v2_uri={tenpay_gw_base_url}/gateway/normalrefundquery.xml
|
||||
# \u9000\u6b3e\u7533\u8bf7
|
||||
refund_v2_uri={tenpay_ssl_base_url}/refundapi/gateway/refund.xml
|
||||
# v2\u9000\u6b3e\u7533\u8bf7
|
||||
refundapply_v2_uri={tenpay_ssl_base_url}/refundapi/gateway/refund.xml
|
||||
|
||||
# \u8ba2\u5355\u67e5\u8be2
|
||||
orderquery_v3_uri={mch_base_url}/pay/orderquery
|
||||
|
||||
@ -2,7 +2,7 @@ package com.foxinmy.weixin4j.mp.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.type.QRType;
|
||||
import com.foxinmy.weixin4j.type.QRType;
|
||||
|
||||
/**
|
||||
* 二维码参数对象
|
||||
@ -28,7 +28,7 @@ public class QRParameter implements Serializable {
|
||||
/**
|
||||
* 二维码类型
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.type.QRType
|
||||
* @see com.foxinmy.weixin4j.type.QRType
|
||||
*/
|
||||
private QRType qrType;
|
||||
/**
|
||||
|
||||
@ -1,455 +0,0 @@
|
||||
package com.foxinmy.weixin4j.mp.payment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinHttpClient;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.JsPayRequestV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.NativePayResponseV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.PayPackageV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.PayPackageV3;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.PayRequestV3;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.PrePay;
|
||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.mp.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* 支付工具类(JSAPI,NATIVE,MicroPay)
|
||||
*
|
||||
* @className PayUtil
|
||||
* @author jy
|
||||
* @date 2014年10月28日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class PayUtil {
|
||||
/**
|
||||
* 生成JSAPI字符串
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param WeixinMpAccount
|
||||
* 商户信息
|
||||
* @since V2 & V3
|
||||
* @return 支付json串
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJson(PayPackage payPackage,
|
||||
WeixinMpAccount weixinAccount) throws PayException {
|
||||
if (payPackage instanceof PayPackageV2) {
|
||||
return createPayJsRequestJsonV2((PayPackageV2) payPackage,
|
||||
weixinAccount);
|
||||
} else if (payPackage instanceof PayPackageV3) {
|
||||
return createPayJsRequestJsonV3((PayPackageV3) payPackage,
|
||||
weixinAccount);
|
||||
} else {
|
||||
throw new PayException("unknown pay");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(PayPackageV2 payPackage,
|
||||
WeixinMpAccount weixinAccount) {
|
||||
if (StringUtil.isBlank(payPackage.getPartner())) {
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
}
|
||||
JsPayRequestV2 jsPayRequest = new JsPayRequestV2(weixinAccount,
|
||||
payPackage);
|
||||
jsPayRequest.setPaySign(paysignSha(jsPayRequest,
|
||||
weixinAccount.getPaySignKey()));
|
||||
jsPayRequest.setSignType(SignType.SHA1);
|
||||
return JSON.toJSONString(jsPayRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param body
|
||||
* 支付详情
|
||||
* @param orderNo
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param ip
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(String body, String orderNo,
|
||||
double orderFee, String notify_url, String ip,
|
||||
WeixinMpAccount weixinAccount) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(body, orderNo, orderFee,
|
||||
notify_url, ip);
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
return createPayJsRequestJsonV2(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* sha签名(一般用于V2.x支付接口)
|
||||
*
|
||||
* @param obj
|
||||
* 签名对象
|
||||
* @return
|
||||
*/
|
||||
public static String paysignSha(Object obj) {
|
||||
return DigestUtil.SHA1(MapUtil.toJoinString(obj, false, true, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* sha签名(一般用于V2.x支付接口)
|
||||
*
|
||||
* @param obj
|
||||
* 签名对象
|
||||
* @param paySignKey
|
||||
* 支付API的密钥<font color="red">请注意排序放进去的是put("appKey",
|
||||
* paySignKey)</font>
|
||||
* @return
|
||||
*/
|
||||
public static String paysignSha(Object obj, String paySignKey) {
|
||||
Map<String, String> extra = new HashMap<String, String>();
|
||||
extra.put("appKey", paySignKey);
|
||||
return DigestUtil.SHA1(MapUtil.toJoinString(obj, false, true, extra));
|
||||
}
|
||||
|
||||
/**
|
||||
* md5签名(一般用于V3.x支付接口)
|
||||
*
|
||||
* @param obj
|
||||
* 签名对象
|
||||
* @param paySignKey
|
||||
* 支付API的密钥
|
||||
* @return
|
||||
*/
|
||||
public static String paysignMd5(Object obj, String paySignKey) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// a--->string1
|
||||
sb.append(MapUtil.toJoinString(obj, false, false, null));
|
||||
// b--->
|
||||
// 在 string1 最后拼接上 key=paternerKey 得到 stringSignTemp 字符串,并 对
|
||||
// stringSignTemp 进行 md5 运算
|
||||
// 再将得到的 字符串所有字符转换为大写 ,得到 sign 值 signValue。
|
||||
sb.append("&key=").append(paySignKey);
|
||||
return DigestUtil.MD5(sb.toString()).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V3.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param body
|
||||
* 订单描述
|
||||
* @param orderNo
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param notifyUrl
|
||||
* 支付通知地址
|
||||
* @param ip
|
||||
* ip地址
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJsonV3(String openId, String body,
|
||||
String orderNo, double orderFee, String notifyUrl, String ip,
|
||||
WeixinMpAccount weixinAccount) throws PayException {
|
||||
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, openId, body,
|
||||
orderNo, orderFee, ip, TradeType.JSAPI);
|
||||
payPackage.setNotifyUrl(notifyUrl);
|
||||
return createPayJsRequestJsonV3(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V3.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
* @throws PayException
|
||||
*/
|
||||
public static String createPayJsRequestJsonV3(PayPackageV3 payPackage,
|
||||
WeixinMpAccount weixinAccount) throws PayException {
|
||||
String paySignKey = weixinAccount.getPaySignKey();
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
PrePay prePay = createPrePay(payPackage, paySignKey);
|
||||
PayRequestV3 jsPayRequest = new PayRequestV3(prePay);
|
||||
jsPayRequest.setSignType(SignType.MD5);
|
||||
jsPayRequest.setPaySign(paysignMd5(jsPayRequest, paySignKey));
|
||||
return JSON.toJSONString(jsPayRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一下单接口</br>
|
||||
* 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI
|
||||
* 、APP等不同场景生成交易串调起支付。
|
||||
*
|
||||
* @param payPackage
|
||||
* 包含订单信息的对象
|
||||
* @param paySignKey
|
||||
* <font color="red">如果sign为空 则拿paysignkey进行签名</font>
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.PayPackageV3
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.PrePay
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1">统一下单接口</a>
|
||||
* @return 预支付对象
|
||||
*/
|
||||
private final static WeixinHttpClient httpClient = new WeixinHttpClient();
|
||||
|
||||
public static PrePay createPrePay(PayPackageV3 payPackage, String paySignKey)
|
||||
throws PayException {
|
||||
if (StringUtil.isBlank(payPackage.getSign())) {
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
}
|
||||
String payJsRequestXml = XmlStream.toXML(payPackage);
|
||||
try {
|
||||
WeixinResponse response = httpClient.post(URLConsts.UNIFIEDORDER,
|
||||
payJsRequestXml);
|
||||
PrePay prePay = response.getAsObject(new TypeReference<PrePay>() {
|
||||
});
|
||||
if (!prePay.getReturnCode().equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
throw new PayException(prePay.getReturnMsg(),
|
||||
prePay.getReturnCode());
|
||||
}
|
||||
if (!prePay.getResultCode().equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
throw new PayException(prePay.getResultCode(),
|
||||
prePay.getErrCodeDes());
|
||||
}
|
||||
return prePay;
|
||||
} catch (WeixinException e) {
|
||||
throw new PayException(e.getErrorCode(), e.getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 生成编辑地址请求
|
||||
* </p>
|
||||
*
|
||||
* err_msg edit_address:ok获取编辑收货地址成功</br> edit_address:fail获取编辑收货地址失败</br>
|
||||
* userName 收货人姓名</br> telNumber 收货人电话</br> addressPostalCode 邮编</br>
|
||||
* proviceFirstStageName 国标收货地址第一级地址</br> addressCitySecondStageName
|
||||
* 国标收货地址第二级地址</br> addressCountiesThirdStageName 国标收货地址第三级地址</br>
|
||||
* addressDetailInfo 详细收货地址信息</br> nationalCode 收货地址国家码</br>
|
||||
*
|
||||
* @param appId
|
||||
* 公众号的ID
|
||||
* @param url
|
||||
* 当前访问页的URL
|
||||
* @param accessToken
|
||||
* snsapi_base授权时产生的token
|
||||
* @return
|
||||
*/
|
||||
public static String createAddressRequestJson(String appId, String url,
|
||||
String accessToken) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appId", appId);
|
||||
map.put("timeStamp", DateUtil.timestamp2string());
|
||||
map.put("nonceStr", RandomUtil.generateString(16));
|
||||
map.put("url", url);
|
||||
map.put("accessToken", accessToken);
|
||||
String sign = paysignSha(map);
|
||||
map.remove("url");
|
||||
map.remove("accessToken");
|
||||
map.put("scope", "jsapi_address");
|
||||
map.put("signType", SignType.SHA1.name().toLowerCase());
|
||||
map.put("addrSign", sign);
|
||||
|
||||
return JSON.toJSONString(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V2.x NativePay支付链接
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @param productId
|
||||
* 与订单ID等价
|
||||
* @return 支付链接
|
||||
*/
|
||||
public static String createNativePayRequestURLV2(
|
||||
WeixinMpAccount weixinAccount, String productId) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("productid", productId);
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
String sign = paysignSha(map);
|
||||
return String.format(URLConsts.NATIVEURLV2, sign, weixinAccount.getId(),
|
||||
productId, timestamp, noncestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V3.x NativePay支付(扫码支付)链接
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 支付配置信息
|
||||
* @param productId
|
||||
* 与订单ID等价
|
||||
* @return 支付链接
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
|
||||
*/
|
||||
public static String createNativePayRequestURLV3(
|
||||
WeixinMpAccount weixinAccount, String productId) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("mch_id", weixinAccount.getMchId());
|
||||
map.put("time_stamp", timestamp);
|
||||
map.put("nonce_str", noncestr);
|
||||
map.put("product_id", productId);
|
||||
String sign = paysignMd5(map, weixinAccount.getPaySignKey());
|
||||
return String.format(URLConsts.NATIVEURLV3, sign, weixinAccount.getId(),
|
||||
weixinAccount.getMchId(), productId, timestamp, noncestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V2.x NATIVE回调时的响应字符串
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @return
|
||||
*/
|
||||
public static String createNativePayResponseV2(
|
||||
WeixinMpAccount weixinAccount, PayPackageV2 payPackage) {
|
||||
NativePayResponseV2 payRequest = new NativePayResponseV2(weixinAccount,
|
||||
payPackage);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("package", payRequest.getPackageInfo());
|
||||
map.put("retcode", payRequest.getRetCode());
|
||||
map.put("reterrmsg", payRequest.getRetMsg());
|
||||
payRequest.setPaySign(paysignSha(map));
|
||||
return XmlStream.toXML(payRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交被扫支付
|
||||
*
|
||||
* @param authCode
|
||||
* 扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param attach
|
||||
* 附加数据
|
||||
* @param orderNo
|
||||
* 商户内部唯一订单号
|
||||
* @param orderFee
|
||||
* 商品总额 单位元
|
||||
* @param ip
|
||||
* 订单生成的机器 IP
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付的订单信息
|
||||
* @see {@link com.foxinmy.weixin4j.mp.payment.PayUtil#createMicroPay(MicroPayPackage, WeixinMpAccount)}
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static com.foxinmy.weixin4j.mp.payment.v3.Order createMicroPay(
|
||||
String authCode, String body, String attach, String orderNo,
|
||||
double orderFee, String ip, WeixinMpAccount weixinAccount)
|
||||
throws WeixinException {
|
||||
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body,
|
||||
attach, orderNo, orderFee, ip, authCode);
|
||||
return createMicroPay(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交被扫支付:收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,由商户收银台或者商户后台调用该接口发起支付.
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付的订单信息
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.Order
|
||||
* @see <a
|
||||
* href="http://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10">提交被扫支付API</a>
|
||||
*/
|
||||
public static com.foxinmy.weixin4j.mp.payment.v3.Order createMicroPay(
|
||||
MicroPayPackage payPackage, WeixinMpAccount weixinAccount)
|
||||
throws WeixinException {
|
||||
String sign = paysignMd5(payPackage, weixinAccount.getPaySignKey());
|
||||
payPackage.setSign(sign);
|
||||
String para = XmlStream.toXML(payPackage);
|
||||
WeixinResponse response = httpClient.post(URLConsts.MICROPAYURL, para);
|
||||
return response
|
||||
.getAsObject(new TypeReference<com.foxinmy.weixin4j.mp.payment.v3.Order>() {
|
||||
});
|
||||
}
|
||||
|
||||
private static String JSAPIV2() {
|
||||
WeixinMpAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinMpAccount.class);
|
||||
return createPayJsRequestJsonV2("支付测试", "JSAPI01", 0.01d, "127.0.0.0",
|
||||
"http://127.0.0.1/jsapi/notify", weixinAccount);
|
||||
}
|
||||
|
||||
private static String NATIVEV2() {
|
||||
WeixinMpAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinMpAccount.class);
|
||||
return createNativePayRequestURLV2(weixinAccount, "P1");
|
||||
}
|
||||
|
||||
private static String JSAPIV3() throws PayException {
|
||||
WeixinMpAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinMpAccount.class);
|
||||
return createPayJsRequestJsonV3("oyFLst1bqtuTcxK-ojF8hOGtLQao", "支付测试",
|
||||
"JSAPI01", 0.01d, "http://127.0.0.1/jsapi/notify", "127.0.0.0",
|
||||
weixinAccount);
|
||||
}
|
||||
|
||||
private static String NATIVEV3() {
|
||||
WeixinMpAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinMpAccount.class);
|
||||
return createNativePayRequestURLV3(weixinAccount, "P1");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws PayException {
|
||||
// V2版本下的JS支付
|
||||
System.out.println(JSAPIV2());
|
||||
// V2版本下的原生支付
|
||||
System.out.println(NATIVEV2());
|
||||
// V3版本下的JS支付
|
||||
System.out.println(JSAPIV3());
|
||||
// V3版本下的原生支付
|
||||
System.out.println(NATIVEV3());
|
||||
}
|
||||
}
|
||||
@ -8,12 +8,12 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.SignType;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
|
||||
/**
|
||||
* 调用V2.x接口返回的公用字段
|
||||
*
|
||||
* @className ApiResult
|
||||
* @className ApiResultV2
|
||||
* @author jy
|
||||
* @date 2014年12月30日
|
||||
* @since JDK 1.7
|
||||
@ -21,7 +21,7 @@ import com.foxinmy.weixin4j.mp.type.SignType;
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ApiResult implements Serializable {
|
||||
public class ApiResultV2 implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2876899595643466203L;
|
||||
/**
|
||||
@ -63,7 +63,7 @@ public class ApiResult implements Serializable {
|
||||
@XmlElement(name = "sign_type")
|
||||
private SignType signType;
|
||||
|
||||
protected ApiResult() {
|
||||
protected ApiResultV2() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
|
||||
@ -37,7 +37,7 @@ public class JsPayRequestV2 extends PayRequest {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public JsPayRequestV2(WeixinMpAccount weixinAccount, PayPackageV2 payPackage) {
|
||||
public JsPayRequestV2(WeixinPayAccount weixinAccount, PayPackageV2 payPackage) {
|
||||
this.setAppId(weixinAccount.getId());
|
||||
this.setPackageInfo(package2string(payPackage,
|
||||
weixinAccount.getPartnerKey()));
|
||||
|
||||
@ -5,7 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.payment.JsPayNotify;
|
||||
import com.foxinmy.weixin4j.payment.JsPayNotify;
|
||||
|
||||
/**
|
||||
* V2 Native支付回调时POST的信息
|
||||
|
||||
@ -5,7 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
|
||||
/**
|
||||
* V2 Native支付时的回调响应
|
||||
@ -36,7 +36,7 @@ public class NativePayResponseV2 extends JsPayRequestV2 {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public NativePayResponseV2(WeixinMpAccount weixinAccount,
|
||||
public NativePayResponseV2(WeixinPayAccount weixinAccount,
|
||||
PayPackageV2 payPackage) {
|
||||
super(weixinAccount, payPackage);
|
||||
this.retCode = "0";
|
||||
|
||||
@ -3,20 +3,20 @@ package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeState;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.TradeState;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
* V2订单信息
|
||||
*
|
||||
* @className Order
|
||||
* @className OrderV2
|
||||
* @author jy
|
||||
* @date 2014年11月2日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Order extends ApiResult {
|
||||
public class OrderV2 extends ApiResultV2 {
|
||||
|
||||
private static final long serialVersionUID = 4543552984506609920L;
|
||||
|
||||
@ -5,7 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.payment.PayBaseInfo;
|
||||
import com.foxinmy.weixin4j.payment.PayBaseInfo;
|
||||
|
||||
/**
|
||||
* V2维权POST的数据
|
||||
|
||||
@ -8,7 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayPackage;
|
||||
import com.foxinmy.weixin4j.payment.PayPackage;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,172 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* V2支付工具类(JSAPI,NATIVE)
|
||||
*
|
||||
* @className PayUtil2
|
||||
* @author jy
|
||||
* @date 2014年10月28日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class PayUtil2 {
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(PayPackageV2 payPackage,
|
||||
WeixinPayAccount weixinAccount) {
|
||||
if (StringUtil.isBlank(payPackage.getPartner())) {
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
}
|
||||
JsPayRequestV2 jsPayRequest = new JsPayRequestV2(weixinAccount,
|
||||
payPackage);
|
||||
jsPayRequest.setPaySign(paysignSha(jsPayRequest,
|
||||
weixinAccount.getPaySignKey()));
|
||||
jsPayRequest.setSignType(SignType.SHA1);
|
||||
return JSON.toJSONString(jsPayRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param body
|
||||
* 支付详情
|
||||
* @param orderNo
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param ip
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(String body, String orderNo,
|
||||
double orderFee, String notify_url, String ip,
|
||||
WeixinPayAccount weixinAccount) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(body, orderNo, orderFee,
|
||||
notify_url, ip);
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
return createPayJsRequestJsonV2(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* sha签名(一般用于V2.x支付接口)
|
||||
*
|
||||
* @param obj
|
||||
* 签名对象
|
||||
* @return
|
||||
*/
|
||||
public static String paysignSha(Object obj) {
|
||||
return DigestUtil.SHA1(MapUtil.toJoinString(obj, false, true, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* sha签名(一般用于V2.x支付接口)
|
||||
*
|
||||
* @param obj
|
||||
* 签名对象
|
||||
* @param paySignKey
|
||||
* 支付API的密钥<font color="red">请注意排序放进去的是put("appKey",
|
||||
* paySignKey)</font>
|
||||
* @return
|
||||
*/
|
||||
public static String paysignSha(Object obj, String paySignKey) {
|
||||
Map<String, String> extra = new HashMap<String, String>();
|
||||
extra.put("appKey", paySignKey);
|
||||
return DigestUtil.SHA1(MapUtil.toJoinString(obj, false, true, extra));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V2.x NativePay支付链接
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @param productId
|
||||
* 与订单ID等价
|
||||
* @return 支付链接
|
||||
*/
|
||||
public static String createNativePayRequestURLV2(
|
||||
WeixinPayAccount weixinAccount, String productId) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("productid", productId);
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
String sign = paysignSha(map);
|
||||
return String
|
||||
.format("weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&nocestr=%s",
|
||||
sign, weixinAccount.getId(), productId, timestamp,
|
||||
noncestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V2.x NATIVE回调时的响应字符串
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @return
|
||||
*/
|
||||
public static String createNativePayResponseV2(
|
||||
WeixinPayAccount weixinAccount, PayPackageV2 payPackage) {
|
||||
NativePayResponseV2 payRequest = new NativePayResponseV2(weixinAccount,
|
||||
payPackage);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(16);
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("package", payRequest.getPackageInfo());
|
||||
map.put("retcode", payRequest.getRetCode());
|
||||
map.put("reterrmsg", payRequest.getRetMsg());
|
||||
payRequest.setPaySign(paysignSha(map));
|
||||
return XmlStream.toXML(payRequest);
|
||||
}
|
||||
|
||||
private static String JSAPIV2() {
|
||||
WeixinPayAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinPayAccount.class);
|
||||
return createPayJsRequestJsonV2("支付测试", "JSAPI01", 0.01d, "127.0.0.0",
|
||||
"http://127.0.0.1/jsapi/notify", weixinAccount);
|
||||
}
|
||||
|
||||
private static String NATIVEV2() {
|
||||
WeixinPayAccount weixinAccount = JSON.parseObject(
|
||||
ConfigUtil.getValue("account"), WeixinPayAccount.class);
|
||||
return createNativePayRequestURLV2(weixinAccount, "P1");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws PayException {
|
||||
// V2版本下的JS支付
|
||||
System.out.println(JSAPIV2());
|
||||
// V2版本下的原生支付
|
||||
System.out.println(NATIVEV2());
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.mp.payment.PayBaseInfo;
|
||||
import com.foxinmy.weixin4j.payment.PayBaseInfo;
|
||||
|
||||
/**
|
||||
* V2告警通知
|
||||
|
||||
@ -6,14 +6,14 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.RefundChannel;
|
||||
import com.foxinmy.weixin4j.mp.type.RefundStatus;
|
||||
import com.foxinmy.weixin4j.type.RefundChannel;
|
||||
import com.foxinmy.weixin4j.type.RefundStatus;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* V2退款详细
|
||||
*
|
||||
* @className RefundDetail
|
||||
* @className RefundDetailV2
|
||||
* @author jy
|
||||
* @date 2014年11月6日
|
||||
* @since JDK 1.7
|
||||
@ -21,7 +21,7 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class RefundDetail extends ApiResult {
|
||||
public class RefundDetailV2 extends ApiResultV2 {
|
||||
|
||||
private static final long serialVersionUID = -3687863914168618620L;
|
||||
|
||||
@ -68,7 +68,7 @@ public class RefundDetail extends ApiResult {
|
||||
@JSONField(name = "reccv_user_name")
|
||||
private String reccvUserName;
|
||||
|
||||
protected RefundDetail() {
|
||||
protected RefundDetailV2() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
@ -13,15 +13,15 @@ import com.foxinmy.weixin4j.xml.ListsuffixResult;
|
||||
/**
|
||||
* V2退款记录
|
||||
*
|
||||
* @className RefundRecord
|
||||
* @className RefundRecordV2
|
||||
* @author jy
|
||||
* @date 2014年11月1日
|
||||
* @since JDK 1.7
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundDetail
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundDetailV2
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class RefundRecord extends ApiResult {
|
||||
public class RefundRecordV2 extends ApiResultV2 {
|
||||
|
||||
private static final long serialVersionUID = -2971132874939642721L;
|
||||
|
||||
@ -47,9 +47,9 @@ public class RefundRecord extends ApiResult {
|
||||
* 退款详情
|
||||
*/
|
||||
@ListsuffixResult
|
||||
private List<RefundDetail> refundList;
|
||||
private List<RefundDetailV2> refundList;
|
||||
|
||||
protected RefundRecord() {
|
||||
protected RefundRecordV2() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
@ -65,11 +65,11 @@ public class RefundRecord extends ApiResult {
|
||||
return refundCount;
|
||||
}
|
||||
|
||||
public List<RefundDetail> getRefundList() {
|
||||
public List<RefundDetailV2> getRefundList() {
|
||||
return refundList;
|
||||
}
|
||||
|
||||
public void setRefundList(List<RefundDetail> refundList) {
|
||||
public void setRefundList(List<RefundDetailV2> refundList) {
|
||||
this.refundList = refundList;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
/**
|
||||
* V2退款申请结果
|
||||
*
|
||||
* @className RefundResult
|
||||
* @className RefundResultV2
|
||||
* @author jy
|
||||
* @date 2014年11月6日
|
||||
* @since JDK 1.7
|
||||
@ -18,7 +18,7 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class RefundResult extends RefundDetail {
|
||||
public class RefundResultV2 extends RefundDetailV2 {
|
||||
|
||||
private static final long serialVersionUID = -3687863914168618620L;
|
||||
|
||||
@ -35,7 +35,7 @@ public class RefundResult extends RefundDetail {
|
||||
@JSONField(name = "out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
protected RefundResult() {
|
||||
protected RefundResultV2() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
@ -19,20 +19,4 @@ public final class URLConsts {
|
||||
* 公众平台jssdk获取token的url
|
||||
*/
|
||||
public static final String JS_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";
|
||||
/**
|
||||
* 商户平台下统一订单生成的url
|
||||
*/
|
||||
public static final String UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
||||
/**
|
||||
* 商户平台下刷卡支付的url
|
||||
*/
|
||||
public static final String MICROPAYURL = "https://api.mch.weixin.qq.com/pay/micropay";
|
||||
/**
|
||||
* V2支付下natvie支付的url
|
||||
*/
|
||||
public static final String NATIVEURLV2 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&noncestr=%s";
|
||||
/**
|
||||
* 商户平台(V3)下native支付的url
|
||||
*/
|
||||
public static final String NATIVEURLV3 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
|
||||
}
|
||||
|
||||
@ -3,12 +3,12 @@ package com.foxinmy.weixin4j.mp.test;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPayment;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.MPPaymentResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.Redpacket;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.RedpacketSendResult;
|
||||
import com.foxinmy.weixin4j.mp.type.MPPaymentCheckNameType;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 现金发放测试
|
||||
|
||||
@ -8,12 +8,11 @@ import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.mp.WeixinPayProxy;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponDetail;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponStock;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.payment.WeixinPayProxy;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -27,12 +26,10 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
||||
*/
|
||||
public class CouponTest {
|
||||
protected final static WeixinPayProxy WEIXINPAY;
|
||||
protected final static WeixinMpAccount ACCOUNT;
|
||||
protected final static WeixinPayAccount ACCOUNT;
|
||||
static {
|
||||
ACCOUNT = new WeixinMpAccount("appid",
|
||||
"appsecret",
|
||||
"paysign", "mchid");
|
||||
WEIXINPAY = new WeixinPayProxy(ACCOUNT, new FileTokenStorager());
|
||||
ACCOUNT = new WeixinPayAccount("appid", "appsecret", "paysign", "mchid");
|
||||
WEIXINPAY = new WeixinPayProxy(ACCOUNT);
|
||||
}
|
||||
protected final File caFile = new File("证书文件路径(*.p12)");
|
||||
|
||||
|
||||
@ -10,48 +10,50 @@ import org.junit.Test;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.XmlResult;
|
||||
import com.foxinmy.weixin4j.mp.WeixinPayProxy;
|
||||
import com.foxinmy.weixin4j.mp.model.WeixinMpAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.ApiResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.Order;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.PayPackageV3;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.PrePay;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.mp.type.IdType;
|
||||
import com.foxinmy.weixin4j.mp.type.TradeType;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.mp.api.Pay2Api;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
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.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.IdType;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
|
||||
public class PayTest {
|
||||
private final static WeixinPayProxy PAY2;
|
||||
private final static Pay2Api PAY2;
|
||||
private final static WeixinPayProxy PAY3;
|
||||
private final static WeixinMpAccount ACCOUNT2;
|
||||
private final static WeixinMpAccount ACCOUNT3;
|
||||
private final static WeixinPayAccount ACCOUNT2;
|
||||
private final static WeixinPayAccount ACCOUNT3;
|
||||
static {
|
||||
ACCOUNT2 = new WeixinMpAccount("请填入v2版本的appid", "请填入v2版本的appSecret",
|
||||
ACCOUNT2 = new WeixinPayAccount("请填入v2版本的appid", "请填入v2版本的appSecret",
|
||||
"请填入v3版本的paysignkey", "请填入v2版本的partnerId", "请填入v2版本的partnerKey");
|
||||
PAY2 = new WeixinPayProxy(ACCOUNT2, new FileTokenStorager());
|
||||
ACCOUNT3 = new WeixinMpAccount("请填入v3版本的appid", "请填入v3版本的appSecret",
|
||||
PAY2 = new Pay2Api(ACCOUNT2, new FileTokenStorager());
|
||||
ACCOUNT3 = new WeixinPayAccount("请填入v3版本的appid", "请填入v3版本的appSecret",
|
||||
"请填入v3版本的paysignkey", "请填入v3版本的mchid");
|
||||
PAY3 = new WeixinPayProxy(ACCOUNT3, new FileTokenStorager());
|
||||
PAY3 = new WeixinPayProxy(ACCOUNT3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderQueryV2() throws WeixinException {
|
||||
System.err.println(PAY2.orderQueryV2("D14110500021"));
|
||||
System.err.println(PAY2.orderQuery(new IdQuery("D14110500021",
|
||||
IdType.REFUNDNO)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refundV2() throws WeixinException {
|
||||
File caFile = new File("签名文件,如12333.pfx");
|
||||
IdQuery idQuery = new IdQuery("D15020300005", IdType.TRADENO);
|
||||
System.err.println(PAY2.refundV2(caFile, idQuery, "1422925555037", 16d,
|
||||
16d, "1221928801", "111111", null, null, null));
|
||||
System.err.println(PAY2.refundApply(caFile, idQuery, "1422925555037",
|
||||
16d, 16d, "1221928801", "111111", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refundQueryV2() throws WeixinException {
|
||||
System.err.println(PAY2.refundQueryV2(new IdQuery("D14123000004",
|
||||
System.err.println(PAY2.refundQuery(new IdQuery("D14123000004",
|
||||
IdType.TRADENO)));
|
||||
refundQueryV3();
|
||||
}
|
||||
@ -68,7 +70,7 @@ public class PayTest {
|
||||
|
||||
@Test
|
||||
public void orderQueryV3() throws WeixinException {
|
||||
Order order = PAY3.orderQueryV3(new IdQuery("T0002", IdType.TRADENO));
|
||||
Order order = PAY3.orderQuery(new IdQuery("T0002", IdType.TRADENO));
|
||||
System.err.println(order);
|
||||
String sign = order.getSign();
|
||||
order.setSign(null);
|
||||
@ -80,7 +82,7 @@ public class PayTest {
|
||||
|
||||
@Test
|
||||
public void refundQueryV3() throws WeixinException {
|
||||
com.foxinmy.weixin4j.mp.payment.v3.RefundRecord record = PAY3
|
||||
com.foxinmy.weixin4j.payment.mch.RefundRecord record = PAY3
|
||||
.refundQueryV3(new IdQuery("TT_1427183696238", IdType.TRADENO));
|
||||
System.err.println(record);
|
||||
// 这里的验证签名需要把details循环拼接
|
||||
@ -108,9 +110,10 @@ public class PayTest {
|
||||
public void refundV3() throws WeixinException {
|
||||
File caFile = new File("签名文件如123.p12");
|
||||
IdQuery idQuery = new IdQuery("TT_1427183696238", IdType.TRADENO);
|
||||
com.foxinmy.weixin4j.mp.payment.v3.RefundResult result = PAY3.refundV3(
|
||||
caFile, idQuery, "TT_R" + System.currentTimeMillis(), 0.01d,
|
||||
0.01d, null, "10020674");
|
||||
com.foxinmy.weixin4j.payment.mch.RefundResult result = PAY3
|
||||
.refundApply(caFile, idQuery,
|
||||
"TT_R" + System.currentTimeMillis(), 0.01d, 0.01d,
|
||||
null, "10020674");
|
||||
System.err.println(result);
|
||||
String sign = result.getSign();
|
||||
result.setSign(null);
|
||||
@ -122,7 +125,7 @@ public class PayTest {
|
||||
|
||||
@Test
|
||||
public void nativeV3() throws WeixinException {
|
||||
PayPackageV3 payPackageV3 = new PayPackageV3(ACCOUNT3,
|
||||
MchPayPackage payPackageV3 = new MchPayPackage(ACCOUNT3,
|
||||
"oyFLst1bqtuTcxK-ojF8hOGtLQao", "native测试", "T0001", 0.1d,
|
||||
"127.0.0.1", TradeType.NATIVE);
|
||||
payPackageV3.setProductId("0001");
|
||||
|
||||
@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecord;
|
||||
import com.foxinmy.weixin4j.mp.payment.v3.Order;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
@ -64,7 +64,7 @@ public class XmlstreamTest {
|
||||
sb.toString(), Order.class));
|
||||
}
|
||||
|
||||
public static RefundRecord xml2refundRecordV2() throws Exception {
|
||||
public static RefundRecordV2 xml2refundRecordV2() throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(
|
||||
@ -78,7 +78,7 @@ public class XmlstreamTest {
|
||||
|
||||
}
|
||||
return ListsuffixResultDeserializer.deserialize(sb.toString(),
|
||||
RefundRecord.class);
|
||||
RefundRecordV2.class);
|
||||
}
|
||||
|
||||
public static void xml2refundRecordV3() throws Exception {
|
||||
@ -96,7 +96,7 @@ public class XmlstreamTest {
|
||||
}
|
||||
System.err.println(ListsuffixResultDeserializer.deserialize(
|
||||
sb.toString(),
|
||||
com.foxinmy.weixin4j.mp.payment.v3.RefundRecord.class));
|
||||
com.foxinmy.weixin4j.payment.mch.RefundRecord.class));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@ -26,6 +26,12 @@ weixin4j-qy
|
||||
* OauthApi `oauth授权登陆API`
|
||||
|
||||
* SuiteApi `第三方应用API`
|
||||
|
||||
* Pay3Api `商户平台支付API`
|
||||
|
||||
* CouponApi `代金券API`
|
||||
|
||||
* CashApi `现金API`
|
||||
|
||||
如何使用
|
||||
--------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user