删除多余的类
This commit is contained in:
parent
952a286a59
commit
9ad976efda
@ -25,6 +25,39 @@ public class SqbConfig {
|
|||||||
@Value("${pay.sqb.vendorKey}")
|
@Value("${pay.sqb.vendorKey}")
|
||||||
private String vendorKey;
|
private String vendorKey;
|
||||||
|
|
||||||
|
@Value("${pay.sqb.notifyUrl}")
|
||||||
|
private String defaultNotifyUrl;
|
||||||
|
|
||||||
|
@Value("${pay.sqb.notifyBaseUrl}")
|
||||||
|
private String defaultNotifyBaseUrl;
|
||||||
|
|
||||||
|
@Value("${pay.sqb.proxy}")
|
||||||
|
private String proxyPath;
|
||||||
|
|
||||||
|
public String getDefaultNotifyUrl() {
|
||||||
|
return defaultNotifyUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultNotifyUrl(String defaultNotifyUrl) {
|
||||||
|
this.defaultNotifyUrl = defaultNotifyUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultNotifyBaseUrl() {
|
||||||
|
return defaultNotifyBaseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultNotifyBaseUrl(String defaultNotifyBaseUrl) {
|
||||||
|
this.defaultNotifyBaseUrl = defaultNotifyBaseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyPath() {
|
||||||
|
return proxyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyPath(String proxyPath) {
|
||||||
|
this.proxyPath = proxyPath;
|
||||||
|
}
|
||||||
|
|
||||||
public String getApiDomain() {
|
public String getApiDomain() {
|
||||||
return apiDomain;
|
return apiDomain;
|
||||||
}
|
}
|
||||||
|
@ -2,33 +2,50 @@ package com.ruoyi.pay.sqb.service.Impl;
|
|||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.KeyStoreException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.UnrecoverableKeyException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
|
import com.ruoyi.common.utils.http.HttpClientUtil;
|
||||||
import com.ruoyi.common.utils.sign.Md5Utils;
|
import com.ruoyi.common.utils.sign.Md5Utils;
|
||||||
import com.ruoyi.pay.domain.PayOrder;
|
import com.ruoyi.pay.domain.PayOrder;
|
||||||
import com.ruoyi.pay.sqb.config.SqbConfig;
|
import com.ruoyi.pay.sqb.config.SqbConfig;
|
||||||
import com.ruoyi.pay.sqb.utils.HttpUtil;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SQBServiceImpl {
|
public class SQBServiceImpl {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SqbConfig sqbConfig;
|
private SqbConfig sqbConfig;
|
||||||
|
|
||||||
@Value("${pay.sqb.notifyUrl}")
|
/**
|
||||||
private String defaultNotifyUrl;
|
* http POST 请求
|
||||||
|
*
|
||||||
@Value("${pay.sqb.notifyBaseUrl}")
|
* @param url:请求地址
|
||||||
private String defaultNotifyBaseUrl;
|
* @param body: body实体字符串
|
||||||
|
* @param sign:签名
|
||||||
@Value("${pay.sqb.proxy}")
|
* @param sn: 序列号
|
||||||
private String proxyPath;
|
* @return
|
||||||
|
*/
|
||||||
|
public static String httpPost(String url, Object body, String sign, String sn)
|
||||||
|
throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||||
|
String xmlRes = "{}";
|
||||||
|
try {
|
||||||
|
Map<String, String> header = new HashMap<>();
|
||||||
|
header.put("Authorization", sn + " " + sign);
|
||||||
|
xmlRes = HttpClientUtil.sendHttpPost(url, body, header);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return xmlRes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算字符串的MD5值
|
* 计算字符串的MD5值
|
||||||
@ -62,7 +79,7 @@ public class SQBServiceImpl {
|
|||||||
params.put("client_sn", clientSn); // 客户方终端编号,一般客户方或系统给收银终端的编号,必填
|
params.put("client_sn", clientSn); // 客户方终端编号,一般客户方或系统给收银终端的编号,必填
|
||||||
params.put("name", name); // 客户方终端名称,必填
|
params.put("name", name); // 客户方终端名称,必填
|
||||||
String sign = getSign(params.toString() + sqbConfig.getVendorKey());
|
String sign = getSign(params.toString() + sqbConfig.getVendorKey());
|
||||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConfig.getVendorSn());
|
String result = httpPost(url, params.toString(), sign, sqbConfig.getVendorSn());
|
||||||
JSONObject retObj = JSON.parseObject(result);
|
JSONObject retObj = JSON.parseObject(result);
|
||||||
String resCode = retObj.get("result_code").toString();
|
String resCode = retObj.get("result_code").toString();
|
||||||
if (!resCode.equals("200"))
|
if (!resCode.equals("200"))
|
||||||
@ -91,7 +108,7 @@ public class SQBServiceImpl {
|
|||||||
params.put("os_info", "Mac OS");
|
params.put("os_info", "Mac OS");
|
||||||
params.put("sdk_version", "Java SDK v1.0");
|
params.put("sdk_version", "Java SDK v1.0");
|
||||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConfig.getTerminalSn());
|
String result = httpPost(url, params.toString(), sign, sqbConfig.getTerminalSn());
|
||||||
JSONObject retObj = JSON.parseObject(result);
|
JSONObject retObj = JSON.parseObject(result);
|
||||||
String resCode = retObj.get("result_code").toString();
|
String resCode = retObj.get("result_code").toString();
|
||||||
if (!resCode.equals("200"))
|
if (!resCode.equals("200"))
|
||||||
@ -122,7 +139,7 @@ public class SQBServiceImpl {
|
|||||||
params.put("operator", "kay"); // 门店操作员
|
params.put("operator", "kay"); // 门店操作员
|
||||||
|
|
||||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||||
String result = HttpUtil.httpPost(url, params, sign, sqbConfig.getTerminalSn());
|
String result = httpPost(url, params, sign, sqbConfig.getTerminalSn());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -144,7 +161,7 @@ public class SQBServiceImpl {
|
|||||||
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一;且长度不超过64字节
|
params.put("client_sn", payOrder.getOrderNumber()); // 商户系统订单号,必须在商户系统内唯一;且长度不超过64字节
|
||||||
System.out.println(params.toString() + sqbConfig.getTerminalKey());
|
System.out.println(params.toString() + sqbConfig.getTerminalKey());
|
||||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||||
String result = HttpUtil.httpPost(url, params, sign, sqbConfig.getTerminalSn());
|
String result = httpPost(url, params, sign, sqbConfig.getTerminalSn());
|
||||||
JSONObject retObj = JSON.parseObject(result);
|
JSONObject retObj = JSON.parseObject(result);
|
||||||
String resCode = retObj.get("result_code").toString();
|
String resCode = retObj.get("result_code").toString();
|
||||||
if (!resCode.equals("200"))
|
if (!resCode.equals("200"))
|
||||||
@ -165,6 +182,9 @@ public class SQBServiceImpl {
|
|||||||
payOrder.setRemark("支付");
|
payOrder.setRemark("支付");
|
||||||
}
|
}
|
||||||
String orderNotifyUrl;
|
String orderNotifyUrl;
|
||||||
|
String defaultNotifyUrl = sqbConfig.getDefaultNotifyUrl();
|
||||||
|
String defaultNotifyBaseUrl = sqbConfig.getDefaultNotifyBaseUrl();
|
||||||
|
String proxyPath = sqbConfig.getProxyPath();
|
||||||
if (notifyBaseUrl != null && !notifyBaseUrl.trim().equals("")) {
|
if (notifyBaseUrl != null && !notifyBaseUrl.trim().equals("")) {
|
||||||
orderNotifyUrl = notifyBaseUrl + defaultNotifyUrl;
|
orderNotifyUrl = notifyBaseUrl + defaultNotifyUrl;
|
||||||
} else {
|
} else {
|
||||||
@ -174,7 +194,6 @@ public class SQBServiceImpl {
|
|||||||
orderNotifyUrl = "http://" + ServletUtils.getRequest().getServerName() + proxyPath + defaultNotifyUrl;
|
orderNotifyUrl = "http://" + ServletUtils.getRequest().getServerName() + proxyPath + defaultNotifyUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(orderNotifyUrl);
|
|
||||||
String param = "" +
|
String param = "" +
|
||||||
"client_sn=" + payOrder.getOrderNumber() +
|
"client_sn=" + payOrder.getOrderNumber() +
|
||||||
"¬ify_url=" + orderNotifyUrl +
|
"¬ify_url=" + orderNotifyUrl +
|
||||||
@ -191,8 +210,6 @@ public class SQBServiceImpl {
|
|||||||
"&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") +
|
"&subject=" + URLEncoder.encode(payOrder.getRemark(), "UTF-8") +
|
||||||
"&terminal_sn=" + sqbConfig.getTerminalSn() +
|
"&terminal_sn=" + sqbConfig.getTerminalSn() +
|
||||||
"&total_amount=" + Long.valueOf(payOrder.getTotalAmount().toString());
|
"&total_amount=" + Long.valueOf(payOrder.getTotalAmount().toString());
|
||||||
System.out.println(param);
|
|
||||||
System.out.println(orderNotifyUrl);
|
|
||||||
String sign = getSign(param + "&key=" + sqbConfig.getTerminalKey());
|
String sign = getSign(param + "&key=" + sqbConfig.getTerminalKey());
|
||||||
return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase();
|
return "https://qr.shouqianba.com/gateway?" + urlParam + "&sign=" + sign.toUpperCase();
|
||||||
}
|
}
|
||||||
@ -214,7 +231,7 @@ public class SQBServiceImpl {
|
|||||||
params.put("operator", SecurityUtils.getUsername()); // 门店操作员
|
params.put("operator", SecurityUtils.getUsername()); // 门店操作员
|
||||||
|
|
||||||
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
String sign = getSign(params.toString() + sqbConfig.getTerminalKey());
|
||||||
String result = HttpUtil.httpPost(url, params.toString(), sign, sqbConfig.getTerminalSn());
|
String result = httpPost(url, params.toString(), sign, sqbConfig.getTerminalSn());
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
@ -236,7 +253,7 @@ public class SQBServiceImpl {
|
|||||||
params.put("client_sn", "18348290098298292838"); // 商户系统订单号,必须在商户系统内唯一;且长度不超过64字节
|
params.put("client_sn", "18348290098298292838"); // 商户系统订单号,必须在商户系统内唯一;且长度不超过64字节
|
||||||
|
|
||||||
String sign = getSign(params.toString() + terminal_key);
|
String sign = getSign(params.toString() + terminal_key);
|
||||||
String result = HttpUtil.httpPost(url, params.toString(), sign, terminal_sn);
|
String result = httpPost(url, params.toString(), sign, terminal_sn);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
package com.ruoyi.pay.sqb.utils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.KeyStoreException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.UnrecoverableKeyException;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.ClientProtocolException;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
|
||||||
import org.apache.http.conn.ssl.TrustStrategy;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
|
|
||||||
import com.ruoyi.common.utils.http.HttpClientUtil;
|
|
||||||
|
|
||||||
public class HttpUtil {
|
|
||||||
public static String httpPostWithoutException(String url, String string, String sign, String sn) {
|
|
||||||
String xmlRes = "{}";
|
|
||||||
try {
|
|
||||||
xmlRes = httpPost(url, string, sign, sn);
|
|
||||||
} catch (UnrecoverableKeyException e) {
|
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
|
|
||||||
} catch (KeyStoreException e) {
|
|
||||||
|
|
||||||
} catch (KeyManagementException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return xmlRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* http POST 请求
|
|
||||||
*
|
|
||||||
* @param url:请求地址
|
|
||||||
* @param body: body实体字符串
|
|
||||||
* @param sign:签名
|
|
||||||
* @param sn: 序列号
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String httpPost(String url, Object body, String sign, String sn)
|
|
||||||
throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
|
||||||
String xmlRes = "{}";
|
|
||||||
// HttpClient client = createSSLClientDefault();
|
|
||||||
// HttpPost httpost = new HttpPost(url);
|
|
||||||
try {
|
|
||||||
Map<String, String> header = new HashMap<>();
|
|
||||||
header.put("Authorization", sn + " " + sign);
|
|
||||||
xmlRes = HttpClientUtil.sendHttpPost(url, body, header);
|
|
||||||
// System.out.println("Request string: " + body);
|
|
||||||
// // 所有请求的body都需采用UTF-8编码
|
|
||||||
// StringEntity entity = new StringEntity(body, "UTF-8");//
|
|
||||||
// entity.setContentType("application/json");
|
|
||||||
// httpost.setEntity(entity);
|
|
||||||
|
|
||||||
// // 支付平台所有的API仅支持JSON格式的请求调用,HTTP请求头Content-Type设为application/json
|
|
||||||
// httpost.addHeader("Content-Type", "application/json");
|
|
||||||
|
|
||||||
// // 支付平台所有的API调用都需要签名验证,签名首部: Authorization: sn + " " + sign
|
|
||||||
// httpost.addHeader("Authorization", sn + " " + sign);
|
|
||||||
// System.out.println("Authorization" + sn + " " + sign);
|
|
||||||
// HttpResponse response = client.execute(httpost);
|
|
||||||
|
|
||||||
// // 所有响应也采用UTF-8编码
|
|
||||||
// xmlRes = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
||||||
// System.out.println("Response string: " + xmlRes);
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
return xmlRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CloseableHttpClient createSSLClientDefault() {
|
|
||||||
try {
|
|
||||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
|
||||||
// 信任所有
|
|
||||||
public boolean isTrusted(X509Certificate[] chain,
|
|
||||||
String authType) throws CertificateException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}).build();
|
|
||||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
|
|
||||||
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
|
|
||||||
} catch (KeyManagementException e) {
|
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
|
|
||||||
} catch (KeyStoreException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return HttpClients.createDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String doGet(String url, String parameter) {
|
|
||||||
String uriAPI = url + "?" + parameter; // "http://XXXXX?str=I+am+get+String";
|
|
||||||
String result = "";
|
|
||||||
HttpClient client = createSSLClientDefault();
|
|
||||||
HttpGet httpRequst = new HttpGet(uriAPI);
|
|
||||||
try {
|
|
||||||
|
|
||||||
HttpResponse httpResponse = client.execute(httpRequst);// 其中HttpGet是HttpUriRequst的子类
|
|
||||||
if (httpResponse.getStatusLine().getStatusCode() == 200) {
|
|
||||||
HttpEntity httpEntity = httpResponse.getEntity();
|
|
||||||
result = EntityUtils.toString(httpEntity);// 取出应答字符串
|
|
||||||
// 一般来说都要删除多余的字符
|
|
||||||
result.replaceAll("\r", "");// 去掉返回结果中的"\r"字符,否则会在结果字符串后面显示一个小方格
|
|
||||||
} else
|
|
||||||
httpRequst.abort();
|
|
||||||
} catch (ClientProtocolException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result = e.getMessage().toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
result = e.getMessage().toString();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user