签名类接口化
This commit is contained in:
@@ -34,12 +34,15 @@ import com.foxinmy.weixin4j.http.weixin.WeixinSSLRequestExecutor;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayOldAccount;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.OrderV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.PayPackageV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundResultV2;
|
||||
import com.foxinmy.weixin4j.mp.oldpayment.OrderV2;
|
||||
import com.foxinmy.weixin4j.mp.oldpayment.PayPackageV2;
|
||||
import com.foxinmy.weixin4j.mp.oldpayment.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.mp.oldpayment.RefundResultV2;
|
||||
import com.foxinmy.weixin4j.mp.oldpayment.WeixinOldPaymentSignature;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.sign.WeixinPaymentSignature;
|
||||
import com.foxinmy.weixin4j.sign.WeixinSignature;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
@@ -58,7 +61,7 @@ import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
/**
|
||||
* V2老支付API
|
||||
*
|
||||
* @className Pay2Api
|
||||
* @className PayOldApi
|
||||
* @author jy
|
||||
* @date 2014年10月28日
|
||||
* @since JDK 1.6
|
||||
@@ -66,8 +69,10 @@ import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
*/
|
||||
public class PayOldApi extends MpApi {
|
||||
|
||||
private final WeixinPayOldAccount payAccount;
|
||||
private final WeixinPayOldAccount weixinAccount;
|
||||
private final TokenHolder tokenHolder;
|
||||
private final WeixinSignature weixinMD5Signature;
|
||||
private final WeixinOldPaymentSignature weixinOldSignature;
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置信息
|
||||
@@ -90,14 +95,19 @@ public class PayOldApi extends MpApi {
|
||||
WeixinPayOldAccount.class), tokenStorager);
|
||||
}
|
||||
|
||||
public PayOldApi(WeixinPayOldAccount payAccount, TokenStorager tokenStorager) {
|
||||
this.payAccount = payAccount;
|
||||
public PayOldApi(WeixinPayOldAccount weixinAccount,
|
||||
TokenStorager tokenStorager) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.tokenHolder = new TokenHolder(new WeixinTokenCreator(
|
||||
payAccount.getId(), payAccount.getSecret()), tokenStorager);
|
||||
weixinAccount.getId(), weixinAccount.getSecret()),
|
||||
tokenStorager);
|
||||
this.weixinMD5Signature = new WeixinPaymentSignature(
|
||||
weixinAccount.getPartnerKey());
|
||||
this.weixinOldSignature = new WeixinOldPaymentSignature();
|
||||
}
|
||||
|
||||
public WeixinPayOldAccount getPayAccount() {
|
||||
return this.payAccount;
|
||||
return this.weixinAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,10 +172,10 @@ public class PayOldApi extends MpApi {
|
||||
payPackage.setProductFee(productFee);
|
||||
payPackage.setGoodsTag(goodsTag);
|
||||
PayRequest payRequest = new PayRequest(getPayAccount().getId(),
|
||||
DigestUtil.packageSign(payPackage, getPayAccount()
|
||||
weixinOldSignature.sign(payPackage, getPayAccount()
|
||||
.getPartnerKey()));
|
||||
payRequest.setPaySign(DigestUtil.paysignSha(payRequest, getPayAccount()
|
||||
.getPaySignKey()));
|
||||
payRequest.setPaySign(weixinOldSignature.sign(payRequest,
|
||||
getPayAccount().getPaySignKey()));
|
||||
payRequest.setSignType(SignType.SHA1);
|
||||
return JSON.toJSONString(payRequest);
|
||||
}
|
||||
@@ -186,9 +196,9 @@ public class PayOldApi extends MpApi {
|
||||
map.put("noncestr", noncestr);
|
||||
map.put("productid", productId);
|
||||
map.put("appkey", getPayAccount().getPaySignKey());
|
||||
String sign = DigestUtil.paysignSha(map, null);
|
||||
String ordernative_v2_uri = getRequestUri("ordernative_v2_uri");
|
||||
return String.format(ordernative_v2_uri, sign, getPayAccount().getId(),
|
||||
String sign = weixinOldSignature.sign(map);
|
||||
String nativepay_uri = getRequestUri("nativepay_old_uri");
|
||||
return String.format(nativepay_uri, sign, getPayAccount().getId(),
|
||||
productId, timestamp, noncestr);
|
||||
}
|
||||
|
||||
@@ -198,12 +208,12 @@ public class PayOldApi extends MpApi {
|
||||
* @param idQuery
|
||||
* 订单号
|
||||
* @return 订单信息
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.OrderV2
|
||||
* @see com.foxinmy.weixin4j.mp.oldpayment.OrderV2
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public OrderV2 orderQuery(IdQuery idQuery) throws WeixinException {
|
||||
String orderquery_uri = getRequestUri("orderquery_v2_uri");
|
||||
public OrderV2 queryOrder(IdQuery idQuery) throws WeixinException {
|
||||
String orderquery_uri = getRequestUri("orderquery_old_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(idQuery.getType().getName()).append("=")
|
||||
@@ -221,7 +231,7 @@ public class PayOldApi extends MpApi {
|
||||
obj.put("appkey", getPayAccount().getPaySignKey());
|
||||
obj.put("package", sb.toString());
|
||||
obj.put("timestamp", timestamp);
|
||||
String signature = DigestUtil.paysignSha(obj, null);
|
||||
String signature = weixinOldSignature.sign(obj);
|
||||
|
||||
obj.clear();
|
||||
obj.put("appid", getPayAccount().getId());
|
||||
@@ -251,7 +261,7 @@ public class PayOldApi extends MpApi {
|
||||
* 败后重新提交,要采用原来的 out_refund_no。总退款金额不能超过用户实际支付金额。</br>
|
||||
* </p>
|
||||
*
|
||||
* @param caFile
|
||||
* @param certificate
|
||||
* 证书文件(V2版本后缀为*.pfx)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
@@ -268,18 +278,17 @@ public class PayOldApi extends MpApi {
|
||||
* 如 opUserPasswd
|
||||
*
|
||||
* @return 退款申请结果
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundResultV2
|
||||
* @see com.foxinmy.weixin4j.mp.oldpayment.RefundResultV2
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
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("refundapply_v2_uri");
|
||||
protected RefundResultV2 applyRefund(InputStream certificate,
|
||||
IdQuery idQuery, String outRefundNo, double totalFee,
|
||||
double refundFee, String opUserId, Map<String, String> mopara)
|
||||
throws WeixinException {
|
||||
String refund_uri = getRequestUri("refundapply_old_uri");
|
||||
WeixinResponse response = null;
|
||||
InputStream ca = null;
|
||||
try {
|
||||
ca = new FileInputStream(caFile);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("input_charset", Consts.UTF_8.name());
|
||||
// 版本号
|
||||
@@ -298,24 +307,23 @@ public class PayOldApi extends MpApi {
|
||||
if (mopara != null && !mopara.isEmpty()) {
|
||||
map.putAll(mopara);
|
||||
}
|
||||
String sign = DigestUtil.paysignMd5(map, getPayAccount()
|
||||
.getPartnerKey());
|
||||
String sign = weixinMD5Signature.sign(map);
|
||||
map.put("sign", sign.toUpperCase());
|
||||
|
||||
SSLContext ctx = null;
|
||||
KeyStore ks = null;
|
||||
String jksPwd = "";
|
||||
File jksFile = new File(String.format("%s/tenpay_cacert.jks",
|
||||
caFile.getParent()));
|
||||
Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"))));
|
||||
// create jks ca
|
||||
if (!jksFile.exists()) {
|
||||
CertificateFactory cf = CertificateFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.X509);
|
||||
.getInstance(Consts.X509);
|
||||
java.security.cert.Certificate cert = cf
|
||||
.generateCertificate(PayOldApi.class
|
||||
.getResourceAsStream("cacert.pem"));
|
||||
ks = KeyStore
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.JKS);
|
||||
ks = KeyStore.getInstance(Consts.JKS);
|
||||
ks.load(null, null);
|
||||
ks.setCertificateEntry("tenpay", cert);
|
||||
FileOutputStream os = new FileOutputStream(jksFile);
|
||||
@@ -324,20 +332,20 @@ public class PayOldApi extends MpApi {
|
||||
}
|
||||
// load jks ca
|
||||
TrustManagerFactory tmf = TrustManagerFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.SunX509);
|
||||
ks = KeyStore.getInstance(com.foxinmy.weixin4j.model.Consts.JKS);
|
||||
.getInstance(Consts.SunX509);
|
||||
ks = KeyStore.getInstance(Consts.JKS);
|
||||
FileInputStream is = new FileInputStream(jksFile);
|
||||
ks.load(is, jksPwd.toCharArray());
|
||||
tmf.init(ks);
|
||||
is.close();
|
||||
// load pfx ca
|
||||
KeyManagerFactory kmf = KeyManagerFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.SunX509);
|
||||
ks = KeyStore.getInstance(com.foxinmy.weixin4j.model.Consts.PKCS12);
|
||||
ks.load(ca, getPayAccount().getPartnerId().toCharArray());
|
||||
.getInstance(Consts.SunX509);
|
||||
ks = KeyStore.getInstance(Consts.PKCS12);
|
||||
ks.load(certificate, getPayAccount().getPartnerId().toCharArray());
|
||||
kmf.init(ks, getPayAccount().getPartnerId().toCharArray());
|
||||
|
||||
ctx = SSLContext.getInstance(com.foxinmy.weixin4j.model.Consts.TLS);
|
||||
ctx = SSLContext.getInstance(Consts.TLS);
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
|
||||
new SecureRandom());
|
||||
|
||||
@@ -349,9 +357,9 @@ public class PayOldApi extends MpApi {
|
||||
} catch (Exception e) {
|
||||
throw new WeixinException(e);
|
||||
} finally {
|
||||
if (ca != null) {
|
||||
if (certificate != null) {
|
||||
try {
|
||||
ca.close();
|
||||
certificate.close();
|
||||
} catch (IOException e) {
|
||||
;
|
||||
}
|
||||
@@ -364,7 +372,7 @@ public class PayOldApi extends MpApi {
|
||||
/**
|
||||
* 退款申请
|
||||
*
|
||||
* @param caFile
|
||||
* @param certificate
|
||||
* 证书文件(V2版本后缀为*.pfx)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
@@ -379,21 +387,21 @@ public class PayOldApi extends MpApi {
|
||||
* 操作员帐号, 默认为商户号
|
||||
* @param opUserPasswd
|
||||
* 操作员密码,默认为商户后台登录密码
|
||||
* @see {@link #refundApply(File, IdQuery, String, double, double, String, Map)}
|
||||
* @see {@link #applyRefund(InputStream, IdQuery, String, double, double, String, Map)}
|
||||
*/
|
||||
public RefundResultV2 refundApply(File caFile, IdQuery idQuery,
|
||||
public RefundResultV2 applyRefund(InputStream certificate, 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 refundApply(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
opUserId, mopara);
|
||||
return applyRefund(certificate, idQuery, outRefundNo, totalFee,
|
||||
refundFee, opUserId, mopara);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款申请
|
||||
*
|
||||
* @param caFile
|
||||
* @param certificate
|
||||
* 证书文件(V2版本后缀为*.pfx)
|
||||
* @param idQuery
|
||||
* 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
|
||||
@@ -417,10 +425,10 @@ public class PayOldApi extends MpApi {
|
||||
* @param refundType
|
||||
* 为空或者填 1:商户号余额退款;2:现金帐号 退款;3:优先商户号退款,若商户号余额不足, 再做现金帐号退款。使用 2 或
|
||||
* 3 时,需联系财 付通开通此功能
|
||||
* @see {@link #refundApply(File, IdQuery, String, double, double, String, Map)}
|
||||
* @see {@link #applyRefund(InputStream, IdQuery, String, double, double, String, Map)}
|
||||
* @return 退款结果
|
||||
*/
|
||||
public RefundResultV2 refundApply(File caFile, IdQuery idQuery,
|
||||
public RefundResultV2 applyRefund(InputStream certificate, IdQuery idQuery,
|
||||
String outRefundNo, double totalFee, double refundFee,
|
||||
String opUserId, String opUserPasswd, String recvUserId,
|
||||
String reccvUserName, RefundType refundType) throws WeixinException {
|
||||
@@ -435,8 +443,8 @@ public class PayOldApi extends MpApi {
|
||||
if (refundType != null) {
|
||||
mopara.put("refund_type", Integer.toString(refundType.getVal()));
|
||||
}
|
||||
return refundApply(caFile, idQuery, outRefundNo, totalFee, refundFee,
|
||||
opUserId, mopara);
|
||||
return applyRefund(certificate, idQuery, outRefundNo, totalFee,
|
||||
refundFee, opUserId, mopara);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -474,7 +482,7 @@ public class PayOldApi extends MpApi {
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
String downloadbill_uri = getRequestUri("downloadbill_v2_uri");
|
||||
String downloadbill_uri = getRequestUri("downloadbill_old_uri");
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("spid", getPayAccount().getPartnerId());
|
||||
@@ -523,19 +531,18 @@ public class PayOldApi extends MpApi {
|
||||
* 四个参数必填一个,优先级为:
|
||||
* refund_id>out_refund_no>transaction_id>out_trade_no
|
||||
* @return 退款记录
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundDetailV2
|
||||
* @see com.foxinmy.weixin4j.mp.oldpayment.RefundRecordV2
|
||||
* @see com.foxinmy.weixin4j.mp.oldpayment.RefundDetailV2
|
||||
* @since V2
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public RefundRecordV2 refundQuery(IdQuery idQuery) throws WeixinException {
|
||||
String refundquery_uri = getRequestUri("refundquery_v2_uri");
|
||||
public RefundRecordV2 queryRefund(IdQuery idQuery) throws WeixinException {
|
||||
String refundquery_uri = getRequestUri("refundquery_old_uri");
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("input_charset", Consts.UTF_8.name());
|
||||
map.put("partner", getPayAccount().getPartnerId());
|
||||
map.put(idQuery.getType().getName(), idQuery.getId());
|
||||
String sign = DigestUtil.paysignMd5(map, getPayAccount()
|
||||
.getPartnerKey());
|
||||
String sign = weixinMD5Signature.sign(map);
|
||||
map.put("sign", sign.toLowerCase());
|
||||
WeixinResponse response = weixinExecutor.get(refundquery_uri, map);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
@@ -561,7 +568,7 @@ public class PayOldApi extends MpApi {
|
||||
public JsonResult deliverNotify(String openId, String transid,
|
||||
String outTradeNo, boolean status, String statusMsg)
|
||||
throws WeixinException {
|
||||
String delivernotify_uri = getRequestUri("delivernotify_uri");
|
||||
String delivernotify_uri = getRequestUri("delivernotify_old_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
@@ -573,7 +580,7 @@ public class PayOldApi extends MpApi {
|
||||
map.put("deliver_timestamp", DateUtil.timestamp2string());
|
||||
map.put("deliver_status", status ? "1" : "0");
|
||||
map.put("deliver_msg", statusMsg);
|
||||
map.put("app_signature", DigestUtil.paysignSha(map, null));
|
||||
map.put("app_signature", weixinOldSignature.sign(map));
|
||||
map.put("sign_method", SignType.SHA1.name().toLowerCase());
|
||||
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
@@ -594,11 +601,10 @@ public class PayOldApi extends MpApi {
|
||||
*/
|
||||
public JsonResult updateFeedback(String openId, String feedbackId)
|
||||
throws WeixinException {
|
||||
String payfeedback_update_uri = getRequestUri("payfeedback_update_uri");
|
||||
String payfeedback_uri = getRequestUri("payfeedback_old_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
payfeedback_update_uri, token.getAccessToken(), openId,
|
||||
feedbackId));
|
||||
payfeedback_uri, token.getAccessToken(), openId, feedbackId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
api_base_url=https://api.weixin.qq.com
|
||||
api_cgi_url={api_base_url}/cgi-bin
|
||||
mp_base_url=https://mp.weixin.qq.com/cgi-bin
|
||||
mch_base_url=https://api.mch.weixin.qq.com
|
||||
tenpay_base_url=http://mch.tenpay.com
|
||||
tenpay_ssl_base_url=https://mch.tenpay.com
|
||||
tenpay_gw_base_url=https://gw.tenpay.com
|
||||
|
||||
|
||||
# \u7f51\u9875\u6388\u6743\u83b7\u53d6\u7528\u6237\u4fe1\u606f
|
||||
sns_user_auth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect
|
||||
#open_user_auth_uri=https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect
|
||||
@@ -107,7 +105,6 @@ kfsession_list_uri={api_base_url}/customservice/kfsession/getsessionlist?access_
|
||||
kfsession_wait_uri={api_base_url}/customservice/kfsession/getwaitcase?access_token=%s
|
||||
# \u957f\u94fe\u63a5\u8f6c\u77ed\u94fe\u63a5
|
||||
shorturl_uri={api_cgi_url}/shorturl?access_token=%s
|
||||
p_shorturl_uri={mch_base_url}/tools/shorturl
|
||||
# \u8bbe\u7f6e\u5907\u6ce8\u540d
|
||||
updateremark_uri={api_cgi_url}/user/info/updateremark?access_token=%s
|
||||
# \u8bbe\u7f6e\u6a21\u677f\u6d88\u606f\u6240\u5904\u884c\u4e1a
|
||||
@@ -126,48 +123,26 @@ template_send_uri={api_cgi_url}/message/template/send?access_token=%s
|
||||
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
|
||||
|
||||
# v2\u8ba2\u5355\u67e5\u8be2
|
||||
orderquery_v2_uri={api_base_url}/pay/orderquery?access_token=%s
|
||||
# v2native\u652f\u4ed8
|
||||
ordernative_v2_uri=weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&nocestr=%s\udbff\udce0\udbff\udce0\udbff\udce0\udbff\udce0\udbff\udc57\udbff\udc57\udbff\udc57\udbff\udc57\udbff\udc71\udbff\udc71\udbff\udc71\udbff\udc71\udbff\udc54\udbff\udc54\udbff\udc54\udbff\udc54\udbff\udc53\udbff\udc53\udbff\udc53\udbff\udc53\udbff\udce0\udbff\udce0\udbff\udce0\udbff\udce0\udbff\udc76\udbff\udc76\udbff\udc76\udbff\udc76\udbff\udcdc\udbff\udcdc\udbff\udcdc\udbff\udcdc\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcde\udbff\udcde\udbff\udcde\udbff\udcde\udbff\udc69\udbff\udc69\udbff\udc69\udbff\udc69\udbff\udcdf\udbff\udcdf\udbff\udcdf\udbff\udcdf\udbff\udc69\udbff\udc69\udbff\udc69\udbff\udc69\udbff\udc77\udbff\udc77\udbff\udc77\udbff\udc77\udbff\udc57\udbff\udc57\udbff\udc57\udbff\udc57\udbff\udc71\udbff\udc71\udbff\udc71\udbff\udc71\udbff\udc54\udbff\udc54\udbff\udc54\udbff\udc54\udbff\udc68\udbff\udc68\udbff\udc68\udbff\udc68\udbff\udcdc\udbff\udcdc\udbff\udcdc\udbff\udcdc\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd\udbff\udcdd
|
||||
# \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
|
||||
# v2\u5bf9\u8d26\u5355\u4e0b\u8f7d
|
||||
downloadbill_v2_uri={tenpay_base_url}/cgi-bin/mchdown_real_new.cgi
|
||||
# v2\u9000\u6b3e\u67e5\u8be2
|
||||
refundquery_v2_uri={tenpay_gw_base_url}/gateway/normalrefundquery.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
|
||||
# \u5173\u95ed\u8ba2\u5355
|
||||
closeorder_uri={mch_base_url}/pay/closeorder
|
||||
# \u5bf9\u8d26\u5355\u4e0b\u8f7d
|
||||
downloadbill_v3_uri={mch_base_url}/pay/downloadbill
|
||||
# \u9000\u6b3e\u67e5\u8be2
|
||||
refundquery_v3_uri={mch_base_url}/pay/refundquery
|
||||
# \u9000\u6b3e\u7533\u8bf7
|
||||
refund_v3_uri={mch_base_url}/secapi/pay/refund
|
||||
# \u51b2\u6b63\u64a4\u9500
|
||||
reverse_uri={mch_base_url}/secapi/pay/reverse
|
||||
# \u88ab\u626b\u652f\u4ed8
|
||||
micropay_uri={mch_base_url}/pay/micropay
|
||||
# \u63a5\u53e3\u4e0a\u62a5
|
||||
pay_report_uri={mch_base_url}/payitil/report
|
||||
|
||||
# \u7edf\u4e00\u8ba2\u5355\u751f\u6210
|
||||
unifiedorder_uri={mch_base_url}/pay/unifiedorder
|
||||
# native\u652f\u4ed8\u94fe\u63a5
|
||||
nativepay_v2_uri=weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&noncestr=%s
|
||||
nativepay_v3_uri=weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s
|
||||
|
||||
# \u6570\u636e\u7edf\u8ba1
|
||||
datacube_uri={api_base_url}/datacube/%s?access_token=%s
|
||||
|
||||
##########################\u8001\u7248\u672c\u652f\u4ed8~start
|
||||
# \u8ba2\u5355\u67e5\u8be2
|
||||
orderquery_old_uri={api_base_url}/pay/orderquery?access_token=%s
|
||||
# \u53d1\u8d27\u901a\u77e5
|
||||
delivernotify_old_uri={api_base_url}/pay/delivernotify?access_token=%s
|
||||
# \u7ef4\u6743\u5904\u7406
|
||||
payfeedback_old_uri={api_base_url}/payfeedback/update?access_token=%s&openid=%s&feedbackid=%s
|
||||
# \u5bf9\u8d26\u5355\u4e0b\u8f7d
|
||||
downloadbill_old_uri={tenpay_base_url}/cgi-bin/mchdown_real_new.cgi
|
||||
# \u9000\u6b3e\u67e5\u8be2
|
||||
refundquery_old_uri={tenpay_gw_base_url}/gateway/normalrefundquery.xml
|
||||
# \u9000\u6b3e\u7533\u8bf7
|
||||
refundapply_old_uri={tenpay_ssl_base_url}/refundapi/gateway/refund.xml
|
||||
# native\u652f\u4ed8
|
||||
nativepay_old_uri=weixin://wxpay/bizpayurl?sign=%s&appid=%s&productid=%s×tamp=%s&noncestr=%s
|
||||
##########################\u8001\u7248\u672c\u652f\u4ed8~end
|
||||
|
||||
# \u4e0a\u4f20\u6c38\u4e45\u56fe\u6587\u7d20\u6750
|
||||
material_article_upload_uri={api_cgi_url}/material/add_news?access_token=%s
|
||||
# \u4e0a\u4f20\u6c38\u4e45\u5a92\u4f53\u7d20\u6750
|
||||
@@ -183,19 +158,4 @@ material_media_count_uri={api_cgi_url}/material/get_materialcount?access_token=%
|
||||
# \u83b7\u53d6\u5a92\u4f53\u7d20\u6750\u5217\u8868
|
||||
material_media_list_uri={api_cgi_url}/material/batchget_material?access_token=%s
|
||||
# \u81ea\u52a8\u56de\u590d\u89c4\u5219
|
||||
autoreply_setting_get_uri={api_cgi_url}/get_current_autoreply_info?access_token=%s
|
||||
|
||||
# \u53d1\u653e\u4ee3\u91d1\u5238
|
||||
coupon_send_uri={mch_base_url}/mmpaymkttransfers/send_coupon
|
||||
# \u67e5\u8be2\u4ee3\u91d1\u5238\u6279\u6b21\u4fe1\u606f
|
||||
couponstock_query_uri={mch_base_url}/mmpaymkttransfers/query_coupon_stock
|
||||
# \u67e5\u8be2\u4ee3\u91d1\u5238\u8be6\u7ec6\u4fe1\u606f
|
||||
coupondetail_query_uri={mch_base_url}/promotion/query_coupon
|
||||
# \u53d1\u9001\u73b0\u91d1\u7ea2\u5305
|
||||
redpack_send_uri={mch_base_url}/mmpaymkttransfers/sendredpack
|
||||
# \u67e5\u8be2\u73b0\u91d1\u7ea2\u5305
|
||||
redpack_query_uri={mch_base_url}/mmpaymkttransfers/gethbinfo
|
||||
# \u4f01\u4e1a\u5411\u4e2a\u4eba\u4ed8\u6b3e
|
||||
mp_payment_uri={mch_base_url}/mmpaymkttransfers/promotion/transfers
|
||||
# \u4f01\u4e1a\u4ed8\u6b3e\u67e5\u8be2
|
||||
mp_payquery_uri={mch_base_url}/mmpaymkttransfers/gettransferinfo
|
||||
autoreply_setting_get_uri={api_cgi_url}/get_current_autoreply_info?access_token=%s
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
+6
-5
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -11,7 +11,6 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayOldAccount;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
|
||||
/**
|
||||
* V2 Native支付时的回调响应
|
||||
@@ -64,10 +63,12 @@ public class NativePayResponseV2 extends PayRequest {
|
||||
*/
|
||||
public NativePayResponseV2(WeixinPayOldAccount weixinAccount,
|
||||
PayPackageV2 payPackage) {
|
||||
super(weixinAccount.getId(), DigestUtil.packageSign(payPackage,
|
||||
weixinAccount.getPartnerKey()));
|
||||
super(weixinAccount.getId(), null);
|
||||
this.retCode = "0";
|
||||
this.retMsg = "OK";
|
||||
WeixinOldPaymentSignature weixinSignature = new WeixinOldPaymentSignature();
|
||||
setPackageInfo(weixinSignature.sign(payPackage,
|
||||
weixinAccount.getPartnerKey()));
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", weixinAccount.getId());
|
||||
map.put("appkey", weixinAccount.getPaySignKey());
|
||||
@@ -76,7 +77,7 @@ public class NativePayResponseV2 extends PayRequest {
|
||||
map.put("package", getPackageInfo());
|
||||
map.put("retcode", getRetCode());
|
||||
map.put("reterrmsg", getRetMsg());
|
||||
this.setPaySign(DigestUtil.paysignSha(map, null));
|
||||
this.setPaySign(weixinSignature.sign(map));
|
||||
}
|
||||
|
||||
public String getRetCode() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.foxinmy.weixin4j.xml.ListsuffixResult;
|
||||
* @author jy
|
||||
* @date 2014年11月1日
|
||||
* @since JDK 1.6
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v2.RefundDetailV2
|
||||
* @see com.foxinmy.weixin4j.mp.oldpayment.RefundDetailV2
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.foxinmy.weixin4j.mp.oldpayment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPath;
|
||||
import com.foxinmy.weixin4j.sign.AbstractWeixinSignature;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
|
||||
/**
|
||||
* 老版本支付签名
|
||||
*
|
||||
* @className WeixinOldPaymentSignature
|
||||
* @author jy
|
||||
* @date 2016年3月26日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class WeixinOldPaymentSignature extends AbstractWeixinSignature {
|
||||
|
||||
@Override
|
||||
public boolean lowerCase() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sign(Object obj) {
|
||||
return DigestUtil.SHA1(join(obj).toString());
|
||||
}
|
||||
|
||||
public String sign(Object obj, String paySignKey) {
|
||||
if (obj instanceof Map) {
|
||||
JSONPath.set(obj, "appKey", paySignKey);
|
||||
} else {
|
||||
((JSONObject) JSON.toJSON(obj)).put("appKey", paySignKey);
|
||||
}
|
||||
return DigestUtil.SHA1(join(obj).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* package拼接签名
|
||||
*
|
||||
* @param packageInfo
|
||||
* package对象
|
||||
* @param partnerKey
|
||||
* 签名key
|
||||
* @return
|
||||
*/
|
||||
public String sign(PayPackageV2 packageInfo, String partnerKey) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// a.对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序) 后,
|
||||
// 使用 URL 键值 对的格式(即 key1=value1&key2=value2...)拼接成字符串 string1
|
||||
// 注意:值为空的参数不参与签名
|
||||
sb.append(MapUtil.toJoinString(packageInfo, false, false));
|
||||
// b--->
|
||||
// 在 string1 最后拼接上 key=signKey 得到 stringSignTemp 字符串,并 对
|
||||
// stringSignTemp 进行 md5 运算
|
||||
// 再将得到的 字符串所有字符转换为大写 ,得到 sign 值 signValue。
|
||||
sb.append("&key=").append(partnerKey);
|
||||
// c---> & d---->
|
||||
String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
|
||||
sb.delete(0, sb.length());
|
||||
// c.对传入参数中所有键值对的 value 进行 urlencode 转码后重新拼接成字符串 string2
|
||||
sb.append(MapUtil.toJoinString(packageInfo, true, false))
|
||||
.append("&sign=").append(sign);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.foxinmy.weixin4j.mp.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -36,20 +38,21 @@ public class PayTest {
|
||||
|
||||
@Test
|
||||
public void orderQueryV2() throws WeixinException {
|
||||
System.err.println(PAY2.orderQuery(new IdQuery("D14110500021",
|
||||
System.err.println(PAY2.queryOrder(new IdQuery("D14110500021",
|
||||
IdType.REFUNDNO)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refundV2() throws WeixinException {
|
||||
public void refundV2() throws WeixinException, IOException {
|
||||
IdQuery idQuery = new IdQuery("D15020300005", IdType.TRADENO);
|
||||
System.err.println(PAY2.refundApply(caFile, idQuery, "1422925555037",
|
||||
16d, 16d, "1221928801", "111111", null, null, null));
|
||||
System.err.println(PAY2.applyRefund(new FileInputStream(caFile),
|
||||
idQuery, "1422925555037", 16d, 16d, "1221928801", "111111",
|
||||
null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refundQueryV2() throws WeixinException {
|
||||
System.err.println(PAY2.refundQuery(new IdQuery("D14123000004",
|
||||
System.err.println(PAY2.queryRefund(new IdQuery("D14123000004",
|
||||
IdType.TRADENO)));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.mp.oldpayment.RefundRecordV2;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
Reference in New Issue
Block a user