上报修改
parent
f2e2835076
commit
980477b790
|
@ -10,7 +10,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class DataMessageUtils {
|
||||
|
||||
private static Gson gson = new Gson();
|
||||
public static Gson gson = new Gson();
|
||||
|
||||
private static final String sendToTapDBURL = "https://e.tapdb.net/event";
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ljsd.jieling.logic.store;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.config.reportData.DataMessageUtils;
|
||||
|
@ -270,7 +271,7 @@ public class BuyGoodsNewLogic {
|
|||
jsonObject.put("who", user.getPlayerInfoManager().getOpenId());
|
||||
ReportBaseBean reportBaseBean = ReportUtil.baseBeanMap.get(uid);
|
||||
JSONObject jsonObject2 = new JSONObject();
|
||||
jsonObject2.put("_deviceid", reportBaseBean != null ? reportBaseBean.getIdfa_sOr_imei_s() : "");
|
||||
jsonObject2.put("_deviceid", reportBaseBean != null ? reportBaseBean.getIdfa_sOr_imei_s() : "11111");
|
||||
jsonObject2.put("_transactionid", orderId);
|
||||
jsonObject2.put("_paymenttype", "alipay");
|
||||
jsonObject2.put("_currencytype", "CNY");
|
||||
|
@ -282,16 +283,9 @@ public class BuyGoodsNewLogic {
|
|||
jsonObject2.put("_androidid", reportBaseBean != null ? reportBaseBean.getIdfa_sOr_imei_s() : "");
|
||||
jsonObject2.put("_oaid", "");
|
||||
jsonObject2.put("_mac", reportBaseBean != null ? reportBaseBean.getNetwork_s() : "");
|
||||
|
||||
jsonObject.put("context", jsonObject2);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("appid","e7ba14d6442b0ec225289bc846826092");
|
||||
params.put("who", user.getPlayerInfoManager().getOpenId());
|
||||
params.put("context", jsonObject2.toJSONString());
|
||||
String result = HttpPool.doPost(DataMessageUtils.restURL, params);
|
||||
// String result = HttpPool.doPost(DataMessageUtils.restURL, jsonObject);
|
||||
LOGGER.info("onChargeSuccess uid={} REST付费上报={} 参数={}", user.getId(), result, jsonObject.toJSONString());
|
||||
String result = HttpPool.sendPost2(DataMessageUtils.restURL, DataMessageUtils.gson.toJson(jsonObject));
|
||||
LOGGER.info("onChargeSuccess uid={} REST付费上报={} 参数={}", user.getId(), result, jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,20 @@
|
|||
package com.ljsd.jieling.util.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpPool {
|
||||
private static PoolingHttpClientConnectionManager poolConnection = new PoolingHttpClientConnectionManager();
|
||||
|
@ -98,103 +89,36 @@ public class HttpPool {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String doPost(String url, Map<String,String> parms) throws IOException {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
List<NameValuePair> nvps =getFromMap(parms);
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
||||
httpPost.addHeader("Content-Type", "application/json");
|
||||
CloseableHttpResponse response2 = httpclient.execute(httpPost);
|
||||
public static String sendPost2(String url, String data) {
|
||||
String response = null;
|
||||
|
||||
try {
|
||||
HttpEntity entity = response2.getEntity();
|
||||
return EntityUtils.toString(entity);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
response2.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<NameValuePair> getFromMap(Map<String,String> parms){
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>(parms.size());
|
||||
for(Map.Entry<String,String> item : parms.entrySet()){
|
||||
nvps.add(new BasicNameValuePair(item.getKey(), item.getValue()));
|
||||
}
|
||||
return nvps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装Post请求路径
|
||||
* @param url
|
||||
* @param jsonObject
|
||||
* @return
|
||||
*/
|
||||
public static String doPost(String url, JSONObject jsonObject) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
String result = "";
|
||||
// 创建httpClient实例
|
||||
httpClient = HttpClients.createDefault();
|
||||
// 创建httpPost远程连接实例
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 配置请求参数实例
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(35000)// 设置连接主机服务超时时间
|
||||
.setConnectionRequestTimeout(35000)// 设置连接请求超时时间
|
||||
.setSocketTimeout(60000)// 设置读取数据连接超时时间
|
||||
.build();
|
||||
// 为httpPost实例设置配置
|
||||
httpPost.setConfig(requestConfig);
|
||||
// 设置请求头
|
||||
httpPost.addHeader("Content-Type", "application/json");
|
||||
// 封装post请求参数
|
||||
if (jsonObject.size() > 0){
|
||||
List<NameValuePair> nvps = new ArrayList<>();
|
||||
Iterator<Map.Entry<String, Object>> iterator = jsonObject.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Object> mapEntry = iterator.next();
|
||||
nvps.add(new BasicNameValuePair(mapEntry.getKey(), mapEntry.getValue().toString()));
|
||||
}
|
||||
// 为httpPost设置封装好的请求参数
|
||||
CloseableHttpClient httpclient = null;
|
||||
CloseableHttpResponse httpresponse = null;
|
||||
try {
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
// httpClient对象执行post请求,并返回响应参数对象
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
// 从响应对象中获取响应内容
|
||||
HttpEntity entity = httpResponse.getEntity();
|
||||
result = EntityUtils.toString(entity);
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
httpclient = HttpClients.createDefault();
|
||||
HttpPost httppost = new HttpPost(url);
|
||||
StringEntity stringentity = new StringEntity(data,
|
||||
ContentType.create("application/json", "UTF-8"));
|
||||
httppost.setEntity(stringentity);
|
||||
httpresponse = httpclient.execute(httppost);
|
||||
response = EntityUtils
|
||||
.toString(httpresponse.getEntity());
|
||||
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != httpResponse) {
|
||||
try {
|
||||
httpResponse.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (httpclient != null) {
|
||||
httpclient.close();
|
||||
}
|
||||
if (null != httpClient) {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (httpresponse != null) {
|
||||
httpresponse.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue