Get_airticle.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.happy.common.http;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.google.gson.Gson;
  4. import com.happy.Model.weixin.AccessToken;
  5. import com.happy.Model.weixin.WeiXinUtil;
  6. import com.happy.Until.HttpUtils;
  7. import com.happy.common.model.airticle.*;
  8. import java.awt.*;
  9. import java.util.List;
  10. public class Get_airticle {
  11. public static List<Item_content> get(int page, int rows) throws Exception {
  12. Gson gson = new Gson();
  13. int start = (page - 1) * rows;// 每页的起始下标
  14. String access_token = "";
  15. JSONObject json = new JSONObject();
  16. json.put("grant_type", "client_credential");
  17. json.put("appid", "wx19d0b6ab36feedf4");
  18. json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
  19. String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
  20. access_token = HttpsClient.sendJson(url,json);
  21. access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
  22. JSONObject data = new JSONObject();
  23. data.put("offset", start);
  24. data.put("count", rows);
  25. data.put("no_content", 0);
  26. String msg = HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token="+access_token, data);
  27. Item item = JSONObject.parseObject(msg,Item.class);
  28. return item.getItem();
  29. }
  30. public static int getTotal() throws Exception {
  31. Gson gson = new Gson();
  32. String access_token = "";
  33. JSONObject json = new JSONObject();
  34. json.put("grant_type", "client_credential");
  35. json.put("appid", "wx19d0b6ab36feedf4");
  36. json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
  37. String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
  38. access_token = HttpsClient.sendJson(url,json);
  39. System.out.println(access_token);
  40. access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
  41. JSONObject data = new JSONObject();
  42. String msg = HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/count?access_token="+access_token, data);
  43. System.out.println(msg);
  44. New_count item = JSONObject.parseObject(msg, New_count.class);
  45. return item.getTotal_count();
  46. }
  47. }