Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
peizhen-java
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PeiZhen-Java
peizhen-java
Commits
e4f9dc0c
Commit
e4f9dc0c
authored
Sep 13, 2023
by
zhengyunfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信支付init
parent
fcb44dd4
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
295 additions
and
4 deletions
+295
-4
pz-admin/src/main/resources/application.yml
+6
-3
pz-common/pom.xml
+5
-1
pz-common/src/main/java/com/pz/common/config/WechatPayProperties.java
+4
-0
pz-common/src/main/java/com/pz/common/config/WxPayConfiguration.java
+41
-0
pz-system/src/main/java/com/pz/system/service/IPayService.java
+97
-0
pz-system/src/main/java/com/pz/system/service/impl/PayServiceImpl.java
+142
-0
No files found.
pz-admin/src/main/resources/application.yml
View file @
e4f9dc0c
...
@@ -287,12 +287,15 @@ wechat:
...
@@ -287,12 +287,15 @@ wechat:
aesKey
:
#微信小程序消息服务器配置的EncodingAESKey
aesKey
:
#微信小程序消息服务器配置的EncodingAESKey
msgDataFormat
:
JSON
msgDataFormat
:
JSON
pay
:
pay
:
mch-id
:
1640662528
appId
:
wx6cc2fd1bca9472ae
#微信公众号或者小程序等的appid
mch-key
:
FogyUzGHMnsoUU3exYyDO8DEKEtNjsSx
mchId
:
1640662528
#微信支付商户号
key-path
:
classpath:/apiclient_cert.p12
mchKey
:
FogyUzGHMnsoUU3exYyDO8DEKEtNjsSx
#微信支付商户密钥
keyPath
:
classpath:/apiclient_cert.p12
# p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头)
---
# 文件上传设置
---
# 文件上传设置
file
:
file
:
#upload-path: /www/wwwroot/pz/upload
#upload-path: /www/wwwroot/pz/upload
upload-path
:
D:/www/wwwroot/pz/upload
upload-path
:
D:/www/wwwroot/pz/upload
#注意:响应路径必须加上file后缀
#注意:响应路径必须加上file后缀
response-path
:
https://www.pz.com/file
response-path
:
https://www.pz.com/file
pz-common/pom.xml
View file @
e4f9dc0c
...
@@ -172,7 +172,11 @@
...
@@ -172,7 +172,11 @@
<version>
4.5.5.B
</version>
<version>
4.5.5.B
</version>
</dependency>
</dependency>
<!--微信支付-->
<!--微信支付-->
<dependency>
<groupId>
com.github.binarywang
</groupId>
<artifactId>
weixin-java-pay
</artifactId>
<version>
4.5.0
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
pz-common/src/main/java/com/pz/common/config/WechatPayProperties.java
View file @
e4f9dc0c
...
@@ -13,6 +13,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
...
@@ -13,6 +13,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public
class
WechatPayProperties
{
public
class
WechatPayProperties
{
/**
/**
* 设置微信公众号或者小程序等的appid
*/
private
String
appId
;
/**
* 微信支付商户号
* 微信支付商户号
*/
*/
private
String
mchId
;
private
String
mchId
;
...
...
pz-common/src/main/java/com/pz/common/config/WxPayConfiguration.java
0 → 100644
View file @
e4f9dc0c
package
com
.
pz
.
common
.
config
;
import
com.github.binarywang.wxpay.config.WxPayConfig
;
import
com.github.binarywang.wxpay.service.WxPayService
;
import
com.github.binarywang.wxpay.service.impl.WxPayServiceImpl
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author Binary Wang
*/
@Configuration
@ConditionalOnClass
(
WxPayService
.
class
)
@EnableConfigurationProperties
(
WechatPayProperties
.
class
)
@AllArgsConstructor
public
class
WxPayConfiguration
{
private
WechatPayProperties
properties
;
@Bean
@ConditionalOnMissingBean
public
WxPayService
wxService
()
{
WxPayConfig
payConfig
=
new
WxPayConfig
();
payConfig
.
setAppId
(
StringUtils
.
trimToNull
(
this
.
properties
.
getAppId
()));
payConfig
.
setMchId
(
StringUtils
.
trimToNull
(
this
.
properties
.
getMchId
()));
payConfig
.
setMchKey
(
StringUtils
.
trimToNull
(
this
.
properties
.
getMchKey
()));
payConfig
.
setKeyPath
(
StringUtils
.
trimToNull
(
this
.
properties
.
getKeyPath
()));
// 可以指定是否使用沙箱环境
payConfig
.
setUseSandboxEnv
(
false
);
WxPayService
wxPayService
=
new
WxPayServiceImpl
();
wxPayService
.
setConfig
(
payConfig
);
return
wxPayService
;
}
}
pz-system/src/main/java/com/pz/system/service/IPayService.java
0 → 100644
View file @
e4f9dc0c
package
com
.
pz
.
system
.
service
;
import
com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest
;
import
com.github.binarywang.wxpay.bean.request.WxPayRefundRequest
;
import
com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest
;
import
com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult
;
import
com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult
;
import
com.github.binarywang.wxpay.bean.result.WxPayRefundResult
;
import
com.github.binarywang.wxpay.exception.WxPayException
;
import
com.pz.common.core.domain.PageQuery
;
import
com.pz.common.core.page.TableDataInfo
;
import
com.pz.system.domain.bo.CityBo
;
import
com.pz.system.domain.vo.CityVo
;
import
java.util.Collection
;
import
java.util.List
;
/**
* 城市Service接口
*
* @author ruoyi
* @date 2023-09-07
*/
public
interface
IPayService
{
/**
* <pre>
* 查询订单(详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2)
* 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。
* 需要调用查询接口的情况:
* ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;
* ◆ 调用支付接口后,返回系统错误或未知交易状态情况;
* ◆ 调用被扫支付API,返回USERPAYING的状态;
* ◆ 调用关单或撤销接口API之前,需确认支付状态;
* 接口地址:https://api.mch.weixin.qq.com/pay/orderquery
* </pre>
*
* @param transactionId 微信订单号
* @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。
*/
WxPayOrderQueryResult
queryOrder
(
String
transactionId
,
String
outTradeNo
)
throws
WxPayException
;
/**
* 统一下单
* 调用统一下单接口,并组装生成支付所需参数对象.
*
* @param request 统一下单请求参数
* @param <T> 请使用{@link com.github.binarywang.wxpay.bean.order}包下的类
* @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象
*/
<
T
>
T
createOrder
(
WxPayUnifiedOrderRequest
request
)
throws
WxPayException
;
/**
* <pre>
* 微信支付-申请退款
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
* 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund
* </pre>
*
* @param request 请求对象
* @return 退款操作结果
*/
WxPayRefundResult
refund
(
WxPayRefundRequest
request
)
throws
WxPayException
;
/**
* <pre>
* 微信支付-查询退款
* 应用场景:
* 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,
* 银行卡支付的退款3个工作日后重新查询退款状态。
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
* 接口链接:https://api.mch.weixin.qq.com/pay/refundquery
* </pre>
* 以下四个参数四选一
*
* @param transactionId 微信订单号
* @param outTradeNo 商户订单号
* @param outRefundNo 商户退款单号
* @param refundId 微信退款单号
* @return 退款信息
*/
WxPayRefundQueryResult
refundQuery
(
String
transactionId
,
String
outTradeNo
,
String
outRefundNo
,
String
refundId
)
throws
WxPayException
;
/**
* 支付回调通知处理
* 微信请求的接口,要求可以公网访问,要放开token校验
* @param xmlData 微信提交的请求参数
*/
String
parseOrderNotifyResult
(
String
xmlData
)
throws
WxPayException
;
/**
* 退款回调通知处理
* 微信请求的接口,要求可以公网访问,要放开token校验
* @param xmlData 微信提交的请求参数
*/
String
parseRefundNotifyResult
(
String
xmlData
)
throws
WxPayException
;
}
pz-system/src/main/java/com/pz/system/service/impl/PayServiceImpl.java
0 → 100644
View file @
e4f9dc0c
package
com
.
pz
.
system
.
service
.
impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse
;
import
com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult
;
import
com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult
;
import
com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult
;
import
com.github.binarywang.wxpay.bean.request.*
;
import
com.github.binarywang.wxpay.bean.result.*
;
import
com.github.binarywang.wxpay.exception.WxPayException
;
import
com.github.binarywang.wxpay.service.WxPayService
;
import
com.pz.common.core.domain.PageQuery
;
import
com.pz.common.core.page.TableDataInfo
;
import
com.pz.system.domain.City
;
import
com.pz.system.domain.bo.CityBo
;
import
com.pz.system.domain.vo.CityVo
;
import
com.pz.system.mapper.CityMapper
;
import
com.pz.system.service.ICityService
;
import
com.pz.system.service.IPayService
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
java.io.File
;
import
java.util.Collection
;
import
java.util.List
;
/**
* 城市Service业务层处理
*
* @author ruoyi
* @date 2023-09-07
*/
@RequiredArgsConstructor
@Service
public
class
PayServiceImpl
implements
IPayService
{
@Autowired
private
WxPayService
wxService
;
/**
* <pre>
* 查询订单(详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2)
* 该接口提供所有微信支付订单的查询,商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。
* 需要调用查询接口的情况:
* ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;
* ◆ 调用支付接口后,返回系统错误或未知交易状态情况;
* ◆ 调用被扫支付API,返回USERPAYING的状态;
* ◆ 调用关单或撤销接口API之前,需确认支付状态;
* 接口地址:https://api.mch.weixin.qq.com/pay/orderquery
* </pre>
*
* @param transactionId 微信订单号
* @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。
*/
@Override
public
WxPayOrderQueryResult
queryOrder
(
String
transactionId
,
String
outTradeNo
)
throws
WxPayException
{
return
this
.
wxService
.
queryOrder
(
transactionId
,
outTradeNo
);
}
/**
* 调用统一下单接口,并组装生成支付所需参数对象.
*
* @param request 统一下单请求参数
* @param <T> 请使用{@link com.github.binarywang.wxpay.bean.order}包下的类
* @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象
*/
@Override
public
<
T
>
T
createOrder
(
WxPayUnifiedOrderRequest
request
)
throws
WxPayException
{
return
this
.
wxService
.
createOrder
(
request
);
}
/**
* <pre>
* 微信支付-申请退款
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
* 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund
* </pre>
*
* @param request 请求对象
* @return 退款操作结果
*/
@Override
public
WxPayRefundResult
refund
(
WxPayRefundRequest
request
)
throws
WxPayException
{
return
this
.
wxService
.
refund
(
request
);
}
/**
* <pre>
* 微信支付-查询退款
* 应用场景:
* 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,
* 银行卡支付的退款3个工作日后重新查询退款状态。
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
* 接口链接:https://api.mch.weixin.qq.com/pay/refundquery
* </pre>
* 以下四个参数四选一
*
* @param transactionId 微信订单号
* @param outTradeNo 商户订单号
* @param outRefundNo 商户退款单号
* @param refundId 微信退款单号
* @return 退款信息
*/
@Override
public
WxPayRefundQueryResult
refundQuery
(
String
transactionId
,
String
outTradeNo
,
String
outRefundNo
,
String
refundId
)
throws
WxPayException
{
return
this
.
wxService
.
refundQuery
(
transactionId
,
outTradeNo
,
outRefundNo
,
refundId
);
}
/**
* 支付回调通知处理
* @param xmlData
* @return
* @throws WxPayException
*/
@Override
public
String
parseOrderNotifyResult
(
String
xmlData
)
throws
WxPayException
{
// 参数解析
final
WxPayOrderNotifyResult
notifyResult
=
this
.
wxService
.
parseOrderNotifyResult
(
xmlData
);
// TODO 根据自己业务场景需要构造返回对象
return
WxPayNotifyResponse
.
success
(
"成功"
);
}
/**
* 退款回调通知处理
* @param xmlData
* @return
* @throws WxPayException
*/
@Override
public
String
parseRefundNotifyResult
(
String
xmlData
)
throws
WxPayException
{
// 参数解析
final
WxPayRefundNotifyResult
result
=
this
.
wxService
.
parseRefundNotifyResult
(
xmlData
);
// TODO 根据自己业务场景需要构造返回对象
return
WxPayNotifyResponse
.
success
(
"成功"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment