Przeglądaj źródła

#252 添加图文消息留言管理中打开已群发文章评论的接口

master
Binary Wang 5 lat temu
rodzic
commit
be78d8c125
6 zmienionych plików z 113 dodań i 1 usunięć
  1. +22
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java
  2. +9
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
  3. +11
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java
  4. +27
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java
  5. +16
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java
  6. +28
    -0
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java

+ 22
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCommentService.java Wyświetl plik

@@ -0,0 +1,22 @@
package me.chanjar.weixin.mp.api;

import me.chanjar.weixin.common.error.WxErrorException;

/**
* 评论数据管理.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-06-16
*/
public interface WxMpCommentService {
/**
* 打开已群发文章评论.
* https://api.weixin.qq.com/cgi-bin/comment/open?access_token=ACCESS_TOKEN
* 参数 是否必须 类型 说明
*
* @param msgDataId 群发返回的msg_data_id
* @param index 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
* @throws WxErrorException 异常
*/
void open(Integer msgDataId, Integer index) throws WxErrorException;
}

+ 9
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java Wyświetl plik

@@ -526,4 +526,13 @@ public interface WxMpService {
void setAiOpenService(WxMpAiOpenService aiOpenService);

void setMarketingService(WxMpMarketingService marketingService);

/**
* 返回评论数据管理接口方法的实现类对象,以方便调用其各个接口.
*
* @return WxMpWifiService
*/
WxMpCommentService getCommentService();

void setCommentService(WxMpCommentService commentService);
}

+ 11
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java Wyświetl plik

@@ -62,6 +62,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this);
private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this);
private WxMpMarketingService marketingService = new WxMpMarketingServiceImpl(this);
private WxMpCommentService commentService = new WxMpCommentServiceImpl(this);

private Map<String, WxMpConfigStorage> configStorageMap;

@@ -608,4 +609,14 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
public void setMarketingService(WxMpMarketingService marketingService) {
this.marketingService = marketingService;
}

@Override
public WxMpCommentService getCommentService() {
return this.commentService;
}

@Override
public void setCommentService(WxMpCommentService commentService) {
this.commentService = commentService;
}
}

+ 27
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImpl.java Wyświetl plik

@@ -0,0 +1,27 @@
package me.chanjar.weixin.mp.api.impl;

import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpCommentService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;

/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-06-16
*/
@RequiredArgsConstructor
public class WxMpCommentServiceImpl implements WxMpCommentService {
private final WxMpService wxMpService;

@Override
public void open(Integer msgDataId, Integer index) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("msg_data_id", msgDataId);
if (index != null) {
json.addProperty("index", index);
}
this.wxMpService.post(WxMpApiUrl.Comment.OPEN, json.toString());
}
}

+ 16
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java Wyświetl plik

@@ -807,7 +807,6 @@ public interface WxMpApiUrl {
}
}


@AllArgsConstructor
enum User implements WxMpApiUrl {
/**
@@ -839,4 +838,20 @@ public interface WxMpApiUrl {
return buildUrl(config.getHostConfig(), prefix, path);
}
}

@AllArgsConstructor
enum Comment implements WxMpApiUrl {
/**
* 打开已群发文章评论.
*/
OPEN(API_DEFAULT_HOST_URL, "/cgi-bin/comment/open");

private String prefix;
private String path;

@Override
public String getUrl(WxMpConfigStorage config) {
return buildUrl(config.getHostConfig(), prefix, path);
}
}
}

+ 28
- 0
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCommentServiceImplTest.java Wyświetl plik

@@ -0,0 +1,28 @@
package me.chanjar.weixin.mp.api.impl;

import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

/**
* 测试类.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2019-06-16
*/

@Test
@Guice(modules = ApiTestModule.class)
public class WxMpCommentServiceImplTest {
@Inject
private WxMpService wxService;

@Test
public void testOpen() throws WxErrorException {
this.wxService.getCommentService().open(1, null);
this.wxService.getCommentService().open(1, 0);
}
}

Ładowanie…
Anuluj
Zapisz