|
|
@@ -130,7 +130,8 @@ public class XReconnectionManager extends AbstractConnectionListener {
|
|
|
}
|
|
|
} else if (checkTokenStatus == 1) {// 表示检查成功Token过期(或出现不能继续请求Token状态的异常),停止重新登陆
|
|
|
doReconnecting = false;
|
|
|
- conflict();
|
|
|
+ //TODO 关闭自动登录 可能出现账号异常情况
|
|
|
+// conflict();
|
|
|
} else if (checkTokenStatus == 2) {// 2、表示检查成功,Token没有改变,可以继续下面的重新登陆
|
|
|
break;
|
|
|
}
|
|
|
@@ -185,128 +186,131 @@ public class XReconnectionManager extends AbstractConnectionListener {
|
|
|
* @return
|
|
|
*/
|
|
|
private int syncCheckToken() {// 同步网络请求Token
|
|
|
- if (CoreService.DEBUG)
|
|
|
+ if (CoreService.DEBUG) {
|
|
|
Log.d(CoreService.TAG, "开始重新登陆前的 Token 状态检查");
|
|
|
- Log.d("wang","开始重新登陆前的 Token 状态检查");
|
|
|
- String requestUrl = MyApplication.getInstance().getConfig().USER_LOGIN_AUTO;
|
|
|
- if (requestUrl == null) {
|
|
|
- return 1;
|
|
|
- }
|
|
|
- HttpURLConnection httpConn = null;
|
|
|
- DataOutputStream out = null;
|
|
|
- InputStream is = null;
|
|
|
- try {
|
|
|
- URL url = new URL(requestUrl);
|
|
|
- httpConn = (HttpURLConnection) url.openConnection();
|
|
|
- httpConn.setDoOutput(true);
|
|
|
- httpConn.setDoInput(true);
|
|
|
- httpConn.setConnectTimeout(5 * 1000);
|
|
|
- httpConn.setReadTimeout(5 * 1000);
|
|
|
- httpConn.setRequestMethod("POST");
|
|
|
- httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
- out = new DataOutputStream(httpConn.getOutputStream());
|
|
|
- // 参数
|
|
|
- String access_token = MyApplication.getInstance().mAccessToken;
|
|
|
- if (TextUtils.isEmpty(access_token)) {
|
|
|
- access_token = UserSp.getInstance(mContext).getAccessToken(null);
|
|
|
- }
|
|
|
+ Log.d("wang", "开始重新登陆前的 Token 状态检查");
|
|
|
+ String requestUrl = MyApplication.getInstance().getConfig().USER_LOGIN_AUTO;
|
|
|
+ if (requestUrl == null) {
|
|
|
+ Log.i("gongpengming", "requestUrl 为空");
|
|
|
|
|
|
- if (TextUtils.isEmpty(access_token)) {
|
|
|
return 1;
|
|
|
}
|
|
|
+ HttpURLConnection httpConn = null;
|
|
|
+ DataOutputStream out = null;
|
|
|
+ InputStream is = null;
|
|
|
+ try {
|
|
|
+ URL url = new URL(requestUrl);
|
|
|
+ httpConn = (HttpURLConnection) url.openConnection();
|
|
|
+ httpConn.setDoOutput(true);
|
|
|
+ httpConn.setDoInput(true);
|
|
|
+ httpConn.setConnectTimeout(5 * 1000);
|
|
|
+ httpConn.setReadTimeout(5 * 1000);
|
|
|
+ httpConn.setRequestMethod("POST");
|
|
|
+ httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
+ out = new DataOutputStream(httpConn.getOutputStream());
|
|
|
+ // 参数
|
|
|
+ String access_token = MyApplication.getInstance().mAccessToken;
|
|
|
+ if (TextUtils.isEmpty(access_token)) {
|
|
|
+ access_token = UserSp.getInstance(mContext).getAccessToken(null);
|
|
|
+ }
|
|
|
|
|
|
- String serial = DeviceInfoUtil.getDeviceId(mContext);
|
|
|
- if (TextUtils.isEmpty(serial)) {
|
|
|
- return 1;
|
|
|
- }
|
|
|
- if (CoreService.DEBUG) {
|
|
|
- Log.d(CoreService.TAG, "requestUrl:" + requestUrl);
|
|
|
- Log.d(CoreService.TAG, "access_token:" + access_token);
|
|
|
- Log.d(CoreService.TAG, "serial:" + serial);
|
|
|
- }
|
|
|
+ if (TextUtils.isEmpty(access_token)) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("access_token=" + access_token + "&");
|
|
|
- String user = ((XMPPTCPConnection) mConnection).getDirectUser();
|
|
|
- Log.d("wang","user..."+ user);
|
|
|
- if (user == null) {
|
|
|
- Log.d("wang","user == null");
|
|
|
- return 1;
|
|
|
- }
|
|
|
- sb.append("userId=" + StringUtils.parseName(user) + "&");
|
|
|
- sb.append("serial=" + serial);
|
|
|
- out.write(sb.toString().getBytes("UTF-8"));
|
|
|
- out.flush();
|
|
|
-
|
|
|
- int statusCode = httpConn.getResponseCode();
|
|
|
- if (statusCode != 200) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- is = httpConn.getInputStream();
|
|
|
- if (is == null) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- StringBuffer buffer = new StringBuffer();
|
|
|
- int len = -1;
|
|
|
- byte[] data = new byte[1024];
|
|
|
- try {
|
|
|
- while ((len = is.read(data)) != -1) {
|
|
|
- buffer.append(new String(data, 0, len));
|
|
|
+ String serial = DeviceInfoUtil.getDeviceId(mContext);
|
|
|
+ if (TextUtils.isEmpty(serial)) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if (CoreService.DEBUG) {
|
|
|
+ Log.d(CoreService.TAG, "requestUrl:" + requestUrl);
|
|
|
+ Log.d(CoreService.TAG, "access_token:" + access_token);
|
|
|
+ Log.d(CoreService.TAG, "serial:" + serial);
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- String result = buffer.toString();
|
|
|
- if (CoreService.DEBUG) {
|
|
|
- Log.d(CoreService.TAG, "检查状态result:" + result);
|
|
|
- }
|
|
|
|
|
|
- if (TextUtils.isEmpty(result)) {
|
|
|
- Log.d("wang","result==null");
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append("access_token=" + access_token + "&");
|
|
|
+ String user = ((XMPPTCPConnection) mConnection).getDirectUser();
|
|
|
+ Log.d("wang", "user..." + user);
|
|
|
+ if (user == null) {
|
|
|
+ Log.d("wang", "user == null");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ sb.append("userId=" + StringUtils.parseName(user) + "&");
|
|
|
+ sb.append("serial=" + serial);
|
|
|
+ out.write(sb.toString().getBytes("UTF-8"));
|
|
|
+ out.flush();
|
|
|
|
|
|
- try {
|
|
|
- JSONObject jsonObject = JSON.parseObject(result);
|
|
|
- int resultCode = jsonObject.getIntValue(Result.RESULT_CODE);
|
|
|
- if (resultCode != 1) {
|
|
|
+ int statusCode = httpConn.getResponseCode();
|
|
|
+ if (statusCode != 200) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ is = httpConn.getInputStream();
|
|
|
+ if (is == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ int len = -1;
|
|
|
+ byte[] data = new byte[1024];
|
|
|
+ try {
|
|
|
+ while ((len = is.read(data)) != -1) {
|
|
|
+ buffer.append(new String(data, 0, len));
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String result = buffer.toString();
|
|
|
+ if (CoreService.DEBUG) {
|
|
|
+ Log.d(CoreService.TAG, "检查状态result:" + result);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(result)) {
|
|
|
+ Log.d("wang", "result==null");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- LoginAuto loginAuto = JSON.parseObject(jsonObject.getString(Result.DATA), LoginAuto.class);
|
|
|
- if (loginAuto != null) {// 判断时候要继续重新登陆
|
|
|
- int tokenExists = loginAuto.getTokenExists();// 1=令牌存在、0=令牌不存在
|
|
|
- int serialStatus = loginAuto.getSerialStatus();// 1=没有设备号、2=设备号一致、3=设备号不一致
|
|
|
- if (serialStatus == 2) {// 设备号一致,说明没有切换过设备
|
|
|
- if (tokenExists == 1) {// Token存在,
|
|
|
- return 2;
|
|
|
- } else {// Token 不存在
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ int resultCode = jsonObject.getIntValue(Result.RESULT_CODE);
|
|
|
+ if (resultCode != 1) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginAuto loginAuto = JSON.parseObject(jsonObject.getString(Result.DATA), LoginAuto.class);
|
|
|
+ if (loginAuto != null) {// 判断时候要继续重新登陆
|
|
|
+ int tokenExists = loginAuto.getTokenExists();// 1=令牌存在、0=令牌不存在
|
|
|
+ int serialStatus = loginAuto.getSerialStatus();// 1=没有设备号、2=设备号一致、3=设备号不一致
|
|
|
+ if (serialStatus == 2) {// 设备号一致,说明没有切换过设备
|
|
|
+ if (tokenExists == 1) {// Token存在,
|
|
|
+ return 2;
|
|
|
+ } else {// Token 不存在
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ } else {// 设备号不一致,那么就是切换过手机
|
|
|
return 1;
|
|
|
}
|
|
|
- } else {// 设备号不一致,那么就是切换过手机
|
|
|
- return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
}
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (out != null) {
|
|
|
- out.close();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (is != null) {
|
|
|
+ is.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- if (is != null) {
|
|
|
- is.close();
|
|
|
+ if (httpConn != null) {
|
|
|
+ httpConn.disconnect();
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (httpConn != null) {
|
|
|
- httpConn.disconnect();
|
|
|
}
|
|
|
}
|
|
|
return 0;
|