圣诞快乐
# v1.3 更新列表
1. 【新增】砍价
2. 【新增】拼团
3. 【新增】一号通
4. 【修复】商品sku 编辑时出现商品属性对应错误的问题
5. 【修复】商品推广海报生成二维码可能会出错的问题【小程序调试中】
6. 【修复】微信公众号和小程序头像可能获取不到的问题
7. 【修复】下单时可能会出错的问题
8. 【修复】pc管理端用户访问量
9. 【修复】微信退款
10. 【修复】管理端订单状态可能出现不正确的情况
11. 【修复】WEB管理端-菜单色调,短信API更新,首页用户访问量,系统设置tab是自动选择下一及表单
12. 【修复】系统设置出现更新不正确的问题
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.constants.Constants;
|
||||
import com.exception.CrmebException;
|
||||
@@ -131,8 +132,8 @@ public class CrmebUtil {
|
||||
* @param args String[] 字符串数组
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println(encryptPassword("123456", "admin"));
|
||||
// System.out.println(decryptPassowrd("L8qdg72wbeQ=", "admin"));
|
||||
// System.out.println(encryptPassword("123456", "admin"));
|
||||
System.out.println(decryptPassowrd("", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -742,7 +743,10 @@ public class CrmebUtil {
|
||||
|
||||
public static String getSign(Map<String, Object> map, String signKey){
|
||||
String result = CrmebUtil.mapToStringUrl(map) + "&key=" + signKey;
|
||||
return DigestUtils.md5Hex(result).toUpperCase();
|
||||
// return DigestUtils.md5Hex(result).toUpperCase();
|
||||
String sign = SecureUtil.md5(result).toUpperCase();
|
||||
System.out.println("sign ========== " + sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.constants.Constants;
|
||||
import com.exception.CrmebException;
|
||||
import com.utils.vo.dateLimitUtilVo;
|
||||
@@ -121,9 +124,7 @@ public final class DateUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期,指定格式
|
||||
* 描述:<描述函数实现的功能>.
|
||||
*
|
||||
* 获取当前时间戳(秒级)
|
||||
* @return
|
||||
*/
|
||||
public static Long getTime() {
|
||||
@@ -346,6 +347,15 @@ public final class DateUtil {
|
||||
return Integer.parseInt(timestamp);
|
||||
}
|
||||
|
||||
//获取时间戳10位
|
||||
public static int getSecondTimestamp(Long timeMillis){
|
||||
if (null == timeMillis) {
|
||||
return 0;
|
||||
}
|
||||
String timestamp = String.valueOf(timeMillis / 1000);
|
||||
return Integer.parseInt(timestamp);
|
||||
}
|
||||
|
||||
//获取时间戳11位
|
||||
public static int getSecondTimestamp(){
|
||||
Date date = strToDate(nowDateTime(Constants.DATE_FORMAT), Constants.DATE_FORMAT);
|
||||
@@ -581,4 +591,43 @@ public final class DateUtil {
|
||||
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||
return hour;
|
||||
}
|
||||
|
||||
/**
|
||||
* 13位时间戳转字符串
|
||||
* @param timestamp
|
||||
* @param dateFormat
|
||||
* @return
|
||||
*/
|
||||
public static String timestamp2DateStr(Long timestamp, String dateFormat) {
|
||||
if (ObjectUtil.isNull(timestamp)) {
|
||||
return "";
|
||||
}
|
||||
if (StrUtil.isBlank(dateFormat)) {
|
||||
dateFormat = Constants.DATE_FORMAT;
|
||||
}
|
||||
Date date = new Date(timestamp);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
|
||||
return simpleDateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转13位时间戳
|
||||
*/
|
||||
public static Long dateStr2Timestamp(String dateStr, String type) {
|
||||
DateTime parse = cn.hutool.core.date.DateUtil.parse(dateStr);
|
||||
if (StrUtil.isNotBlank(type)) {
|
||||
if (type.equals(Constants.DATE_TIME_TYPE_BEGIN)) {
|
||||
parse = cn.hutool.core.date.DateUtil.beginOfDay(parse);
|
||||
}
|
||||
if (type.equals(Constants.DATE_TIME_TYPE_END)) {
|
||||
parse = cn.hutool.core.date.DateUtil.endOfDay(parse);
|
||||
}
|
||||
}
|
||||
return parse.getTime();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(StringUtils.strip("fsfsdf", "f"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -281,11 +281,11 @@ public class ExcelUtil {
|
||||
|
||||
CellStyle cellStyle = wb.createCellStyle();
|
||||
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
||||
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
|
||||
// cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||
// cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
|
||||
|
||||
Font font = wb.createFont();
|
||||
font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
|
||||
// font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
|
||||
cellStyle.setFont(font);
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell.setCellValue(columnName);
|
||||
|
||||
98
crmeb/src/main/java/com/utils/ExportUtil.java
Normal file
98
crmeb/src/main/java/com/utils/ExportUtil.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.exception.CrmebException;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 导出工具类
|
||||
* +----------------------------------------------------------------------
|
||||
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: CRMEB Team <admin@crmeb.com>
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
public class ExportUtil {
|
||||
|
||||
/**
|
||||
* 导出Excel文件
|
||||
* @param fileName 文件名
|
||||
* @param title 文件标题
|
||||
* @param voList 数据列表
|
||||
* @param aliasMap 别名Map(别名需要与数据列表的数据对应)
|
||||
* @return 返回给前端的文件名(路径+文件名)
|
||||
*/
|
||||
public static String exportExecl(String fileName, String title, List<?> voList, LinkedHashMap<String, String> aliasMap) {
|
||||
if (StrUtil.isBlank(fileName)) {
|
||||
throw new CrmebException("文件名不能为空");
|
||||
}
|
||||
if (StrUtil.isBlank(title)) {
|
||||
throw new CrmebException("标题不能为空");
|
||||
}
|
||||
if (CollUtil.isEmpty(voList)) {
|
||||
throw new CrmebException("数据列表不能为空");
|
||||
}
|
||||
if (CollUtil.isEmpty(aliasMap)) {
|
||||
throw new CrmebException("别名map不能为空");
|
||||
}
|
||||
|
||||
// 文件名部分
|
||||
String newFileName = UploadUtil.getWebPath() + fileName;
|
||||
String filePath = UploadUtil.getServerPath();
|
||||
|
||||
// 判断是否存在当前目录,不存在则创建
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
fileName = filePath.concat(fileName);
|
||||
|
||||
// 通过工具类创建writer
|
||||
ExcelWriter writer = ExcelUtil.getWriter(fileName);
|
||||
// ExcelWriter writer = ExcelUtil.getWriter("d:/writeMapTest.xlsx");
|
||||
CellStyle headCellStyle = writer.getHeadCellStyle();
|
||||
Font font = writer.createFont();
|
||||
font.setBold(true);
|
||||
headCellStyle.setFont(font);
|
||||
|
||||
//自定义标题别名
|
||||
aliasMap.forEach((key, value) -> writer.addHeaderAlias(key, value));
|
||||
// 合并单元格后的标题行,使用默认标题样式
|
||||
writer.merge(aliasMap.size() - 1, title);
|
||||
writer.merge(aliasMap.size() - 1, StrUtil.format("生成时间:{}", DateUtil.nowDateTimeStr()));
|
||||
//设置宽度自适应
|
||||
writer.setColumnWidth(-1, 22);
|
||||
// 一次性写出内容,使用默认样式,强制输出标题
|
||||
writer.write(voList, true);
|
||||
// 关闭writer,释放内存
|
||||
writer.close();
|
||||
|
||||
return newFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传部分设置
|
||||
*/
|
||||
public static void setUpload(String rootPath, String modelPath, String type) {
|
||||
if (StrUtil.isBlank(rootPath) || StrUtil.isBlank(modelPath) || StrUtil.isBlank(type)) {
|
||||
throw new CrmebException("请检查上传参数,上传参数不能为空");
|
||||
}
|
||||
UploadUtil.setRootPath(rootPath);
|
||||
UploadUtil.setModelPath(modelPath);
|
||||
UploadUtil.setType(type);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
179
crmeb/src/main/java/com/utils/OnePassUtil.java
Normal file
179
crmeb/src/main/java/com/utils/OnePassUtil.java
Normal file
@@ -0,0 +1,179 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.constants.OnePassConstants;
|
||||
import com.exception.CrmebException;
|
||||
import com.zbkj.crmeb.pass.vo.OnePassLoginVo;
|
||||
import com.zbkj.crmeb.system.service.SystemConfigService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 一号通工具类
|
||||
* +----------------------------------------------------------------------
|
||||
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: CRMEB Team <admin@crmeb.com>
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
@Component
|
||||
public class OnePassUtil {
|
||||
|
||||
@Autowired
|
||||
private SystemConfigService systemConfigService;
|
||||
@Autowired
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 获取一号通登录对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public OnePassLoginVo getLoginVo() {
|
||||
String account = systemConfigService.getValueByKey("sms_account");// 获取配置账号
|
||||
if (StrUtil.isBlank(account)) {
|
||||
throw new CrmebException("请配置一号通账号!");
|
||||
}
|
||||
String token = systemConfigService.getValueByKey("sms_token"); //获取配置密码
|
||||
if (StrUtil.isBlank(token)) {
|
||||
throw new CrmebException("请配置一号通密码!");
|
||||
}
|
||||
String secret = SecureUtil.md5(account + SecureUtil.md5(token));
|
||||
OnePassLoginVo loginVo = new OnePassLoginVo();
|
||||
loginVo.setAccount(account);
|
||||
loginVo.setSecret(secret);
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一号通token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getToken(OnePassLoginVo loginVo) {
|
||||
boolean exists = redisUtil.exists(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
if (exists) {
|
||||
Object token = redisUtil.get(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
return token.toString();
|
||||
}
|
||||
// 缓存中不存在token,重新获取,存入缓存
|
||||
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||
map.add("account", loginVo.getAccount());
|
||||
map.add("secret", loginVo.getSecret());
|
||||
JSONObject jsonObject = postFrom(OnePassConstants.ONE_PASS_API_URL + OnePassConstants.USER_LOGIN_URI, map, null);
|
||||
String accessToken = "";
|
||||
Long expiresIn = 0L;
|
||||
accessToken = OnePassConstants.ONE_PASS_USER_TOKEN_PREFIX.concat(jsonObject.getJSONObject("data").getString("access_token"));
|
||||
expiresIn = jsonObject.getJSONObject("data").getLong("expires_in");
|
||||
expiresIn = expiresIn - DateUtil.getTime();
|
||||
redisUtil.set(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()), accessToken, expiresIn, TimeUnit.SECONDS);
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一号通token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getToken() {
|
||||
OnePassLoginVo loginVo = getLoginVo();
|
||||
boolean exists = redisUtil.exists(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
if (exists) {
|
||||
Object token = redisUtil.get(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
return token.toString();
|
||||
}
|
||||
// 缓存中不存在token,重新获取,存入缓存
|
||||
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||
map.add("account", loginVo.getAccount());
|
||||
map.add("secret", loginVo.getSecret());
|
||||
JSONObject jsonObject = postFrom(OnePassConstants.ONE_PASS_API_URL + OnePassConstants.USER_LOGIN_URI, map, null);
|
||||
String accessToken = "";
|
||||
Long expiresIn = 0L;
|
||||
accessToken = OnePassConstants.ONE_PASS_USER_TOKEN_PREFIX.concat(jsonObject.getJSONObject("data").getString("access_token"));
|
||||
expiresIn = jsonObject.getJSONObject("data").getLong("expires_in");
|
||||
expiresIn = expiresIn - DateUtil.getTime();
|
||||
redisUtil.set(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()), accessToken, expiresIn, TimeUnit.SECONDS);
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除token
|
||||
*/
|
||||
public void removeToken(OnePassLoginVo loginVo) {
|
||||
boolean exists = redisUtil.exists(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
if (exists) {
|
||||
redisUtil.remove(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除token
|
||||
*/
|
||||
public void removeToken() {
|
||||
OnePassLoginVo loginVo = getLoginVo();
|
||||
boolean exists = redisUtil.exists(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
if (exists) {
|
||||
redisUtil.remove(StrUtil.format(OnePassConstants.ONE_PASS_TOKEN_KEY_PREFIX, loginVo.getSecret()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求from表单模式提交
|
||||
*/
|
||||
public JSONObject postFrom(String url, MultiValueMap<String, Object> param, Map<String, String> header) {
|
||||
String result = restTemplateUtil.postFromUrlencoded(url, param, header);
|
||||
return checkResult(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测结构请求返回的数据
|
||||
*
|
||||
* @param result 接口返回的结果
|
||||
* @return JSONObject
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-16
|
||||
*/
|
||||
private JSONObject checkResult(String result) {
|
||||
if (StringUtils.isBlank(result)) {
|
||||
throw new CrmebException("一号通平台接口异常,没任何数据返回!");
|
||||
}
|
||||
JSONObject jsonObject = null;
|
||||
try {
|
||||
jsonObject = JSONObject.parseObject(result);
|
||||
} catch (Exception e) {
|
||||
throw new CrmebException("一号通平台接口异常!");
|
||||
}
|
||||
if (OnePassConstants.ONE_PASS_ERROR_CODE.equals(jsonObject.getInteger("status"))) {
|
||||
throw new CrmebException("一号通平台接口" + jsonObject.getString("msg"));
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求的headerMap
|
||||
*
|
||||
* @param accessToken
|
||||
* @return
|
||||
*/
|
||||
public HashMap<String, String> getCommonHeader(String accessToken) {
|
||||
HashMap<String, String> header = CollUtil.newHashMap();
|
||||
header.put("Authorization", accessToken);
|
||||
return header;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,24 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -9,7 +26,18 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -35,6 +63,11 @@ public class RestTemplateUtil {
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
public static final String WXPAYSDK_VERSION = "WXPaySDK/3.0.9";
|
||||
public static final String USER_AGENT = WXPAYSDK_VERSION +
|
||||
" (" + System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version") +
|
||||
") Java/" + System.getProperty("java.version") + " HttpClient/" + HttpClient.class.getPackage().getImplementationVersion();
|
||||
|
||||
/**
|
||||
* 发送GET请求
|
||||
* @param url
|
||||
@@ -205,12 +238,74 @@ public class RestTemplateUtil {
|
||||
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, requestEntity, String.class);
|
||||
try{
|
||||
return new String(Objects.requireNonNull(responseEntity.getBody()).getBytes("ISO8859-1"), StandardCharsets.UTF_8);
|
||||
System.out.println("responseEntity"+responseEntity);
|
||||
return new String(Objects.requireNonNull(responseEntity.getBody()).getBytes("UTF-8"), StandardCharsets.UTF_8);
|
||||
}catch (Exception e){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送POST-JSON请求(微信退款专用)
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
|
||||
public String postWXRefundXml(String url, String xml, String mchId, String path) throws Exception {
|
||||
KeyStore clientStore = KeyStore.getInstance("PKCS12");
|
||||
// 读取本机存放的PKCS12证书文件
|
||||
FileInputStream instream = new FileInputStream(path);
|
||||
try {
|
||||
// 指定PKCS12的密码(商户ID)
|
||||
clientStore.load(instream, mchId.toCharArray());
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
|
||||
// 实例化密钥库 & 初始化密钥工厂
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(clientStore, mchId.toCharArray());
|
||||
|
||||
// 创建 SSLContext
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
|
||||
|
||||
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
|
||||
sslContext,
|
||||
new String[]{"TLSv1"},
|
||||
null,
|
||||
new DefaultHostnameVerifier());
|
||||
|
||||
BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(
|
||||
RegistryBuilder.<ConnectionSocketFactory>create()
|
||||
.register("http", PlainConnectionSocketFactory.getSocketFactory())
|
||||
.register("https", sslConnectionSocketFactory)
|
||||
.build(),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
HttpClient httpClient = HttpClientBuilder.create()
|
||||
.setConnectionManager(connManager)
|
||||
.build();
|
||||
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(8*1000).setConnectTimeout(6*1000).build();
|
||||
httpPost.setConfig(requestConfig);
|
||||
|
||||
StringEntity postEntity = new StringEntity(xml, "UTF-8");
|
||||
httpPost.addHeader("Content-Type", "text/xml");
|
||||
httpPost.addHeader("User-Agent", USER_AGENT + " " + mchId);
|
||||
httpPost.setEntity(postEntity);
|
||||
|
||||
HttpResponse httpResponse = httpClient.execute(httpPost);
|
||||
org.apache.http.HttpEntity httpEntity = httpResponse.getEntity();
|
||||
return EntityUtils.toString(httpEntity, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送POST 表单请求
|
||||
*
|
||||
@@ -341,7 +436,6 @@ public class RestTemplateUtil {
|
||||
HttpEntity<MultiValueMap<String, Object>> requestEntity =
|
||||
new HttpEntity<>(params, headers);
|
||||
|
||||
String body = restTemplate.postForEntity( url, requestEntity, String.class).getBody();
|
||||
return body;
|
||||
return restTemplate.postForEntity(url, requestEntity, String.class).getBody();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class UploadUtil {
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-05-08
|
||||
*/
|
||||
private static String getServerPath() {
|
||||
public static String getServerPath() {
|
||||
// 文件分隔符转化为当前系统的格式
|
||||
return FilenameUtils.separatorsToSystem( getRootPath() + getWebPath());
|
||||
}
|
||||
@@ -228,7 +228,7 @@ public class UploadUtil {
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-05-08
|
||||
*/
|
||||
private static String getWebPath() {
|
||||
public static String getWebPath() {
|
||||
// 文件分隔符转化为当前系统的格式
|
||||
return getType() + getModelPath() + DateUtil.nowDate(Constants.DATE_FORMAT_DATE).replace("-", "/") + "/";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -53,7 +55,9 @@ public class UrlUtil {
|
||||
entity.params = new HashMap<>();
|
||||
for (String param : params) {
|
||||
String[] keyValue = param.split("=");
|
||||
entity.params.put(keyValue[0], keyValue[1]);
|
||||
if (keyValue.length > 1) {
|
||||
entity.params.put(keyValue[0], keyValue[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import com.constants.RegularConstants;
|
||||
import com.exception.CrmebException;
|
||||
import com.zbkj.crmeb.system.model.SystemConfig;
|
||||
@@ -192,4 +193,28 @@ public class ValidateFormUtil {
|
||||
Pattern pattern = Pattern.compile(regular);
|
||||
return pattern.matcher(value).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否是手机号,不是则抛出异常
|
||||
* @param phone 手机号
|
||||
* @param errMsg 异常内容
|
||||
*/
|
||||
public static void isPhoneException(String phone, String errMsg) {
|
||||
boolean match = ReUtil.isMatch(RegularConstants.PHONE_TWO, phone);
|
||||
if (!match) {
|
||||
throw new CrmebException(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否是手机号,不是则抛出异常
|
||||
* @param phone 手机号
|
||||
* @param errMsg 异常内容
|
||||
*/
|
||||
public static void isPhoneException(String phone) {
|
||||
boolean match = ReUtil.isMatch(RegularConstants.PHONE_TWO, phone);
|
||||
if (!match) {
|
||||
throw new CrmebException("请输入正确的手机号");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
51
crmeb/src/main/java/com/utils/WxPayUtil.java
Normal file
51
crmeb/src/main/java/com/utils/WxPayUtil.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.utils;
|
||||
|
||||
import com.constants.Constants;
|
||||
import com.exception.CrmebException;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 微信支付工具类
|
||||
* +----------------------------------------------------------------------
|
||||
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: CRMEB Team <admin@crmeb.com>
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
public class WxPayUtil {
|
||||
|
||||
/**
|
||||
* TODO 后期微信签名生成、校验等在这里开发
|
||||
*/
|
||||
|
||||
/**
|
||||
* 处理 HTTPS API返回数据,转换成Map对象。return_code为SUCCESS时,验证签名。
|
||||
*
|
||||
* @param xmlStr API返回的XML格式数据
|
||||
* @return Map类型数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HashMap<String, Object> processResponseXml(String xmlStr) throws Exception {
|
||||
String RETURN_CODE = "return_code";
|
||||
String return_code;
|
||||
HashMap<String, Object> respData = XmlUtil.xmlToMap(xmlStr);
|
||||
if (respData.containsKey(RETURN_CODE)) {
|
||||
return_code = (String) respData.get(RETURN_CODE);
|
||||
} else {
|
||||
throw new CrmebException(String.format("No `return_code` in XML: %s", xmlStr));
|
||||
}
|
||||
|
||||
if (return_code.equals(Constants.FAIL)) {
|
||||
return respData;
|
||||
} else if (return_code.equals(Constants.SUCCESS)) {
|
||||
return respData;
|
||||
} else {
|
||||
throw new CrmebException(String.format("return_code value %s is invalid in XML: %s", return_code, xmlStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,14 +46,12 @@ public class XmlUtil {
|
||||
map.put(element.getName(), element.getText());
|
||||
}
|
||||
} catch (IOException | DocumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally{
|
||||
try {
|
||||
assert in != null;
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user