基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

37 lines
1.3 KiB

  1. import 'package:dio/dio.dart';
  2. import 'package:zhiying_comm/zhiying_comm.dart';
  3. class TaobaoLoader {
  4. static Future<List<String>> loadImages(String id) async {
  5. String url =
  6. 'http://h5api.m.taobao.com/h5/mtop.taobao.detail.getdesc/6.0/?api=mtop.taobao.detail.getdesc&appkey=12574478&data={"type":"0","f":"TB1AsvbfnqWBKNjSZFx8qwpLpla","id":"${id.toString()}"}&dataType=json&jsv=2.4.11&sign=e93a97b7e9a9a459297f4e689051c895&t=1538180732308&type=json';
  7. Dio dio = Dio();
  8. Response response = await dio.get(url);
  9. // Logger.debug(response.data.toString());
  10. Map<String, dynamic> json = Map<String, dynamic>.from(response.data);
  11. List<String> images = List();
  12. try {
  13. Map<String, dynamic> data = json['data'];
  14. List list = json['data']['wdescContent']['pages'];
  15. for (var item in list) {
  16. Logger.debug(item);
  17. RegExp exp = new RegExp("(?<=<img(.*?)>)(.*?)(?=</img>)");
  18. String image = exp.stringMatch(item.toString());
  19. if (image != null && image != '') {
  20. if (image.startsWith('//')) {
  21. images.add('http:' + image);
  22. } else
  23. if (image.startsWith('https://') || image.startsWith('http://')) {
  24. images.add(image);
  25. }
  26. }
  27. }
  28. } catch (err) {
  29. Logger.error(err);
  30. }
  31. return images;
  32. }
  33. }