From 7373fc9072a8de92f3d82d625c2f3177051b8bea Mon Sep 17 00:00:00 2001 From: wangkai Date: Thu, 14 Apr 2022 14:23:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E3=80=91=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E7=9B=B4=E6=92=AD=EF=BC=8C=E6=B4=BB=E5=8A=A8=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=8F=82=E6=95=B0=E5=8F=96=E5=80=BC=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpLivingService.java | 2 +- .../bean/living/WxCpLivingCreateRequest.java | 10 ++--- .../chanjar/weixin/cp/api/WxCpLivingTest.java | 42 +++++++++++++++++++ .../impl/WxCpGroupRobotServiceImplTest.java | 2 +- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpLivingService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpLivingService.java index 4b417e90f..380c3bfc5 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpLivingService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpLivingService.java @@ -84,7 +84,7 @@ public interface WxCpLivingService { * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/living/create?access_token=ACCESS_TOKEN * * @param request 创建预约直播请求参数. - * @return + * @return livingId(直播id) * @throws WxErrorException */ String livingCreate(WxCpLivingCreateRequest request) throws WxErrorException; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/living/WxCpLivingCreateRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/living/WxCpLivingCreateRequest.java index 6da6b81e5..4272a0372 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/living/WxCpLivingCreateRequest.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/living/WxCpLivingCreateRequest.java @@ -1,14 +1,12 @@ package me.chanjar.weixin.cp.bean.living; import com.google.gson.annotations.SerializedName; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import lombok.experimental.Accessors; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import java.io.Serializable; +import java.util.List; /** * 创建预约直播请求. @@ -57,10 +55,12 @@ public class WxCpLivingCreateRequest implements Serializable { @SerializedName("activity_detail") private ActivityDetail activityDetail; + @Getter + @Setter public static class ActivityDetail implements Serializable { @SerializedName("image_list") - private String[] imageList; + private List imageList; @SerializedName("description") private String description; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpLivingTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpLivingTest.java index 295f0497f..4305c26c9 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpLivingTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpLivingTest.java @@ -1,6 +1,7 @@ package me.chanjar.weixin.cp.api; import lombok.extern.slf4j.Slf4j; +import lombok.val; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.bean.living.*; @@ -10,6 +11,7 @@ import org.eclipse.jetty.util.ajax.JSON; import org.testng.annotations.Test; import java.io.InputStream; +import java.util.ArrayList; import java.util.Date; /** @@ -34,6 +36,46 @@ public class WxCpLivingTest { wxCpService = new WxCpServiceImpl(); wxCpService.setWxCpConfigStorage(config); + /** + * 测试创建直播 + */ + WxCpLivingCreateRequest createRequest = new WxCpLivingCreateRequest(); + createRequest.setAnchorUserid("WangKai"); + createRequest.setTheme("直播1"); + + long currentTimeMillis = System.currentTimeMillis() + 3600000L; + createRequest.setLivingStart(currentTimeMillis); + createRequest.setLivingDuration(3600L); + createRequest.setType(4); + createRequest.setDescription("这是通用直播1"); + + val activityDetail = new WxCpLivingCreateRequest.ActivityDetail(); + activityDetail.setDescription("活动描述,非活动类型的直播不用传"); + +// String[] strings = new String[]{"MEDIA_ID_2", "MEDIA_ID_1"}; + ArrayList imageList = new ArrayList(); + imageList.add("MEDIA_ID_1"); + imageList.add("MEDIA_ID_2"); + + activityDetail.setImageList(imageList); + createRequest.setActivityDetail(activityDetail); + + String livingCreate = wxCpService.getLivingService().livingCreate(createRequest); + log.info("返回的直播id为:{}", livingCreate); + + WxCpLivingCreateRequest thisReq = WxCpLivingCreateRequest.fromJson(createRequest.toJson()); + log.info("返回的数据:{}", thisReq.toJson()); + + // 创建预约直播 + String createJson = "{\"anchor_userid\":\"ChenHu\",\"theme\":\"theme\",\"living_start\":164037820420,\"living_duration\":3600,\"description\":\"test description\",\"type\":4,\"remind_time\":60,\"activity_cover_mediaid\":\"MEDIA_ID\",\"activity_share_mediaid\":\"MEDIA_ID\",\"activity_detail\":{\"description\":\"活动描述,非活动类型的直播不用传\",\"image_list\":[\"xxxx1\",\"xxxx1\"]}}"; + WxCpLivingCreateRequest requestData = WxCpLivingCreateRequest.fromJson(createJson); + String thisLivingId = wxCpService.getLivingService().livingCreate(requestData); + log.info("livingId为:{}", thisLivingId); + + + /** + * other api + */ String livingCode = wxCpService.getLivingService().getLivingCode("o50by5NezHciWnoexJsrI49ILNqI", "lvOQpTDwAAD2MYuOq9y_bmLNMJfbbdGw"); log.info(JSON.toString(livingCode)); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java index 57bd9b750..c1a09f359 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImplTest.java @@ -61,7 +61,7 @@ public class WxCpGroupRobotServiceImplTest { @Test public void testSendNews() throws WxErrorException { NewArticle article = new NewArticle("图文消息测试", "hello world", "http://www.baidu.com", - "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", null); + "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", null, null, null); robotService.sendNews(Stream.of(article).collect(Collectors.toList())); } } -- Gitee From d5a480315cdab47fc408360f883e6455aa8f41bc Mon Sep 17 00:00:00 2001 From: nadirvishun Date: Thu, 14 Apr 2022 11:52:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20#2587=20=E3=80=90=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E3=80=91=E5=A2=9E=E5=8A=A0=E8=B7=AF=E7=94=B1=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=B1=A0=E5=85=B3=E9=97=AD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/message/WxMaMessageRouter.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java index 031c688c5..e2c497e13 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/message/WxMaMessageRouter.java @@ -51,6 +51,51 @@ public class WxMaMessageRouter { this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker(); } + /** + * 使用自定义的 {@link ExecutorService}. + */ + public WxMaMessageRouter(WxMaService wxMaService, ExecutorService executorService) { + this.wxMaService = wxMaService; + this.executorService = executorService; + this.sessionManager = new StandardSessionManager(); + this.exceptionHandler = new LogExceptionHandler(); + this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker(); + } + + /** + * 系统退出前,应该调用该方法 + */ + public void shutDownExecutorService() { + this.executorService.shutdown(); + } + + /** + * 系统退出前,应该调用该方法,增加了超时时间检测 + */ + public void shutDownExecutorService(Integer second) { + this.executorService.shutdown(); + try { + if (!this.executorService.awaitTermination(second, TimeUnit.SECONDS)) { + this.executorService.shutdownNow(); + if (!this.executorService.awaitTermination(second, TimeUnit.SECONDS)) + log.error("线程池未关闭!"); + } + } catch (InterruptedException ie) { + this.executorService.shutdownNow(); + Thread.currentThread().interrupt(); + } + } + + /** + *
+   * 设置自定义的 {@link ExecutorService}
+   * 如果不调用该方法,默认使用内置的
+   * 
+ */ + public void setExecutorService(ExecutorService executorService) { + this.executorService = executorService; + } + /** * 开始一个新的Route规则. */ -- Gitee From a8eb176fe9ab433800944d9b1f24f1ab985bf5eb Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 14 Apr 2022 14:32:58 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:new:=20#2588=20=E3=80=90=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E3=80=91=E4=BB=A3=E7=A0=81=E7=AE=A1=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BF=A1=E6=81=AF=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaCodeService.java | 8 ++ .../miniapp/api/impl/WxMaCodeServiceImpl.java | 6 ++ .../bean/code/WxMaCodeVersionInfo.java | 91 +++++++++++++++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 1 + .../api/impl/WxMaCodeServiceImplTest.java | 30 +++--- 5 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionInfo.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java index 7c13818b8..e560a1512 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCodeService.java @@ -105,6 +105,14 @@ public interface WxMaCodeService { */ WxMaCodeVersionDistribution getSupportVersion() throws WxErrorException; + /** + * 查询小程序版本信息 + * + * @return 小程序的体验版和线上版本信息 + * @throws WxErrorException 失败时抛出,具体错误码请看此接口的注释文档 + */ + WxMaCodeVersionInfo getVersionInfo() throws WxErrorException; + /** * 设置最低基础库版本(仅供第三方代小程序调用). * diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java index 37265cfe5..68271254a 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java @@ -138,6 +138,12 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { return WxMaCodeVersionDistribution.fromJson(responseContent); } + @Override + public WxMaCodeVersionInfo getVersionInfo() throws WxErrorException { + String responseContent = this.service.post(GET_VERSION_INFO_URL, "{}"); + return WxMaCodeVersionInfo.fromJson(responseContent); + } + @Override public void setSupportVersion(String version) throws WxErrorException { JsonObject param = new JsonObject(); diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionInfo.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionInfo.java new file mode 100644 index 000000000..32999382f --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/code/WxMaCodeVersionInfo.java @@ -0,0 +1,91 @@ +package cn.binarywang.wx.miniapp.bean.code; + +import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 查询小程序版本信息 + * + * @author LeonXi + * @since 2022-04-13 16:45 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WxMaCodeVersionInfo implements Serializable { + + private static final long serialVersionUID = 6929700728659511688L; + + /** + * 体验版信息 + */ + @SerializedName("exp_info") + private ExpInfo expInfo; + + /** + * 线上版信息 + */ + @SerializedName("release_info") + private ReleaseInfo releaseInfo; + + public static WxMaCodeVersionInfo fromJson(String json) { + return WxMaGsonBuilder.create().fromJson(json, WxMaCodeVersionInfo.class); + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class ExpInfo implements Serializable { + + private static final long serialVersionUID = 6315578419554592943L; + + /** + * 提交体验版的时间 + */ + @SerializedName("exp_time") + private Long expTime; + + /** + * 体验版版本信息 + */ + @SerializedName("exp_version") + private String expVersion; + + /** + * 体验版版本描述 + */ + @SerializedName("exp_desc") + private String expDesc; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class ReleaseInfo implements Serializable { + + private static final long serialVersionUID = 2098307354673939939L; + + /** + * 发布线上版的时间 + */ + @SerializedName("release_time") + private Long releaseTime; + + /** + * 线上版版本信息 + */ + @SerializedName("release_version") + private String releaseVersion; + + /** + * 线上版本描述 + */ + @SerializedName("release_desc") + private String releaseDesc; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index 4377b148b..0124943b6 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -70,6 +70,7 @@ public class WxMaApiUrlConstants { String GET_SUPPORT_VERSION_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/getweappsupportversion"; String SET_SUPPORT_VERSION_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/setweappsupportversion"; String UNDO_CODE_AUDIT_URL = "https://api.weixin.qq.com/wxa/undocodeaudit"; + String GET_VERSION_INFO_URL = "https://api.weixin.qq.com/wxa/getversioninfo"; } public interface Express { diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java index 0a4aca45e..bac7bab5b 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImplTest.java @@ -1,25 +1,21 @@ package cn.binarywang.wx.miniapp.api.impl; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.testng.annotations.*; - import cn.binarywang.wx.miniapp.api.WxMaCodeService; import cn.binarywang.wx.miniapp.api.WxMaService; -import cn.binarywang.wx.miniapp.bean.code.WxMaCategory; -import cn.binarywang.wx.miniapp.bean.code.WxMaCodeAuditStatus; -import cn.binarywang.wx.miniapp.bean.code.WxMaCodeCommitRequest; -import cn.binarywang.wx.miniapp.bean.code.WxMaCodeExtConfig; -import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest; -import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution; +import cn.binarywang.wx.miniapp.bean.code.*; import cn.binarywang.wx.miniapp.config.WxMaConfig; import cn.binarywang.wx.miniapp.test.ApiTestModule; import com.google.inject.Inject; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -import static org.testng.Assert.*; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; /** * @author Charming @@ -143,6 +139,12 @@ public class WxMaCodeServiceImplTest { System.out.println(distribution); } + @Test + public void testGetVersionInfo() throws Exception { + WxMaCodeVersionInfo versionInfo = wxService.getCodeService().getVersionInfo(); + System.out.println(versionInfo); + } + @Test public void testSetSupportVersion() throws Exception { wxService.getCodeService().setSupportVersion("1.2.0"); -- Gitee