更新优化
This commit is contained in:
@@ -298,6 +298,90 @@ public class HttpMD5SendInfoUtil {
|
||||
|
||||
}
|
||||
|
||||
public static void sendHttp(final String postUrl, Map<String, String> params, final OnCallBackFromNet callBack) {
|
||||
|
||||
HttpHelper.loadData(HttpMethod.GET, Url.getTimestamp,null, new RequestCallBack<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResponseInfo<String> info) {
|
||||
Map<String, String> param=new HashMap<>();
|
||||
if(params != null){
|
||||
param.putAll(params);
|
||||
}
|
||||
|
||||
String uuid = SharePrefUtil.getString(getContext(), Constant.uuid, "");
|
||||
if(StringUtil.isEmpty(uuid))
|
||||
{
|
||||
uuid= LogoutHelper.addUMTokenuuid;
|
||||
}
|
||||
param.put("user_uuid", uuid);
|
||||
TimestampBean bean = GsonTools.fromGsonToBean(info.result, TimestampBean.class);
|
||||
param.put("timestamp", bean.getTimestamp());
|
||||
param.put("client_type", "A");
|
||||
param.put("version", UpdateVersionUtils.getVersionName());
|
||||
new Thread() {
|
||||
public void run() {
|
||||
String encoding = "UTF-8";
|
||||
Gson gson = new Gson();
|
||||
String params = gson.toJson(param);
|
||||
byte[] data;
|
||||
try {
|
||||
String sign = SignUtil.getSign(param);
|
||||
LogUtil.i("params = "+params.toString());
|
||||
data = params.getBytes(encoding);
|
||||
URL url = new URL(postUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setRequestProperty("Content-Type","application/json");
|
||||
conn.setRequestProperty("sign",sign);
|
||||
conn.setRequestProperty("Content-Length",String.valueOf(data.length));
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
OutputStream outStream = conn.getOutputStream();
|
||||
outStream.write(data);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
int ssss=conn.getResponseCode() ;
|
||||
if (ssss == 200) {
|
||||
InputStream inStream = conn.getInputStream();
|
||||
String result = new String(StreamTool.readInputStream(inStream), "UTF-8");
|
||||
String string = new String(result);
|
||||
LogUtil.i("result = "+result);
|
||||
JSONObject jsonObject = new JSONObject(string);
|
||||
String optString = jsonObject.optString("code");
|
||||
String message = jsonObject.optString("message");
|
||||
// Log.d("okhttp","result = "+result);
|
||||
Log.d("okhttp","getRealyWorldToken "+result);
|
||||
if ("200".equals(optString)) {
|
||||
LogUtil.e("请求成功");
|
||||
callBack.onCallbackFromThread(string);
|
||||
}
|
||||
else{
|
||||
callBack.onCallbackFromThread(string);
|
||||
}
|
||||
}else {
|
||||
LogUtil.e("Code = "+ssss);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.e("提交失败,请重试 = "+e.getMessage());
|
||||
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException arg0, String arg1) {
|
||||
// ToastUtil.showToast("请求失败,请重试");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void sendJsonPostParamTokenMD5(Context context,final OnCallBackFromNet callBack){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user