提交 9f7596a1 编写于 作者: J Javen205

🏗 调整微信支付 v3 接口授权认证类型为枚举

上级 de53d0a2
package com.ijpay.core.enums;
/**
* <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付等常用的支付方式以及各种常用的接口。</p>
*
* <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
*
* <p>IJPay 交流群: 723992875、864988890</p>
*
* <p>Node.js 版: <a href="https://gitee.com/javen205/TNWX">https://gitee.com/javen205/TNWX</a></p>
*
* <p>微信支付 v3 接口授权认证类型枚举</p>
*
* @author Javen
*/
public enum AuthTypeEnum {
/**
* 国密
*/
SM("WECHATPAY2-SM2-WITH-SM3", "国密算法"),
/**
* RSA
*/
RSA("WECHATPAY2-SHA256-RSA2048", "RSA算法"),
;
private final String url;
private final String desc;
AuthTypeEnum(String url, String desc) {
this.url = url;
this.desc = desc;
}
/**
* 获取枚举URL
*
* @return 枚举编码
*/
public String getUrl() {
return url;
}
/**
* 获取详细的描述信息
*
* @return 描述信息
*/
public String getDesc() {
return desc;
}
}
......@@ -398,7 +398,7 @@ public class PayKit {
* @param nonceStr 请求随机串
* @param timestamp 时间戳
* @param signature 签名值
* @param authType 认证类型,目前为WECHATPAY2-SHA256-RSA2048
* @param authType 认证类型
* @return 请求头 Authorization
*/
public static String getAuthorization(String mchId, String serialNo, String nonceStr, String timestamp, String signature, String authType) {
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ijpay.core.IJPayHttpResponse;
import com.ijpay.core.enums.AuthTypeEnum;
import com.ijpay.core.enums.RequestMethodEnum;
import com.ijpay.core.enums.SignType;
......@@ -578,7 +579,7 @@ public class WxPayKit {
String serialNo, String keyPath, String body) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = PayKit.generateStr();
return buildAuthorization(method, urlSuffix, mchId, serialNo, keyPath, body, nonceStr, timestamp, authType);
......@@ -600,7 +601,7 @@ public class WxPayKit {
String serialNo, PrivateKey privateKey, String body) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = PayKit.generateStr();
return buildAuthorization(method, urlSuffix, mchId, serialNo, privateKey, body, nonceStr, timestamp, authType);
......
......@@ -20,6 +20,7 @@ import com.ijpay.wxpay.enums.v2.PayApiEnum;
import com.ijpay.wxpay.enums.v2.ProfitSharingApiEnum;
import com.ijpay.wxpay.enums.v2.RedPackApiEnum;
import com.ijpay.wxpay.enums.v2.TransferApiEnum;
import com.ijpay.core.enums.AuthTypeEnum;
import java.io.File;
import java.io.InputStream;
......@@ -255,9 +256,9 @@ public class WxPayApi {
* @throws Exception 接口执行异常
*/
public static IJPayHttpResponse v3(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String platSerialNo, String keyPath,
String body, String nonceStr, long timestamp, String authType,
File file) throws Exception {
String mchId, String serialNo, String platSerialNo, String keyPath,
String body, String nonceStr, long timestamp, String authType,
File file) throws Exception {
// 构建 Authorization
String authorization = WxPayKit.buildAuthorization(method, urlSuffix, mchId, serialNo,
keyPath, body, nonceStr, timestamp, authType);
......@@ -299,9 +300,9 @@ public class WxPayApi {
* @throws Exception 接口执行异常
*/
public static IJPayHttpResponse v3(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String platSerialNo, PrivateKey privateKey,
String body, String nonceStr, long timestamp, String authType,
File file) throws Exception {
String mchId, String serialNo, String platSerialNo, PrivateKey privateKey,
String body, String nonceStr, long timestamp, String authType,
File file) throws Exception {
// 构建 Authorization
String authorization = WxPayKit.buildAuthorization(method, urlSuffix, mchId, serialNo,
privateKey, body, nonceStr, timestamp, authType);
......@@ -339,9 +340,9 @@ public class WxPayApi {
* @throws Exception 接口执行异常
*/
public static IJPayHttpResponse v3(RequestMethodEnum method, String urlPrefix, String urlSuffix, String mchId,
String serialNo, String platSerialNo, String keyPath, String body) throws Exception {
String serialNo, String platSerialNo, String keyPath, String body) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = WxPayKit.generateStr();
return v3(method, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, keyPath, body, nonceStr, timestamp, authType, null);
}
......@@ -361,9 +362,9 @@ public class WxPayApi {
* @throws Exception 接口执行异常
*/
public static IJPayHttpResponse v3(RequestMethodEnum method, String urlPrefix, String urlSuffix, String mchId,
String serialNo, String platSerialNo, PrivateKey privateKey, String body) throws Exception {
String serialNo, String platSerialNo, PrivateKey privateKey, String body) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = WxPayKit.generateStr();
return v3(method, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, privateKey, body, nonceStr, timestamp, authType, null);
}
......@@ -383,10 +384,10 @@ public class WxPayApi {
* @throws Exception 接口执行异常
*/
public static IJPayHttpResponse v3(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String platSerialNo, String keyPath,
Map<String, String> params) throws Exception {
String mchId, String serialNo, String platSerialNo, String keyPath,
Map<String, String> params) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = WxPayKit.generateStr();
if (null != params && !params.keySet().isEmpty()) {
urlSuffix = urlSuffix.concat("?").concat(PayKit.createLinkString(params, true));
......@@ -409,10 +410,10 @@ public class WxPayApi {
* @throws Exception 接口执行异常
*/
public static IJPayHttpResponse v3(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String platSerialNo, PrivateKey privateKey,
Map<String, String> params) throws Exception {
String mchId, String serialNo, String platSerialNo, PrivateKey privateKey,
Map<String, String> params) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = WxPayKit.generateStr();
if (null != params && !params.keySet().isEmpty()) {
urlSuffix = urlSuffix.concat("?").concat(PayKit.createLinkString(params, true));
......@@ -436,7 +437,7 @@ public class WxPayApi {
*/
public static IJPayHttpResponse v3(String urlPrefix, String urlSuffix, String mchId, String serialNo, String platSerialNo, String keyPath, String body, File file) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = WxPayKit.generateStr();
return v3(RequestMethodEnum.UPLOAD, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, keyPath, body, nonceStr, timestamp, authType, file);
}
......@@ -458,7 +459,7 @@ public class WxPayApi {
public static IJPayHttpResponse v3(String urlPrefix, String urlSuffix, String mchId, String serialNo,
String platSerialNo, PrivateKey privateKey, String body, File file) throws Exception {
long timestamp = System.currentTimeMillis() / 1000;
String authType = "WECHATPAY2-SHA256-RSA2048";
String authType = AuthTypeEnum.RSA.getUrl();
String nonceStr = WxPayKit.generateStr();
return v3(RequestMethodEnum.UPLOAD, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, privateKey, body, nonceStr, timestamp, authType, file);
}
......@@ -483,9 +484,9 @@ public class WxPayApi {
*/
@Deprecated
public static Map<String, Object> v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String platSerialNo, String keyPath,
String body, String nonceStr, long timestamp, String authType,
File file) throws Exception {
String mchId, String serialNo, String platSerialNo, String keyPath,
String body, String nonceStr, long timestamp, String authType,
File file) throws Exception {
IJPayHttpResponse response = v3(method, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, keyPath, body, nonceStr, timestamp, authType, file);
return buildResMap(response);
}
......@@ -505,7 +506,7 @@ public class WxPayApi {
*/
@Deprecated
public static Map<String, Object> v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix, String mchId,
String serialNo, String keyPath, String body) throws Exception {
String serialNo, String keyPath, String body) throws Exception {
IJPayHttpResponse response = v3(method, urlPrefix, urlSuffix, mchId, serialNo, null, keyPath, body);
return buildResMap(response);
}
......@@ -526,7 +527,7 @@ public class WxPayApi {
*/
@Deprecated
public static Map<String, Object> v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix, String mchId,
String serialNo, String platSerialNo, String keyPath, String body) throws Exception {
String serialNo, String platSerialNo, String keyPath, String body) throws Exception {
IJPayHttpResponse response = v3(method, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, keyPath, body);
return buildResMap(response);
}
......@@ -547,8 +548,8 @@ public class WxPayApi {
*/
@Deprecated
public static Map<String, Object> v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String platSerialNo, String keyPath,
Map<String, String> params) throws Exception {
String mchId, String serialNo, String platSerialNo, String keyPath,
Map<String, String> params) throws Exception {
IJPayHttpResponse response = v3(method, urlPrefix, urlSuffix, mchId, serialNo, platSerialNo, keyPath, params);
return buildResMap(response);
}
......@@ -568,8 +569,8 @@ public class WxPayApi {
*/
@Deprecated
public static Map<String, Object> v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix,
String mchId, String serialNo, String keyPath,
Map<String, String> params) throws Exception {
String mchId, String serialNo, String keyPath,
Map<String, String> params) throws Exception {
IJPayHttpResponse response = v3(method, urlPrefix, urlSuffix, mchId, serialNo, null, keyPath, params);
return buildResMap(response);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册