Просмотр исходного кода

//add tag

release_toaliyun_real
xhxu 4 лет назад
Родитель
Сommit
e51b6e263e
2 измененных файлов: 62 добавлений и 61 удалений
  1. +2
    -1
      mallinkService/src/main/java/com/iformall/douyin/pay/DouYinPayHelper.java
  2. +60
    -60
      mallinkService/src/main/java/com/iformall/utils/HttpUtil.java

+ 2
- 1
mallinkService/src/main/java/com/iformall/douyin/pay/DouYinPayHelper.java Просмотреть файл

@@ -120,7 +120,7 @@ public class DouYinPayHelper {

public static String doPost(String url, Map<String, Object> params) {
return HttpUtil.payPost(url, JSON.toJSONString(params));
return HttpUtil.doPost(url,null, JSON.toJSONString(params));
}
//服务端预下单
@@ -260,6 +260,7 @@ public class DouYinPayHelper {
//小程序开发者为分账方进件
//POST https://developer.toutiao.com/api/apps/ecpay/saas/app_add_sub_merchant
public static AppAddSubMerchantResult appAddSubMerchant(AppAddSubMerchant appAddSubMerchant) {
// String response = HttpUtil.doPost("https://developer.toutiao.com/api/apps/ecpay/saas/app_add_sub_merchant",null,JSON.toJSONString(appAddSubMerchant.toRequestMap()));
String response = doPost("https://developer.toutiao.com/api/apps/ecpay/saas/app_add_sub_merchant", appAddSubMerchant.toRequestMap());
JSONObject jsonObject = JSON.parseObject(response);
Integer code = jsonObject.getInteger("err_no");


+ 60
- 60
mallinkService/src/main/java/com/iformall/utils/HttpUtil.java Просмотреть файл

@@ -423,64 +423,64 @@ public class HttpUtil {
// return null;
// }

// /**
// * post请求(用于请求json格式的参数)
// * @param url
// * @param params
// * @return
// */
// public static String doPost(String url, Map<String,String> headMap, String params){
//
// CloseableHttpClient httpclient = HttpClients.createDefault();
// HttpPost httpPost = new HttpPost(url);// 创建httpPost
// httpPost.setHeader("Accept", "application/json");
// httpPost.setHeader("Content-Type", "application/json");
//
// if(headMap != null){
// Set<String> set = headMap.keySet();
// for(String key: set){
// httpPost.addHeader(key,headMap.get(key));
// }
// }
//
// String charSet = "UTF-8";
// StringEntity entity = new StringEntity(params, charSet);
// httpPost.setEntity(entity);
// CloseableHttpResponse response = null;
//
// try {
// response = httpclient.execute(httpPost);
// StatusLine status = response.getStatusLine();
// int state = status.getStatusCode();
// if (state == HttpStatus.SC_OK) {
// HttpEntity responseEntity = response.getEntity();
// String jsonString = EntityUtils.toString(responseEntity);
// return jsonString;
// }
// else{
// logger.info("请求返回:"+state+"("+url+")");
// }
// }
// catch(Exception e){
// logger.error(e.getMessage());
// return null;
// }
// finally {
// if (response != null) {
// try {
// response.close();
// } catch (IOException e) {
// logger.error(e.getMessage());
// }
// }
// try {
// httpclient.close();
// } catch (IOException e) {
// logger.error(e.getMessage());
// }
// }
// return null;
// }
/**
* post请求(用于请求json格式的参数)
* @param url
* @param params
* @return
*/
public static String doPost(String url, Map<String,String> headMap, String params){
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);// 创建httpPost
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
if(headMap != null){
Set<String> set = headMap.keySet();
for(String key: set){
httpPost.addHeader(key,headMap.get(key));
}
}
String charSet = "UTF-8";
StringEntity entity = new StringEntity(params, charSet);
httpPost.setEntity(entity);
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpPost);
StatusLine status = response.getStatusLine();
int state = status.getStatusCode();
if (state == HttpStatus.SC_OK) {
HttpEntity responseEntity = response.getEntity();
String jsonString = EntityUtils.toString(responseEntity);
return jsonString;
}
else{
logger.info("请求返回:"+state+"("+url+")");
}
}
catch(Exception e){
logger.error(e.getMessage());
return null;
}
finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
}
try {
httpclient.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
}
return null;
}


public static String payPost(String url, String params) {
@@ -504,8 +504,8 @@ public class HttpUtil {
private static String exec(okhttp3.Request request) {
try {
okhttp3.Response response = OkHttpClient.newCall(request).execute();
String header = response.header("X-Tt-Logid");
logger.info("X-Tt-Logid="+header);
// String header = response.header("X-Tt-Logid");
// logger.info("X-Tt-Logid="+header);
if (!response.isSuccessful())
throw new RuntimeException("Unexpected code " + response);
return response.body().string();


Загрузка…
Отмена
Сохранить