/** 将设备Token提交服务器 */ public void postDeviceTokenToServiceLocked() { DebugUtils.logD(TAG, "postDeviceTokenToServiceLocked()"); try { if (MyAccountManager.getInstance().hasLoginned() && !TextUtils.isEmpty(getDeviceTotke()) && !getDeviceTotkeStatus()) { InputStream is = NetworkUtils.openContectionLocked( HaierServiceObject.getUpdateDeviceTokenUrl( String.valueOf(MyAccountManager.getInstance().getAccountObject().mAccountUid), getDeviceTotke(), "android"), MyApplication.getInstance().getSecurityKeyValuesObject()); if (is != null) { HaierResultObject result = HaierResultObject.parse(NetworkUtils.getContentFromInput(is)); NetworkUtils.closeInputStream(is); saveDeviceTokenStatus(result.isOpSuccessfully()); DebugUtils.logD(TAG, result.toString()); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override protected HaierResultObject doInBackground(Void... params) { HaierResultObject resultObject = new HaierResultObject(); mAccountObject = new AccountObject(); ; try { MyApplication.getInstance() .postAsync( new Runnable() { @Override public void run() { mStatusView.setText(R.string.msg_login_download_accountinfo_wait); } }); _is = NetworkUtils.openContectionLocked( HaierServiceObject.getLoginOrUpdateUrl(mTel, mPwd), null); resultObject = HaierResultObject.parse(NetworkUtils.getContentFromInput(_is)); if (resultObject.isOpSuccessfully()) { // 登录成功,我们解析登录返回数据 AccountParser.parseAccountData(resultObject.mJsonData, mAccountObject); if (mAccountObject != null && mAccountObject.hasUid()) { boolean saveAccountOk = MyAccountManager.getInstance() .saveAccountObject( LoginOrUpdateAccountDialog.this.getContentResolver(), mAccountObject); if (!saveAccountOk) { // 登录成功了,但本地数据保存失败,通常不会走到这里 resultObject.mStatusMessage = LoginOrUpdateAccountDialog.this.getString(R.string.msg_login_save_success); } } } } catch (ClientProtocolException e) { e.printStackTrace(); resultObject.mStatusMessage = e.getMessage(); } catch (IOException e) { e.printStackTrace(); resultObject.mStatusMessage = MyApplication.getInstance().getGernalNetworkError(); } catch (JSONException e) { e.printStackTrace(); resultObject.mStatusMessage = e.getMessage(); } finally { NetworkUtils.closeInputStream(_is); } return resultObject; }
/** * 记录交换 * * @param downloadedMm 要下载的名号 * @param exchangeMm 用于交换的名号 * @return 如果记录成功,返回true,否则返回false */ public static boolean recordExchange(String downloadedMm, String exchangeMm) { StringBuilder sb = new StringBuilder("http://www.mingdown.com/cell/jiaohuan.ashx?"); sb.append("mm1=").append(downloadedMm).append("&mm2=").append(exchangeMm); try { InputStream is = NetworkUtils.openContectionLocked( sb.toString(), MyApplication.getInstance().getSecurityKeyValuesObject()); if (is == null) { return false; } String resultStr = NetworkUtils.getContentFromInput(is); DebugUtils.logD(TAG, "service return " + resultStr); if ("ok".equals(resultStr)) { DebugUtils.logD(TAG, "finish recording exchange " + resultStr); return true; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; }