Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
IJPay
提交
29ceaf56
I
IJPay
项目概览
int
/
IJPay
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
29ceaf56
编写于
2月 27, 2020
作者:
J
Javen205
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✅
测试 Api-v3 上传文件、Delete 接口
上级
9054365f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
109 addition
and
8 deletion
+109
-8
IJPay-WxPay/src/test/java/com/ijpay/wxpay/WxPayKitTest.java
IJPay-WxPay/src/test/java/com/ijpay/wxpay/WxPayKitTest.java
+109
-8
未找到文件。
IJPay-WxPay/src/test/java/com/ijpay/wxpay/WxPayKitTest.java
浏览文件 @
29ceaf56
...
...
@@ -6,6 +6,7 @@ import cn.hutool.core.io.file.FileWriter;
import
cn.hutool.crypto.SecureUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.ijpay.core.enums.RequestMethod
;
import
com.ijpay.core.enums.SignType
;
import
com.ijpay.core.kit.AesUtil
;
import
com.ijpay.core.kit.PayKit
;
import
com.ijpay.core.kit.WxPayKit
;
...
...
@@ -52,6 +53,8 @@ public class WxPayKitTest {
String
keyPath
=
"/Users/Javen/cert/apiclient_key.pem"
;
String
certPath
=
"/Users/Javen/cert/apiclient_cert.pem"
;
String
certPath2
=
"/Users/Javen/cert/apiclient_cert.p12"
;
String
mchId
=
"xxx"
;
// 商户API证书序列号
// 使用证书解析工具 https://myssl.com/cert_decode.html 查看
...
...
@@ -89,9 +92,80 @@ public class WxPayKitTest {
}
@Test
public
void
v3Execution
()
{
public
void
v3Get
()
{
// 获取平台证书列表
try
{
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
GET
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
GET_CERTIFICATES
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
);
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
GET
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
GET_CERTIFICATES
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
);
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
v3Delete
()
{
// 创建/查询/更新/删除投诉通知回调
try
{
HashMap
<
String
,
String
>
hashMap
=
new
HashMap
<>();
hashMap
.
put
(
"url"
,
"https://qq.com"
);
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
POST
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
MERCHANT_SERVICE_COMPLAINTS_NOTIFICATIONS
.
toString
(),
mchId
,
serialNo
,
keyPath
,
JSONUtil
.
toJsonStr
(
hashMap
)
);
System
.
out
.
println
(
result
);
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
DELETE
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
MERCHANT_SERVICE_COMPLAINTS_NOTIFICATIONS
.
toString
(),
mchId
,
serialNo
,
keyPath
,
""
);
// 如果返回的为 204 表示删除成功
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
upload
()
{
//TODO 待测试 证书上传文件
try
{
String
filePath
=
"/Users/Javen/Documents/pic/cat.png"
;
HashMap
<
String
,
String
>
hashMap
=
new
HashMap
<>();
hashMap
.
put
(
"mch_id"
,
mchId
);
hashMap
.
put
(
"media_hash"
,
PayKit
.
md5
(
FileUtil
.
readUtf8String
(
filePath
)).
toLowerCase
());
hashMap
.
put
(
"sign_type"
,
SignType
.
HMACSHA256
.
toString
());
String
sign
=
WxPayKit
.
createSign
(
hashMap
,
apiKey3
,
SignType
.
HMACSHA256
);
hashMap
.
put
(
"sign"
,
sign
);
System
.
out
.
println
(
hashMap
);
String
result
=
WxPayApi
.
execution
(
WxDomain
.
CHINA
.
toString
().
concat
(
WxApiType
.
MCH_UPLOAD_MEDIA
.
toString
()),
hashMap
,
certPath2
,
mchId
,
filePath
);
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -100,18 +174,29 @@ public class WxPayKitTest {
@Test
public
void
v3Upload
()
{
//
TODO 签名异常
//
v3 接口上传文件
try
{
String
filePath
=
"/Users/Javen/Documents/pic/cat.png"
;
File
file
=
FileUtil
.
newFile
(
filePath
);
String
sha256
=
SecureUtil
.
sha256
(
file
);
HashMap
<
Object
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"filename"
,
file
.
getName
());
map
.
put
(
"sha256"
,
sha256
);
body
=
JSONUtil
.
toJsonStr
(
map
);
System
.
out
.
println
(
body
);
String
result
=
WxPayApi
.
v3Upload
(
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
UPLOAD_MEDIA
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
,
file
);
String
result
=
WxPayApi
.
v3Upload
(
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
MERCHANT_UPLOAD_MEDIA
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
,
file
);
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -119,15 +204,23 @@ public class WxPayKitTest {
}
@Test
public
void
u
serServiceState
()
{
public
void
payScoreU
serServiceState
()
{
try
{
Map
<
String
,
String
>
params
=
new
HashMap
<>();
params
.
put
(
"service_id"
,
"500001"
);
params
.
put
(
"appid"
,
"wxd678efh567hg6787"
);
params
.
put
(
"openid"
,
"oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"
);
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
GET
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
USER_SERVICE_STATE
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
,
params
);
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
GET
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
PAY_SCORE_USER_SERVICE_STATE
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
,
params
);
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -160,7 +253,15 @@ public class WxPayKitTest {
System
.
out
.
println
(
body
);
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
POST
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
PAY_AFTER_ORDERS
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
);
String
result
=
WxPayApi
.
v3Execution
(
RequestMethod
.
POST
,
WxDomain
.
CHINA
.
toString
(),
WxApiType
.
PAY_AFTER_ORDERS
.
toString
(),
mchId
,
serialNo
,
keyPath
,
body
);
System
.
out
.
println
(
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录