Parcourir la source

Merge remote-tracking branch 'origin/master'

zhangbin il y a 1 an
Parent
commit
47aa1de5ba

+ 6 - 0
nbjk-admin/src/main/resources/application-local.yml

@@ -106,6 +106,12 @@ gzh:
     appId: wx457ba48e0801c0b6
     appSecret: 0212a4fc020cdc0c968eb17126d5fee1
 
+# 微信公众号 驾助服务教练
+gzh2:
+    appId: wx6d48405bbcf130be
+    appSecret: 0212a4fc020cdc0c968eb17126d5fee1
+
+
 # 小程序
 xcx:
     appId: wx97bbc22daac9362a

+ 50 - 35
nbjk-admin/src/test/java/com/miaxis/test/WxGzhTest.java

@@ -14,25 +14,31 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 @SpringBootTest(classes = NbjkApplication.class)
 @RunWith(SpringRunner.class)
 public class WxGzhTest {
 
     @Autowired
-    private IWxGzhService wxGzhServicee;
+    private IWxGzhService wxGzhService;
     @Autowired
     private IWxService wxService;
 
     @Test
     public void getUserInfo() throws IOException {
-        String token = wxGzhServicee.getGzhToken();
-        WxMaterialList wxMaterialList = new WxMaterialList();
-        wxMaterialList.setType("video");
-        wxMaterialList.setOffset("0");
-        wxMaterialList.setCount("20");
-        String result = wxService.getBatchMateria(token,wxMaterialList);
+        String token = wxGzhService.getGzhToken();
+        Map<String,String> param = new HashMap();
+        param.put("appid","wx457ba48e0801c0b6");
+        String result = wxService.clearQuota(token,param);
         System.out.println(result);
+ //       WxMaterialList wxMaterialList = new WxMaterialList();
+//        wxMaterialList.setType("video");
+//        wxMaterialList.setOffset("0");
+//        wxMaterialList.setCount("20");
+//        String result = wxService.getBatchMateria(token,wxMaterialList);
+//        System.out.println(result);
 //        WxMaterial wxMaterial = new WxMaterial();
 //        wxMaterial.setMedia_id("kD88pyQSlAfJYQIBpBp75Wjs3tWIgKQI6jw--s8kDrZ0AuuQDMyA89LU5CX8UMFY");
 //        String result2 = wxService.getMateria(token,wxMaterial);
@@ -43,34 +49,43 @@ public class WxGzhTest {
 
     @Test
     public void getWxFreepublish() {
-        String token = wxGzhServicee.getGzhToken();
-        WxFreepublish wxFreepublish = new WxFreepublish();
-        wxFreepublish.setOffset("0");
-        wxFreepublish.setCount("20");
-        wxFreepublish.setNo_content("1");
-        String result = wxService.getFreepublish(token, wxFreepublish);
-        JSONObject json = JSONObject.parseObject(result);
-        JSONArray jsonArray = json.getJSONArray("item");
-
-        for (int i = 0; i < jsonArray.size(); i++) {
-            JSONObject jsonB= jsonArray.getJSONObject(i);
-            String articleId = jsonB.getString("article_id");
-            JSONObject content = jsonB.getJSONObject("content");
-            JSONArray newsItem = content.getJSONArray("news_item");
-            JSONObject newsItem0 = newsItem.getJSONObject(0);
-            String title = newsItem0.getString("title");
-            String url = newsItem0.getString("url");
-            String thumbUrl = newsItem0.getString("thumb_url");
-            String isDeleted = newsItem0.getString("is_deleted");
-
-            System.out.println(articleId);
-            System.out.println(title);
-            System.out.println(url);
-            System.out.println(thumbUrl);
-            System.out.println(isDeleted);
-        }
-
-        System.out.println(result);
+        String token = wxGzhService.getGzhToken();
+        int totalCount = 0;
+        int countPerPage = 20;
+
+      //  do {
+            WxFreepublish wxFreepublish = new WxFreepublish();
+            wxFreepublish.setOffset(String.valueOf(totalCount));
+            wxFreepublish.setCount(String.valueOf(countPerPage));
+            wxFreepublish.setNo_content("1");
+
+            String result = wxService.getFreepublish(token, wxFreepublish);
+            JSONObject json = JSONObject.parseObject(result);
+            JSONArray jsonArray = json.getJSONArray("item");
+
+            if (jsonArray==null || jsonArray.isEmpty()) {
+              //  break;
+            }
+
+            for (int i = 0; i < jsonArray.size(); i++) {
+                JSONObject jsonB = jsonArray.getJSONObject(i);
+                String articleId = jsonB.getString("article_id");
+                JSONObject content = jsonB.getJSONObject("content");
+                JSONArray newsItem = content.getJSONArray("news_item");
+                JSONObject newsItem0 = newsItem.getJSONObject(0);
+                String title = newsItem0.getString("title");
+                String url = newsItem0.getString("url");
+                String thumbUrl = newsItem0.getString("thumb_url");
+                String isDeleted = newsItem0.getString("is_deleted");
+
+                System.out.println(articleId);
+                System.out.println(title);
+                System.out.println(url);
+                System.out.println(thumbUrl);
+                System.out.println(isDeleted);
+                System.out.println(result);
+            }
+      //  } while (true);
 
 
     }

+ 2 - 0
nbjk-service/src/main/java/com/miaxis/wx/service/IWxGzhService.java

@@ -18,6 +18,8 @@ public interface IWxGzhService {
      */
     String getGzhToken();
 
+
+
     /**
      * 获取微信临时公众号token
      * @return

+ 10 - 0
nbjk-service/src/main/java/com/miaxis/wx/service/IWxService.java

@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.Map;
+
 /**
  *
  * 微信接口
@@ -133,4 +135,12 @@ public interface IWxService {
      */
     @PostMapping(value = "/cgi-bin/material/get_material")
     String getMateria(@RequestParam("access_token") String accessToken, WxMaterial wxMaterial);
+
+
+    /**
+     * 清空api的调用quota
+     */
+    @PostMapping(value = "cgi-bin/clear_quota")
+    String clearQuota(@RequestParam("access_token") String accessToken, Map<String,String> params);
+
 }

+ 2 - 1
nbjk-service/src/main/java/com/miaxis/wx/service/impl/WxGzhServiceImpl.java

@@ -84,7 +84,8 @@ public class WxGzhServiceImpl implements IWxGzhService {
             String result = wxSendService.getStableAccessToken(stableTokenDTO);
             JSONObject json = JSONObject.parseObject(result);
             token = json.getString("access_token");
-            expiresIn = 1800;
+            String expiresInStr = json.getString("expires_in");
+            expiresIn = Integer.parseInt(expiresInStr);
 //            expiresIn = json.getIntValue("expires_in");
 //            if (expiresIn <= 0){
 //                expiresIn = 7000;