/** { JsonConst.RETCODE:"00000", "retInfo":"登录UHOME云平台成功。", “userId”:”100013957366151422” } */ @Override public HomeUser parseLoginResult(String result, Context context) { // TODO Auto-generated method stub if (TextUtils.isEmpty(result)) { return null; } HomeUser homeUser = new HomeUser(); try { JSONObject job = new JSONObject(result); homeUser.error = job.optString(JsonConst.RETCODE); homeUser.id = job.optString("userId"); homeUser.error_info = job.optString("retInfo"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (Const.R3RESULT_OK.equals(homeUser.error)) { String assResult = NetWorkFactory.getInstance(context).assignAdapter(homeUser.id); // 动态获取接入网关地址 parseAssignAdapter(assResult, homeUser); } return homeUser; }
/** * @author wjc * @param result * @param homeUser void { JsonConst.RETCODE: "00000", "retInfo": "success", "appId": * "MB-SMARTAIR1-0001", "appAdapter": { "id": "15", "type": null, "name": "UH-UADAPTER1-0001", * "uri": "http://103.8.220.165:56701", "m2mCallbackUri": null } */ private void parseAssignAdapter(String result, HomeUser homeUser) { if (result == null) return; try { JSONObject job = new JSONObject(result); String retCode = job.getString("retCode"); if (retCode.equals("00000")) { // JSONObject appAdapterJob = job.getJSONObject("appAdapter"); // String uri = appAdapterJob.getString("uri"); String uri = job.optString("agAddr"); String ip = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf(":")); String port = uri.substring(uri.lastIndexOf(":") + 1, uri.length()); Log.d("star", "ip : " + ip + " port : " + port); homeUser.gw_domain = ip; // 北京测试环境 homeUser.gw_port = Integer.valueOf(port); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } }