33
This commit is contained in:
@@ -0,0 +1,363 @@
|
||||
package cn.shangyu.gdxzExpert.utils;
|
||||
|
||||
import static cn.shangyu.gdxzExpert.utils.UIUtils.getContext;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.hjq.window.EasyWindow;
|
||||
import com.lidroid.xutils.exception.HttpException;
|
||||
import com.lidroid.xutils.http.ResponseInfo;
|
||||
import com.lidroid.xutils.http.callback.RequestCallBack;
|
||||
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.shangyu.gdxzExpert.R;
|
||||
import cn.shangyu.gdxzExpert.bean.TimestampBean;
|
||||
import cn.shangyu.gdxzExpert.http.HttpHelper;
|
||||
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
|
||||
import cn.shangyu.gdxzExpert.netease.config.LogoutHelper;
|
||||
|
||||
/**
|
||||
* @author 作者 wcx
|
||||
* @version 创建时间:2018-7-11 上午11:22:00
|
||||
* 类说明
|
||||
*/
|
||||
public class HttpMD5SendInfoUtil {
|
||||
/**
|
||||
* 签到
|
||||
* */
|
||||
|
||||
public static void sendJsonPostParamtoNetSignMD5(final String postUrl,final Map<String, String> param,Context mContext) {
|
||||
HttpHelper.loadData(HttpMethod.GET, Url.getTimestamp,null, new RequestCallBack<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResponseInfo<String> info) {
|
||||
// SharePrefUtil.saveString(mActivity,
|
||||
// Url.getExpertroll,
|
||||
// info.result);
|
||||
String uuid = SharePrefUtil.getString(getContext(), Constant.uuid, "");
|
||||
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);
|
||||
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 (conn.getResponseCode() == 200) {
|
||||
InputStream inStream = conn.getInputStream();
|
||||
String result = new String(StreamTool.readInputStream(inStream), "UTF-8");
|
||||
String string = new String(result);
|
||||
JSONObject jsonObject = new JSONObject(string);
|
||||
String optString = jsonObject.optString("code");
|
||||
String message = jsonObject.optString("message");
|
||||
if ("200".equals(optString)) {
|
||||
Constant.isRefreshpoint = true;//个人中心界面刷新
|
||||
ToastUtil.showMessage(message);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
// mShowDialog.dismiss();
|
||||
// closeProgressDialog();
|
||||
} finally {
|
||||
// if (!top_right_text.isClickable()) {
|
||||
// top_right_text.setClickable(true);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
|
||||
// Log.i("TAG", "result = "+info.result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException arg0, String arg1) {
|
||||
// ToastUtil.showToast("请求失败,请重试");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 无需结果请求,1.指南下载数量 2.增加视频阅读数量
|
||||
* */
|
||||
public static void sendJsonPostParamNoResultMD5(final String postUrl,final Map<String, String> param) {
|
||||
|
||||
HttpHelper.loadData(HttpMethod.GET, Url.getTimestamp,null, new RequestCallBack<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResponseInfo<String> info) {
|
||||
// SharePrefUtil.saveString(mActivity,
|
||||
// Url.getExpertroll,
|
||||
// info.result);
|
||||
String uuid = SharePrefUtil.getString(getContext(), Constant.uuid, "");
|
||||
if(StringUtil.isEmpty(uuid))
|
||||
{
|
||||
uuid= LogoutHelper.addUMTokenuuid;
|
||||
}
|
||||
if(CommonUtil.BigModule())
|
||||
{
|
||||
param.put("app_type", "1");
|
||||
}
|
||||
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");
|
||||
if ("200".equals(optString)) {
|
||||
LogUtil.e("请求成功");
|
||||
}
|
||||
}else {
|
||||
LogUtil.e("Code = "+ssss);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.e("提交失败,请重试 = "+e.getMessage());
|
||||
// ToastUtil.showMessage("提交失败,请重试");
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
// mShowDialog.dismiss();
|
||||
// closeProgressDialog();
|
||||
} finally {
|
||||
// if (!top_right_text.isClickable()) {
|
||||
// top_right_text.setClickable(true);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
|
||||
// Log.i("TAG", "result = "+info.result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException arg0, String arg1) {
|
||||
// ToastUtil.showToast("请求失败,请重试");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
public static void sendJsonPostParamTokenMD5s(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<>();
|
||||
String uuid = SharePrefUtil.getString(getContext(), Constant.uuid, "");
|
||||
if(StringUtil.isEmpty(uuid))
|
||||
{
|
||||
uuid= LogoutHelper.addUMTokenuuid;
|
||||
}
|
||||
if(CommonUtil.BigModule())
|
||||
{
|
||||
param.put("app_type", "1");
|
||||
}
|
||||
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(Url.getRealyWorldToken);
|
||||
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){
|
||||
|
||||
EasyWindow.with((Activity) context).setGravity(Gravity.CENTER)
|
||||
|
||||
.setContentView(R.layout.float_cent_dialogqs).setBackgroundDimAmount(0.5f)
|
||||
.setText(R.id.tv_infotitle, "温馨提示")
|
||||
.setText(R.id.tv_tishi, "查询失败,请点击重试再次查询")
|
||||
.setVisibility(R.id.r_b, View.VISIBLE)
|
||||
.setText(android.R.id.message, "确定")
|
||||
.setOutsideTouchable(false)
|
||||
.setOnClickListener(android.R.id.message, new EasyWindow.OnClickListener<TextView>() {
|
||||
|
||||
@Override
|
||||
public void onClick(EasyWindow<?> window, TextView view) {
|
||||
window.cancel();
|
||||
sendJsonPostParamTokenMD5s(callBack);
|
||||
|
||||
}
|
||||
})
|
||||
.setOnClickListener(R.id.btn_cancel, new EasyWindow.OnClickListener<TextView>() {
|
||||
|
||||
@Override
|
||||
public void onClick(EasyWindow<?> window, TextView view) {
|
||||
window.cancel();
|
||||
|
||||
}
|
||||
}).show();
|
||||
|
||||
}
|
||||
public static int hasrealtoken(String s)
|
||||
{
|
||||
try {
|
||||
JSONObject jsonObject=new JSONObject(s);
|
||||
if("200".equals(jsonObject.optString("code")))
|
||||
{
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if(
|
||||
"30007".equals(jsonObject.optString("code"))||"30012".equals(jsonObject.optString("code")))
|
||||
{
|
||||
SharePrefUtil.saveString(getContext(),"x_access_token","");
|
||||
return 0;
|
||||
}
|
||||
else if(
|
||||
"30014".equals(jsonObject.optString("code"))||"30020".equals(jsonObject.optString("code")))
|
||||
{
|
||||
SharePrefUtil.saveString(getContext(),"x_access_token","");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user