新增海关接口

This commit is contained in:
jinyu 2016-03-27 17:40:35 +08:00
parent 223ba9d693
commit 1a2530d4c6
20 changed files with 746 additions and 149 deletions

View File

@ -664,3 +664,5 @@
+ weixin4j-base:删除Mciro支付接口,新增MCIROPayRequest对象
+ weixin4j-base:支付对象优化
+ weixin4j-base:新增海关接口

View File

@ -54,11 +54,12 @@ public class CashApi extends MchApi {
* @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>
* href="https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5">发放红包接口说明</a>
* @throws WeixinException
*/
public RedpacketSendResult sendRedpack(InputStream certificate,
Redpacket redpacket) throws WeixinException {
redpacket.declareWeixinPayAccount(weixinAccount);
JSONObject obj = (JSONObject) JSON.toJSON(redpacket);
obj.put("wxappid", obj.remove("appid"));
obj.put("sign", weixinSignature.sign(obj));
@ -136,6 +137,7 @@ public class CashApi extends MchApi {
*/
public CorpPaymentResult sendCorpPayment(InputStream certificate,
CorpPayment payment) throws WeixinException {
payment.declareWeixinPayAccount(weixinAccount);
JSONObject obj = (JSONObject) JSON.toJSON(payment);
obj.put("mchid", obj.remove("mch_id"));
obj.put("mch_appid", obj.remove("appid"));

View File

@ -0,0 +1,84 @@
package com.foxinmy.weixin4j.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.mch.CustomsOrder;
import com.foxinmy.weixin4j.payment.mch.CustomsOrderRecord;
import com.foxinmy.weixin4j.payment.mch.CustomsOrderResult;
import com.foxinmy.weixin4j.type.CustomsCity;
import com.foxinmy.weixin4j.type.IdQuery;
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
import com.foxinmy.weixin4j.xml.XmlStream;
/**
* 报关接口
*
* @className CustomsApi
* @author jy
* @date 2016年3月67日
* @since JDK 1.7
* @see
*/
public class CustomsApi extends MchApi {
public CustomsApi(WeixinPayAccount weixinAccount) {
super(weixinAccount);
}
/**
* 订单附加信息提交
*
* @param customsOrder
* 附加订单信息
* @return 报关结果
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrder
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrderResult
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">附加订单信息</a>
* @throws WeixinException
*/
public CustomsOrderResult declareCustomsOrder(CustomsOrder customsOrder)
throws WeixinException {
JSONObject para = (JSONObject) JSON.toJSON(customsOrder);
para.put("appid", weixinAccount.getId());
para.put("mch_id", weixinAccount.getMchId());
para.put("sign", weixinSignature.sign(para));
String param = XmlStream.map2xml(para);
WeixinResponse response = weixinExecutor.post(
getRequestUri("customsorder_declare_uri"), param);
return response.getAsObject(new TypeReference<CustomsOrderResult>() {
});
}
/**
* 订单附加信息查询
*
* @param idQuery
* out_trade_no,transaction_id,sub_order_no,sub_order_id四选一
* @param customsCity
* 海关
* @return 报关记录
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrderRecord
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">附加订单信息</a>
* @throws WeixinException
*/
public CustomsOrderRecord queryCustomsOrder(IdQuery idQuery,
CustomsCity customsCity) throws WeixinException {
JSONObject para = new JSONObject();
para.put("appid", weixinAccount.getId());
para.put("mch_id", weixinAccount.getMchId());
para.put(idQuery.getType().getName(), idQuery.getId());
para.put("customs", customsCity.name());
para.put("sign", weixinSignature.sign(para));
String param = XmlStream.map2xml(para);
WeixinResponse response = weixinExecutor.post(
getRequestUri("customsorder_query_uri"), param);
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
CustomsOrderRecord.class);
}
}

View File

@ -18,7 +18,6 @@ import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.exception.WeixinPayException;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.http.weixin.XmlResult;
import com.foxinmy.weixin4j.model.Consts;
@ -79,27 +78,14 @@ public class PayApi extends MchApi {
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1">统一下单接口</a>
* @return 预支付对象
*/
public PrePay createPrePay(MchPayPackage payPackage)
throws WeixinPayException {
public PrePay createPrePay(MchPayPackage payPackage) throws WeixinException {
payPackage.declareWeixinPayAccount(weixinAccount);
payPackage.setSign(weixinSignature.sign(payPackage));
String payJsRequestXml = XmlStream.toXML(payPackage);
try {
WeixinResponse response = weixinExecutor.post(
getRequestUri("order_create_uri"), payJsRequestXml);
PrePay prePay = response.getAsObject(new TypeReference<PrePay>() {
return response.getAsObject(new TypeReference<PrePay>() {
});
if (!prePay.getReturnCode().equalsIgnoreCase(Consts.SUCCESS)) {
throw new WeixinPayException(prePay.getReturnMsg(),
prePay.getReturnCode());
}
if (!prePay.getResultCode().equalsIgnoreCase(Consts.SUCCESS)) {
throw new WeixinPayException(prePay.getResultCode(),
prePay.getErrCodeDes());
}
return prePay;
} catch (WeixinException e) {
throw new WeixinPayException(e.getErrorCode(), e.getErrorMsg());
}
}
/**
@ -113,10 +99,10 @@ public class PayApi extends MchApi {
* @see com.foxinmy.weixin4j.payment.mch.MICROPayRequest 刷卡支付
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest APP支付
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest WAP支付
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createPayRequest(MchPayPackage payPackage)
throws WeixinPayException {
throws WeixinException {
PrePay prePay = createPrePay(payPackage);
String tradeType = payPackage.getTradeType();
if (TradeType.APP.name().equalsIgnoreCase(tradeType)) {
@ -130,7 +116,6 @@ public class PayApi extends MchApi {
return new WAPPayRequest(prePay.getPrepayId(), weixinAccount);
} else if (TradeType.MICROPAY.name().equalsIgnoreCase(tradeType)) {
String para = XmlStream.toXML(payPackage);
try {
WeixinResponse response = weixinExecutor.post(
getRequestUri("micropay_uri"), para);
MICROPayRequest microPayRequest = response
@ -138,11 +123,8 @@ public class PayApi extends MchApi {
});
microPayRequest.setPaymentAccount(weixinAccount);
return microPayRequest;
} catch (WeixinException e) {
throw new WeixinPayException(e);
}
} else {
throw new WeixinPayException("unknown tradeType:" + tradeType);
throw new WeixinException("unknown tradeType:" + tradeType);
}
}
@ -185,17 +167,17 @@ public class PayApi extends MchApi {
* @see com.foxinmy.weixin4j.payment.mch.MICROPayRequest 刷卡支付
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest APP支付
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest WAP支付
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createPayRequest(String body, String detail,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, TradeType tradeType, String openId,
String productId, String attach, Date timeStart, Date timeExpire,
String goodsTag, String limitPay, String subOpenId)
throws WeixinPayException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, notifyUrl, createIp, tradeType, openId,
null, productId, attach);
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, tradeType, openId, null,
productId, attach);
payPackage.setTimeStart(timeStart);
payPackage.setTimeExpire(timeExpire);
payPackage.setGoodsTag(goodsTag);
@ -224,14 +206,14 @@ public class PayApi extends MchApi {
* 附加数据 非必填
* @see com.foxinmy.weixin4j.payment.mch.JSAPIPayRequest
* @return JSAPI支付对象
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createJSPayRequest(String openId, String body,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, String attach) throws WeixinPayException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, notifyUrl, createIp, TradeType.JSAPI,
openId, null, null, attach);
String createIp, String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.JSAPI, openId, null,
null, attach);
return createPayRequest(payPackage);
}
@ -317,14 +299,14 @@ public class PayApi extends MchApi {
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4">模式一</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public NativePayResponse createNativePayResponse(String productId,
String body, String outTradeNo, double totalFee, String notifyUrl,
String createIp, String attach) throws WeixinPayException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, notifyUrl, createIp, TradeType.NATIVE,
null, null, productId, attach);
String createIp, String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.NATIVE, null, null,
productId, attach);
PrePay prePay = createPrePay(payPackage);
return new NativePayResponse(weixinAccount, prePay.getPrepayId());
}
@ -351,14 +333,14 @@ public class PayApi extends MchApi {
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5">模式二</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createNativePayRequest(String productId, String body,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, String attach) throws WeixinPayException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, notifyUrl, createIp, TradeType.NATIVE,
null, null, productId, attach);
String createIp, String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.NATIVE, null, null,
productId, attach);
return createPayRequest(payPackage);
}
@ -381,14 +363,14 @@ public class PayApi extends MchApi {
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_1">APP支付</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createAppPayRequest(String body, String outTradeNo,
double totalFee, String notifyUrl, String createIp, String attach)
throws WeixinPayException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, notifyUrl, createIp, TradeType.APP, null,
null, null, attach);
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.APP, null, null, null,
attach);
return createPayRequest(payPackage);
}
@ -411,14 +393,14 @@ public class PayApi extends MchApi {
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1">WAP支付</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createWAPPayRequest(String body, String outTradeNo,
double totalFee, String notifyUrl, String createIp, String attach)
throws WeixinPayException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, notifyUrl, createIp, TradeType.WAP, null,
null, null, attach);
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.WAP, null, null, null,
attach);
return createPayRequest(payPackage);
}
@ -447,9 +429,9 @@ public class PayApi extends MchApi {
public MchPayRequest createMICROPayRequest(String authCode, String body,
String outTradeNo, double totalFee, String createIp, String attach)
throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(weixinAccount, body,
outTradeNo, totalFee, null, createIp, TradeType.MICROPAY, null,
null, null, attach);
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, null, createIp, TradeType.MICROPAY, null, null, null,
attach);
return createPayRequest(payPackage);
}

View File

@ -8,7 +8,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.mch.MerchantResult;
import com.foxinmy.weixin4j.util.DateUtil;
@ -91,8 +90,6 @@ public class PayPackage extends MerchantResult {
/**
* 订单对象
*
* @param weixinPayAccount
* 商户信息 必填
* @param body
* 订单描述 必填
* @param detail
@ -114,11 +111,9 @@ public class PayPackage extends MerchantResult {
* @param goodsTag
* 订单标记 非必填
*/
public PayPackage(WeixinPayAccount weixinPayAccount, String body,
String detail, String outTradeNo, double totalFee,
String notifyUrl, String createIp, String attach, Date timeStart,
Date timeExpire, String goodsTag) {
super(weixinPayAccount);
public PayPackage(String body, String detail, String outTradeNo,
double totalFee, String notifyUrl, String createIp, String attach,
Date timeStart, Date timeExpire, String goodsTag) {
this.body = body;
this.detail = detail;
this.outTradeNo = outTradeNo;

View File

@ -8,9 +8,9 @@ import java.util.Date;
import com.foxinmy.weixin4j.api.CashApi;
import com.foxinmy.weixin4j.api.CouponApi;
import com.foxinmy.weixin4j.api.CustomsApi;
import com.foxinmy.weixin4j.api.PayApi;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.exception.WeixinPayException;
import com.foxinmy.weixin4j.http.weixin.XmlResult;
import com.foxinmy.weixin4j.model.Pageable;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
@ -20,6 +20,9 @@ import com.foxinmy.weixin4j.payment.coupon.CouponStock;
import com.foxinmy.weixin4j.payment.mch.CorpPayment;
import com.foxinmy.weixin4j.payment.mch.CorpPaymentRecord;
import com.foxinmy.weixin4j.payment.mch.CorpPaymentResult;
import com.foxinmy.weixin4j.payment.mch.CustomsOrder;
import com.foxinmy.weixin4j.payment.mch.CustomsOrderRecord;
import com.foxinmy.weixin4j.payment.mch.CustomsOrderResult;
import com.foxinmy.weixin4j.payment.mch.MchPayPackage;
import com.foxinmy.weixin4j.payment.mch.MchPayRequest;
import com.foxinmy.weixin4j.payment.mch.MerchantResult;
@ -35,6 +38,7 @@ import com.foxinmy.weixin4j.payment.mch.RefundResult;
import com.foxinmy.weixin4j.payment.mch.SettlementRecord;
import com.foxinmy.weixin4j.type.BillType;
import com.foxinmy.weixin4j.type.CurrencyType;
import com.foxinmy.weixin4j.type.CustomsCity;
import com.foxinmy.weixin4j.type.IdQuery;
import com.foxinmy.weixin4j.type.TradeType;
import com.foxinmy.weixin4j.util.Weixin4jSettings;
@ -62,6 +66,10 @@ public class WeixinPayProxy {
* 现金API
*/
private final CashApi cashApi;
/**
* 海关API
*/
private final CustomsApi customsApi;
/**
* 配置相关
*/
@ -85,6 +93,7 @@ public class WeixinPayProxy {
this.payApi = new PayApi(settings.getWeixinPayAccount());
this.couponApi = new CouponApi(settings.getWeixinPayAccount());
this.cashApi = new CashApi(settings.getWeixinPayAccount());
this.customsApi = new CustomsApi(settings.getWeixinPayAccount());
}
/**
@ -110,8 +119,7 @@ public class WeixinPayProxy {
* href="http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1">统一下单接口</a>
* @return 预支付对象
*/
public PrePay createPrePay(MchPayPackage payPackage)
throws WeixinPayException {
public PrePay createPrePay(MchPayPackage payPackage) throws WeixinException {
return payApi.createPrePay(payPackage);
}
@ -127,10 +135,10 @@ public class WeixinPayProxy {
* @see com.foxinmy.weixin4j.payment.mch.MICROPayRequest 刷卡支付
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest APP支付
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest WAP支付
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createPayRequest(MchPayPackage payPackage)
throws WeixinPayException {
throws WeixinException {
return payApi.createPayRequest(payPackage);
}
@ -174,14 +182,14 @@ public class WeixinPayProxy {
* @see com.foxinmy.weixin4j.payment.mch.MICROPayRequest 刷卡支付
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest APP支付
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest WAP支付
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createPayRequest(String body, String detail,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, TradeType tradeType, String openId,
String productId, String attach, Date timeStart, Date timeExpire,
String goodsTag, String limitPay, String subOpenId)
throws WeixinPayException {
throws WeixinException {
return payApi.createPayRequest(body, detail, outTradeNo, totalFee,
notifyUrl, createIp, tradeType, openId, productId, attach,
timeStart, timeExpire, goodsTag, limitPay, subOpenId);
@ -207,11 +215,11 @@ public class WeixinPayProxy {
* @see com.foxinmy.weixin4j.api.PayApi
* @see com.foxinmy.weixin4j.payment.mch.JSAPIPayRequest
* @return JSAPI支付对象
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createJSPayRequest(String openId, String body,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, String attach) throws WeixinPayException {
String createIp, String attach) throws WeixinException {
return payApi.createJSPayRequest(openId, body, outTradeNo, totalFee,
notifyUrl, createIp, attach);
}
@ -278,11 +286,11 @@ public class WeixinPayProxy {
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4">模式一</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public NativePayResponse createNativePayResponse(String productId,
String body, String outTradeNo, double totalFee, String notifyUrl,
String createIp, String attach) throws WeixinPayException {
String createIp, String attach) throws WeixinException {
return payApi.createNativePayResponse(productId, body, outTradeNo,
totalFee, notifyUrl, createIp, attach);
}
@ -310,11 +318,11 @@ public class WeixinPayProxy {
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5">模式二</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createNativePayRequest(String productId, String body,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, String attach) throws WeixinPayException {
String createIp, String attach) throws WeixinException {
return payApi.createNativePayRequest(productId, body, outTradeNo,
totalFee, notifyUrl, createIp, attach);
}
@ -339,11 +347,11 @@ public class WeixinPayProxy {
* @see com.foxinmy.weixin4j.payment.mch.APPPayRequest
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_1">APP支付</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createAppPayRequest(String body, String outTradeNo,
double totalFee, String notifyUrl, String createIp, String attach)
throws WeixinPayException {
throws WeixinException {
return payApi.createAppPayRequest(body, outTradeNo, totalFee,
notifyUrl, createIp, attach);
}
@ -368,11 +376,11 @@ public class WeixinPayProxy {
* @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1">WAP支付</a>
* @throws WeixinPayException
* @throws WeixinException
*/
public MchPayRequest createWAPPayRequest(String body, String outTradeNo,
double totalFee, String notifyUrl, String createIp, String attach)
throws WeixinPayException {
throws WeixinException {
return payApi.createWAPPayRequest(body, outTradeNo, totalFee,
notifyUrl, createIp, attach);
}
@ -891,5 +899,42 @@ public class WeixinPayProxy {
return cashApi.queryExchageRate(currencyType, date);
}
/**
* 订单附加信息提交
*
* @param customsOrder
* 附加订单信息
* @return 报关结果
* @see com.foxinmy.weixin4j.api.CustomsApi
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrder
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrderResult
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">附加订单信息</a>
* @throws WeixinException
*/
public CustomsOrderResult declareCustomsOrder(CustomsOrder customsOrder)
throws WeixinException {
return customsApi.declareCustomsOrder(customsOrder);
}
/**
* 订单附加信息查询
*
* @param idQuery
* out_trade_no,transaction_id,sub_order_no,sub_order_id四选一
* @param customsCity
* 海关
* @return 报关记录
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrderRecord
* @see com.foxinmy.weixin4j.api.CustomsApi
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">附加订单信息</a>
* @throws WeixinException
*/
public CustomsOrderRecord queryCustomsOrder(IdQuery idQuery,
CustomsCity customsCity) throws WeixinException {
return customsApi.queryCustomsOrder(idQuery, customsCity);
}
public final static String VERSION = "1.6.7";
}

View File

@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.type.MPPaymentCheckNameType;
import com.foxinmy.weixin4j.util.DateUtil;
@ -72,8 +71,6 @@ public class CorpPayment extends MerchantResult {
/**
* 企业付款
*
* @param weixinPayAccount
* 商户信息
* @param outTradeNo
* 商户的订单号
* @param openId
@ -87,10 +84,9 @@ public class CorpPayment extends MerchantResult {
* @param clientIp
* 调用接口IP
*/
public CorpPayment(WeixinPayAccount weixinPayAccount, String outTradeNo,
String openId, MPPaymentCheckNameType checkNameType, String desc,
double amount, String clientIp) {
super(weixinPayAccount);
public CorpPayment(String outTradeNo, String openId,
MPPaymentCheckNameType checkNameType, String desc, double amount,
String clientIp) {
this.outTradeNo = outTradeNo;
this.openId = openId;
this.checkNameType = checkNameType;

View File

@ -0,0 +1,217 @@
package com.foxinmy.weixin4j.payment.mch;
import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.type.CredentialType;
import com.foxinmy.weixin4j.type.CurrencyType;
import com.foxinmy.weixin4j.type.CustomsCity;
/**
* 报关对象
*
* @className CustomsOrder
* @author jy
* @date 2016年3月27日
* @since JDK 1.6
* @see
*/
public class CustomsOrder extends MerchantResult {
private static final long serialVersionUID = 799510373861612386L;
/**
* 微信支付订单号
*/
@XmlElement(name = "transaction_id")
@JSONField(name = "transaction_id")
private String transactionId;
/**
* 商户订单号
*/
@XmlElement(name = "out_trade_no")
@JSONField(name = "out_trade_no")
private String outTradeNo;
/**
* 商户子订单号如有拆单则必传
*/
@XmlElement(name = "sub_order_no")
@JSONField(name = "sub_order_no")
private String subOrderNo;
/**
* 货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
*
* @see com.foxinmy.weixin4j.mp.type.CurrencyType
*/
@XmlElement(name = "fee_type")
@JSONField(name = "fee_type")
private CurrencyType feeType;
/**
* 子订单金额以分为单位不能超过原订单金额order_fee=transport_fee+product_fee应付金额=物流费+商品价格
* 如有拆单则必传
*/
@XmlElement(name = "order_fee")
@JSONField(name = "order_fee")
private String orderFee;
/**
* 物流费用以分为单位如有拆单则必传
*/
@XmlElement(name = "transport_fee")
@JSONField(name = "transport_fee")
private String transportFee;
/**
* 商品费用以分为单位如有拆单则必传
*/
@XmlElement(name = "product_fee")
@JSONField(name = "product_fee")
private String productFee;
/**
* 关税以分为单位
*/
@XmlElement(name = "duty")
@JSONField(name = "duty")
private String dutyFee;
/**
* 海关
*/
@XmlElement(name = "customs")
@JSONField(name = "customs")
private CustomsCity customsCity;
/**
* 商户在海关登记的备案号customsCity非NO此参数必填
*/
@XmlElement(name = "mch_customs_no")
@JSONField(name = "mch_customs_no")
private String customsNo;
/**
* 证件类型暂只支持身份证该参数是指用户信息商户若有用户信息可上送系统将以商户上传的数据为准进行海关通关报备
*/
@XmlElement(name = "cert_type")
@JSONField(name = "cert_type")
private CredentialType credentialType;
/**
* 证件号码身份证号该参数是指用户信息商户若有用户信息可上送系统将以商户上传的数据为准进行海关通关报备
*/
@XmlElement(name = "cert_id")
@JSONField(name = "cert_id")
private String credentialId;
/**
* 用户姓名该参数是指用户信息商户若有用户信息可上送系统将以商户上传的数据为准进行海关通关报备
*/
@XmlElement(name = "name")
@JSONField(name = "name")
private String uname;
public CustomsOrder(String transactionId, String outTradeNo) {
this.transactionId = transactionId;
this.outTradeNo = outTradeNo;
this.customsCity = CustomsCity.NO;
}
public String getSubOrderNo() {
return subOrderNo;
}
public void setSubOrderNo(String subOrderNo) {
this.subOrderNo = subOrderNo;
}
public CurrencyType getFeeType() {
return feeType;
}
public void setFeeType(CurrencyType feeType) {
this.feeType = feeType;
}
public String getOrderFee() {
return orderFee;
}
public void setOrderFee(String orderFee) {
this.orderFee = orderFee;
}
public String getTransportFee() {
return transportFee;
}
public void setTransportFee(String transportFee) {
this.transportFee = transportFee;
}
public String getProductFee() {
return productFee;
}
public void setProductFee(String productFee) {
this.productFee = productFee;
}
public String getDutyFee() {
return dutyFee;
}
public void setDutyFee(String dutyFee) {
this.dutyFee = dutyFee;
}
public CustomsCity getCustomsCity() {
return customsCity;
}
public void setCustomsCity(CustomsCity customsCity) {
this.customsCity = customsCity;
}
public String getCustomsNo() {
return customsNo;
}
public void setCustomsNo(String customsNo) {
this.customsNo = customsNo;
}
public CredentialType getCredentialType() {
return credentialType;
}
public void setCredentialType(CredentialType credentialType) {
this.credentialType = credentialType;
}
public String getCredentialId() {
return credentialId;
}
public void setCredentialId(String credentialId) {
this.credentialId = credentialId;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getTransactionId() {
return transactionId;
}
public String getOutTradeNo() {
return outTradeNo;
}
@Override
public String toString() {
return "CustomsOrder [transactionId=" + transactionId + ", outTradeNo="
+ outTradeNo + ", subOrderNo=" + subOrderNo + ", feeType="
+ feeType + ", orderFee=" + orderFee + ", transportFee="
+ transportFee + ", productFee=" + productFee + ", dutyFee="
+ dutyFee + ", customsCity=" + customsCity + ", customsNo="
+ customsNo + ", credentialType=" + credentialType
+ ", credentialId=" + credentialId + ", uname=" + uname + ", "
+ super.toString() + "]";
}
}

View File

@ -0,0 +1,73 @@
package com.foxinmy.weixin4j.payment.mch;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.xml.ListsuffixResult;
/**
* 报关记录
*
* @className CustomsOrderRecord
* @author jy
* @date 2016年3月27日
* @since JDK 1.6
* @see
*/
public class CustomsOrderRecord extends MerchantResult {
private static final long serialVersionUID = -1675090110657154049L;
/**
* 微信支付订单号
*/
@XmlElement(name = "transaction_id")
@JSONField(name = "transaction_id")
private String transactionId;
/**
* 笔数
*/
@XmlElement(name = "count")
@JSONField(name = "count")
private int orderCount;
/**
* 报关详情
*
* @see com.foxinmy.weixin4j.payment.mch.CustomsOrderResult
*/
@ListsuffixResult
private List<CustomsOrderResult> customsOrderList;
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public int getOrderCount() {
return orderCount;
}
public void setOrderCount(int orderCount) {
this.orderCount = orderCount;
}
public List<CustomsOrderResult> getCustomsOrderList() {
return customsOrderList;
}
public void setCustomsOrderList(List<CustomsOrderResult> customsOrderList) {
this.customsOrderList = customsOrderList;
}
@Override
public String toString() {
return "CustomsOrderRecord [transactionId=" + transactionId
+ ", orderCount=" + orderCount + ", customsOrderList="
+ customsOrderList + "]";
}
}

View File

@ -0,0 +1,124 @@
package com.foxinmy.weixin4j.payment.mch;
import java.util.Date;
import javax.xml.bind.annotation.XmlElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.type.CustomsSatus;
import com.foxinmy.weixin4j.util.DateUtil;
/**
* 报关结果
*
* @className CustomsOrderResult
* @author jy
* @date 2016年3月27日
* @since JDK 1.6
* @see
*/
public class CustomsOrderResult extends MerchantResult {
private static final long serialVersionUID = 799510373861612386L;
/**
* 状态码
*/
private String state;
/**
* 微信支付订单号
*/
@XmlElement(name = "transaction_id")
@JSONField(name = "transaction_id")
private String transactionId;
/**
* 商户订单号
*/
@XmlElement(name = "out_trade_no")
@JSONField(name = "out_trade_no")
private String outTradeNo;
/**
* 商户子订单号
*/
@XmlElement(name = "sub_order_no")
@JSONField(name = "sub_order_no")
private String subOrderNo;
/**
* 微信子订单号
*
*/
@XmlElement(name = "sub_order_id")
@JSONField(name = "sub_order_id")
private String subOrderId;
/**
* 最后更新时间
*/
@XmlElement(name = "modify_time")
@JSONField(name = "modify_time")
private String modifyTime;
public String getState() {
return state;
}
@JSONField(serialize = false)
public CustomsSatus getFormatState() {
return CustomsSatus.valueOf(state.toUpperCase());
}
public void setState(String state) {
this.state = state;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getOutTradeNo() {
return outTradeNo;
}
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
public String getSubOrderNo() {
return subOrderNo;
}
public void setSubOrderNo(String subOrderNo) {
this.subOrderNo = subOrderNo;
}
public String getSubOrderId() {
return subOrderId;
}
public void setSubOrderId(String subOrderId) {
this.subOrderId = subOrderId;
}
public String getModifyTime() {
return modifyTime;
}
@JSONField(serialize = false)
public Date getFormatModifyTime() {
return DateUtil.parse2yyyyMMddHHmmss(modifyTime);
}
public void setModifyTime(String modifyTime) {
this.modifyTime = modifyTime;
}
@Override
public String toString() {
return "CustomsOrderResult [state=" + state + ", transactionId="
+ transactionId + ", outTradeNo=" + outTradeNo
+ ", subOrderNo=" + subOrderNo + ", subOrderId=" + subOrderId
+ ", modifyTime=" + modifyTime + "]";
}
}

View File

@ -8,7 +8,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.PayPackage;
import com.foxinmy.weixin4j.type.TradeType;
@ -73,8 +72,6 @@ public class MchPayPackage extends PayPackage {
/**
* 微信支付
*
* @param weixinAccount
* 商户信息 必填
* @param body
* 支付详情 必填
* @param outTradeNo
@ -96,20 +93,17 @@ public class MchPayPackage extends PayPackage {
* @param attach
* 支付时附加信息 非必填
*/
public MchPayPackage(WeixinPayAccount weixinAccount, String body,
String outTradeNo, double totalFee, String notifyUrl,
String createIp, TradeType tradeType, String openId,
String authCode, String productId, String attach) {
this(weixinAccount, body, null, outTradeNo, totalFee, notifyUrl,
createIp, tradeType, openId, authCode, productId, attach, null,
null, null, null, null);
public MchPayPackage(String body, String outTradeNo, double totalFee,
String notifyUrl, String createIp, TradeType tradeType,
String openId, String authCode, String productId, String attach) {
this(body, null, outTradeNo, totalFee, notifyUrl, createIp, tradeType,
openId, authCode, productId, attach, null, null, null, null,
null);
}
/**
* 完整参数
*
* @param weixinAccount
* 商户信息 必填
* @param body
* 支付详情 必填
* @param detail
@ -146,14 +140,13 @@ public class MchPayPackage extends PayPackage {
* 用户在子商户appid下的唯一标识 非必填
* openid和sub_openid可以选传其中之一如果选择传sub_openid ,则必须传sub_appid
*/
public MchPayPackage(WeixinPayAccount weixinPayAccount, String body,
String detial, String outTradeNo, double totalFee,
String notifyUrl, String createIp, TradeType tradeType,
String openId, String authCode, String productId, String attach,
Date timeStart, Date timeExpire, String goodsTag, String limitPay,
String subOpenId) {
super(weixinPayAccount, body, detial, outTradeNo, totalFee, notifyUrl,
createIp, attach, timeStart, timeExpire, goodsTag);
public MchPayPackage(String body, String detial, String outTradeNo,
double totalFee, String notifyUrl, String createIp,
TradeType tradeType, String openId, String authCode,
String productId, String attach, Date timeStart, Date timeExpire,
String goodsTag, String limitPay, String subOpenId) {
super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
timeStart, timeExpire, goodsTag);
this.tradeType = tradeType.name();
this.openId = openId;
this.authCode = authCode;

View File

@ -85,15 +85,6 @@ public class MerchantResult extends XmlResult {
super(returnCode, returnMsg);
}
public MerchantResult(WeixinPayAccount weixinPayAccount) {
this.appId = weixinPayAccount.getId();
this.mchId = weixinPayAccount.getMchId();
this.deviceInfo = weixinPayAccount.getDeviceInfo();
this.subId = weixinPayAccount.getSubId();
this.subMchId = weixinPayAccount.getSubMchId();
this.nonceStr = RandomUtil.generateString(16);
}
public String getAppId() {
return appId;
}
@ -177,6 +168,22 @@ public class MerchantResult extends XmlResult {
return recall != null && recall.equalsIgnoreCase("y");
}
/**
* 赋值给对应字段
*
* @param weixinPayAccount
* 商户信息
*/
@JSONField(deserialize = false)
public void declareWeixinPayAccount(WeixinPayAccount weixinPayAccount) {
this.appId = weixinPayAccount.getId();
this.mchId = weixinPayAccount.getMchId();
this.deviceInfo = weixinPayAccount.getDeviceInfo();
this.subId = weixinPayAccount.getSubId();
this.subMchId = weixinPayAccount.getSubMchId();
this.nonceStr = RandomUtil.generateString(16);
}
@Override
public String toString() {
return "appId=" + appId + ", mchId=" + mchId + ", subId=" + subId

View File

@ -103,8 +103,6 @@ public class Redpacket extends MerchantResult {
/**
* 红包
*
* @param weixinPayAccount
* 商户信息
* @param outTradeNo
* 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填
* @param sendName
@ -127,17 +125,13 @@ public class Redpacket extends MerchantResult {
public Redpacket(WeixinPayAccount weixinPayAccount, String outTradeNo,
String sendName, String openid, double totalAmount, int totalNum,
String wishing, String clientIp, String actName, String remark) {
this(weixinPayAccount, null, null, outTradeNo, sendName, openid,
totalAmount, totalNum, wishing, clientIp, actName, remark);
this(null, null, outTradeNo, sendName, openid, totalAmount, totalNum,
wishing, clientIp, actName, remark);
}
/**
* 红包 完整参数
*
* @param appId
* 公众号唯一标识 必填
* @param mchId
* 微信支付商户号 必填
* @param subMchId
* 子商户商户号 非必填
* @param subMsgId
@ -163,11 +157,9 @@ public class Redpacket extends MerchantResult {
* @param remark
* 备注 必填
*/
public Redpacket(WeixinPayAccount weixinPayAccount, String subMsgId,
String consumeMchId, String outTradeNo, String sendName,
String openid, double totalAmount, int totalNum, String wishing,
String clientIp, String actName, String remark) {
super(weixinPayAccount);
public Redpacket(String subMsgId, String consumeMchId, String outTradeNo,
String sendName, String openid, double totalAmount, int totalNum,
String wishing, String clientIp, String actName, String remark) {
this.subMsgId = subMsgId;
this.consumeMchId = consumeMchId;
this.outTradeNo = outTradeNo;

View File

@ -53,3 +53,7 @@ native_pay_uri=weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s
settlement_query_uri={mch_base_url}/pay/settlementquery
# \u67e5\u8be2\u6c47\u7387
exchagerate_query_uri={mch_base_url}/pay/queryexchagerate
# \u8ba2\u5355\u9644\u52a0\u4fe1\u606f\u63d0\u4ea4
customsorder_declare_uri={mch_base_url}/mch/customs/customdeclareorder
# \u8ba2\u5355\u9644\u52a0\u4fe1\u606f\u67e5\u8be2
customsorder_query_uri={mch_base_url}/mch/customs/customdeclarequery

View File

@ -0,0 +1,23 @@
package com.foxinmy.weixin4j.type;
/**
* 证件类型
*
* @className CredentialType
* @author jy
* @date 2016年3月27日
* @since JDK 1.6
* @see
*/
public enum CredentialType {
IDCARD("身份证");
CredentialType(String name) {
this.name = name;
}
private String name;
public String getName() {
return this.name;
}
}

View File

@ -0,0 +1,26 @@
package com.foxinmy.weixin4j.type;
/**
* 海关
*
* @className CustomsCity
* @author jy
* @date 2016年3月27日
* @since JDK 1.6
* @see
*/
public enum CustomsCity {
NO("无需上报海关"), GUANGZHOU("广州"), HANGZHOU("杭州"), NINGBO("宁波"), ZHENGZHOU_BS(
"郑州(保税物流中心)"), CHONGQING("重庆"), XIAN("西安"), SHANGHAI("上海"), ZHENGZHOU_ZH(
"郑州(综保区)");
private String name;
CustomsCity(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}

View File

@ -0,0 +1,24 @@
package com.foxinmy.weixin4j.type;
/**
* 报关状态
*
* @className CustomsSatus
* @author jy
* @date 2016年3月27日
* @since JDK 1.6
* @see
*/
public enum CustomsSatus {
UNDECLARED("未申报"), SUBMITTED("申报已提交"), PROCESSING("申报中"), SUCCESS("申报成功"), FAIL(
"申报失败"), EXCEPT("海关接口异常");
private String sate;
CustomsSatus(String sate) {
this.sate = sate;
}
public String getSate() {
return this.sate;
}
}

View File

@ -25,7 +25,15 @@ public enum IdType {
/**
* 商户退款号
*/
REFUNDNO("out_refund_no");
REFUNDNO("out_refund_no"),
/**
* 商户子订单号
*/
SUBORDERNO("sub_order_no"),
/**
* 微信子订单号
*/
SUBORDERID("sub_order_id");
private String name;
IdType(String name) {

View File

@ -44,7 +44,7 @@ public class CashTest extends PayTest {
@Test
public void sendCorpPayment() throws WeixinException, IOException {
CorpPayment payment = new CorpPayment(ACCOUNT, "MP001",
CorpPayment payment = new CorpPayment("MP001",
"ofW1gwok9vZIyle0YbA-eQe83Uk8",
MPPaymentCheckNameType.NO_CHECK, "企业付款测试", 1d, "127.0.0.1");
CorpPaymentResult result = PAY.sendCorpPayment(new FileInputStream(

View File

@ -107,9 +107,9 @@ public class PayTest {
@Test
public void nativePay() throws WeixinException {
MchPayPackage payPackageV3 = new MchPayPackage(ACCOUNT, "native测试",
"T0001", 0.1d, "notify_url", "127.0.0.1", TradeType.NATIVE,
null, null, "productId", null);
MchPayPackage payPackageV3 = new MchPayPackage("native测试", "T0001",
0.1d, "notify_url", "127.0.0.1", TradeType.NATIVE, null, null,
"productId", null);
PrePay prePay = null;
try {
prePay = PAY.createPrePay(payPackageV3);