mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-22 18:11:39 +08:00
优化
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.egzosn.pay.common.util.sign.sm3;
|
||||
package com.egzosn.pay.common.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Util
|
||||
public class Util
|
||||
{
|
||||
/**
|
||||
* 整形转换成网络传输的字节流(字节数组)型数据
|
||||
@@ -226,7 +226,7 @@ public class Util
|
||||
* @return 十六进制char[]
|
||||
*/
|
||||
public static char[] encodeHex(byte[] data, boolean toLowerCase) {
|
||||
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
|
||||
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.egzosn.pay.common.util.sign;
|
||||
|
||||
import com.egzosn.pay.common.util.sign.sm3.SM3Digest;
|
||||
import com.egzosn.pay.common.util.sign.encrypt.sm3.SM3Digest;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
@@ -63,6 +63,39 @@ public enum SignUtils {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.RSA2.sign(content, key, characterEncoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.RSA2.verify(text, sign, publicKey, characterEncoding);
|
||||
}
|
||||
},
|
||||
SHA1 {
|
||||
@Override
|
||||
public String createSign(String content, String key, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.SHA1.sign(content, key, characterEncoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.SHA1.verify(text, sign, publicKey, characterEncoding);
|
||||
}
|
||||
},
|
||||
SHA256 {
|
||||
@Override
|
||||
public String createSign(String content, String key, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.SHA256.sign(content, key, characterEncoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.SHA256.verify(text, sign, publicKey, characterEncoding);
|
||||
}
|
||||
},
|
||||
SM3 {
|
||||
@Override
|
||||
public String createSign(String content, String key, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.RSA2.sign(content, key, characterEncoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String text, String sign, String publicKey, String characterEncoding) {
|
||||
return com.egzosn.pay.common.util.sign.encrypt.RSA2.verify(text, sign, publicKey, characterEncoding);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package com.egzosn.pay.common.util.sign.sm3;
|
||||
package com.egzosn.pay.common.util.sign.encrypt.sm3;
|
||||
|
||||
import com.egzosn.pay.common.util.Util;
|
||||
|
||||
public class SM3
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.egzosn.pay.common.util.sign.sm3;
|
||||
package com.egzosn.pay.common.util.sign.encrypt.sm3;
|
||||
|
||||
public class SM3Digest
|
||||
{
|
||||
@@ -129,15 +129,5 @@ public class SM3Digest
|
||||
{
|
||||
return BYTE_LENGTH;
|
||||
}
|
||||
//
|
||||
// public static void main(String[] args)
|
||||
// {
|
||||
// byte[] md = new byte[32];
|
||||
// byte[] msg1 = "ererfeiisgod".getBytes();
|
||||
// SM3Digest sm3 = new SM3Digest();
|
||||
// sm3.update(msg1, 0, msg1.length);
|
||||
// sm3.doFinal(md, 0);
|
||||
// String s = new String(Hex.encode(md));
|
||||
// System.out.println(s.toUpperCase());
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.egzosn.pay.union.SDK;
|
||||
import com.egzosn.pay.common.util.str.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
@@ -34,7 +35,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*
|
||||
*/
|
||||
public class CertUtil {
|
||||
//日志
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
protected static final Log log = LogFactory.getLog(CertUtil.class);
|
||||
|
||||
public static final String UNIONPAY_CNNAME = "中国银联股份有限公司";
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.egzosn.pay.common.bean.result.PayException;
|
||||
import com.egzosn.pay.common.exception.PayErrorException;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.util.MatrixToImageWriter;
|
||||
import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.common.util.str.StringUtils;
|
||||
import com.egzosn.pay.union.SDK.CertUtil;
|
||||
import com.egzosn.pay.union.SDK.SDKConfig;
|
||||
@@ -47,6 +48,7 @@ public class UnionPayService extends BasePayService {
|
||||
SDKConfig.getConfig().loadPropertiesFromSrc();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 银联全渠道系统,产品参数,除了encoding自行选择外其他不需修改
|
||||
* @return 返回参数集合
|
||||
@@ -55,7 +57,7 @@ public class UnionPayService extends BasePayService {
|
||||
Map<String ,String> params = new HashMap<>();
|
||||
params.put(SDKConstants.param_version, SDKConfig.getConfig().getVersion());
|
||||
params.put(SDKConstants.param_encoding, payConfigStorage.getInputCharset().toUpperCase());
|
||||
params.put(SDKConstants.param_signMethod, SDKConfig.getConfig().getSignMethodByStr(payConfigStorage.getSignType()));
|
||||
|
||||
params.put(SDKConstants.param_merId, payConfigStorage.getPid());
|
||||
//接入类型,商户接入填0 ,不需修改(0:直连商户, 1: 收单机构 2:平台商户)
|
||||
params.put(SDKConstants.param_accessType, "0");
|
||||
@@ -130,6 +132,7 @@ public class UnionPayService extends BasePayService {
|
||||
@Override
|
||||
public Map orderInfo (PayOrder order) {
|
||||
Map<String, String> params = this.getCommonParam();
|
||||
|
||||
UnionTransactionType type = (UnionTransactionType)order.getTransactionType();
|
||||
type.convertMap(params);
|
||||
switch (type){
|
||||
@@ -153,6 +156,55 @@ public class UnionPayService extends BasePayService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据签名类型获取银联签名对应的参数
|
||||
* @param signType 签名类型
|
||||
* @return 签名参数
|
||||
*/
|
||||
public String getSignMethod(SignUtils signType) {
|
||||
switch (signType) {
|
||||
case RSA:
|
||||
case RSA2:
|
||||
return SDKConstants.SIGNMETHOD_RSA;
|
||||
case SHA256:
|
||||
return SDKConstants.SIGNMETHOD_SHA256;
|
||||
case SM3:
|
||||
return SDKConstants.SIGNMETHOD_SM3;
|
||||
default:
|
||||
return SDKConstants.SIGNMETHOD_RSA;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建签名
|
||||
*
|
||||
* @param content 需要签名的内容
|
||||
* @param characterEncoding 字符编码
|
||||
* @return 签名
|
||||
*/
|
||||
@Override
|
||||
public String createSign(String content, String characterEncoding) {
|
||||
|
||||
return SignUtils.valueOf(payConfigStorage.getSignType()).createSign(content, payConfigStorage.getKeyPrivate(),characterEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成并设置签名
|
||||
* @param parameters 请求参数
|
||||
* @return 请求参数
|
||||
*/
|
||||
private Map<String, Object> setSign(Map<String, Object> parameters){
|
||||
SignUtils signUtils = SignUtils.valueOf(payConfigStorage.getSignType());
|
||||
parameters.put(SDKConstants.param_signMethod, getSignMethod(signUtils));
|
||||
|
||||
String sign = createSign( SignUtils.parameterText(parameters, "&"), payConfigStorage.getInputCharset());
|
||||
|
||||
parameters.put("sign", sign);
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取输出二维码,用户返回给支付端,
|
||||
*
|
||||
@@ -162,6 +214,9 @@ public class UnionPayService extends BasePayService {
|
||||
@Override
|
||||
public BufferedImage genQrPay (PayOrder order) {
|
||||
Map<String ,String > params = orderInfo(order);
|
||||
|
||||
|
||||
|
||||
CertUtil.sign(params,payConfigStorage.getInputCharset().toUpperCase());
|
||||
JSONObject response = getHttpRequestTemplate().postForObject(SDKConfig.getConfig().getBackRequestUrl(),params,JSONObject.class);
|
||||
if(SDKUtils.validate(response,payConfigStorage.getInputCharset().toUpperCase())){
|
||||
|
||||
@@ -19,10 +19,10 @@ public enum UnionTransactionType implements TransactionType{
|
||||
CONSUME("01","06","000000","08"),
|
||||
//消费撤销
|
||||
CONSUME_UNDO("31","00","000000","08"),
|
||||
//查询
|
||||
QUERY("00","00","000201",""),
|
||||
//退款
|
||||
REFUND("04","00","000000","08"),
|
||||
//查询
|
||||
QUERY("00","00","000201",""),
|
||||
//对账文件下载
|
||||
File_Transfer("00","00","000201","")
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user