Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Jeepay
Commits
9f49f261
Commit
9f49f261
authored
Sep 22, 2021
by
dingzhiwei
Browse files
小新支付通道封装统一支付方法
parent
a2112511
Changes
3
Hide whitespace changes
Inline
Side-by-side
jeepay-payment/src/main/java/com/jeequan/jeepay/pay/channel/xxpay/XxpayPaymentService.java
View file @
9f49f261
...
...
@@ -15,15 +15,24 @@
*/
package
com.jeequan.jeepay.pay.channel.xxpay
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jeequan.jeepay.core.constants.CS
;
import
com.jeequan.jeepay.core.entity.PayOrder
;
import
com.jeequan.jeepay.core.model.params.xxpay.XxpayNormalMchParams
;
import
com.jeequan.jeepay.core.utils.JeepayKit
;
import
com.jeequan.jeepay.pay.channel.AbstractPaymentService
;
import
com.jeequan.jeepay.pay.model.MchAppConfigContext
;
import
com.jeequan.jeepay.pay.rqrs.AbstractRS
;
import
com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg
;
import
com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ
;
import
com.jeequan.jeepay.pay.util.PaywayUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
/*
* 支付接口: 小新支付
* 支付方式: 自适应
...
...
@@ -33,6 +42,7 @@ import org.springframework.stereotype.Service;
* @date 2021/9/20 20:00
*/
@Service
@Slf4j
public
class
XxpayPaymentService
extends
AbstractPaymentService
{
@Override
...
...
@@ -55,4 +65,60 @@ public class XxpayPaymentService extends AbstractPaymentService {
return
PaywayUtil
.
getRealPaywayService
(
this
,
payOrder
.
getWayCode
()).
pay
(
rq
,
payOrder
,
mchAppConfigContext
);
}
/**
* 统一支付处理
* @param payOrder
* @param params
* @param paramMap
* @param channelRetMsg
* @return
*/
protected
JSONObject
doPay
(
PayOrder
payOrder
,
XxpayNormalMchParams
params
,
Map
paramMap
,
ChannelRetMsg
channelRetMsg
)
{
// 生成签名
String
sign
=
XxpayKit
.
getSign
(
paramMap
,
params
.
getKey
());
paramMap
.
put
(
"sign"
,
sign
);
// 支付下单地址
String
payUrl
=
XxpayKit
.
getPaymentUrl
(
params
.
getPayUrl
());
String
resStr
=
""
;
try
{
resStr
=
HttpUtil
.
createPost
(
payUrl
+
"?"
+
JeepayKit
.
genUrlParams
(
paramMap
)).
timeout
(
60
*
1000
).
execute
().
body
();
}
catch
(
Exception
e
)
{
log
.
error
(
"http error"
,
e
);
}
if
(
StringUtils
.
isEmpty
(
resStr
))
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_FAIL
);
channelRetMsg
.
setChannelErrCode
(
""
);
channelRetMsg
.
setChannelErrMsg
(
"请求"
+
getIfCode
()+
"接口异常"
);
return
null
;
}
JSONObject
resObj
=
JSONObject
.
parseObject
(
resStr
);
if
(!
"0"
.
equals
(
resObj
.
getString
(
"retCode"
))){
String
retMsg
=
resObj
.
getString
(
"retMsg"
);
log
.
error
(
"请求"
+
getIfCode
()+
"返回结果异常, resObj={}"
,
resObj
.
toJSONString
());
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_FAIL
);
channelRetMsg
.
setChannelErrCode
(
""
);
channelRetMsg
.
setChannelErrMsg
(
retMsg
);
return
null
;
}
// 验证响应数据签名
String
checkSign
=
resObj
.
getString
(
"sign"
);
resObj
.
remove
(
"sign"
);
if
(!
checkSign
.
equals
(
XxpayKit
.
getSign
(
resObj
,
params
.
getKey
())))
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_FAIL
);
return
null
;
}
// 订单状态-2:订单已关闭,0-订单生成,1-支付中,2-支付成功,3-业务处理完成,4-已退款
String
orderStatus
=
resObj
.
getString
(
"orderStatus"
);
if
(
"2"
.
equals
(
orderStatus
)
||
"3"
.
equals
(
orderStatus
))
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_SUCCESS
);
}
else
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
WAITING
);
}
return
resObj
;
}
}
jeepay-payment/src/main/java/com/jeequan/jeepay/pay/channel/xxpay/payway/AliBar.java
View file @
9f49f261
...
...
@@ -15,13 +15,9 @@
*/
package
com.jeequan.jeepay.pay.channel.xxpay.payway
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jeequan.jeepay.core.entity.PayOrder
;
import
com.jeequan.jeepay.core.exception.BizException
;
import
com.jeequan.jeepay.core.model.params.xxpay.XxpayNormalMchParams
;
import
com.jeequan.jeepay.core.utils.JeepayKit
;
import
com.jeequan.jeepay.pay.channel.xxpay.XxpayKit
;
import
com.jeequan.jeepay.pay.channel.xxpay.XxpayPaymentService
;
import
com.jeequan.jeepay.pay.model.MchAppConfigContext
;
import
com.jeequan.jeepay.pay.rqrs.AbstractRS
;
...
...
@@ -61,11 +57,10 @@ public class AliBar extends XxpayPaymentService {
@Override
public
AbstractRS
pay
(
UnifiedOrderRQ
rq
,
PayOrder
payOrder
,
MchAppConfigContext
mchAppConfigContext
){
AliBarOrderRQ
bizRQ
=
(
AliBarOrderRQ
)
rq
;
XxpayNormalMchParams
params
=
mchAppConfigContext
.
getNormalMchParamsByIfCode
(
getIfCode
(),
XxpayNormalMchParams
.
class
);
// 构造支付请求参数
Map
<
String
,
Object
>
paramMap
=
new
TreeMap
();
// 接口类型
paramMap
.
put
(
"mchId"
,
params
.
getMchId
());
paramMap
.
put
(
"productId"
,
"8021"
);
// 支付宝条码
paramMap
.
put
(
"mchOrderNo"
,
payOrder
.
getPayOrderId
());
...
...
@@ -78,59 +73,13 @@ public class AliBar extends XxpayPaymentService {
paramMap
.
put
(
"subject"
,
payOrder
.
getSubject
());
paramMap
.
put
(
"body"
,
payOrder
.
getBody
());
paramMap
.
put
(
"extra"
,
bizRQ
.
getAuthCode
());
String
sign
=
XxpayKit
.
getSign
(
paramMap
,
params
.
getKey
());
paramMap
.
put
(
"sign"
,
sign
);
// 构造函数响应数据
AliBarOrderRS
res
=
ApiResBuilder
.
buildSuccess
(
AliBarOrderRS
.
class
);
ChannelRetMsg
channelRetMsg
=
new
ChannelRetMsg
();
res
.
setChannelRetMsg
(
channelRetMsg
);
// 设置支付下单地址
String
payUrl
=
XxpayKit
.
getPaymentUrl
(
params
.
getPayUrl
());
String
resStr
=
""
;
try
{
resStr
=
HttpUtil
.
createPost
(
payUrl
+
"?"
+
JeepayKit
.
genUrlParams
(
paramMap
)).
timeout
(
60
*
1000
).
execute
().
body
();
}
catch
(
Exception
e
)
{
log
.
error
(
"http error"
,
e
);
}
if
(
StringUtils
.
isEmpty
(
resStr
))
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_FAIL
);
channelRetMsg
.
setChannelErrCode
(
""
);
channelRetMsg
.
setChannelErrMsg
(
"请求"
+
getIfCode
()+
"接口异常"
);
return
res
;
}
JSONObject
resObj
=
JSONObject
.
parseObject
(
resStr
);
if
(!
"0"
.
equals
(
resObj
.
getString
(
"retCode"
))){
String
retMsg
=
resObj
.
getString
(
"retMsg"
);
log
.
error
(
"请求"
+
getIfCode
()+
"返回结果异常, resObj={}"
,
resObj
.
toJSONString
());
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_FAIL
);
channelRetMsg
.
setChannelErrCode
(
""
);
channelRetMsg
.
setChannelErrMsg
(
retMsg
);
return
res
;
}
// 验证响应数据签名
String
checkSign
=
resObj
.
getString
(
"sign"
);
resObj
.
remove
(
"sign"
);
if
(!
checkSign
.
equals
(
XxpayKit
.
getSign
(
resObj
,
params
.
getKey
())))
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_FAIL
);
return
res
;
}
// 订单状态-2:订单已关闭,0-订单生成,1-支付中,2-支付成功,3-业务处理完成,4-已退款
String
orderStatus
=
resObj
.
getString
(
"orderStatus"
);
if
(
"2"
.
equals
(
orderStatus
)
||
"3"
.
equals
(
orderStatus
))
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
CONFIRM_SUCCESS
);
}
else
{
channelRetMsg
.
setChannelState
(
ChannelRetMsg
.
ChannelState
.
WAITING
);
}
// 发起支付
doPay
(
payOrder
,
params
,
paramMap
,
channelRetMsg
);
return
res
;
}
}
jeepay-payment/src/main/java/com/jeequan/jeepay/pay/channel/xxpay/payway/WxBar.java
0 → 100644
View file @
9f49f261
/*
* Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.jeequan.jeepay.pay.channel.xxpay.payway
;
import
com.jeequan.jeepay.core.entity.PayOrder
;
import
com.jeequan.jeepay.core.exception.BizException
;
import
com.jeequan.jeepay.core.model.params.xxpay.XxpayNormalMchParams
;
import
com.jeequan.jeepay.pay.channel.xxpay.XxpayPaymentService
;
import
com.jeequan.jeepay.pay.model.MchAppConfigContext
;
import
com.jeequan.jeepay.pay.rqrs.AbstractRS
;
import
com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg
;
import
com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ
;
import
com.jeequan.jeepay.pay.rqrs.payorder.payway.AliBarOrderRS
;
import
com.jeequan.jeepay.pay.rqrs.payorder.payway.WxBarOrderRQ
;
import
com.jeequan.jeepay.pay.util.ApiResBuilder
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
java.util.TreeMap
;
/*
* 小新支付 微信条码支付
*
* @author jmdhappy
* @site https://www.jeequan.com
* @date 2021/9/22 20:09
*/
@Service
(
"xxpayPaymentByWxBarService"
)
//Service Name需保持全局唯一性
@Slf4j
public
class
WxBar
extends
XxpayPaymentService
{
@Override
public
String
preCheck
(
UnifiedOrderRQ
rq
,
PayOrder
payOrder
)
{
WxBarOrderRQ
bizRQ
=
(
WxBarOrderRQ
)
rq
;
if
(
StringUtils
.
isEmpty
(
bizRQ
.
getAuthCode
())){
throw
new
BizException
(
"用户支付条码[authCode]不可为空"
);
}
return
null
;
}
@Override
public
AbstractRS
pay
(
UnifiedOrderRQ
rq
,
PayOrder
payOrder
,
MchAppConfigContext
mchAppConfigContext
){
WxBarOrderRQ
bizRQ
=
(
WxBarOrderRQ
)
rq
;
XxpayNormalMchParams
params
=
mchAppConfigContext
.
getNormalMchParamsByIfCode
(
getIfCode
(),
XxpayNormalMchParams
.
class
);
// 构造支付请求参数
Map
<
String
,
Object
>
paramMap
=
new
TreeMap
();
paramMap
.
put
(
"mchId"
,
params
.
getMchId
());
paramMap
.
put
(
"productId"
,
"8020"
);
// 微信条码
paramMap
.
put
(
"mchOrderNo"
,
payOrder
.
getPayOrderId
());
paramMap
.
put
(
"amount"
,
payOrder
.
getAmount
()
+
""
);
paramMap
.
put
(
"currency"
,
"cny"
);
paramMap
.
put
(
"clientIp"
,
payOrder
.
getClientIp
());
paramMap
.
put
(
"device"
,
"web"
);
paramMap
.
put
(
"returnUrl"
,
getReturnUrl
());
paramMap
.
put
(
"notifyUrl"
,
getNotifyUrl
(
payOrder
.
getPayOrderId
()));
paramMap
.
put
(
"subject"
,
payOrder
.
getSubject
());
paramMap
.
put
(
"body"
,
payOrder
.
getBody
());
paramMap
.
put
(
"extra"
,
bizRQ
.
getAuthCode
());
// 构造函数响应数据
AliBarOrderRS
res
=
ApiResBuilder
.
buildSuccess
(
AliBarOrderRS
.
class
);
ChannelRetMsg
channelRetMsg
=
new
ChannelRetMsg
();
res
.
setChannelRetMsg
(
channelRetMsg
);
// 发起支付
doPay
(
payOrder
,
params
,
paramMap
,
channelRetMsg
);
return
res
;
}
}
Write
Preview
Supports
Markdown
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