Commit 5db5faa2718e795d5e2ee972db3c450679ff756e

Authored by wugian
1 parent 9d65ca5e

基本流程,获取相关信息

... ... @@ -35,7 +35,7 @@ public class AppUpdateUtils {
35 35 private static final String UPDATE_ADS_VIDEO_INFO = API_ROOT + "/Api/Agent/CheckAdVedio?checkCode=";
36 36 private String updateApkUrl = API_ROOT + "/Api/Agent/CheckAppVersion?machineType=";// + XgimiDevice.getDeviceType() + "&imei=" + SystemUtils.getPID();
37 37 private String updatePosterUrl = API_ROOT + "/Agent/GetPoster?imei=";// + SystemUtils.getPID();
38   - private String GET_AGENT_INFO = API_ROOT + "/Api/Agent/GetInfo?imei=";
  38 + private String getAgentInfo = API_ROOT + "/Api/Agent/GetInfo?imei=";
39 39
40 40 private Context context;
41 41 private boolean showNoUpdate = true;
... ... @@ -291,7 +291,7 @@ public class AppUpdateUtils {
291 291 public void updateAgentInfo() {
292 292 String verJson = null;
293 293 try {
294   - verJson = OkHttpClientManager.getAsString(GET_AGENT_INFO + pid);
  294 + verJson = OkHttpClientManager.getAsString(getAgentInfo + pid);
295 295 } catch (Exception e) {
296 296 e.printStackTrace();
297 297 }
... ... @@ -323,7 +323,7 @@ public class AppUpdateUtils {
323 323 }
324 324 long l = System.currentTimeMillis() / 1000;
325 325 try {
326   - l = OkHttpClientManager.getSysTime(GET_AGENT_INFO + pid);
  326 + l = OkHttpClientManager.getSysTime(getAgentInfo + pid);
327 327 } catch (IOException | ParseException e) {
328 328 e.printStackTrace();
329 329 }
... ...
... ... @@ -8,6 +8,7 @@ import com.google.gson.Gson;
8 8 import com.google.gson.internal.$Gson$Types;
9 9 import com.squareup.okhttp.Call;
10 10 import com.squareup.okhttp.Callback;
  11 +import com.squareup.okhttp.Dns;
11 12 import com.squareup.okhttp.FormEncodingBuilder;
12 13 import com.squareup.okhttp.Headers;
13 14 import com.squareup.okhttp.HttpUrl;
... ... @@ -33,13 +34,18 @@ import java.lang.reflect.Type;
33 34 import java.net.CookieManager;
34 35 import java.net.CookiePolicy;
35 36 import java.net.FileNameMap;
  37 +import java.net.InetAddress;
36 38 import java.net.URLConnection;
  39 +import java.net.UnknownHostException;
37 40 import java.security.KeyManagementException;
38 41 import java.security.NoSuchAlgorithmException;
39 42 import java.security.cert.CertificateException;
40 43 import java.text.ParseException;
  44 +import java.util.ArrayList;
  45 +import java.util.Arrays;
41 46 import java.util.Date;
42 47 import java.util.HashMap;
  48 +import java.util.List;
43 49 import java.util.Map;
44 50 import java.util.Set;
45 51
... ... @@ -56,7 +62,26 @@ public class OkHttpClientManager {
56 62 mOkHttpClient = new OkHttpClient();
57 63 //cookie enabled
58 64 mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
59   -
  65 + mOkHttpClient.setDns(new Dns() {
  66 + @Override
  67 + public List<InetAddress> lookup(String hostname) throws UnknownHostException {
  68 + if (hostname == null)
  69 + throw new UnknownHostException("hostname == null");
  70 + if (hostname.equals("ft.qnbar.cn")) {
  71 +// String[] ips = new String[]{"10.10.4.1"};
  72 +// List<InetAddress> addresses = new ArrayList<InetAddress>();
  73 +// for (int i = 0; i < ips.length; i++) {
  74 +// addresses.add(InetAddress.getByName(ips[i]));
  75 +// }
  76 +// return addresses;
  77 + List<InetAddress> addresses = new ArrayList<InetAddress>();
  78 + addresses.add(InetAddress.getByName("10.10.4.6"));
  79 + return addresses;
  80 + } else {
  81 + return Arrays.asList(InetAddress.getAllByName(hostname));
  82 + }
  83 + }
  84 + });
60 85 // Create a trust manager that does not validate certificate chains
61 86 TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
62 87 @Override
... ...
1 1 package com.qnbar.smc.service;
2 2
3   -import java.util.List;
4   -
5 3 /**
6 4 * Created by wugian on 2017/3/11.
7 5 */
8 6
9 7 public class SocketResponse {
10 8
  9 +
11 10 /**
12   - * code : 1001
13   - * msg : roomsn is registered!please use reconnect
  11 + * code : 0
  12 + * msg :
14 13 * data : []
15   - * cmd :
  14 + * cmd : openDoor
16 15 */
17 16
18 17 private int code;
19 18 private String msg;
20 19 private String cmd;
21   - private List<?> data;
  20 +// private List<?> data;
22 21
23 22 public int getCode() {
24 23 return code;
... ... @@ -44,11 +43,11 @@ public class SocketResponse {
44 43 this.cmd = cmd;
45 44 }
46 45
47   - public List<?> getData() {
48   - return data;
49   - }
50   -
51   - public void setData(List<?> data) {
52   - this.data = data;
53   - }
  46 +// public List<?> getData() {
  47 +// return data;
  48 +// }
  49 +//
  50 +// public void setData(List<?> data) {
  51 +// this.data = data;
  52 +// }
54 53 }
... ...
... ... @@ -30,11 +30,11 @@ public class SocketService extends Service {
30 30 private static final int ROOM_NOT_EXIST_M = 1002;
31 31 private static final int HEAT_BEAT_RTN = 1003;
32 32
33   - public static final String HOST = "121.43.189.162";// "192.168.1.21";//
  33 + public static final String HOST = "10.10.4.6";// "192.168.1.21";//
34 34 public static final int PORT = 9501;
35 35
36 36 public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容
37   - public String testRoomSn = "000003";
  37 + public String testRoomSn = "R170413034374";
38 38
39 39 private ReadThread mReadThread;
40 40 private HeatBeatThread mHeatBeatThread;
... ... @@ -83,7 +83,7 @@ public class SocketService extends Service {
83 83 context = this;
84 84 //TODO change the room sn
85 85 if (!"LETEST".equals(SystemUtils.getPid(context, BuildConfig.MACHINE_TYPE))) {
86   - testRoomSn = "000002";
  86 + testRoomSn = "R170413034374";
87 87 }
88 88 new InitSocketThread().start();
89 89 Log.d(TAG, "socket service onCreate");
... ... @@ -197,7 +197,7 @@ public class SocketService extends Service {
197 197 Log.d(TAG, "end:" + message.contains(END_SYMBOL) + "");
198 198 Log.d(TAG, "recv msg:" + message);
199 199 try {
200   - SocketResponse socketResponse = gson.fromJson(message.trim(), SocketResponse.class);
  200 + SocketResponse socketResponse = gson.fromJson(message.substring(0, message.length() - 8), SocketResponse.class);
201 201 switch (socketResponse.getCode()) {
202 202 case SUCESS_MESSAGE:
203 203 Log.d(TAG, "success:" + socketResponse.getCmd());
... ...
... ... @@ -17,7 +17,7 @@ import com.xgimi.gimicinema.application.FangTangApplication;
17 17 * Created by wugian on 2017/4/7
18 18 */
19 19 public class RoomInfoModelImpl implements IRoomInfoModel {
20   - private static final String ROOT_URL = "https:/hulong.nat123.net/";
  20 + private static final String ROOT_URL = "https://ft.qnbar.cn/develop/";
21 21 private static final String ROOM_INFO_BY_IMEI_URL = ROOT_URL + "tcp/getRoomInfoByimei?imei=";
22 22 private static final String ROOM_STATUS_BY_ROOM_SN_URL = ROOT_URL + "tcp/getRoomStatus?room_sn=";
23 23 private static final String ROOM_QRCODE_BY_ORDER_SN = ROOT_URL + "tcp/getEndQRCode?order_sn=";
... ... @@ -54,7 +54,7 @@ public class RoomInfoModelImpl implements IRoomInfoModel {
54 54 e.printStackTrace();
55 55 }
56 56 boolean equals = roomInfoStr.equals(response);
57   - if (roomInfo1 != null && !equals) {
  57 + if (roomInfo1 != null && roomInfo1.getData() != null && !equals) {
58 58 Utils.saveString(applicationContext, "room-info", response);
59 59 listener.onGetRoomInfoUpdate(roomInfo1);
60 60 } else {
... ...
Please register or login to post a comment