Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63ae9e7433 | ||
|
|
2d242988e1 | ||
|
|
c976264581 | ||
|
|
b7c068e1ae |
@@ -5,7 +5,7 @@
|
|||||||
<meta charset='UTF-8'>
|
<meta charset='UTF-8'>
|
||||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
<title>顺诚百宝箱</title>
|
<title>支付测试- 顺诚百宝箱</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let response = await fetch('/pay/createOrder?n=' + n + '&t=test');
|
let response = await fetch('/pay/createOrder?n=' + n + '&t=test');
|
||||||
let res = eval("(" + await response.text() + ")");
|
let res = JSON.parse(await response.text());
|
||||||
|
|
||||||
if (res.code == 1) {
|
if (res.code == 1) {
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
alert('获取二维码失败');
|
alert('获取二维码失败');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('.imgs').html("<img src='data:image/jpg;base64," + img + "'><br><a href='" + code + "'>手机点这里打开支付宝APP</a><br>使用支付宝扫一扫<br><button onclick='selectPay(" + id + ")'>查询支付状态</button> <button onclick='getPayQr()'>刷新二维码</button>");
|
$('.imgs').html("<img src='data:image/jpg;base64," + img + "'><br><a href='alipays://platformapi/startapp?saId=10000007&qrcode=" + code + "'>手机点这里打开支付宝APP</a><br>使用支付宝扫一扫<br><button onclick='selectPay(" + id + ")'>查询支付状态</button> <button onclick='getPayQr()'>刷新二维码</button>");
|
||||||
subscribe(id);
|
subscribe(id);
|
||||||
|
|
||||||
} else alert('遇到错误 ' + res.msg);
|
} else alert('遇到错误 ' + res.msg);
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
await subscribe(id);
|
await subscribe(id);
|
||||||
} else {
|
} else {
|
||||||
// 获取并显示消息
|
// 获取并显示消息
|
||||||
let message = eval("(" + await response.text() + ")");
|
let message = JSON.parse(await response.text());
|
||||||
|
|
||||||
// 再次调用 subscribe() 以获取下一条消息
|
// 再次调用 subscribe() 以获取下一条消息
|
||||||
if (message.msg == "已支付") {
|
if (message.msg == "已支付") {
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
*/
|
*/
|
||||||
async function selectPay(id) {
|
async function selectPay(id) {
|
||||||
let response = await fetch('/pay/queryPay?id=' + id);
|
let response = await fetch('/pay/queryPay?id=' + id);
|
||||||
let res = eval("(" + await response.text() + ")");
|
let res = JSON.parse(await response.text());
|
||||||
|
|
||||||
if (response.status == 200 && res.msg == "已支付") {
|
if (response.status == 200 && res.msg == "已支付") {
|
||||||
return okPay();
|
return okPay();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -48,14 +48,7 @@ import org.apache.http.util.EntityUtils;
|
|||||||
*/
|
*/
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
private static final CloseableHttpClient httpClient;
|
|
||||||
public static final String CHARSET = "UTF-8";
|
public static final String CHARSET = "UTF-8";
|
||||||
// 采用静态代码块,初始化超时时间配置,再根据配置生成默认httpClient对象
|
|
||||||
static {
|
|
||||||
//10秒相应超时
|
|
||||||
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
|
||||||
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String doGet(String url, Map<String, String> params) {
|
public static String doGet(String url, Map<String, String> params) {
|
||||||
return doGet(url, params, CHARSET);
|
return doGet(url, params, CHARSET);
|
||||||
@@ -83,6 +76,8 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
HttpGet httpGet = null;
|
HttpGet httpGet = null;
|
||||||
|
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||||
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
try {
|
try {
|
||||||
if (params != null && !params.isEmpty()) {
|
if (params != null && !params.isEmpty()) {
|
||||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||||
@@ -159,6 +154,8 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
|
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||||
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
try {
|
try {
|
||||||
if (pairs != null && pairs.size() > 0) {
|
if (pairs != null && pairs.size() > 0) {
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
||||||
@@ -397,6 +394,8 @@ public class HttpUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HttpGet httpGet = new HttpGet(url);
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||||
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
try {
|
try {
|
||||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
CloseableHttpResponse response = httpClient.execute(httpGet);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user