CommonBiz.java
7.79 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
package com.cjs.site.biz.pub;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
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.site.dao.pub.SysDateDao;
import com.cjs.site.dao.pub.SysParamValueDao;
import com.cjs.site.util.lang.DateEnum;
import com.cjs.site.util.lang.DateUtil;
import com.cjs.site.util.lang.JsonUtil;
import com.cjs.site.util.lang.StringUtil;
import com.cjs.site.util.t2.T2Result;
import com.cjs.site.util.t2.T2Util;
import com.cjs.site.util.web.DesUtil;
import chinapnr.SecureLink;
@Service
public class CommonBiz {
Logger log = LogManager.getLogger();
@Autowired
private SysDateDao sysDao;
@Autowired
private SysParamValueDao sysParamValue;
@Value("${${env}.pnr.operId}")
private String operId;
@Value("${${env}.pnr.pbKey}")
private String pbKey;
public boolean checkTime(boolean checkDate, int beginTimeId, int endTimeId) { if (checkDate) {
Map params = new HashMap();
params.put("function_id", "619824");
T2Result queryResult = T2Util.request(params, "619824");
if ("0".equals(((Map)queryResult.getData().get(0)).get("business_flag"))) {
return false;
}
}
int nowtime = Integer.parseInt(DateUtil.getNow(DateEnum.UNSIGNED_TIME));
String beginTime = this.sysParamValue.getValueById(beginTimeId);
String endTime = this.sysParamValue.getValueById(endTimeId);
boolean flag = (Integer.parseInt(beginTime) <= nowtime) && (
Integer.parseInt(endTime) >= nowtime);
return flag;
}
/**
* 检查开户时间
*
* @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 ("0".equals(queryResult.getData().get(0).get("business_flag"))) {
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;
}
public boolean checkKitingTime() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("function_id", "619824");
T2Result queryResult = T2Util.request(params, "619824");
if ("0".equals(queryResult.getData().get(0).get("business_flag"))) {
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_fund");
String endTime = sysParamValue.getParamValue("end_time_fund");
boolean flag = Integer.parseInt(beginTime) <= nowtime
&& Integer.parseInt(endTime) >= nowtime;
if (!flag) {
return false;
}
return true;
}
public boolean checkChargeTime() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HHmmss");
int nowtime = Integer.parseInt(sdf.format(new Date()).substring(11));
String beginTime = sysParamValue.getParamValue("begin_time_charge");
String endTime = sysParamValue.getParamValue("end_time_charge");
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");
log.debug("检查交易所交易状态:" + result);
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);
}
log.info(build.toString());
String MsgBuf = DesUtil.MD5(build.toString());
SecureLink secureLink = new SecureLink();
String path = CommonBiz.class.getResource("/pay/").getFile();
try {
secureLink.SignMsg(operId, path + "MerPrK" + operId + ".key", MsgBuf.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return secureLink.getChkValue();
}
@SuppressWarnings("unchecked")
public String decrypt(String retStr) {
Map<String, String> params = JsonUtil.fromJson(retStr, HashMap.class);
String[] str = retStr.split("\r\n");
StringBuilder build = new StringBuilder();
String ChkValue = "";
for (int i = 0; i < str.length; i++) {
if (!str[i].substring(1, str[i].indexOf("=")).equals("check_value")) {
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");
// }
return params.get("RespCode");
}
/**
* 获得数据库的当前时间
*/
public Date getSysdate() {
return sysDao.getSysdate();//获得数据库当前日期
}
public boolean isWorkingDay(String date) {
return false;
}
/** 格式化日期为恒生的格式 */
public void formatDate(Map<String, Object> params) {
String startDate = StringUtil.castString(params.get("startDate"));
String endDate = StringUtil.castString(params.get("endDate"));
params.put("startDate", this.formatDate(startDate));
params.put("endDate", this.formatDate(endDate));
}
/** 格式化日期为恒生的格式 */
public String formatDate(String date) {
if (StringUtils.isBlank(date)) {
return "";
}
if (date.length() > 8) {
Date date2 = DateUtil.parseDate(date, DateEnum.DATE);
return DateUtil.parseDate(date2, DateEnum.UNSIGNED_DATE);
} else {
Date date2 = DateUtil.parseDate(date, DateEnum.UNSIGNED_DATE);
return DateUtil.parseDate(date2, DateEnum.DATE);
}
}
}