Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
V
volunteer_service
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
licc
volunteer_service
Commits
02b37e12
Commit
02b37e12
authored
Apr 27, 2021
by
cy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支付代码整理
parent
f1359fdd
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
419 deletions
+61
-419
WxPayService.java
.../src/main/java/cn/wisenergy/service/app/WxPayService.java
+1
-1
AliPayServiceImpl.java
...java/cn/wisenergy/service/app/impl/AliPayServiceImpl.java
+7
-5
WxPayService1Impl.java
...java/cn/wisenergy/service/app/impl/WxPayService1Impl.java
+0
-255
WxPayServiceImpl.java
.../java/cn/wisenergy/service/app/impl/WxPayServiceImpl.java
+39
-35
WxPayUtil.java
...ce/src/main/java/cn/wisenergy/service/util/WxPayUtil.java
+12
-0
PayController.java
.../cn/wisenergy/web/admin/controller/app/PayController.java
+2
-10
TestWxPayController.java
...senergy/web/admin/controller/app/TestWxPayController.java
+0
-113
No files found.
wisenergy-service/src/main/java/cn/wisenergy/service/app/
Test
WxPayService.java
→
wisenergy-service/src/main/java/cn/wisenergy/service/app/WxPayService.java
View file @
02b37e12
...
...
@@ -13,7 +13,7 @@ import java.util.SortedMap;
/**
* @author chnegyan
*/
public
interface
Test
WxPayService
{
public
interface
WxPayService
{
/**
* pc端微信支付
* @Param 支付信息
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AliPayServiceImpl.java
View file @
02b37e12
...
...
@@ -9,6 +9,7 @@ import cn.wisenergy.model.vo.AddLimitVo;
import
cn.wisenergy.service.app.AliPayService
;
import
cn.wisenergy.service.app.UserLimitService
;
import
cn.wisenergy.service.common.Common
;
import
cn.wisenergy.service.util.WxPayUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alipay.api.AlipayClient
;
import
com.alipay.api.AlipayResponse
;
...
...
@@ -64,7 +65,8 @@ public class AliPayServiceImpl implements AliPayService {
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
Common
.
PAY_URL
,
APP_ID
,
PRIVATE_KEY
,
"json"
,
CHARSET
,
ALIPAY_PUBLIC_KEY
,
"RSA2"
);
AlipayTradePagePayRequest
alipayRequest
=
new
AlipayTradePagePayRequest
();
String
tradeNo
=
"21"
+
System
.
currentTimeMillis
();
//生成唯一订单号
String
tradeNo
=
WxPayUtil
.
getOrderIdByUUId
();
//支付成功跳转地址
alipayRequest
.
setReturnUrl
(
Common
.
RETURN_URL_PC
);
//支付回调地址
...
...
@@ -81,7 +83,7 @@ public class AliPayServiceImpl implements AliPayService {
try
{
AlipayTradePagePayResponse
response
=
alipayClient
.
pageExecute
(
alipayRequest
);
form
=
response
.
getBody
();
System
.
out
.
println
(
form
);
log
.
info
(
"AliPayServiceImpl[]doPost[]alipayClient.result.form:"
+
form
);
httpResponse
.
setContentType
(
"text/html;charset=UTF-8"
);
//直接将完整的表单html输出到页面
httpResponse
.
getWriter
().
write
(
form
);
...
...
@@ -115,12 +117,12 @@ public class AliPayServiceImpl implements AliPayService {
}
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
Common
.
PAY_URL
,
APP_ID
,
PRIVATE_KEY
,
"json"
,
CHARSET
,
ALIPAY_PUBLIC_KEY
,
"RSA2"
);
AlipayTradeWapPayRequest
alipayRequest
=
new
AlipayTradeWapPayRequest
();
String
tradeNo
=
"21"
+
System
.
currentTimeMillis
();
//生成唯一订单号
String
tradeNo
=
WxPayUtil
.
getOrderIdByUUId
();
//支付成功跳转地址
alipayRequest
.
setReturnUrl
(
Common
.
RETURN_URL_WAP
);
//支付后回调地址
alipayRequest
.
setNotifyUrl
(
Common
.
NOTIFY_URL
);
alipayRequest
.
setBizContent
(
"{"
+
"\"out_trade_no\":\""
+
tradeNo
+
"\","
+
"\"total_amount\":"
+
payPageDto
.
getTotal
()
+
","
+
...
...
@@ -133,7 +135,7 @@ public class AliPayServiceImpl implements AliPayService {
try
{
AlipayResponse
response
=
alipayClient
.
pageExecute
(
alipayRequest
);
form
=
response
.
getBody
();
System
.
out
.
println
(
form
);
log
.
info
(
"AliPayServiceImpl[]wapAliPay[]alipayClient.result.form:"
+
form
);
httpResponse
.
setContentType
(
"text/html;charset=UTF-8"
);
//直接将完整的表单html输出到页面
httpResponse
.
getWriter
().
write
(
form
);
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/WxPayService1Impl.java
deleted
100644 → 0
View file @
f1359fdd
This diff is collapsed.
Click to expand it.
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/
Test
WxPayServiceImpl.java
→
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/WxPayServiceImpl.java
View file @
02b37e12
...
...
@@ -5,7 +5,7 @@ import cn.wisenergy.mapper.PayRecordMapper;
import
cn.wisenergy.model.app.PayRecord
;
import
cn.wisenergy.model.dto.PayPageDto
;
import
cn.wisenergy.model.vo.AddLimitVo
;
import
cn.wisenergy.service.app.
Test
WxPayService
;
import
cn.wisenergy.service.app.WxPayService
;
import
cn.wisenergy.service.app.UserLimitService
;
import
cn.wisenergy.service.util.MapToXmlUtils
;
import
cn.wisenergy.service.util.WxPayUtil
;
...
...
@@ -33,7 +33,7 @@ import static com.baomidou.mybatisplus.core.toolkit.Constants.MD5;
*/
@Service
@Slf4j
public
class
TestWxPayServiceImpl
implements
Test
WxPayService
{
public
class
WxPayServiceImpl
implements
WxPayService
{
//统一下单接口链接
public
static
String
unifiedOrderUrl
=
"https://api.mch.weixin.qq.com/pay/unifiedorder"
;
...
...
@@ -68,19 +68,22 @@ public class TestWxPayServiceImpl implements TestWxPayService {
if
(
null
==
payPageDto
||
null
==
payPageDto
.
getTotal
())
{
return
R
.
error
(
"入参不能为空"
);
}
String
tradeNo
=
"21"
+
System
.
currentTimeMillis
();
//生成唯一订单号
String
tradeNo
=
WxPayUtil
.
getOrderIdByUUId
();
//商品id
String
product_id
=
"10"
+
System
.
currentTimeMillis
();
String
time_expire
=
WxPayUtil
.
getOrderExpireTime
(
2
*
60
*
1000L
);
//支付过期时间
String
time_expire
=
WxPayUtil
.
getOrderExpireTime
(
2
*
60
*
1000L
);
//生成预支付订单,充值结果设为失败(result=1)
try
{
//生成【统一下单API】所需参数的接口
String
orderInfo
=
WxPayUtil
.
createOrderInfo
(
payPageDto
,
tradeNo
,
product_id
,
time_expire
,
appid
,
mchid
,
key
);
System
.
out
.
println
(
orderInfo
);
String
orderInfo
=
WxPayUtil
.
createOrderInfo
(
payPageDto
,
tradeNo
,
product_id
,
time_expire
,
appid
,
mchid
,
key
);
log
.
info
(
"WxPayServiceImpl[]wxPay[]xmlInfo.orderInfo:"
+
orderInfo
);
//调用统一下单接口
Map
<
String
,
String
>
map
=
unifiedOrder
(
unifiedOrderUrl
,
orderInfo
);
Map
<
String
,
String
>
map
=
unifiedOrder
(
unifiedOrderUrl
,
orderInfo
);
String
code_url
=
map
.
get
(
"code_url"
);
log
.
info
(
"
支付返回信息:"
,
map
.
get
(
"return_msg"
)
);
if
(
map
!=
null
&&
"SUCCESS"
.
equals
(
map
.
get
(
"return_code"
))
&&
"SUCCESS"
.
equals
(
map
.
get
(
"result_code"
)))
{
log
.
info
(
"
WxPayServiceImpl[]wxPcPay[]unifiedOrder.result.map:"
+
map
);
if
(
map
!=
null
&&
"SUCCESS"
.
equals
(
map
.
get
(
"return_code"
))
&&
"SUCCESS"
.
equals
(
map
.
get
(
"result_code"
)))
{
PayRecord
payRecord
=
new
PayRecord
();
payRecord
.
setMoney
(
payPageDto
.
getTotal
());
payRecord
.
setResult
(
1
);
...
...
@@ -90,10 +93,9 @@ public class TestWxPayServiceImpl implements TestWxPayService {
payRecordMapper
.
add
(
payRecord
);
}
Map
<
String
,
String
>
objMap
=
new
HashMap
<>();
System
.
out
.
println
(
"code_url:"
+
code_url
);
objMap
.
put
(
"tradeNo"
,
tradeNo
);
objMap
.
put
(
"time_expire"
,
time_expire
);
objMap
.
put
(
"code_url"
,
code_url
);
objMap
.
put
(
"tradeNo"
,
tradeNo
);
objMap
.
put
(
"time_expire"
,
time_expire
);
objMap
.
put
(
"code_url"
,
code_url
);
return
R
.
ok
(
"0"
,
objMap
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -109,18 +111,19 @@ public class TestWxPayServiceImpl implements TestWxPayService {
if
(
null
==
payPageDto
||
null
==
payPageDto
.
getTotal
())
{
return
R
.
error
(
"入参不能为空"
);
}
String
tradeNo
=
"21"
+
System
.
currentTimeMillis
();
//生成唯一订单号
String
tradeNo
=
WxPayUtil
.
getOrderIdByUUId
();
//生成预支付订单,充值结果设为失败(result=1)
try
{
//生成【统一下单API】所需参数的接口
String
orderInfo
=
WxPayUtil
.
createOrderInfoH5
(
payPageDto
,
tradeNo
,
request
,
appid
,
mchid
,
key
);
System
.
out
.
println
(
orderInfo
);
String
orderInfo
=
WxPayUtil
.
createOrderInfoH5
(
payPageDto
,
tradeNo
,
request
,
appid
,
mchid
,
key
);
log
.
info
(
"WxPayServiceImpl[]h5WxPay[]xmlInfo.orderInfo:"
+
orderInfo
);
//调用统一下单接口
Map
<
String
,
String
>
map
=
unifiedOrder
(
unifiedOrderUrl
,
orderInfo
);
Map
<
String
,
String
>
map
=
unifiedOrder
(
unifiedOrderUrl
,
orderInfo
);
String
urlString
=
URLEncoder
.
encode
(
"https://jygkzy.com/#/history"
,
"GBK"
);
String
mweb_url
=
map
.
get
(
"mweb_url"
)
+
"&redirect_url="
+
urlString
;
log
.
info
(
"
返回信息:"
,
map
.
get
(
"return_msg"
)
);
if
(
map
!=
null
&&
"SUCCESS"
.
equals
(
map
.
get
(
"return_code"
))
&&
"SUCCESS"
.
equals
(
map
.
get
(
"result_code"
)))
{
log
.
info
(
"
WxPayServiceImpl[]h5WxPay[]unifiedOrder.result.map:"
+
map
);
if
(
map
!=
null
&&
"SUCCESS"
.
equals
(
map
.
get
(
"return_code"
))
&&
"SUCCESS"
.
equals
(
map
.
get
(
"result_code"
)))
{
PayRecord
payRecord
=
new
PayRecord
();
payRecord
.
setMoney
(
payPageDto
.
getTotal
());
payRecord
.
setResult
(
1
);
...
...
@@ -148,16 +151,16 @@ public class TestWxPayServiceImpl implements TestWxPayService {
SortedMap
<
String
,
String
>
mapParams
=
new
TreeMap
<>();
//随机字符串
String
nonce_str
=
RandomStringUtils
.
randomAlphanumeric
(
16
);
String
tradeNo
=
"21"
+
System
.
currentTimeMillis
();
//生成唯一订单号
String
tradeNo
=
WxPayUtil
.
getOrderIdByUUId
();
//生成预支付订单,充值结果设为失败(result=1)
try
{
//生成【统一下单API】所需参数的接口
String
orderInfo
=
WxPayUtil
.
createOrderInfoWx
(
payPageDto
,
tradeNo
,
nonce_str
,
Applets_ID
,
secrt_key
,
mchid
,
key
);
System
.
out
.
println
(
orderInfo
);
String
orderInfo
=
WxPayUtil
.
createOrderInfoWx
(
payPageDto
,
tradeNo
,
nonce_str
,
Applets_ID
,
secrt_key
,
mchid
,
key
);
log
.
info
(
"WxPayServiceImpl[]WxPayApplets[]xmlInfo.orderInfo:"
+
orderInfo
);
//调用统一下单接口
Map
<
String
,
String
>
map
=
unifiedOrder
(
unifiedOrderUrl
,
orderInfo
);
String
return_msg
=
map
.
get
(
"return_msg"
);
log
.
info
(
"支付返回信息:"
,
return_msg
);
Map
<
String
,
String
>
map
=
unifiedOrder
(
unifiedOrderUrl
,
orderInfo
);
log
.
info
(
"WxPayServiceImpl[]WxPayApplets[]unifiedOrder.result.map:"
+
map
);
if
(
"SUCCESS"
.
equals
(
map
.
get
(
"return_code"
))
&&
"SUCCESS"
.
equals
(
map
.
get
(
"result_code"
)))
{
PayRecord
record
=
new
PayRecord
();
record
.
setMoney
(
payPageDto
.
getTotal
());
...
...
@@ -176,10 +179,10 @@ public class TestWxPayServiceImpl implements TestWxPayService {
mapParams
.
put
(
"timeStamp"
,
timeStamp
+
""
);
mapParams
.
put
(
"signType"
,
MD5
);
//二次签名
String
paySign
=
WxPayUtil
.
createSign
(
mapParams
,
key
);
String
paySign
=
WxPayUtil
.
createSign
(
mapParams
,
key
);
mapParams
.
put
(
"paySign"
,
paySign
);
}
return
R
.
ok
(
"0"
,
mapParams
);
return
R
.
ok
(
"0"
,
mapParams
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
R
.
error
(
"支付参数获取失败"
);
...
...
@@ -190,7 +193,8 @@ public class TestWxPayServiceImpl implements TestWxPayService {
/***
* 微信统一下单
*/
public
Map
<
String
,
String
>
unifiedOrder
(
String
url
,
String
info
)
throws
Exception
{
public
Map
<
String
,
String
>
unifiedOrder
(
String
url
,
String
info
)
throws
Exception
{
log
.
info
(
"开始微信统一下单...."
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
//加入数据
conn
.
setRequestMethod
(
"POST"
);
...
...
@@ -218,7 +222,7 @@ public class TestWxPayServiceImpl implements TestWxPayService {
*/
@Override
public
void
wxPayCallBack
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
System
.
out
.
println
(
"进入微信回调
"
);
log
.
info
(
"开始微信回调....
"
);
BufferedOutputStream
out
=
new
BufferedOutputStream
(
response
.
getOutputStream
());
InputStream
inStream
=
request
.
getInputStream
();
ByteArrayOutputStream
outSteam
=
new
ByteArrayOutputStream
();
...
...
@@ -255,7 +259,7 @@ public class TestWxPayServiceImpl implements TestWxPayService {
+
"<return_msg><![CDATA[报文为空]]></return_msg>"
+
"</xml> "
;
}
}
else
{
}
else
{
resXml
=
"<xml>"
+
"<return_code><![CDATA[SUCCESS]]></return_code>"
+
"<return_msg><![CDATA[OK]]></return_msg>"
+
"</xml> "
;
}
...
...
@@ -272,17 +276,17 @@ public class TestWxPayServiceImpl implements TestWxPayService {
* 订单状态查询
*/
@Override
public
R
<
Map
<
String
,
String
>>
wxQuery
(
String
out_trade_no
)
{
public
R
<
Map
<
String
,
String
>>
wxQuery
(
String
out_trade_no
)
{
QueryWrapper
<
PayRecord
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"trade_no"
,
out_trade_no
);
queryWrapper
.
eq
(
"trade_no"
,
out_trade_no
);
PayRecord
payRecord
=
payRecordMapper
.
selectOne
(
queryWrapper
);
Map
<
String
,
String
>
result
=
new
HashMap
<>();
result
.
put
(
"return_code"
,
"SUCCESS"
);
result
.
put
(
"result_code"
,
"SUCCESS"
);
result
.
put
(
"trade_state"
,
"SUCCESS"
);
if
(
payRecord
.
getResult
()==
0
)
{
return
R
.
ok
(
0
,
result
);
}
else
{
if
(
payRecord
.
getResult
()
==
0
)
{
return
R
.
ok
(
0
,
result
);
}
else
{
return
R
.
error
(
"支付失败"
);
}
}
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/util/WxPayUtil.java
View file @
02b37e12
...
...
@@ -158,4 +158,16 @@ public class WxPayUtil {
return
sdf
.
format
(
afterDate
);
}
/**
* 生成16位唯一订单号
* @return
*/
public
static
String
getOrderIdByUUId
()
{
int
first
=
new
Random
(
10
).
nextInt
(
8
)
+
1
;
int
hashCodeV
=
UUID
.
randomUUID
().
toString
().
hashCode
();
if
(
hashCodeV
<
0
)
{
//有可能是负数
hashCodeV
=
-
hashCodeV
;
}
return
first
+
String
.
format
(
"%015d"
,
hashCodeV
);
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/PayController.java
View file @
02b37e12
...
...
@@ -4,8 +4,7 @@ import cn.wisenergy.common.utils.R;
import
cn.wisenergy.model.dto.PayPageDto
;
import
cn.wisenergy.model.dto.PayQueryDto
;
import
cn.wisenergy.service.app.AliPayService
;
import
cn.wisenergy.service.app.TestWxPayService
;
import
cn.wisenergy.service.app.WxPayService1
;
import
cn.wisenergy.service.app.WxPayService
;
import
cn.wisenergy.service.common.Common
;
import
com.alipay.api.AlipayApiException
;
import
com.alipay.api.AlipayClient
;
...
...
@@ -22,15 +21,8 @@ import org.apache.ibatis.annotations.Param;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.crypto.IllegalBlockSizeException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.security.InvalidKeyException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.SignatureException
;
import
java.security.spec.InvalidKeySpecException
;
import
java.util.Map
;
import
java.util.SortedMap
;
...
...
@@ -47,7 +39,7 @@ import java.util.SortedMap;
public
class
PayController
{
@Autowired
private
Test
WxPayService
testWxPayService
;
private
WxPayService
testWxPayService
;
@Autowired
private
AliPayService
aliPayService
;
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/TestWxPayController.java
deleted
100644 → 0
View file @
f1359fdd
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.service.util.SubCodeUtil
;
import
cn.wisenergy.service.wxpay.WxCommon
;
import
com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse
;
import
com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult
;
import
com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult
;
import
com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest
;
import
com.github.binarywang.wxpay.config.WxPayConfig
;
import
com.github.binarywang.wxpay.exception.WxPayException
;
import
com.github.binarywang.wxpay.service.WxPayService
;
import
com.github.binarywang.wxpay.service.impl.WxPayServiceImpl
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author 86187
*/
@Api
(
tags
=
"测试微信支付-管理员登录"
)
@RestController
@RequestMapping
(
"/pay"
)
@Slf4j
public
class
TestWxPayController
{
/**
* 产生订单接口
*
* @param payType 支付类型
* @param id 支付信息id
* @return
* @throws WxPayException
*/
@RequestMapping
(
value
=
"/generatePay/{payType}/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ApiOperation
(
value
=
"微信统一下单接口1"
)
public
R
generatePay2
(
@ApiParam
(
required
=
true
)
@PathVariable
(
value
=
"payType"
)
String
payType
,
@ApiParam
(
required
=
true
)
@PathVariable
(
value
=
"id"
)
String
id
)
throws
WxPayException
{
String
tradeNo
=
SubCodeUtil
.
getNum
();
String
busId
=
"123131313"
;
Integer
fee
=
1
;
WxPayUnifiedOrderRequest
.
WxPayUnifiedOrderRequestBuilder
builder
=
WxPayUnifiedOrderRequest
.
newBuilder
();
WxPayUnifiedOrderRequest
request
=
builder
.
body
(
payType
)
.
totalFee
(
fee
).
outTradeNo
(
tradeNo
)
.
productId
(
"1000000123"
)
.
spbillCreateIp
(
"0.0.0.0"
)
.
tradeType
(
"NATIVE"
).
build
();
request
.
setSignType
(
"MD5"
);
WxPayService
wxPayService
=
getWxPayService
();
WxPayNativeOrderResult
o
=
wxPayService
.
createOrder
(
request
);
System
.
out
.
println
(
o
.
toString
());
return
R
.
ok
(
o
);
}
/**
* 接收支付返回的消息
*
* @param
*/
@RequestMapping
(
value
=
"/parseOrderNotifyResult"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"接收支付返回的消息"
)
@ResponseBody
public
String
parseOrderNotifyResult
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
System
.
out
.
println
(
"============支付回调开始"
);
try
{
String
xmlResult
=
IOUtils
.
toString
(
request
.
getInputStream
(),
request
.
getCharacterEncoding
());
WxPayService
wxPayService
=
getWxPayService
();
WxPayOrderNotifyResult
result
=
wxPayService
.
parseOrderNotifyResult
(
xmlResult
);
System
.
out
.
println
(
result
.
toString
());
// 结果正确
String
orderId
=
result
.
getOutTradeNo
();
String
tradeNo
=
result
.
getTransactionId
();
//String totalFee = WxPayBaseResult.feeToYuan(result.getTotalFee());
//自己处理订单的业务逻辑,需要判断订单是否已经支付过,否则可能会重复调用
System
.
out
.
println
(
"============支付回调结束"
);
return
WxPayNotifyResponse
.
success
(
"处理成功!"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"微信回调结果异常,异常原因{}"
+
e
.
getMessage
());
return
WxPayNotifyResponse
.
fail
(
e
.
getMessage
());
}
}
/**
* 加载配置文件,生成微信payservice对象
*
* @return
*/
private
WxPayService
getWxPayService
()
{
WxPayConfig
payConfig
=
new
WxPayConfig
();
String
app_id
=
"wx39c84a7da8e71c32"
;
String
mchid
=
"1605798036"
;
String
private_key
=
"yHG21lRpqil1X3fWG0VFytxFuXzxIpRd"
;
// payConfig.setAppId(WxCommon.APP_ID);
// payConfig.setMchId(WxCommon.MCHID);
// payConfig.setMchKey(WxCommon.PRIVATE_KEY);
payConfig
.
setAppId
(
app_id
);
payConfig
.
setMchId
(
mchid
);
payConfig
.
setMchKey
(
private_key
);
payConfig
.
setNotifyUrl
(
WxCommon
.
NOTIFY_URL
);
WxPayService
wxPayService
=
new
WxPayServiceImpl
();
wxPayService
.
setConfig
(
payConfig
);
return
wxPayService
;
}
}
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