use of com.mtm.mrecord.mvp.model.entity.ResultKeyGsonBean in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.
the class SplashPresenter method toActDownLoadNetKey.
/**
* 下载网络请求验证码
*/
private void toActDownLoadNetKey() {
ThreadUtils.runThread(new Runnable() {
@Override
public void run() {
HttpClient httpClient = new HttpClient();
Map<String, String> msg = new HashMap<String, String>();
msg.put("appKey", "9c3d77f18e4848d095e626e9b3a009a3");
msg.put("appSecret", "ff265c879c4ac08028e77a6c66078f9ce81c15b6fbc76c18f7a12a97c859c92b");
String params = new Gson().toJson(msg);
StringRequestEntity paramEntity = null;
try {
paramEntity = new StringRequestEntity(params, "application/json", "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
PostMethod postMethod = new PostMethod(Api.POST_KEY);
postMethod.setRequestEntity(paramEntity);
try {
httpClient.executeMethod(postMethod);
} catch (IOException e) {
e.printStackTrace();
}
try {
InputStream inputStream = postMethod.getResponseBodyAsStream();
final String resultKey = convertStreamToString(inputStream);
ThreadUtils.runInMainThread(new Runnable() {
@Override
public void run() {
ResultKeyGsonBean resultKeyBean = new Gson().fromJson(resultKey, ResultKeyGsonBean.class);
String access_token = resultKeyBean.getData().getAccess_token();
GlobalConstantUtils.setToken(access_token);
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(@NonNull ObservableEmitter<String> e) throws Exception {
SystemClock.sleep(2000);
e.onNext("");
e.onComplete();
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Intent intent = new Intent(AppLifecyclesImpl.mAppContext, MainActivity.class);
mRootView.launchActivity(intent);
mRootView.killMyself();
}
});
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
Aggregations