From 9f7596a1108f6b38bf91e261f3adca22e7e399dc Mon Sep 17 00:00:00 2001 From: Javen205 Date: Sat, 1 Apr 2023 17:59:15 +0800 Subject: [PATCH] =?UTF-8?q?:building=5Fconstruction:=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=20v3=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E8=AE=A4=E8=AF=81=E7=B1=BB=E5=9E=8B=E4=B8=BA?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ijpay/core/enums/AuthTypeEnum.java | 54 ++++++++++++++++++ .../main/java/com/ijpay/core/kit/PayKit.java | 2 +- .../java/com/ijpay/core/kit/WxPayKit.java | 5 +- .../main/java/com/ijpay/wxpay/WxPayApi.java | 55 ++++++++++--------- 4 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 IJPay-Core/src/main/java/com/ijpay/core/enums/AuthTypeEnum.java diff --git a/IJPay-Core/src/main/java/com/ijpay/core/enums/AuthTypeEnum.java b/IJPay-Core/src/main/java/com/ijpay/core/enums/AuthTypeEnum.java new file mode 100644 index 0000000..c13929c --- /dev/null +++ b/IJPay-Core/src/main/java/com/ijpay/core/enums/AuthTypeEnum.java @@ -0,0 +1,54 @@ +package com.ijpay.core.enums; + + +/** + *

IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付等常用的支付方式以及各种常用的接口。

+ * + *

不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。

+ * + *

IJPay 交流群: 723992875、864988890

+ * + *

Node.js 版: https://gitee.com/javen205/TNWX

+ * + *

微信支付 v3 接口授权认证类型枚举

+ * + * @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; + } +} diff --git a/IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java b/IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java index 79714bc..72db008 100644 --- a/IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java +++ b/IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java @@ -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) { diff --git a/IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java b/IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java index 2ee6977..0a6f7f4 100644 --- a/IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java +++ b/IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java @@ -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); diff --git a/IJPay-WxPay/src/main/java/com/ijpay/wxpay/WxPayApi.java b/IJPay-WxPay/src/main/java/com/ijpay/wxpay/WxPayApi.java index 77dbd27..b178fae 100644 --- a/IJPay-WxPay/src/main/java/com/ijpay/wxpay/WxPayApi.java +++ b/IJPay-WxPay/src/main/java/com/ijpay/wxpay/WxPayApi.java @@ -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 params) throws Exception { + String mchId, String serialNo, String platSerialNo, String keyPath, + Map 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 params) throws Exception { + String mchId, String serialNo, String platSerialNo, PrivateKey privateKey, + Map 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 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 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 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 v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix, - String mchId, String serialNo, String platSerialNo, String keyPath, - Map params) throws Exception { + String mchId, String serialNo, String platSerialNo, String keyPath, + Map 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 v3Execution(RequestMethodEnum method, String urlPrefix, String urlSuffix, - String mchId, String serialNo, String keyPath, - Map params) throws Exception { + String mchId, String serialNo, String keyPath, + Map params) throws Exception { IJPayHttpResponse response = v3(method, urlPrefix, urlSuffix, mchId, serialNo, null, keyPath, params); return buildResMap(response); } -- GitLab