Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
caa104cd
Commit
caa104cd
authored
Aug 06, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支付宝支付
parent
dcda5cee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
41 deletions
+82
-41
OrderPayBiz.java
...ain/java/com/xxfc/platform/universal/biz/OrderPayBiz.java
+41
-7
OrderRefundBiz.java
.../java/com/xxfc/platform/universal/biz/OrderRefundBiz.java
+41
-34
No files found.
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/biz/OrderPayBiz.java
View file @
caa104cd
...
@@ -277,24 +277,26 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
...
@@ -277,24 +277,26 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
*/
*/
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
private
String
generateAliPayment
(
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
private
String
generateAliPayment
(
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
//实例化客户端
//实例化客户端
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
SystemConfig
.
ALIPAY_PAY_BASE_URL
+
"/gateway.do"
,
AlipayClient
alipayClient
=
getAlipayClient
();
SystemConfig
.
ALIPAY_APPID
,
SystemConfig
.
ALIPAY_PRIVATE_KEY
,
AlipayConstants
.
FORMAT_JSON
,
"utf-8"
,
SystemConfig
.
ALIPAY_PUBLIC_KEY
,
AlipayConstants
.
SIGN_TYPE_RSA2
);
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
try
{
try
{
return
appOrderPay
(
alipayClient
,
orderPayVo
,
notifyUrl
);
return
appOrderPay
(
alipayClient
,
orderPayVo
,
notifyUrl
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
//
return
null
;
return
null
;
}
}
private
AlipayClient
getAlipayClient
()
{
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
SystemConfig
.
ALIPAY_PAY_BASE_URL
+
"/gateway.do"
,
SystemConfig
.
ALIPAY_APPID
,
SystemConfig
.
ALIPAY_PRIVATE_KEY
,
AlipayConstants
.
FORMAT_JSON
,
"utf-8"
,
SystemConfig
.
ALIPAY_PUBLIC_KEY
,
AlipayConstants
.
SIGN_TYPE_RSA2
);
return
alipayClient
;
}
//支付宝APP支付方法
//支付宝APP支付方法
p
ublic
String
appOrderPay
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
p
rivate
String
appOrderPay
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
AlipayTradeAppPayRequest
request
=
new
AlipayTradeAppPayRequest
();
AlipayTradeAppPayRequest
request
=
new
AlipayTradeAppPayRequest
();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
...
@@ -418,6 +420,38 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
...
@@ -418,6 +420,38 @@ public class OrderPayBiz extends BaseBiz<OrderPayMapper, OrderPay> {
log
.
info
(
"response: {}"
+
response
.
getBody
());
log
.
info
(
"response: {}"
+
response
.
getBody
());
}
}
/**
* APP支付退款
* @param
* @param outTradeNo 订单号
* @param tradNo 流水号
* @param refundAmount 退款金额
* @param refundReason 退款原因
* @return
*/
public
boolean
alipayOrderRefund
(
String
outTradeNo
,
String
tradNo
,
Integer
refundAmount
,
String
refundReason
)
{
AlipayClient
alipayClient
=
getAlipayClient
();
AlipayTradeRefundRequest
request
=
new
AlipayTradeRefundRequest
();
request
.
setBizContent
(
"{"
+
"\"out_trade_no\":\""
+
outTradeNo
+
"\","
+
"\"trade_no\":\""
+
tradNo
+
"\","
+
"\"refund_amount\":"
+
refundAmount
+
","
+
"\"out_request_no\":\""
+
refundReason
+
"\""
+
" }"
);
try
{
AlipayTradeRefundResponse
response
=
alipayClient
.
execute
(
request
);
if
(
response
.
isSuccess
()){
return
true
;
}
else
{
return
false
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
info
(
"退款失败请重试"
);
}
return
false
;
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
SystemConfig
.
ALIPAY_PAY_BASE_URL
+
"/gateway.do"
,
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
SystemConfig
.
ALIPAY_PAY_BASE_URL
+
"/gateway.do"
,
...
...
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/biz/OrderRefundBiz.java
View file @
caa104cd
...
@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.entity.Example
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -34,65 +35,71 @@ import static com.xxfc.platform.universal.constant.DictionaryKey.UNIVERSAL_PAY;
...
@@ -34,65 +35,71 @@ import static com.xxfc.platform.universal.constant.DictionaryKey.UNIVERSAL_PAY;
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
OrderRefundBiz
extends
BaseBiz
<
OrderRefundMapper
,
OrderRefund
>
{
public
class
OrderRefundBiz
extends
BaseBiz
<
OrderRefundMapper
,
OrderRefund
>
{
@Autowired
@Autowired
private
OrderPayBiz
payBiz
;
private
OrderPayBiz
payBiz
;
@Value
(
"${universal.cert}"
)
@Value
(
"${universal.cert}"
)
private
String
APICLIENT_CERT
;
private
String
APICLIENT_CERT
;
@Autowired
@Autowired
DictionaryBiz
dictionaryBiz
;
DictionaryBiz
dictionaryBiz
;
//申请退款
//申请退款
public
JSONObject
refund
(
OrderRefundVo
orderRefundVo
)
throws
Exception
{
public
JSONObject
refund
(
OrderRefundVo
orderRefundVo
)
throws
Exception
{
if
(
orderRefundVo
==
null
)
{
if
(
orderRefundVo
==
null
)
{
log
.
error
(
"-----参数为空-----------"
);
log
.
error
(
"-----参数为空-----------"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
}
String
order_no
=
orderRefundVo
.
getOrderNo
();
String
order_no
=
orderRefundVo
.
getOrderNo
();
String
appid
=
SystemConfig
.
APP_ID
;
String
appid
=
SystemConfig
.
APP_ID
;
String
mchId
=
SystemConfig
.
APP_PARTNER
;
String
mchId
=
SystemConfig
.
APP_PARTNER
;
String
partnerKey
=
SystemConfig
.
APP_PARTNER_KEY
;
String
partnerKey
=
SystemConfig
.
APP_PARTNER_KEY
;
Integer
payAmount
=
orderRefundVo
.
getAmount
();
Integer
payAmount
=
orderRefundVo
.
getAmount
();
Integer
refundAmount
=
orderRefundVo
.
getRefundAmount
();
Integer
refundAmount
=
orderRefundVo
.
getRefundAmount
();
//临时处理
//临时处理
Map
<
String
,
Dictionary
>
dictionaryMap
=
dictionaryBiz
.
getAll4Map
();
Map
<
String
,
Dictionary
>
dictionaryMap
=
dictionaryBiz
.
getAll4Map
();
Integer
demotion
=
Integer
.
valueOf
(
dictionaryMap
.
get
(
UNIVERSAL_PAY
+
"_"
+
PAY_DEMOTION
).
getDetail
());
Integer
demotion
=
Integer
.
valueOf
(
dictionaryMap
.
get
(
UNIVERSAL_PAY
+
"_"
+
PAY_DEMOTION
).
getDetail
());
payAmount
=
payAmount
/
demotion
;
payAmount
=
payAmount
/
demotion
;
if
(
payAmount
<=
0
)
{
if
(
payAmount
<=
0
)
{
payAmount
=
1
;
payAmount
=
1
;
}
}
refundAmount
=
refundAmount
/
demotion
;
refundAmount
=
refundAmount
/
demotion
;
if
(
refundAmount
<=
0
)
{
if
(
refundAmount
<=
0
)
{
refundAmount
=
1
;
refundAmount
=
1
;
}
}
String
refundDesc
=
StringUtils
.
isNotBlank
(
orderRefundVo
.
getRefundDesc
())?
orderRefundVo
.
getRefundDesc
()
:
"审核通过,退款"
;
String
refundDesc
=
StringUtils
.
isNotBlank
(
orderRefundVo
.
getRefundDesc
())
?
orderRefundVo
.
getRefundDesc
()
:
"审核通过,退款"
;
String
out_refund_no
=
Snowflake
.
build
()
+
""
;
String
out_refund_no
=
Snowflake
.
build
()
+
""
;
if
(
StringUtils
.
isBlank
(
order_no
)||
StringUtils
.
isBlank
(
appid
)||
StringUtils
.
isBlank
(
mchId
)||
StringUtils
.
isBlank
(
partnerKey
)
if
(
StringUtils
.
isBlank
(
order_no
)
||
StringUtils
.
isBlank
(
appid
)
||
StringUtils
.
isBlank
(
mchId
)
||
StringUtils
.
isBlank
(
partnerKey
)
||
payAmount
==
null
||
payAmount
==
0
||
refundAmount
==
null
||
refundAmount
==
0
)
{
||
payAmount
==
null
||
payAmount
==
0
||
refundAmount
==
null
||
refundAmount
==
0
)
{
log
.
error
(
"-----参数为空-----------"
);
log
.
error
(
"-----参数为空-----------"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
}
log
.
error
(
"-----payAmoun======="
+
payAmount
+
"------refundAmount======"
+
refundAmount
);
log
.
error
(
"-----payAmoun======="
+
payAmount
+
"------refundAmount======"
+
refundAmount
);
Example
example
=
new
Example
(
OrderPay
.
class
);
Example
example
=
new
Example
(
OrderPay
.
class
);
example
.
createCriteria
().
andEqualTo
(
"orderNo"
,
order_no
).
andEqualTo
(
"isDel"
,
0
).
andEqualTo
(
"status"
,
1
);
example
.
createCriteria
().
andEqualTo
(
"orderNo"
,
order_no
).
andEqualTo
(
"isDel"
,
0
).
andEqualTo
(
"status"
,
1
);
List
<
OrderPay
>
list
=
payBiz
.
selectByExample
(
example
);
List
<
OrderPay
>
list
=
payBiz
.
selectByExample
(
example
);
if
(
list
.
size
()==
0
){
if
(
list
.
size
()
==
0
)
{
log
.
error
(
"---支付回调---trade_no====="
+
order_no
+
"----订单不存在或未支付"
);
log
.
error
(
"---支付回调---trade_no====="
+
order_no
+
"----订单不存在或未支付"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
order_no
+
"订单不存在或未支付"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
order_no
+
"订单不存在或未支付"
);
}
OrderPay
orderPay
=
list
.
get
(
0
);
String
out_trade_no
=
orderPay
.
getTradeNo
();
boolean
flag
=
false
;
if
(
orderPay
.
getPayWay
()
==
2
)
{
flag
=
payBiz
.
alipayOrderRefund
(
out_trade_no
,
orderPay
.
getSerialNumber
(),
refundAmount
,
refundDesc
);
}
else
if
(
orderPay
.
getPayWay
()
==
1
){
flag
=
WxPayRefundUtils
.
refund
(
appid
,
mchId
,
partnerKey
,
out_trade_no
,
out_refund_no
,
payAmount
+
""
,
refundAmount
+
""
,
refundDesc
,
APICLIENT_CERT
);
}
}
OrderPay
orderPay
=
list
.
get
(
0
);
String
out_trade_no
=
orderPay
.
getTradeNo
();
if
(
flag
)
{
boolean
flag
=
WxPayRefundUtils
.
refund
(
appid
,
mchId
,
partnerKey
,
out_trade_no
,
out_refund_no
,
payAmount
+
""
,
OrderRefund
orderRefund
=
new
OrderRefund
();
refundAmount
+
""
,
refundDesc
,
APICLIENT_CERT
);
BeanUtils
.
copyProperties
(
orderRefund
,
orderRefundVo
);
if
(
flag
){
if
(
StringUtils
.
isNotBlank
(
orderRefund
.
getRefundDesc
()))
{
OrderRefund
orderRefund
=
new
OrderRefund
();
BeanUtils
.
copyProperties
(
orderRefund
,
orderRefundVo
);
if
(
StringUtils
.
isNotBlank
(
orderRefund
.
getRefundDesc
())){
orderRefund
.
setRefundDesc
(
refundDesc
);
orderRefund
.
setRefundDesc
(
refundDesc
);
}
}
orderRefund
.
setUserId
(
orderPay
.
getUserId
());
orderRefund
.
setUserId
(
orderPay
.
getUserId
());
...
...
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