小么熊🐻 1 год назад
Родитель
Сommit
d18c10c018

+ 40 - 3
nbjk-admin/src/test/java/com/miaxis/test/WxGzhTest.java

@@ -1,6 +1,9 @@
 package com.miaxis.test;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.miaxis.NbjkApplication;
+import com.miaxis.wx.dto.WxFreepublish;
 import com.miaxis.wx.dto.WxMaterialList;
 import com.miaxis.wx.service.IWxGzhService;
 import com.miaxis.wx.service.IWxService;
@@ -25,10 +28,10 @@ public class WxGzhTest {
     public void getUserInfo() throws IOException {
         String token = wxGzhServicee.getGzhToken();
         WxMaterialList wxMaterialList = new WxMaterialList();
-        wxMaterialList.setType("image");
+        wxMaterialList.setType("video");
         wxMaterialList.setOffset("0");
-        wxMaterialList.setCount("1");
-        String result = wxService.getBatchMateria(token,wxMaterialList);
+        wxMaterialList.setCount("100");
+        String result = wxService.getBatchMateria(token, wxMaterialList);
         System.out.println(result);
 //        WxMaterial wxMaterial = new WxMaterial();
 //        wxMaterial.setMedia_id("kD88pyQSlAfJYQIBpBp75Wjs3tWIgKQI6jw--s8kDrZ0AuuQDMyA89LU5CX8UMFY");
@@ -38,6 +41,40 @@ 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);
+
+
+    }
+
 
 }
 

+ 36 - 21
nbjk-service/src/main/java/com/miaxis/feign/service/IWxSendService.java

@@ -6,6 +6,7 @@ import com.miaxis.feign.dto.WxGzhBatchUser;
 import com.miaxis.feign.dto.WxMessageCusom;
 import com.miaxis.feign.dto.WxMessageTemplate;
 import com.miaxis.feign.dto.WxQrTicket;
+import com.miaxis.wx.dto.WxStableTokenDTO;
 import feign.Headers;
 import feign.Param;
 import feign.form.FormData;
@@ -18,23 +19,22 @@ import org.springframework.web.bind.annotation.ResponseBody;
 
 /**
  * 微信公众号接口
+ *
  * @author wwl
  * @version 1.0
  * @date 2021/10/20 14:59
  */
