Browse Source

上传文件

陈士柏 2 years ago
parent
commit
98da7d4d39
1 changed files with 53 additions and 0 deletions
  1. 53 0
      mhotel/src/com/happy/common/http/Get_airticle.java

+ 53 - 0
mhotel/src/com/happy/common/http/Get_airticle.java

@@ -0,0 +1,53 @@
+package com.happy.common.http;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.happy.Model.weixin.AccessToken;
+import com.happy.Model.weixin.WeiXinUtil;
+import com.happy.Until.HttpUtils;
+import com.happy.common.model.airticle.*;
+
+import java.awt.*;
+import java.util.List;
+
+public class Get_airticle {
+
+    public static List<Item_content> get(int page, int rows) throws Exception {
+        Gson gson = new Gson();
+        int start = (page - 1) * rows;// 每页的起始下标
+        String access_token = "";
+        JSONObject json = new JSONObject();
+        json.put("grant_type", "client_credential");
+        json.put("appid", "wx19d0b6ab36feedf4");
+        json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
+        String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
+        access_token = HttpsClient.sendJson(url,json);
+        access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
+        JSONObject data = new JSONObject();
+        data.put("offset", start);
+        data.put("count", rows);
+        data.put("no_content", 0);
+        String msg =  HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token="+access_token, data);
+        Item item = JSONObject.parseObject(msg,Item.class);
+        return item.getItem();
+    }
+
+    public static int getTotal() throws Exception {
+        Gson gson = new Gson();
+        String access_token = "";
+        JSONObject json = new JSONObject();
+        json.put("grant_type", "client_credential");
+        json.put("appid", "wx19d0b6ab36feedf4");
+        json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
+        String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
+        access_token = HttpsClient.sendJson(url,json);
+        System.out.println(access_token);
+        access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
+        JSONObject data = new JSONObject();
+        String msg =  HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/count?access_token="+access_token, data);
+        System.out.println(msg);
+        New_count item = JSONObject.parseObject(msg, New_count.class);
+        return item.getTotal_count();
+    }
+
+}