学习笔记
merge合并两个Observable请求
Observable<AESMBO> observable = api.getAES();
String xorValue = "9f48c6ce-07e8-4521-a840-e256f03c3ceb";
String xorKey = "W0CG2fq4jGo3n6EX";
LoginMBO loginMBO = new LoginMBO();
try {
loginMBO.setUsername(EncryptAes.encrypt(loginView.getUserName(), xorValue));
loginMBO.setPassword(EncryptAes.encrypt(loginView.getPassord(), xorValue));
} catch (Exception e) {
e.printStackTrace();
}
loginMBO.setXorKey(xorKey);
String str = JsonUtil.bean2json(loginMBO);
Observable<LoginMBO> loginObservable = api.login(str);
Observable.merge(observable,loginObservable).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<BaseMBO>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull BaseMBO baseMBO) {
if(baseMBO instanceof AESMBO){
Log.e("第一个返回",((AESMBO) baseMBO).getXorKey()+"=="+((AESMBO) baseMBO).getXorValue());
}else if(baseMBO instanceof LoginMBO ){
Log.e("第二个返回",((LoginMBO)baseMBO).getRsCode()+"=="+((LoginMBO)baseMBO).getTicket());
}
}
@Override
public void onError(@NonNull Throwable e) {
}
@Override
public void onComplete() {
}
});
Retrofit
API:
@FormUrlEncoded表单域@Field修饰上传字段@Multipart用来修饰文件上传 @Part修饰每一个元素@FormUrlEncoded @POST("/basic/login/login/loginCs.json") Observable<LoginMBO> login(@Field("mobileParam")String mobileParam);
@Headers("Cache-Control: max-age=640000")
@GET("/widget/list")
List<Widget> widgetList();
@Path路径参数
@GET("{username}") Call<User> getUser(@Path("username") String username);
@Query参数
@POST("users") Call<List<User>> getUsersBySort(@Query("sort") String sort);
@Head注解请求头信息
@Headers("Cache-Control: max-age=640000")@GET("/widget/list")List<Widget> widgetList();