CommonBiz.java
7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package com.cjs.cms.biz.pub;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.cjs.cms.dao.pub.SysParamValueDao;
import com.cjs.cms.util.t2.T2Result;
import com.cjs.cms.util.t2.T2Util;
import com.cjs.cms.util.web.DesUtil;
import chinapnr.SecureLink;
@Service
public class CommonBiz {
Logger log = LogManager.getLogger();
@Autowired
private SysParamValueDao sysParamValue;
@Value("${html.location}")
private String htmlLocation;
@Value("${pnr.operId}")
private String operId;
@Value("${pnr.pbKey}")
private String pbKey;
/**
* 检查是否是交易日
*
* @return
*/
public boolean checkTradeDay() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("function_id", "619824");
T2Result queryResult = T2Util.request(params, "619824");
if (queryResult.getData().get(0).get("business_flag").equals("0")) {
return false;
}
return true;
}
/**
* 检查开户时间
*
* @return true:开户时间;false:非开户时间
*/
public boolean checkOpenTime() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("function_id", "619824");
T2Result queryResult = T2Util.request(params, "619824");
if (queryResult.getData().get(0).get("business_flag").equals("0")) {
return false;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HHmmss");
int nowtime = Integer.parseInt(sdf.format(new Date()).substring(11));
String beginTime = sysParamValue.getParamValue("begin_time_am");
String endTime = sysParamValue.getParamValue("end_time_pm");
boolean flag = Integer.parseInt(beginTime) <= nowtime
&& Integer.parseInt(endTime) >= nowtime;
if (!flag) {
return false;
}
return true;
}
/**
* 检查交易所交易状态
*
* @return business_flag:1:初始化;2:连续竞价;3:闭市
*/
public Integer checkMarketStatus() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("mchexch_type", "O1"); //交易撮合市场
T2Result result = T2Util.request(params, "649013");
return Integer.parseInt(result.getData().get(0).get("business_flag").toString());
}
/**
* 汇付天下接口参数加签
*
* @param params 请求参数
* @return
*/
public String encrypt(Map<String, String> params) {
StringBuilder build = new StringBuilder();
for (String value : params.values()) {
build.append(value);
}
SecureLink secureLink = new SecureLink();
String path = CommonBiz.class.getResource("/pay/").getFile();
//secureLink.SignMsg(operId, path + "MerPrK" + operId + ".key", build.toString());
try {
secureLink.SignMsg(operId, path + "MerPrK" + operId + ".key",
build.toString().getBytes("GBK"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return secureLink.getChkValue();
}
/**
* 汇付新接口加签
* @param params
* @return
*/
public String encryptNew(Map<String, String> params) {
StringBuilder build = new StringBuilder();
for (String value : params.values()) {
build.append(value);
}
String MsgBuf = DesUtil.MD5(build.toString());
SecureLink secureLink = new SecureLink();
String path = CommonBiz.class.getResource("/pay/").getFile();
// secureLink.SignMsg(operId, path + "MerPrK" + operId + ".key", build.toString());
try {
secureLink.SignMsg(operId, path + "MerPrK890040.key", MsgBuf.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return secureLink.getChkValue();
}
/**
* 汇付天下接口参数解签
* @param params
* @param checkValue
* @return
*/
public int decrypt(Map<String, String> params, String checkValue) {
StringBuilder build = new StringBuilder();
for (String value : params.values()) {
build.append(value);
}
SecureLink secureLink = new SecureLink();
String path = CommonBiz.class.getResource("/pay/").getFile();
return secureLink.VeriSignMsg(path + pbKey, build.toString(), checkValue);
}
/**
* 处理汇付天下接口返回字符参数
* @param retStr
* @param replaceStr
* @return
*/
public Map<String, Object> fromReturnStrToMap(String retStr, String replaceStr) {
Map<String, Object> outMap = new HashMap<String, Object>();
String[] str = retStr.split(replaceStr);
String str1, str2;
for (int i = 0; i < str.length; i++) {
str1 = str[i].substring(0, str[i].indexOf("="));
str2 = str[i].substring(str[i].indexOf("=") + 1);
outMap.put(str1, str2);
}
return outMap;
}
/**
* 读取txt文件内容
* @return
* @throws Exception
*/
public List<String> readTxt() throws Exception {
List<String> list = new ArrayList<String>();
File file = new File(htmlLocation + "abc.txt");
if (file.exists() || file.isFile()) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), "GBK");
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
list.add(lineTxt);
}
read.close();
}
return list;
}
public String decrypt(String retStr) {
Map<String, String> params = new HashMap<String, String>();
String[] str = retStr.split("\r\n");
StringBuilder build = new StringBuilder();
String ChkValue = "";
for (int i = 0; i < str.length; i++) {
if (!str[i].substring(0, str[i].indexOf("=")).equals("ChkValue")) {
build.append(str[i].substring(str[i].indexOf("=") + 1));
} else {
ChkValue = str[i].substring(str[i].indexOf("=") + 1);
}
params.put(str[i].substring(0, str[i].indexOf("=")),
str[i].substring(str[i].indexOf("=") + 1));
}
// SecureLink secureLink = new SecureLink();
// String PgKeyFile = CommonBiz.class.getResource("/pay/").getFile() + pbKey;
// int ret=secureLink.VeriSignMsg(PgKeyFile,build.toString(),ChkValue);
// if (ret != 0) {
// log.info("签名错误 ret=" + ret);
// throw new RuntimeException("签名错误");
// }else{
return params.get("RespCode");
// }
}
}