1、HomePagerFragment处理点击
private void handlerItemClick(CategoryDetailBean.DataDTO dataDTO) {
// 处理数据
String title = dataDTO.getTitle();
String url = dataDTO.getClickUrl();
String cover = dataDTO.getPictUrl();
mTicketPresenter = TicketPresenterImpl.getInstance();
mTicketPresenter.getTicket(title, url, cover);
Intent intent = new Intent(getContext(), TicketActivity.class);
startActivity(intent);
}
2、presneter层发起网络请求
@Override
public void getTicket(String title, String url, String cover) {
// 去获取淘口令
String targetUrl = UrlUtils.getPathUrl(url);
cover = UrlUtils.getPathUrl(cover);
LogUtils.d(TAG, "cfx title = " + title + " targetUrl = " + targetUrl + " cover = " + cover);
TicketParamsBean ticketParamsBean = new TicketParamsBean(targetUrl, title);
mRetrofit = RetrofitManager.getInstance().getRetrofit();
API api = mRetrofit.create(API.class);
Call<TicketResultBean> task = api.getTicketResultBeans(ticketParamsBean);
task.enqueue(new Callback<TicketResultBean>() {
@Override
public void onResponse(Call<TicketResultBean> call, Response<TicketResultBean> response) {
int responseCode = response.code();
if (responseCode == HttpURLConnection.HTTP_OK) {
// 请求成功
TicketResultBean ticketResultBean = response.body();
if (ticketResultBean != null) {
LogUtils.d(TAG, "cfx getTicket 请求成功 " + ticketResultBean.toString());
}
} else {
LogUtils.d(TAG, "cfx getTicket 请求失败 responseCode = " + responseCode);
}
}
@Override
public void onFailure(Call<TicketResultBean> call, Throwable t) {
LogUtils.d(TAG, "cfx getTicket 请求失败 t " + t);
}
});
}
3、api
// 获取淘口令的API
@POST("tpwd")
Call<TicketResultBean> getTicketResultBeans(@Body TicketParamsBean ticketParamsBean);
4、点击打印的log
D/TicketPresenterImpl: cfx title = 澳宝洗发水香氛持久留香洗发乳改善干枯毛躁柔顺去屑洗发露480g targetUrl = https://s.click.taobao.com/te=m%3D2%26s%3DC45W49OQ1P5w4vFB6t2Z2ueEDrYVVa64Dne87AjQPk9yINtkUhsv0NEfEYRhTbR5F0qZilp6Jwtm5nS0VR3oT0KAZCke%2BMGJxC%2FP4%2FZfPFbcQmwDRwHnn1oN8CPq4PKMZiqtwk9j5QOk7mVwk%2B4lzKphKZX1agN4EiM%2FlSG%2FbZR%2Fs%2BVC%2FP9i5WZqYwyeyz13aba3w%2B4EEnvGDF1NzTQoPw%3D%3D&scm=1007.19011.125573.0_9660&pvid=e69c84c7-109e-405e-8c48f6a80121fa33&app_pvid=59590_33.51.71.58_842_1647055192915&ptl=floorId:9660;originalFloorId:9660;pvid:e69c84c7-109e-405e-8c48-f6a80121fa33;app_pvid:59590_33.51.71.58_842_1647055192915&union_lens=lensId%3AMAPI%401647055193%402133473a_08a5_17f7c23c403_11e8%4001 cover = https://gw.alicdn.com/bao/uploaded/i3/640739236/O1CN014iyIox2I68me3RC06_!!0-item_pic.jpg
D/TicketPresenterImpl: cfx getTicket 请求成功 TicketResultBean{success=false, code=11111, message='url 不可以为空.', data=null}
D/AutoLooperViewPager: cfx currentItem = 50001
D/AutoLooperViewPager: cfx currentItem = 50001
D/HomePagerFragment: cfx mIndicatorDataSize = 5
D/AutoLooperViewPager: cfx mLooperTime = 4000
D/HomePagerFragment: cfx setOnHomePagerContentClickListener 泉立方色母片纳米防串色吸色片洗衣家庭装混洗不染色护旗舰店官网
D/TicketPresenterImpl: cfx title = 泉立方色母片纳米防串色吸色片洗衣家庭装混洗不染色护旗舰店官网 targetUrl = https://s.click.taobao.com/t?e=m%3D2%26s%3Dj6%2Ft6NOb6oxw4vFB6t2Z2ueEDrYVVa64Dne87AjQPk9yINtkUhsv0NEfEYRhTbR5F0qZilp6Jwtm5nS0VR3oT0KAZCke%2BMGJxC%2FP4%2FZfPFbcQmwDRwHnn1oN8CPq4PKMZiqtwk9j5QPwdDmZ4my9rHaNhhdpPJebtySvWKufIaudKUYV4psxTIAC9vKzlu6r4zO2MiDcHh1SDYAhC1FIysYl7w3%2FA2kb&scm=1007.19011.125573.0_9660&pvid=e69c84c7-109e-405e-8c48-f6a80121fa33&app_pvid=59590_33.51.71.58_842_1647055192915&ptl=floorId:9660;originalFloorId:9660;pvid:e69c84c7-109e-405e-8c48-f6a80121fa33;app_pvid:59590_33.51.71.58_842_1647055192915&union_lens=lensId%3AMAPI%401647055193%402133473a_08a5_17f7c23c402_11bc%4001 cover = https://gw.alicdn.com/bao/uploaded/i1/2206733527373/O1CN01BWcFAh24KsvaGOCJc_!!0-item_pic.jpg
D/TicketPresenterImpl: cfx getTicket 请求成功 TicketResultBean{success=false, code=11111, message='url 不可以为空.', data=null}
D/AutoLooperViewPager: cfx currentItem = 50002
message='url 不可以为空.'
这个报错,你的url参数没有,如果有,就是Url不是领券的那个url,你看看bean类字段的说明,哪个才是领券的。