Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
IJPay
提交
6696e957
I
IJPay
项目概览
int
/
IJPay
9 个月 前同步成功
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
IJPay
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6696e957
编写于
11月 02, 2022
作者:
J
Javen205
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
支持相对路径
上级
117299cc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
12 deletion
+31
-12
IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java
IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java
+22
-1
IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java
IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java
+9
-11
未找到文件。
IJPay-Core/src/main/java/com/ijpay/core/kit/PayKit.java
浏览文件 @
6696e957
...
...
@@ -426,7 +426,10 @@ public class PayKit {
* @throws Exception 异常信息
*/
public
static
PrivateKey
getPrivateKey
(
String
keyPath
)
throws
Exception
{
String
originalKey
=
FileUtil
.
readUtf8String
(
keyPath
);
String
originalKey
=
getCertFileContent
(
keyPath
);
if
(
StrUtil
.
isEmpty
(
originalKey
))
{
throw
new
RuntimeException
(
"商户私钥证书获取失败"
);
}
return
getPrivateKeyByKeyContent
(
originalKey
);
}
...
...
@@ -673,4 +676,22 @@ public class PayKit {
// 相对地址
return
getFileToStream
(
path
);
}
/**
* 通过路径获取证书文件的内容
*
* @param path 文件路径
* @return 文件内容
*/
public
static
String
getCertFileContent
(
String
path
)
{
if
(
StrUtil
.
isBlank
(
path
))
{
return
null
;
}
// 绝对地址
File
file
=
new
File
(
path
);
if
(!
file
.
exists
())
{
path
=
getAbsolutePath
(
path
);
}
return
FileUtil
.
readUtf8String
(
path
);
}
}
IJPay-Core/src/main/java/com/ijpay/core/kit/WxPayKit.java
浏览文件 @
6696e957
package
com.ijpay.core.kit
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
...
...
@@ -8,7 +7,6 @@ import com.ijpay.core.IJPayHttpResponse;
import
com.ijpay.core.enums.RequestMethodEnum
;
import
com.ijpay.core.enums.SignType
;
import
java.io.BufferedInputStream
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.security.PrivateKey
;
...
...
@@ -530,8 +528,8 @@ public class WxPayKit {
* @throws Exception 异常信息
*/
public
static
String
buildAuthorization
(
RequestMethodEnum
method
,
String
urlSuffix
,
String
mchId
,
String
serialNo
,
String
keyPath
,
String
body
,
String
nonceStr
,
long
timestamp
,
String
authType
)
throws
Exception
{
String
serialNo
,
String
keyPath
,
String
body
,
String
nonceStr
,
long
timestamp
,
String
authType
)
throws
Exception
{
// 构建签名参数
String
buildSignMessage
=
PayKit
.
buildSignMessage
(
method
,
urlSuffix
,
timestamp
,
nonceStr
,
body
);
String
signature
=
PayKit
.
createSign
(
buildSignMessage
,
keyPath
);
...
...
@@ -555,8 +553,8 @@ public class WxPayKit {
* @throws Exception 异常信息
*/
public
static
String
buildAuthorization
(
RequestMethodEnum
method
,
String
urlSuffix
,
String
mchId
,
String
serialNo
,
PrivateKey
privateKey
,
String
body
,
String
nonceStr
,
long
timestamp
,
String
authType
)
throws
Exception
{
String
serialNo
,
PrivateKey
privateKey
,
String
body
,
String
nonceStr
,
long
timestamp
,
String
authType
)
throws
Exception
{
// 构建签名参数
String
buildSignMessage
=
PayKit
.
buildSignMessage
(
method
,
urlSuffix
,
timestamp
,
nonceStr
,
body
);
String
signature
=
PayKit
.
createSign
(
buildSignMessage
,
privateKey
);
...
...
@@ -577,7 +575,7 @@ public class WxPayKit {
* @throws Exception 异常信息
*/
public
static
String
buildAuthorization
(
RequestMethodEnum
method
,
String
urlSuffix
,
String
mchId
,
String
serialNo
,
String
keyPath
,
String
body
)
throws
Exception
{
String
serialNo
,
String
keyPath
,
String
body
)
throws
Exception
{
long
timestamp
=
System
.
currentTimeMillis
()
/
1000
;
String
authType
=
"WECHATPAY2-SHA256-RSA2048"
;
...
...
@@ -599,7 +597,7 @@ public class WxPayKit {
* @throws Exception 异常信息
*/
public
static
String
buildAuthorization
(
RequestMethodEnum
method
,
String
urlSuffix
,
String
mchId
,
String
serialNo
,
PrivateKey
privateKey
,
String
body
)
throws
Exception
{
String
serialNo
,
PrivateKey
privateKey
,
String
body
)
throws
Exception
{
long
timestamp
=
System
.
currentTimeMillis
()
/
1000
;
String
authType
=
"WECHATPAY2-SHA256-RSA2048"
;
...
...
@@ -622,7 +620,7 @@ public class WxPayKit {
String
body
=
(
String
)
map
.
get
(
"body"
);
String
nonceStr
=
(
String
)
map
.
get
(
"nonceStr"
);
String
timestamp
=
(
String
)
map
.
get
(
"timestamp"
);
return
verifySignature
(
signature
,
body
,
nonceStr
,
timestamp
,
FileUtil
.
get
InputStream
(
certPath
));
return
verifySignature
(
signature
,
body
,
nonceStr
,
timestamp
,
PayKit
.
getCertFile
InputStream
(
certPath
));
}
/**
...
...
@@ -638,7 +636,7 @@ public class WxPayKit {
String
nonceStr
=
response
.
getHeader
(
"Wechatpay-Nonce"
);
String
signature
=
response
.
getHeader
(
"Wechatpay-Signature"
);
String
body
=
response
.
getBody
();
return
verifySignature
(
signature
,
body
,
nonceStr
,
timestamp
,
FileUtil
.
get
InputStream
(
certPath
));
return
verifySignature
(
signature
,
body
,
nonceStr
,
timestamp
,
PayKit
.
getCertFile
InputStream
(
certPath
));
}
/**
...
...
@@ -785,7 +783,7 @@ public class WxPayKit {
*/
public
static
String
verifyNotify
(
String
serialNo
,
String
body
,
String
signature
,
String
nonce
,
String
timestamp
,
String
key
,
String
certPath
)
throws
Exception
{
BufferedInputStream
inputStream
=
FileUtil
.
get
InputStream
(
certPath
);
InputStream
inputStream
=
PayKit
.
getCertFile
InputStream
(
certPath
);
return
verifyNotify
(
serialNo
,
body
,
signature
,
nonce
,
timestamp
,
key
,
inputStream
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录