WeixinPayProxy新增getWeixinSignature方法
This commit is contained in:
parent
93d4ea5e25
commit
bc93a22563
@ -17,7 +17,7 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 商户支付
|
* 商户支付
|
||||||
*
|
*
|
||||||
* @className MchApi
|
* @className MchApi
|
||||||
* @author jinyu(foxinmy@gmail.com)
|
* @author jinyu(foxinmy@gmail.com)
|
||||||
* @date 2016年3月26日
|
* @date 2016年3月26日
|
||||||
@ -49,7 +49,7 @@ public class MchApi extends BaseApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 SSL支付请求
|
* 创建 SSL支付请求
|
||||||
*
|
*
|
||||||
* @param certificate
|
* @param certificate
|
||||||
* *.p12证书文件
|
* *.p12证书文件
|
||||||
* @return
|
* @return
|
||||||
@ -63,7 +63,7 @@ public class MchApi extends BaseApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付接口请求基本数据
|
* 支付接口请求基本数据
|
||||||
*
|
*
|
||||||
* @param idQuery
|
* @param idQuery
|
||||||
* ID信息 可为空
|
* ID信息 可为空
|
||||||
* @return 基础map
|
* @return 基础map
|
||||||
@ -87,4 +87,13 @@ public class MchApi extends BaseApi {
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信签名类
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public WeixinSignature getWeixinSignature() {
|
||||||
|
return this.weixinSignature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import com.foxinmy.weixin4j.payment.mch.RefundRecord;
|
|||||||
import com.foxinmy.weixin4j.payment.mch.RefundResult;
|
import com.foxinmy.weixin4j.payment.mch.RefundResult;
|
||||||
import com.foxinmy.weixin4j.payment.mch.SettlementRecord;
|
import com.foxinmy.weixin4j.payment.mch.SettlementRecord;
|
||||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||||
|
import com.foxinmy.weixin4j.sign.WeixinSignature;
|
||||||
import com.foxinmy.weixin4j.type.BillType;
|
import com.foxinmy.weixin4j.type.BillType;
|
||||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||||
import com.foxinmy.weixin4j.type.CustomsCity;
|
import com.foxinmy.weixin4j.type.CustomsCity;
|
||||||
@ -104,6 +105,15 @@ public class WeixinPayProxy {
|
|||||||
return this.settings.getPayAccount();
|
return this.settings.getPayAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信签名类
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public WeixinSignature getWeixinSignature() {
|
||||||
|
return this.payApi.getWeixinSignature();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一下单接口</br>
|
* 统一下单接口</br>
|
||||||
* 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI
|
* 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI
|
||||||
|
|||||||
@ -105,10 +105,14 @@ public class PayOldApi extends MpApi {
|
|||||||
this.weixinOldSignature = new WeixinOldPaymentSignature();
|
this.weixinOldSignature = new WeixinOldPaymentSignature();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WeixinOldPayAccount getPayAccount() {
|
public WeixinOldPayAccount getWeixinPayAccount() {
|
||||||
return this.weixinAccount;
|
return this.weixinAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WeixinOldPaymentSignature getWeixinPaymentSignature(){
|
||||||
|
return this.weixinOldSignature;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成V2.x版本JSAPI支付字符串
|
* 生成V2.x版本JSAPI支付字符串
|
||||||
*
|
*
|
||||||
@ -126,7 +130,7 @@ public class PayOldApi extends MpApi {
|
|||||||
*/
|
*/
|
||||||
public String createPayJsRequestJson(String body, String outTradeNo,
|
public String createPayJsRequestJson(String body, String outTradeNo,
|
||||||
double totalFee, String notifyUrl, String createIp) {
|
double totalFee, String notifyUrl, String createIp) {
|
||||||
PayPackageV2 payPackage = new PayPackageV2(getPayAccount()
|
PayPackageV2 payPackage = new PayPackageV2(weixinAccount
|
||||||
.getPartnerId(), body, outTradeNo, totalFee, notifyUrl,
|
.getPartnerId(), body, outTradeNo, totalFee, notifyUrl,
|
||||||
createIp);
|
createIp);
|
||||||
return createPayJsRequestJson(payPackage);
|
return createPayJsRequestJson(payPackage);
|
||||||
@ -140,11 +144,11 @@ public class PayOldApi extends MpApi {
|
|||||||
* @return 支付json串
|
* @return 支付json串
|
||||||
*/
|
*/
|
||||||
public String createPayJsRequestJson(PayPackageV2 payPackage) {
|
public String createPayJsRequestJson(PayPackageV2 payPackage) {
|
||||||
PayRequest payRequest = new PayRequest(getPayAccount().getId(),
|
PayRequest payRequest = new PayRequest(weixinAccount.getId(),
|
||||||
weixinOldSignature.sign(payPackage, getPayAccount()
|
weixinOldSignature.sign(payPackage, weixinAccount
|
||||||
.getPartnerKey()));
|
.getPartnerKey()));
|
||||||
payRequest.setPaySign(weixinOldSignature.sign(payRequest,
|
payRequest.setPaySign(weixinOldSignature.sign(payRequest,
|
||||||
getPayAccount().getPaySignKey()));
|
weixinAccount.getPaySignKey()));
|
||||||
payRequest.setSignType(SignType.SHA1);
|
payRequest.setSignType(SignType.SHA1);
|
||||||
return JSON.toJSONString(payRequest);
|
return JSON.toJSONString(payRequest);
|
||||||
}
|
}
|
||||||
@ -160,14 +164,14 @@ public class PayOldApi extends MpApi {
|
|||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
String timestamp = DateUtil.timestamp2string();
|
String timestamp = DateUtil.timestamp2string();
|
||||||
String noncestr = RandomUtil.generateString(16);
|
String noncestr = RandomUtil.generateString(16);
|
||||||
map.put("appid", getPayAccount().getId());
|
map.put("appid", weixinAccount.getId());
|
||||||
map.put("timestamp", timestamp);
|
map.put("timestamp", timestamp);
|
||||||
map.put("noncestr", noncestr);
|
map.put("noncestr", noncestr);
|
||||||
map.put("productid", productId);
|
map.put("productid", productId);
|
||||||
map.put("appkey", getPayAccount().getPaySignKey());
|
map.put("appkey", weixinAccount.getPaySignKey());
|
||||||
String sign = weixinOldSignature.sign(map);
|
String sign = weixinOldSignature.sign(map);
|
||||||
String nativepay_uri = getRequestUri("nativepay_old_uri");
|
String nativepay_uri = getRequestUri("nativepay_old_uri");
|
||||||
return String.format(nativepay_uri, sign, getPayAccount().getId(),
|
return String.format(nativepay_uri, sign, weixinAccount.getId(),
|
||||||
productId, timestamp, noncestr);
|
productId, timestamp, noncestr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,23 +191,23 @@ public class PayOldApi extends MpApi {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(idQuery.getType().getName()).append("=")
|
sb.append(idQuery.getType().getName()).append("=")
|
||||||
.append(idQuery.getId());
|
.append(idQuery.getId());
|
||||||
sb.append("&partner=").append(getPayAccount().getPartnerId());
|
sb.append("&partner=").append(weixinAccount.getPartnerId());
|
||||||
String part = sb.toString();
|
String part = sb.toString();
|
||||||
sb.append("&key=").append(getPayAccount().getPartnerKey());
|
sb.append("&key=").append(weixinAccount.getPartnerKey());
|
||||||
String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
|
String sign = DigestUtil.MD5(sb.toString()).toUpperCase();
|
||||||
sb.delete(0, sb.length());
|
sb.delete(0, sb.length());
|
||||||
sb.append(part).append("&sign=").append(sign);
|
sb.append(part).append("&sign=").append(sign);
|
||||||
|
|
||||||
String timestamp = DateUtil.timestamp2string();
|
String timestamp = DateUtil.timestamp2string();
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("appid", getPayAccount().getId());
|
obj.put("appid", weixinAccount.getId());
|
||||||
obj.put("appkey", getPayAccount().getPaySignKey());
|
obj.put("appkey", weixinAccount.getPaySignKey());
|
||||||
obj.put("package", sb.toString());
|
obj.put("package", sb.toString());
|
||||||
obj.put("timestamp", timestamp);
|
obj.put("timestamp", timestamp);
|
||||||
String signature = weixinOldSignature.sign(obj);
|
String signature = weixinOldSignature.sign(obj);
|
||||||
|
|
||||||
obj.clear();
|
obj.clear();
|
||||||
obj.put("appid", getPayAccount().getId());
|
obj.put("appid", weixinAccount.getId());
|
||||||
obj.put("package", sb.toString());
|
obj.put("package", sb.toString());
|
||||||
obj.put("timestamp", timestamp);
|
obj.put("timestamp", timestamp);
|
||||||
obj.put("app_signature", signature);
|
obj.put("app_signature", signature);
|
||||||
@ -264,13 +268,13 @@ public class PayOldApi extends MpApi {
|
|||||||
// 填写为 1.0 时,操作员密码为明文
|
// 填写为 1.0 时,操作员密码为明文
|
||||||
// 填写为 1.1 时,操作员密码为 MD5(密码)值
|
// 填写为 1.1 时,操作员密码为 MD5(密码)值
|
||||||
map.put("service_version", "1.1");
|
map.put("service_version", "1.1");
|
||||||
map.put("partner", getPayAccount().getPartnerId());
|
map.put("partner", weixinAccount.getPartnerId());
|
||||||
map.put("out_refund_no", outRefundNo);
|
map.put("out_refund_no", outRefundNo);
|
||||||
map.put("total_fee", DateUtil.formaFee2Fen(totalFee));
|
map.put("total_fee", DateUtil.formaFee2Fen(totalFee));
|
||||||
map.put("refund_fee", DateUtil.formaFee2Fen(refundFee));
|
map.put("refund_fee", DateUtil.formaFee2Fen(refundFee));
|
||||||
map.put(idQuery.getType().getName(), idQuery.getId());
|
map.put(idQuery.getType().getName(), idQuery.getId());
|
||||||
if (StringUtil.isBlank(opUserId)) {
|
if (StringUtil.isBlank(opUserId)) {
|
||||||
opUserId = getPayAccount().getPartnerId();
|
opUserId = weixinAccount.getPartnerId();
|
||||||
}
|
}
|
||||||
map.put("op_user_id", opUserId);
|
map.put("op_user_id", opUserId);
|
||||||
if (mopara != null && !mopara.isEmpty()) {
|
if (mopara != null && !mopara.isEmpty()) {
|
||||||
@ -311,8 +315,8 @@ public class PayOldApi extends MpApi {
|
|||||||
KeyManagerFactory kmf = KeyManagerFactory
|
KeyManagerFactory kmf = KeyManagerFactory
|
||||||
.getInstance(Consts.SunX509);
|
.getInstance(Consts.SunX509);
|
||||||
ks = KeyStore.getInstance(Consts.PKCS12);
|
ks = KeyStore.getInstance(Consts.PKCS12);
|
||||||
ks.load(certificate, getPayAccount().getPartnerId().toCharArray());
|
ks.load(certificate, weixinAccount.getPartnerId().toCharArray());
|
||||||
kmf.init(ks, getPayAccount().getPartnerId().toCharArray());
|
kmf.init(ks, weixinAccount.getPartnerId().toCharArray());
|
||||||
|
|
||||||
ctx = SSLContext.getInstance(Consts.TLS);
|
ctx = SSLContext.getInstance(Consts.TLS);
|
||||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
|
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(),
|
||||||
@ -446,7 +450,7 @@ public class PayOldApi extends MpApi {
|
|||||||
}
|
}
|
||||||
String formatBillDate = DateUtil.fortmat2yyyyMMdd(billDate);
|
String formatBillDate = DateUtil.fortmat2yyyyMMdd(billDate);
|
||||||
String fileName = String.format("weixin4j_bill_%s_%s_%s.txt",
|
String fileName = String.format("weixin4j_bill_%s_%s_%s.txt",
|
||||||
formatBillDate, billType.name().toLowerCase(), getPayAccount()
|
formatBillDate, billType.name().toLowerCase(), weixinAccount
|
||||||
.getId());
|
.getId());
|
||||||
File file = new File(String.format("%s/%s", billPath, fileName));
|
File file = new File(String.format("%s/%s", billPath, fileName));
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -455,12 +459,12 @@ public class PayOldApi extends MpApi {
|
|||||||
String downloadbill_uri = getRequestUri("downloadbill_old_uri");
|
String downloadbill_uri = getRequestUri("downloadbill_old_uri");
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("spid", getPayAccount().getPartnerId());
|
map.put("spid", weixinAccount.getPartnerId());
|
||||||
map.put("trans_time", DateUtil.fortmat2yyyy_MM_dd(billDate));
|
map.put("trans_time", DateUtil.fortmat2yyyy_MM_dd(billDate));
|
||||||
map.put("stamp", DateUtil.timestamp2string());
|
map.put("stamp", DateUtil.timestamp2string());
|
||||||
map.put("cft_signtype", "0");
|
map.put("cft_signtype", "0");
|
||||||
map.put("mchtype", Integer.toString(billType.getVal()));
|
map.put("mchtype", Integer.toString(billType.getVal()));
|
||||||
map.put("key", getPayAccount().getPartnerKey());
|
map.put("key", weixinAccount.getPartnerKey());
|
||||||
String sign = DigestUtil.MD5(MapUtil.toJoinString(map, false, false));
|
String sign = DigestUtil.MD5(MapUtil.toJoinString(map, false, false));
|
||||||
map.put("sign", sign.toLowerCase());
|
map.put("sign", sign.toLowerCase());
|
||||||
WeixinResponse response = weixinExecutor.get(downloadbill_uri, map);
|
WeixinResponse response = weixinExecutor.get(downloadbill_uri, map);
|
||||||
@ -510,7 +514,7 @@ public class PayOldApi extends MpApi {
|
|||||||
String refundquery_uri = getRequestUri("refundquery_old_uri");
|
String refundquery_uri = getRequestUri("refundquery_old_uri");
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("input_charset", Consts.UTF_8.name());
|
map.put("input_charset", Consts.UTF_8.name());
|
||||||
map.put("partner", getPayAccount().getPartnerId());
|
map.put("partner", weixinAccount.getPartnerId());
|
||||||
map.put(idQuery.getType().getName(), idQuery.getId());
|
map.put(idQuery.getType().getName(), idQuery.getId());
|
||||||
String sign = weixinMD5Signature.sign(map);
|
String sign = weixinMD5Signature.sign(map);
|
||||||
map.put("sign", sign.toLowerCase());
|
map.put("sign", sign.toLowerCase());
|
||||||
@ -542,8 +546,8 @@ public class PayOldApi extends MpApi {
|
|||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("appid", getPayAccount().getId());
|
map.put("appid", weixinAccount.getId());
|
||||||
map.put("appkey", getPayAccount().getPaySignKey());
|
map.put("appkey", weixinAccount.getPaySignKey());
|
||||||
map.put("openid", openId);
|
map.put("openid", openId);
|
||||||
map.put("transid", transid);
|
map.put("transid", transid);
|
||||||
map.put("out_trade_no", outTradeNo);
|
map.put("out_trade_no", outTradeNo);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user