1
1
package cn .mrdear .pay .unionpay ;
2
2
3
3
4
- import org .apache .commons .lang3 .StringUtils ;
5
4
import org .slf4j .Logger ;
6
5
import org .slf4j .LoggerFactory ;
7
6
8
- import java .io .IOException ;
9
- import java .text .SimpleDateFormat ;
10
7
import java .util .Date ;
11
8
import java .util .HashMap ;
12
9
import java .util .Map ;
13
10
14
11
import cn .mrdear .pay .unionpay .sdk .AcpService ;
15
12
import cn .mrdear .pay .unionpay .sdk .SDKConfig ;
16
- import cn .mrdear .pay .unionpay . sdk . SecureUtil ;
13
+ import cn .mrdear .pay .util . DateUtil ;
17
14
18
15
/**
19
16
* @author Niu Li
@@ -37,25 +34,17 @@ public UnionPayClient(HashMap<String, String> commonMap) {
37
34
* @param paramMap 要传送的参数
38
35
* @return 生成的form表单
39
36
*/
40
- public String tokenOpen (Map <String , String > paramMap ){
37
+ public String tokenOpen (Map <String , String > paramMap , Map < String , String > customerInfo ){
41
38
paramMap .putAll (commonMap );
42
- paramMap .put ("txnTime" , new SimpleDateFormat ( "yyyyMMddHHmmss" ). format (new Date ()));
39
+ paramMap .put ("txnTime" , DateUtil . formatDate (new Date (), DateUtil . YMDHMS ));
43
40
paramMap .put ("txnType" , "79" );
44
41
paramMap .put ("txnSubType" , "00" );
45
42
paramMap .put ("frontUrl" , UnionPayConfig .FRONTURL );
46
43
paramMap .put ("backUrl" , UnionPayConfig .TOKEN_BACKURL );
47
44
paramMap .put ("tokenPayData" , UnionPayConfig .TOKENPAYDATA );
48
- try {
49
- if (paramMap .get ("customerInfo" ) != null
50
- && !StringUtils .isEmpty (paramMap .get ("customerInfo" ))) {
51
- paramMap .put ("customerInfo" , new String (
52
- SecureUtil .base64Encode (
53
- paramMap .get ("customerInfo" ).getBytes (
54
- UnionPayConfig .ENCODING_UTF8 ))));
55
- }
56
- } catch (IOException e ) {
57
- e .printStackTrace ();
58
- }
45
+ paramMap .put ("customerInfo" ,AcpService .getCustomerInfo (customerInfo ,paramMap .get ("accNo" ),UnionPayConfig .ENCODING_UTF8 ));
46
+ //是否加密取决于商户是否开通了隐私加密权限
47
+ // paramMap.put("customerInfo",AcpService.getCustomerInfoWithEncrypt(customerInfo,paramMap.get("accNo"),UnionPayConfig.ENCODING_UTF8));
59
48
Map <String , String > reqData = AcpService .sign (paramMap ,UnionPayConfig .ENCODING_UTF8 ); //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。
60
49
String requestFrontUrl = SDKConfig .getConfig ().getFrontRequestUrl (); //获取请求银联的前台地址:对应属性文件acp_sdk.properties文件中的acpsdk.frontTransUrl
61
50
String html = AcpService .createAutoFormHtml (requestFrontUrl ,reqData ,UnionPayConfig .ENCODING_UTF8 ); //生成自动跳转的Html表单
@@ -68,21 +57,13 @@ public String tokenOpen(Map<String, String> paramMap){
68
57
* @param paramMap 要传送的参数
69
58
* @return 请求返回的结果
70
59
*/
71
- public Map <String , String > msgSend (Map <String , String > paramMap ){
60
+ public Map <String , String > msgSend (Map <String , String > paramMap , Map < String , String > customerInfo ){
72
61
paramMap .putAll (commonMap );
73
62
paramMap .put ("txnType" , "77" );
74
- paramMap .put ("txnTime" , new SimpleDateFormat ("yyyyMMddHHmmss" ).format (new Date ()));
75
- try {
76
- if (paramMap .get ("customerInfo" ) != null
77
- && !StringUtils .isEmpty (paramMap .get ("customerInfo" ))) {
78
- paramMap .put ("customerInfo" , new String (
79
- SecureUtil .base64Encode (
80
- paramMap .get ("customerInfo" ).getBytes (
81
- UnionPayConfig .ENCODING_UTF8 ))));
82
- }
83
- } catch (IOException e ) {
84
- e .printStackTrace ();
85
- }
63
+ paramMap .put ("txnTime" , DateUtil .formatDate (new Date (),DateUtil .YMDHMS ));
64
+ paramMap .put ("customerInfo" ,AcpService .getCustomerInfo (customerInfo ,paramMap .get ("accNo" ),UnionPayConfig .ENCODING_UTF8 ));
65
+ //是否加密取决于商户是否开通了隐私加密权限
66
+ // paramMap.put("customerInfo",AcpService.getCustomerInfoWithEncrypt(customerInfo,paramMap.get("accNo"),UnionPayConfig.ENCODING_UTF8));
86
67
Map <String , String > reqData = AcpService .sign (paramMap ,UnionPayConfig .ENCODING_UTF8 ); //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。
87
68
String requestBackUrl = SDKConfig .getConfig ().getBackRequestUrl (); //交易请求url从配置文件读取对应属性文件acp_sdk.properties中的 acpsdk.backTransUrl
88
69
Map <String , String > rspData = AcpService .post (reqData ,requestBackUrl ,UnionPayConfig .ENCODING_UTF8 );
@@ -95,24 +76,16 @@ public Map<String, String> msgSend(Map<String, String> paramMap){
95
76
* @param paramMap 需要传送的参数
96
77
* @return 请求结果,消费结果返回异步通知
97
78
*/
98
- public Map <String ,String > consume (Map <String , String > paramMap ){
79
+ public Map <String ,String > consume (Map <String , String > paramMap , Map < String , String > customerInfo ){
99
80
paramMap .putAll (commonMap );
100
81
paramMap .put ("txnType" , "01" );
101
82
paramMap .put ("frontUrl" , UnionPayConfig .FRONTURL );
102
83
paramMap .put ("backUrl" , UnionPayConfig .CONSUME_BACKURL );
103
84
paramMap .put ("customerIp" , "127.0.0.1" );
104
- paramMap .put ("txnTime" , new SimpleDateFormat ("yyyyMMddHHmmss" ).format (new Date ()));
105
- try {
106
- if (paramMap .get ("customerInfo" ) != null
107
- && !StringUtils .isEmpty (paramMap .get ("customerInfo" ))) {
108
- paramMap .put ("customerInfo" , new String (
109
- SecureUtil .base64Encode (
110
- paramMap .get ("customerInfo" ).getBytes (
111
- UnionPayConfig .ENCODING_UTF8 ))));
112
- }
113
- } catch (IOException e ) {
114
- e .printStackTrace ();
115
- }
85
+ paramMap .put ("txnTime" , DateUtil .formatDate (new Date (),DateUtil .YMDHMS ));
86
+ paramMap .put ("customerInfo" ,AcpService .getCustomerInfo (customerInfo ,paramMap .get ("accNo" ),UnionPayConfig .ENCODING_UTF8 ));
87
+ //是否加密取决于商户是否开通了隐私加密权限
88
+ // paramMap.put("customerInfo",AcpService.getCustomerInfoWithEncrypt(customerInfo,paramMap.get("accNo"),UnionPayConfig.ENCODING_UTF8));
116
89
Map <String , String > reqData = AcpService .sign (paramMap ,UnionPayConfig .ENCODING_UTF8 ); //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。
117
90
String requestBackUrl = SDKConfig .getConfig ().getBackRequestUrl (); //交易请求url从配置文件读取对应属性文件acp_sdk.properties中的 acpsdk.backTransUrl
118
91
Map <String , String > rspData = AcpService .post (reqData ,requestBackUrl ,UnionPayConfig .ENCODING_UTF8 ); //发送请求报文并接受同步应答(默认连接超时时间30秒,读取返回结果超时时间30秒);这里调用signData之后,调用submitUrl之前不能对submitFromData中的键值对做任何修改,如果修改会导致验签不通过
@@ -131,20 +104,11 @@ public Map<String,String> refund(Map<String, String> paramMap){
131
104
paramMap .put ("txnSubType" , "00" );
132
105
paramMap .put ("frontUrl" , UnionPayConfig .FRONTURL );
133
106
paramMap .put ("backUrl" , UnionPayConfig .REFUND_BACKURL );
134
- paramMap .put ("txnTime" , new SimpleDateFormat ( "yyyyMMddHHmmss" ). format (new Date ()));
107
+ paramMap .put ("txnTime" , DateUtil . formatDate (new Date (), DateUtil . YMDHMS ));
135
108
Map <String , String > reqData = AcpService .sign (paramMap ,UnionPayConfig .ENCODING_UTF8 );
136
109
String url = SDKConfig .getConfig ().getBackRequestUrl ();
137
110
Map <String , String > rspData = AcpService .post (reqData , url ,UnionPayConfig .ENCODING_UTF8 );
138
111
logger .debug ("银行卡退款结果:" +rspData .toString ());
139
112
return rspData ;
140
113
}
141
-
142
-
143
- /**
144
- * 获取当前消费时间
145
- * @return yyyyMMddHHmmss格式时间
146
- */
147
- public static String getCurrentTime () {
148
- return new SimpleDateFormat ("yyyyMMddHHmmss" ).format (new Date ());
149
- }
150
114
}
0 commit comments