-@FeignClient(name="wxSendService",
-        url = "https://api.weixin.qq.com/cgi-bin",configuration = FeignConfig.class)
+@FeignClient(name = "wxSendService",
+        url = "https://api.weixin.qq.com/cgi-bin", configuration = FeignConfig.class)
 public interface IWxSendService {
 
 
-
-
-
     /**
-     *  获取token
+     * 获取token
+     *
      * @param grant_type
-     * @param appid 第三方用户唯一凭证
-     * @param secret 第三方用户唯一凭证密钥,即appsecret
+     * @param appid      第三方用户唯一凭证
+     * @param secret     第三方用户唯一凭证密钥,即appsecret
      * @return
      */
     @GetMapping(value = "/token")
@@ -43,9 +43,18 @@ public interface IWxSendService {
                           @RequestParam("secret") String secret);
 
 
+    /**
+     * 获取微信静态token
+     * @param wxStableTokenDTO
+     * @return
+     */
+    @PostMapping(value = "/stable_token")
+    String getStableAccessToken(WxStableTokenDTO wxStableTokenDTO);
+
     /**
      * 生成带参数二维码接口
-     *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html
+     * -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html
+     *
      * @param accessToken
      * @param wxQrTicket:二维码参数
      * @return
@@ -56,9 +65,10 @@ public interface IWxSendService {
 
     /**
      * 创建菜单接口
-     *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html
+     * -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html
+     *
      * @param accessToken
-     * @param jsonObject json
+     * @param jsonObject  json
      * @return
      */
     @PostMapping(value = "/menu/create")
@@ -66,10 +76,10 @@ public interface IWxSendService {
     String createMenu(@RequestParam("access_token") String accessToken, JSONObject jsonObject);
 
 
-
     /**
      * 创建菜单接口
-     *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html
+     * -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html
+     *
      * @param accessToken
      * @return
      */
@@ -79,9 +89,10 @@ public interface IWxSendService {
 
     /**
      * 新增永久图文素材
-     *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
+     * -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
+     *
      * @param accessToken
-     * @param jsonObject json
+     * @param jsonObject  json
      * @return
      */
     @PostMapping(value = "/material/add_news")
@@ -91,10 +102,11 @@ public interface IWxSendService {
 
     /**
      * 新增其他类型永久素材
-     *      -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
+     * -文档链接:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
+     *
      * @param accessToken
-     * @param type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
-     * @param media form-data中媒体文件标识,有filename、filelength、content-type等信息
+     * @param type        媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
+     * @param media       form-data中媒体文件标识,有filename、filelength、content-type等信息
      * @return
      */
     @PostMapping(value = "/material/add_material")
@@ -104,9 +116,10 @@ public interface IWxSendService {
 
     /**
      * 获取用户信息
-     * @param token 调用接口凭证
+     *
+     * @param token  调用接口凭证
      * @param openid 普通用户的标识,对当前公众号唯一
-     * @param lang 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
+     * @param lang   返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
      * @return
      */
     @GetMapping(value = "/user/info")
@@ -117,6 +130,7 @@ public interface IWxSendService {
 
     /**
      * 批量获取用户信息
+     *
      * @param token 调用接口凭证
      * @return
      */
@@ -125,6 +139,7 @@ public interface IWxSendService {
 
     /**
      * 发送客服消息
+     *
      * @param accessToken
      * @param messageCusom
      * @return
@@ -135,6 +150,7 @@ public interface IWxSendService {
 
     /**
      * 发送模板消息
+     *
      * @param accessToken
      * @param messageTemplate
      * @return
@@ -144,5 +160,4 @@ public interface IWxSendService {
                                WxMessageTemplate messageTemplate);
 
 
-
 }

+ 7 - 7
nbjk-service/src/main/java/com/miaxis/job/AppAdJob.java

@@ -19,9 +19,9 @@ public class AppAdJob {
     @Scheduled(cron = "0 0 19 * * ?")
     public void openAd()  {
         log.info("--------打开广告!~---------------");
-        SysDictData splashAd = dictDataService.selectDictDataById(104l); //开屏广告
-        SysDictData nativeAd = dictDataService.selectDictDataById(105l); //首页广告
-        SysDictData bannerAd = dictDataService.selectDictDataById(106l); //做题广告
+        SysDictData splashAd = dictDataService.selectDictDataById(104l);
+        SysDictData nativeAd = dictDataService.selectDictDataById(105l);
+        SysDictData bannerAd = dictDataService.selectDictDataById(106l);
 
         splashAd.setDictValue("1");
         nativeAd.setDictValue("1");
@@ -36,13 +36,13 @@ public class AppAdJob {
     @Scheduled(cron = "0 0 6 * * ?")
     public void closeAd()  {
         log.info("--------关闭广告!~---------------");
-        SysDictData splashAd = dictDataService.selectDictDataById(104l);   //开屏
-        SysDictData nativeAd = dictDataService.selectDictDataById(105l);   //首页广告
-        SysDictData bannerAd = dictDataService.selectDictDataById(106l);   //做题广告
+        SysDictData splashAd = dictDataService.selectDictDataById(104l);
+        SysDictData nativeAd = dictDataService.selectDictDataById(105l);
+        SysDictData bannerAd = dictDataService.selectDictDataById(106l);
         splashAd.setDictValue("0");
         nativeAd.setDictValue("0");
         bannerAd.setDictValue("0");
-        dictDataService.updateDictData(splashAd);
+        //dictDataService.updateDictData(splashAd);
         dictDataService.updateDictData(nativeAd);
         //dictDataService.updateDictData(bannerAd);
 

+ 14 - 0
nbjk-service/src/main/java/com/miaxis/wx/dto/WxFreepublish.java

@@ -0,0 +1,14 @@
+package com.miaxis.wx.dto;
+
+import lombok.Data;
+
+@Data
+public class WxFreepublish {
+
+
+
+    private String offset;    //从全部素材的该偏移位置开始返回,0表示从第一个素材返回
+    private String count;  //返回素材的数量,取值在1到20之间
+    private String no_content; // 1 表示不返回 content 字段,0 表示正常返回,默认为 0
+
+}

+ 1 - 0
nbjk-service/src/main/java/com/miaxis/wx/dto/WxStableTokenDTO.java

@@ -9,5 +9,6 @@ public class WxStableTokenDTO {
     private String grant_type;
     private String appid;
     private String secret;
+    private boolean force_refresh;
 
 }

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

@@ -18,6 +18,11 @@ public interface IWxGzhService {
      */
     String getGzhToken();
 
+    /**
+     * 获取微信临时公众号token
+     * @return
+     */
+    String getGzhTokenTemp();
 
     /**
      * 微信推送消息处理

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

@@ -117,6 +117,14 @@ public interface IWxService {
     String getBatchMateria(
             @RequestParam("access_token") String accessToken, WxMaterialList wxMaterial);
 
+    /**
+     * 调用已发布文章列表
+     */
+    @PostMapping(value = "/cgi-bin/freepublish/batchget")
+    String getFreepublish(@RequestParam("access_token") String accessToken, WxFreepublish wxFreepublish);
+
+
+
     /**
      * 调用公众号单个素材
      * @param accessToken

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

@@ -12,6 +12,7 @@ import com.miaxis.feign.service.IWxSendService;
 import com.miaxis.system.service.ISysDictTypeService;
 import com.miaxis.system.service.ISysUserService;
 import com.miaxis.user.service.IUserInfoService;
+import com.miaxis.wx.dto.WxStableTokenDTO;
 import com.miaxis.wx.service.IWxGzhService;
 import com.miaxis.wx.service.IWxMessageEvenService;
 import com.miaxis.wx.service.IWxService;
@@ -74,7 +75,13 @@ public class WxGzhServiceImpl implements IWxGzhService {
             token = (String)redisTemplate.opsForValue().get(Constants.GZH_MESSAGE_TOKEN);
         }
         if (StringUtils.isEmpty(token)|| notEffect(token)){
-            String result = wxSendService.getAccessToken("client_credential",appid,secret);
+            WxStableTokenDTO stableTokenDTO = new WxStableTokenDTO();
+            stableTokenDTO.setGrant_type("client_credential");
+            stableTokenDTO.setAppid(appid);
+            stableTokenDTO.setSecret(secret);
+            stableTokenDTO.setForce_refresh(false);
+
+            String result = wxSendService.getStableAccessToken(stableTokenDTO);
             JSONObject json = JSONObject.parseObject(result);
             token = json.getString("access_token");
             expiresIn = 1800;
@@ -82,10 +89,22 @@ public class WxGzhServiceImpl implements IWxGzhService {
 //            if (expiresIn <= 0){
 //                expiresIn = 7000;
 //            }
-
             redisTemplate.opsForValue().set(Constants.GZH_MESSAGE_TOKEN,token,expiresIn, TimeUnit.SECONDS);
         }
+        return token;
+    }
+
 
+    /**
+     * 获取微信临时公众号token
+     * @return
+     */
+    @Override
+    public String getGzhTokenTemp() {
+        String token = null;
+        String result = wxSendService.getAccessToken("client_credential",appid,secret);
+        JSONObject json = JSONObject.parseObject(result);
+        token = json.getString("access_token");
         return token;
     }