Commit 4f9a20eb authored by huangcb's avatar huangcb

增加货主支付功能

parent 802de6d9
...@@ -181,8 +181,7 @@ ...@@ -181,8 +181,7 @@
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<excludes> <excludes>
<exclude>*.yml</exclude> <exclude>*.yml</exclude>
<exclude>application*.properties</exclude> <exclude>*.properties</exclude>
<exclude>bootstrap.properties</exclude>
<exclude>logback-spring.xml</exclude> <exclude>logback-spring.xml</exclude>
</excludes> </excludes>
<filtering>true</filtering> <filtering>true</filtering>
......
...@@ -23,11 +23,28 @@ public class ApplicationLoadRunner implements ApplicationRunner { ...@@ -23,11 +23,28 @@ public class ApplicationLoadRunner implements ApplicationRunner {
@Value("${spring.application.name}") @Value("${spring.application.name}")
private String applicationName; private String applicationName;
@Value("${spring.profiles.active}")
private String profilesActive;
@Value("${unionpay.acp-sdk.properties.path}")
private String acpSdkPropertiesPath;
@Override @Override
public void run(ApplicationArguments var) { public void run(ApplicationArguments var) {
log.info("-------------------- [{}]初始化完成 --------------------", applicationName); log.info("-------------------- [{}]初始化完成 --------------------", applicationName);
// 从classpath加载acp_sdk.properties文件 // 初始化银联配置文件
initUnionpayProperties();
}
/**
* 初始化银联配置文件
**/
private void initUnionpayProperties() {
if ("dev".equals(profilesActive)) {
SDKConfig.getConfig().loadPropertiesFromSrc(); SDKConfig.getConfig().loadPropertiesFromSrc();
} else {
SDKConfig.getConfig().loadPropertiesFromPath(acpSdkPropertiesPath);
}
} }
} }
...@@ -322,4 +322,7 @@ public class ErrorMessageComponent { ...@@ -322,4 +322,7 @@ public class ErrorMessageComponent {
@Value("${error-message.contract.online.get-by-number.1001}") @Value("${error-message.contract.online.get-by-number.1001}")
private String contractOnlineGetByNumber1001; private String contractOnlineGetByNumber1001;
@Value("${error-message.pay.customer.order.create.1001}")
private String payCustomerOrderCreate1001;
} }
...@@ -10,11 +10,9 @@ import lombok.extern.slf4j.Slf4j; ...@@ -10,11 +10,9 @@ import lombok.extern.slf4j.Slf4j;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.IOException;
import java.nio.charset.Charset; import java.io.UnsupportedEncodingException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/** /**
* @description: Rest请求日志Filter * @description: Rest请求日志Filter
...@@ -55,55 +53,6 @@ public class RestLogFilter implements Filter { ...@@ -55,55 +53,6 @@ public class RestLogFilter implements Filter {
this.logRes(requestWrapper, responseWrapper); this.logRes(requestWrapper, responseWrapper);
} }
/**
* 获取请求返回体
**/
private String getPostBodyStr(HttpServletRequest request) {
String bodyStr = null;
StringBuilder sb = new StringBuilder();
InputStream inputStream = null;
BufferedReader reader = null;
try {
inputStream = request.getInputStream();
reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(CommonConstants.DEFAULT_CHARACTER_ENCODING)));
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line);
}
if (0 == sb.length()) {
Map<String, String> bodyMap = new HashMap<>();
Map<String, String[]> parameterMap = request.getParameterMap();
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
for (String value : entry.getValue()) {
bodyMap.put(entry.getKey(), value);
}
}
bodyStr = bodyMap.toString();
} else {
bodyStr = sb.toString();
}
} catch (IOException e) {
log.error("解析post参数时发生错误:{}", e.getMessage(), e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
return bodyStr;
}
/** /**
* 日志输出请求体 * 日志输出请求体
**/ **/
...@@ -122,7 +71,7 @@ public class RestLogFilter implements Filter { ...@@ -122,7 +71,7 @@ public class RestLogFilter implements Filter {
} }
reqBody = reqBody.replaceFirst("&", ""); reqBody = reqBody.replaceFirst("&", "");
} else if (CommonConstants.HTTP_REQUEST_METHOD_POST.equalsIgnoreCase(method)) { } else if (CommonConstants.HTTP_REQUEST_METHOD_POST.equalsIgnoreCase(method)) {
reqBody = this.getPostBodyStr(requestWrapper); reqBody = ReqUtils.getPostBody(requestWrapper);
} }
// 请求体日志截取 // 请求体日志截取
......
package com.esv.freight.customer.common.pojo;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* @description: 银联APP终端创建支付订单请求参数
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.pojo.AppUnionPayOrder
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/30 13:48
* @version:1.0
*/
@Data
public class AppUnionPayOrderReq {
/**
* 商户代码(网络货运平台在支付平台的商户号)
*/
private String merId;
/**
* 账单号
*/
private String billId;
/**
* 账单描述
*/
private String billDesc;
/**
* 交易金额(单位为分)
*/
private Long txnAmt;
/**
* 请求支付平台订单发送时间
*/
private String txnTime;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.common.pojo;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* @description: 银联APP终端创建支付订单返回参数
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.pojo.AppUnionPayOrder
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/30 13:48
* @version:1.0
*/
@Data
public class AppUnionPayOrderRes {
/**
* 银联受理订单号
*/
private String tn;
/**
* 请求参数
*/
private String reqMessage;
/**
* 返回参数
*/
private String rspMessage;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.common.unionpay;
import lombok.extern.slf4j.Slf4j;
import javax.net.ssl.*;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.cert.X509Certificate;
/**
* @description: 忽略验证ssl证书
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.unionpay.BaseHttpSSLSocketFactory
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/30 14:44
* @version:1.0
*/
@Slf4j
public class BaseHttpSSLSocketFactory extends SSLSocketFactory {
private SSLContext getSSLContext() {
return createEasySSLContext();
}
@Override
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException {
return getSSLContext().getSocketFactory().createSocket(arg0, arg1, arg2, arg3);
}
@Override
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(arg0, arg1, arg2, arg3);
}
@Override
public Socket createSocket(InetAddress arg0, int arg1) throws IOException {
return getSSLContext().getSocketFactory().createSocket(arg0, arg1);
}
@Override
public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException {
return getSSLContext().getSocketFactory().createSocket(arg0, arg1);
}
@Override
public String[] getSupportedCipherSuites() {
// TODO Auto-generated method stub
return null;
}
@Override
public String[] getDefaultCipherSuites() {
// TODO Auto-generated method stub
return null;
}
@Override
public Socket createSocket(Socket arg0, String arg1, int arg2, boolean arg3) throws IOException {
return getSSLContext().getSocketFactory().createSocket(arg0, arg1, arg2, arg3);
}
private SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[]{MyX509TrustManager.manger}, null);
return context;
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
public static class MyX509TrustManager implements X509TrustManager {
static MyX509TrustManager manger = new MyX509TrustManager();
public MyX509TrustManager() {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
/**
* 解决由于服务器证书问题导致HTTPS无法访问的情况 PS:HTTPS hostname wrong: should be <localhost>
*/
public static class TrustAnyHostnameVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
//直接返回true
return true;
}
}
}
package com.esv.freight.customer.common.unionpay;
import com.esv.freight.customer.common.constants.SDKConstants;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @description: demo中用到的方法
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.unionpay.DemoBase
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/30 14:38
* @version:1.0
*/
@Slf4j
public class DemoBase {
//默认配置的是UTF-8
public static String encoding = "UTF-8";
//全渠道固定值
public static String version = SDKConfig.getConfig().getVersion();
//后台服务对应的写法参照 FrontRcvResponse.java
public static String frontUrl = SDKConfig.getConfig().getFrontUrl();
//后台服务对应的写法参照 BackRcvResponse.java
public static String backUrl = SDKConfig.getConfig().getBackUrl();//受理方和发卡方自选填写的域[O]--后台通知地址
// 商户发送交易时间 格式:yyyyMMddHHmmss
public static String getCurrentTime() {
return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
}
// AN8..40 商户订单号,不能含"-"或"_"
public static String getOrderId() {
return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
}
/**
* 组装请求,返回报文字符串用于显示
*
* @param data
* @return
*/
public static String genHtmlResult(Map<String, String> data) {
TreeMap<String, String> tree = new TreeMap<String, String>();
Iterator<Entry<String, String>> it = data.entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> en = it.next();
tree.put(en.getKey(), en.getValue());
}
it = tree.entrySet().iterator();
StringBuffer sf = new StringBuffer();
while (it.hasNext()) {
Entry<String, String> en = it.next();
String key = en.getKey();
String value = en.getValue();
if ("respCode".equals(key)) {
sf.append("<b>" + key + SDKConstants.EQUAL + value + "</br></b>");
} else {
sf.append(key + SDKConstants.EQUAL + value + "</br>");
}
}
return sf.toString();
}
/**
* 功能:解析全渠道商户对账文件中的ZM文件并以List<Map>方式返回
* 适用交易:对账文件下载后对文件的查看
*
* @param filePath ZM文件全路径
* @return 包含每一笔交易中 序列号 和 值 的map序列
*/
public static List<Map> parseZMFile(String filePath) {
int lengthArray[] = {3, 11, 11, 6, 10, 19, 12, 4, 2, 21, 2, 32, 2, 6, 10, 13, 13, 4, 15, 2, 2, 6, 2, 4, 32, 1, 21, 15, 1, 15, 32, 13, 13, 8, 32, 13, 13, 12, 2, 1, 32, 98};
return parseFile(filePath, lengthArray);
}
/**
* 功能:解析全渠道商户对账文件中的ZME文件并以List<Map>方式返回
* 适用交易:对账文件下载后对文件的查看
*
* @param filePath ZME文件全路径
* @return 包含每一笔交易中 序列号 和 值 的map序列
*/
public static List<Map> parseZMEFile(String filePath) {
int lengthArray[] = {3, 11, 11, 6, 10, 19, 12, 4, 2, 2, 6, 10, 4, 12, 13, 13, 15, 15, 1, 12, 2, 135};
return parseFile(filePath, lengthArray);
}
/**
* 功能:解析全渠道商户 ZM,ZME对账文件
*
* @param filePath
* @param lengthArray 参照《全渠道平台接入接口规范 第3部分 文件接口》 全渠道商户对账文件 6.1 ZM文件和6.2 ZME 文件 格式的类型长度组成int型数组
* @return
*/
private static List<Map> parseFile(String filePath, int lengthArray[]) {
List<Map> ZmDataList = new ArrayList<Map>();
try {
String encoding = "gbk"; //文件是gbk编码
File file = new File(filePath);
if (file.isFile() && file.exists()) { //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), "iso-8859-1");
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
byte[] bs = lineTxt.getBytes("iso-8859-1");
//解析的结果MAP,key为对账文件列序号,value为解析的值
Map<Integer, String> ZmDataMap = new LinkedHashMap<Integer, String>();
//左侧游标
int leftIndex = 0;
//右侧游标
int rightIndex = 0;
for (int i = 0; i < lengthArray.length; i++) {
rightIndex = leftIndex + lengthArray[i];
String filed = new String(Arrays.copyOfRange(bs, leftIndex, rightIndex), encoding);
leftIndex = rightIndex + 1;
ZmDataMap.put(i, filed);
}
ZmDataList.add(ZmDataMap);
}
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
return ZmDataList;
}
public static String getFileContentTable(List<Map> dataList, String file) {
StringBuffer tableSb = new StringBuffer("对账文件的规范参考 https://open.unionpay.com/ajweb/help/file/ 产品接口规范->平台接口规范:文件接口</br> 文件【" + file + "】解析后内容如下:");
tableSb.append("<table border=\"1\">");
if (dataList.size() > 0) {
Map<Integer, String> dataMapTmp = dataList.get(0);
tableSb.append("<tr>");
for (Iterator<Integer> it = dataMapTmp.keySet().iterator(); it.hasNext(); ) {
Integer key = it.next();
String value = dataMapTmp.get(key);
System.out.println("序号:" + (key + 1) + " 值: '" + value + "'");
tableSb.append("<td>序号" + (key + 1) + "</td>");
}
tableSb.append("</tr>");
}
for (int i = 0; i < dataList.size(); i++) {
System.out.println("行数: " + (i + 1));
Map<Integer, String> dataMapTmp = dataList.get(i);
tableSb.append("<tr>");
for (Iterator<Integer> it = dataMapTmp.keySet().iterator(); it.hasNext(); ) {
Integer key = it.next();
String value = dataMapTmp.get(key);
System.out.println("序号:" + (key + 1) + " 值: '" + value + "'");
tableSb.append("<td>" + value + "</td>");
}
tableSb.append("</tr>");
}
tableSb.append("</table>");
return tableSb.toString();
}
public static List<String> unzip(String zipFilePath, String outPutDirectory) {
List<String> fileList = new ArrayList<String>();
try {
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFilePath));//输入源zip路径
BufferedInputStream bin = new BufferedInputStream(zin);
BufferedOutputStream bout = null;
File file = null;
ZipEntry entry;
try {
while ((entry = zin.getNextEntry()) != null && !entry.isDirectory()) {
file = new File(outPutDirectory, entry.getName());
if (!file.exists()) {
(new File(file.getParent())).mkdirs();
}
bout = new BufferedOutputStream(new FileOutputStream(file));
int b;
while ((b = bin.read()) != -1) {
bout.write(b);
}
bout.flush();
fileList.add(file.getAbsolutePath());
System.out.println(file + "解压成功");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bin.close();
zin.close();
if (bout != null) {
bout.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return fileList;
}
}
package com.esv.freight.customer.common.unionpay;
import com.esv.freight.customer.common.unionpay.BaseHttpSSLSocketFactory.TrustAnyHostnameVerifier;
import lombok.extern.slf4j.Slf4j;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.*;
import java.util.Map;
import java.util.Map.Entry;
/**
* @description: acpsdk发送后台http请求类
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.unionpay.HttpClient
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/30 14:43
* @version:1.0
*/
@Slf4j
public class HttpClient {
/**
* 目标地址
*/
private URL url;
/**
* 通信连接超时时间
*/
private int connectionTimeout;
/**
* 通信读超时时间
*/
private int readTimeOut;
/**
* 通信结果
*/
private String result;
/**
* 获取通信结果
*
* @return
*/
public String getResult() {
return result;
}
/**
* 设置通信结果
*
* @param result
*/
public void setResult(String result) {
this.result = result;
}
/**
* 构造函数
*
* @param url 目标地址
* @param connectionTimeout HTTP连接超时时间
* @param readTimeOut HTTP读写超时时间
*/
public HttpClient(String url, int connectionTimeout, int readTimeOut) {
try {
this.url = new URL(url);
this.connectionTimeout = connectionTimeout;
this.readTimeOut = readTimeOut;
} catch (MalformedURLException e) {
log.error(e.getMessage(), e);
}
}
/**
* 发送信息到服务端
*
* @param data
* @param encoding
* @return
* @throws Exception
*/
public int send(Map<String, String> data, String encoding) throws Exception {
try {
HttpURLConnection httpURLConnection = createConnection(encoding);
if (null == httpURLConnection) {
throw new Exception("Create httpURLConnection Failure");
}
String sendData = this.getRequestParamString(data, encoding);
log.info("请求报文(对每个报文域的值均已做url编码):[" + sendData + "]");
this.requestServer(httpURLConnection, sendData, encoding);
this.result = this.response(httpURLConnection, encoding);
log.info("Response message:[" + result + "]");
return httpURLConnection.getResponseCode();
} catch (Exception e) {
throw e;
}
}
/**
* 发送信息到服务端 GET方式
*
* @param encoding
* @return
* @throws Exception
*/
public int sendGet(String encoding) throws Exception {
try {
HttpURLConnection httpURLConnection = createConnectionGet(encoding);
if (null == httpURLConnection) {
throw new Exception("创建联接失败");
}
this.result = this.response(httpURLConnection, encoding);
log.info("同步返回报文:[" + result + "]");
return httpURLConnection.getResponseCode();
} catch (Exception e) {
throw e;
}
}
/**
* HTTP Post发送消息
*
* @param connection
* @param message
* @throws IOException
*/
private void requestServer(final URLConnection connection, String message, String encoder) throws Exception {
PrintStream out = null;
try {
connection.connect();
out = new PrintStream(connection.getOutputStream(), false, encoder);
out.print(message);
out.flush();
} catch (Exception e) {
throw e;
} finally {
if (null != out) {
out.close();
}
}
}
/**
* 显示Response消息
*
* @param connection
* @param encoding
* @return
* @throws URISyntaxException
* @throws IOException
*/
private String response(final HttpURLConnection connection, String encoding) throws URISyntaxException, IOException, Exception {
InputStream in = null;
StringBuilder sb = new StringBuilder(1024);
BufferedReader br = null;
try {
if (200 == connection.getResponseCode()) {
in = connection.getInputStream();
sb.append(new String(read(in), encoding));
} else {
in = connection.getErrorStream();
sb.append(new String(read(in), encoding));
}
log.info("HTTP Return Status-Code:[" + connection.getResponseCode() + "]");
return sb.toString();
} catch (Exception e) {
throw e;
} finally {
if (null != br) {
br.close();
}
if (null != in) {
in.close();
}
if (null != connection) {
connection.disconnect();
}
}
}
public static byte[] read(InputStream in) throws IOException {
byte[] buf = new byte[1024];
int length = 0;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
while ((length = in.read(buf, 0, buf.length)) > 0) {
bout.write(buf, 0, length);
}
bout.flush();
return bout.toByteArray();
}
/**
* 创建连接
*
* @return
* @throws ProtocolException
*/
private HttpURLConnection createConnection(String encoding) throws ProtocolException {
HttpURLConnection httpURLConnection = null;
try {
httpURLConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
log.error(e.getMessage(), e);
return null;
}
httpURLConnection.setConnectTimeout(this.connectionTimeout);// 连接超时时间
httpURLConnection.setReadTimeout(this.readTimeOut);// 读取结果超时时间
httpURLConnection.setDoInput(true); // 可读
httpURLConnection.setDoOutput(true); // 可写
httpURLConnection.setUseCaches(false);// 取消缓存
httpURLConnection.setRequestProperty("Content-type",
"application/x-www-form-urlencoded;charset=" + encoding);
httpURLConnection.setRequestMethod("POST");
if ("https".equalsIgnoreCase(url.getProtocol())) {
HttpsURLConnection husn = (HttpsURLConnection) httpURLConnection;
//是否验证https证书,测试环境请设置false,生产环境建议优先尝试true,不行再false
if (!SDKConfig.getConfig().isIfValidateRemoteCert()) {
husn.setSSLSocketFactory(new BaseHttpSSLSocketFactory());
husn.setHostnameVerifier(new TrustAnyHostnameVerifier());//解决由于服务器证书问题导致HTTPS无法访问的情况
}
return husn;
}
return httpURLConnection;
}
/**
* 创建连接
*
* @return
* @throws ProtocolException
*/
private HttpURLConnection createConnectionGet(String encoding) throws ProtocolException {
HttpURLConnection httpURLConnection = null;
try {
httpURLConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
log.error(e.getMessage(), e);
return null;
}
httpURLConnection.setConnectTimeout(this.connectionTimeout);// 连接超时时间
httpURLConnection.setReadTimeout(this.readTimeOut);// 读取结果超时时间
httpURLConnection.setUseCaches(false);// 取消缓存
httpURLConnection.setRequestProperty("Content-type",
"application/x-www-form-urlencoded;charset=" + encoding);
httpURLConnection.setRequestMethod("GET");
if ("https".equalsIgnoreCase(url.getProtocol())) {
HttpsURLConnection husn = (HttpsURLConnection) httpURLConnection;
//是否验证https证书,测试环境请设置false,生产环境建议优先尝试true,不行再false
if (!SDKConfig.getConfig().isIfValidateRemoteCert()) {
husn.setSSLSocketFactory(new BaseHttpSSLSocketFactory());
husn.setHostnameVerifier(new TrustAnyHostnameVerifier());//解决由于服务器证书问题导致HTTPS无法访问的情况
}
return husn;
}
return httpURLConnection;
}
/**
* 将Map存储的对象,转换为key=value&key=value的字符
*
* @param requestParam
* @param coder
* @return
*/
private String getRequestParamString(Map<String, String> requestParam, String coder) {
if (null == coder || "".equals(coder)) {
coder = "UTF-8";
}
StringBuffer sf = new StringBuffer("");
String reqstr = "";
if (null != requestParam && 0 != requestParam.size()) {
for (Entry<String, String> en : requestParam.entrySet()) {
try {
sf.append(en.getKey()
+ "="
+ (null == en.getValue() || "".equals(en.getValue()) ? "" : URLEncoder
.encode(en.getValue(), coder)) + "&");
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(), e);
return "";
}
}
reqstr = sf.substring(0, sf.length() - 1);
}
log.info("Request Message:[" + reqstr + "]");
return reqstr;
}
}
package com.esv.freight.customer.common.util;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import java.util.Iterator;
import java.util.Map;
/**
* @description: Map工具类
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.util.MapUtils
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/06/02 16:04
* @version:1.0
*/
@Slf4j
public class MapUtils {
/**
* description Map转Json
* param [map]
* return com.alibaba.fastjson.JSONObject
* author HuangChaobin
* createTime 2020/06/02 16:04
**/
public static JSONObject map2Json(Map<String, String> map) {
JSONObject json = new JSONObject();
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> en = it.next();
json.put(en.getKey(), en.getValue());
}
return json;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment