Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hls-support-rlwx
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
rl
hls-support-rlwx
Commits
3eca8205
Commit
3eca8205
authored
Apr 20, 2022
by
5359
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口代码调整
parent
95a9ed4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
37 deletions
+129
-37
HclcCmbPolyServiceImpl.java
...ain/java/com/cmb/service/impl/HclcCmbPolyServiceImpl.java
+129
-37
No files found.
core/src/main/java/com/cmb/service/impl/HclcCmbPolyServiceImpl.java
View file @
3eca8205
package
com
.
cmb
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.chinapay.comm.Constants
;
import
com.chinapay.dto.HlsEbankCcbTransaction
;
import
com.chinapay.mapper.HlsEbankCcbTransactionMapper
;
import
com.chinapay.secss.LogUtil
;
import
com.cmb.dto.Ld037
;
import
com.cmb.mapper.Ld037Mapper
;
import
com.cmb.service.HclcCmbPolyService
;
import
com.cmb.util.MD5Utils
;
import
com.cmb.util.SM2Util
;
...
...
@@ -8,12 +14,17 @@ import com.cmb.util.SignatureUtil;
import
com.cmb.util.Utils
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.hand.hap.core.IRequest
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
@Service
public
class
HclcCmbPolyServiceImpl
implements
HclcCmbPolyService
{
...
...
@@ -37,20 +48,44 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
@Value
(
"${cmb.currencyCode}"
)
private
String
currencyCode
;
@Autowired
private
HlsEbankCcbTransactionMapper
hlsEbankCcbTransactionMapper
;
@Autowired
private
Ld037Mapper
ld037Mapper
;
private
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Override
public
JSONObject
getQrcode
(
IRequest
iRequest
,
JSONObject
params
)
{
JSONObject
result
=
new
JSONObject
();
Map
<
String
,
String
>
requestPublicParams
=
JSONObject
.
parseObject
(
params
.
toJSONString
(),
Map
.
class
);
if
(
Objects
.
isNull
(
params
.
get
(
"recamt_id"
)))
{
result
.
put
(
Constants
.
RESP_CODE
,
"E"
);
result
.
put
(
"respMsg"
,
"请求必须参数recamt_id缺失,请检查!"
);
return
result
;
}
//根据recamt_id查询ld037数据生成hls_ebank_ccb_transaction批次记录
Long
recamtId
=
params
.
getLong
(
"recamt_id"
);
Ld037
ld037
=
new
Ld037
();
ld037
.
setId
(
recamtId
);
ld037
=
ld037Mapper
.
selectByPrimaryKey
(
ld037
);
HlsEbankCcbTransaction
hlsEbankCcbTransaction
=
createTransaction
(
ld037
);
// Map<String, String> requestPublicParams = JSONObject.parseObject(params.toJSONString(), Map.class);
// 组装requestBody并加签
String
signResult
=
signMethod
(
requestPublicParams
);
String
signResult
=
getQrRequestParams
(
hlsEbankCcbTransaction
);
if
(
Objects
.
isNull
(
signResult
))
{
result
.
put
(
Constants
.
RESP_CODE
,
"E"
);
result
.
put
(
"respMsg"
,
"收款码申请加签发生异常,请检查!"
);
return
result
;
}
try
{
ObjectMapper
mapper
=
new
ObjectMapper
();
Map
<
String
,
String
>
signResultMap
=
mapper
.
readValue
(
signResult
,
Map
.
class
);
Map
<
String
,
String
>
signResultMap
=
mapper
.
readValue
(
signResult
,
Map
.
class
);
long
currentTimeMills
=
System
.
currentTimeMillis
()
/
1000
;
// 组apiSign加密Map
Map
<
String
,
String
>
apiSign
=
new
TreeMap
<>();
Map
<
String
,
String
>
apiSign
=
new
TreeMap
<>();
apiSign
.
put
(
"appid"
,
appId
);
apiSign
.
put
(
"secret"
,
appSecret
);
apiSign
.
put
(
"sign"
,
signResultMap
.
get
(
"sign"
));
...
...
@@ -67,7 +102,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
apiHeader
.
put
(
"apisign"
,
apiSignString
);
// 发送HTTP post请求
Map
<
String
,
String
>
response
=
Utils
.
postForEntity
(
url
,
signResult
,
apiHeader
);
Map
<
String
,
String
>
response
=
Utils
.
postForEntity
(
url
,
signResult
,
apiHeader
);
/*
版本号 version String(5) 是 固定为0.0.1
编码方式 encoding String(20) 是 固定为UTF-8
...
...
@@ -87,29 +122,54 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
应答信息 respMsg String(256) 是 请求处理失败的详细描述信息
*/
System
.
out
.
println
(
mapper
.
writeValueAsString
(
response
));
logger
.
info
(
"收款码申请返回结果:"
+
mapper
.
writeValueAsString
(
response
));
// 返回结果验签,验证数据的正确性(安全性)
Boolean
checkResult1
=
checkSign
(
mapper
.
writeValueAsString
(
response
));
if
(!
checkResult1
)
{
if
(!
checkResult1
)
{
//数据验签失败的处理,重发或者直接告诉前端发送失败
result
.
put
(
"
errCode"
,
response
.
get
(
"errCode"
));
result
.
put
(
"
respCode"
,
response
.
get
(
"errCode"
));
}
//获取响应结果内容
String
success
=
response
.
get
(
"returnCode"
);
System
.
out
.
println
(
"返回结果:"
+
success
);
result
.
put
(
"qrcode"
,
response
.
get
(
"qrcode"
));
result
.
put
(
"respMsg"
,
response
.
get
(
"respMsg"
));
result
.
put
(
"qrcode"
,
response
.
get
(
"qrcode"
));
result
.
put
(
"respMsg"
,
response
.
get
(
"respMsg"
));
//业务数据的封装。。。
return
result
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
result
.
put
(
"
errCode"
,
"服务器问题"
);
result
.
put
(
"
respCode"
,
"服务器问题"
);
return
result
;
}
}
private
String
signMethod
(
Map
paramsMap
){
//生成招行扫码交易业务批次数据
private
HlsEbankCcbTransaction
createTransaction
(
Ld037
ld037
)
{
HlsEbankCcbTransaction
ccbTransaction
=
new
HlsEbankCcbTransaction
();
ccbTransaction
.
setMerId
(
"3089991701201D0"
);
ccbTransaction
.
setVersion
(
"0.0.1"
);
ccbTransaction
.
setUserId
(
"N003574551"
);
ccbTransaction
.
setStatus
(
"NEW"
);
ccbTransaction
.
setBankType
(
"CMB"
);
ccbTransaction
.
setCount
(
1L
);
ccbTransaction
.
setAmount
(
ld037
.
getAmount
());
ccbTransaction
.
setNewDate
(
new
Date
());
ccbTransaction
.
setCreatedBy
(
1L
);
ccbTransaction
.
setCreationDate
(
new
Date
());
hlsEbankCcbTransactionMapper
.
insert
(
ccbTransaction
);
//生成单据编号 日期+id
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
dateString
=
formatter
.
format
(
new
Date
());
ccbTransaction
.
setTransactionNumber
(
dateString
+
String
.
format
(
"%08d"
,
ccbTransaction
.
getTransactionId
()));
hlsEbankCcbTransactionMapper
.
updateByPrimaryKeySelective
(
ccbTransaction
);
return
ccbTransaction
;
}
private
String
getQrRequestParams
(
HlsEbankCcbTransaction
hlsEbankCcbTransaction
)
{
Map
<
String
,
String
>
requestPublicParams
=
new
TreeMap
<>();
String
requestStr
=
null
;
try
{
...
...
@@ -117,41 +177,49 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
requestPublicParams
.
put
(
"version"
,
version
);
//版本号,固定为0.0.1(必传字段)
requestPublicParams
.
put
(
"encoding"
,
encoding
);
//编码方式,固定为UTF-8(必传)
requestPublicParams
.
put
(
"signMethod"
,
signMethod
);
//签名方法,固定为02,表示签名方式为国密(必传)
// //业务要素
// Map<String, String> requestTransactionParams = new HashMap<>();
// requestTransactionParams.put("body", "聚合支付测试"); //商户号(必传)
// requestTransactionParams.put("currencyCode", "156"); //交易币种,默认156,目前只支持人民币(156)
// requestTransactionParams.put("merId", "3089991074200KV"); //商户号(必传)
// requestTransactionParams.put("notifyUrl", notifyUrl); //交易通知地址(必传)
// requestTransactionParams.put("orderId", "" + System.currentTimeMillis()); //商户订单号(必传)
// requestTransactionParams.put("payValidTime", "1200"); //支付有效时间
// requestTransactionParams.put("termId", "00774411"); //终端号
// requestTransactionParams.put("txnAmt", "1405"); //交易金额,单位为分(必传)
// requestTransactionParams.put("userId", "N003363806"); //收银员
// requestTransactionParams.put("tradeScene", "OFFLINE"); //交易场景
//业务要素
Map
<
String
,
String
>
requestTransactionParams
=
new
HashMap
<>();
requestTransactionParams
.
put
(
"merId"
,
hlsEbankCcbTransaction
.
getMerId
());
//商户号(必传)
requestTransactionParams
.
put
(
"orderId"
,
hlsEbankCcbTransaction
.
getTransactionNumber
());
//商户订单号(必传)
requestTransactionParams
.
put
(
"userId"
,
hlsEbankCcbTransaction
.
getUserId
());
//收银员
// requestTransactionParams.put("termId", "00774411"); //终端号
requestTransactionParams
.
put
(
"payValidTime"
,
"900"
);
//支付有效时间,默认15分钟
requestTransactionParams
.
put
(
"notifyUrl"
,
""
);
//交易通知地址(必传)
BigDecimal
a1
=
new
BigDecimal
(
Double
.
toString
(
hlsEbankCcbTransaction
.
getAmount
()));
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
100
));
requestTransactionParams
.
put
(
"txnAmt"
,
a1
.
multiply
(
b1
).
toString
());
//交易金额,单位为分(必传)
requestTransactionParams
.
put
(
"currencyCode"
,
currencyCode
);
//交易币种,默认156,目前只支持人民币(156)
requestTransactionParams
.
put
(
"body"
,
"聚合支付测试"
);
//商户号(必传)
//商户保留域
JSONObject
mchReserved
=
new
JSONObject
();
mchReserved
.
put
(
"transactionId"
,
hlsEbankCcbTransaction
.
getTransactionId
());
requestTransactionParams
.
put
(
"tradeScene"
,
"OFFLINE"
);
//交易场景
ObjectMapper
mapper
=
new
ObjectMapper
();
requestPublicParams
.
put
(
"biz_content"
,
mapper
.
writeValueAsString
(
paramsMap
));
requestPublicParams
.
put
(
"biz_content"
,
mapper
.
writeValueAsString
(
requestTransactionParams
));
System
.
out
.
println
(
"加签前的报文内容:
"
+
mapper
.
writeValueAsString
(
requestPublicParams
));
logger
.
info
(
"收款码申请加签前的报文内容:
"
+
mapper
.
writeValueAsString
(
requestPublicParams
));
//对待加签内容进行排序拼接
String
signContent
=
SignatureUtil
.
getSignContent
(
requestPublicParams
);
String
signContent
=
SignatureUtil
.
getSignContent
(
requestPublicParams
);
//加签
requestPublicParams
.
put
(
"sign"
,
SM2Util
.
sm2Sign
(
signContent
,
privateKey
));
requestStr
=
mapper
.
writeValueAsString
(
requestPublicParams
);
System
.
out
.
println
(
"加签后的报文内容:"
+
requestStr
);
logger
.
info
(
"收款码申请加签后的报文内容:"
+
requestStr
);
return
requestStr
;
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"加签发生异常!"
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"收款码申请加签发生异常:"
+
e
.
getMessage
()
);
e
.
printStackTrace
();
return
requestStr
;
}
}
private
Boolean
checkSign
(
String
string
){
private
Boolean
checkSign
(
String
string
)
{
System
.
out
.
println
(
"要验签的报文内容:"
+
string
);
try
{
//验签
...
...
@@ -159,7 +227,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
Map
<
String
,
String
>
responseBodyMap
=
objectMapper
.
readValue
(
string
,
Map
.
class
);
String
sign
=
responseBodyMap
.
remove
(
"sign"
);
String
contentStr
=
SignatureUtil
.
getSignContent
(
responseBodyMap
);
boolean
result
=
SM2Util
.
sm2Check
(
contentStr
,
sign
,
publicKey
);
boolean
result
=
SM2Util
.
sm2Check
(
contentStr
,
sign
,
publicKey
);
if
(
result
)
{
System
.
out
.
println
(
"报文验签成功!"
);
...
...
@@ -167,10 +235,34 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
System
.
out
.
println
(
"报文验签失败!"
);
}
return
result
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"验签发生异常!"
);
e
.
printStackTrace
();
return
false
;
}
}
private
Properties
loadProp
(
String
propPath
)
{
Properties
props
=
new
Properties
();
FileInputStream
is
=
null
;
try
{
is
=
new
FileInputStream
(
propPath
);
props
.
load
(
is
);
return
props
;
}
catch
(
Exception
var13
)
{
LogUtil
.
writeErrorLog
(
"加载配置文件失败"
,
var13
);
}
finally
{
if
(
is
!=
null
)
{
try
{
is
.
close
();
}
catch
(
IOException
var12
)
{
;
}
}
}
return
null
;
}
}
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