mp:增加 server 草稿箱的分页、添加;已发布的分页、提交
parent
267b1790ec
commit
5901ab6664
@ -0,0 +1,24 @@
|
|||||||
|
### 请求 /mp/draft/page 接口 => 成功
|
||||||
|
GET {{baseUrl}}/mp/draft/page?accountId=1&pageNo=1&pageSize=10
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
tenant-id: {{adminTenentId}}
|
||||||
|
|
||||||
|
### 请求 /mp/draft/create 接口 => 成功
|
||||||
|
POST {{baseUrl}}/mp/draft/create?accountId=1
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
tenant-id: {{adminTenentId}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"articles": [
|
||||||
|
{
|
||||||
|
"title": "我是标题",
|
||||||
|
"author": "我是作者",
|
||||||
|
"digest": "我是摘要",
|
||||||
|
"content": "我是内容",
|
||||||
|
"contentSourceUrl": "https://www.iocoder.cn",
|
||||||
|
"thumbMediaId": "r6ryvl6LrxBU0miaST4Y-pIcmK-zAAId-9TGgy-DrSLhjVuWbuT3ZBjk9K1yQ0Dn"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package cn.iocoder.yudao.module.mp.controller.admin.news;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||||
|
import cn.iocoder.yudao.module.mp.controller.admin.news.vo.MpDraftPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.mp.framework.mp.core.MpServiceFactory;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.bean.draft.WxMpAddDraft;
|
||||||
|
import me.chanjar.weixin.mp.bean.draft.WxMpDraftItem;
|
||||||
|
import me.chanjar.weixin.mp.bean.draft.WxMpDraftList;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.DRAFT_CREATE_FAIL;
|
||||||
|
import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.DRAFT_LIST_FAIL;
|
||||||
|
|
||||||
|
// TODO 芋艿:权限
|
||||||
|
@Api(tags = "管理后台 - 公众号草稿")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/mp/draft")
|
||||||
|
@Validated
|
||||||
|
public class MpDraftController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MpServiceFactory mpServiceFactory;
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("获得草稿分页")
|
||||||
|
public CommonResult<PageResult<WxMpDraftItem>> getDraftPage(MpDraftPageReqVO reqVO) {
|
||||||
|
// 从公众号查询已发布的图文列表
|
||||||
|
WxMpService mpService = mpServiceFactory.getRequiredMpService(reqVO.getAccountId());
|
||||||
|
WxMpDraftList draftList;
|
||||||
|
try {
|
||||||
|
draftList = mpService.getDraftService().listDraft(PageUtils.getStart(reqVO), reqVO.getPageSize());
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
throw exception(DRAFT_LIST_FAIL, e.getError().getErrorMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回分页
|
||||||
|
return success(new PageResult<>(draftList.getItems(), draftList.getTotalCount().longValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@ApiOperation("创建草稿")
|
||||||
|
@ApiImplicitParam(name = "accountId", value = "公众号账号的编号", required = true,
|
||||||
|
example = "1024", dataTypeClass = Long.class)
|
||||||
|
public CommonResult<String> createDraft(@RequestParam("accountId") Long accountId,
|
||||||
|
@RequestBody WxMpAddDraft reqVO) {
|
||||||
|
WxMpService mpService = mpServiceFactory.getRequiredMpService(accountId);
|
||||||
|
try {
|
||||||
|
String mediaId = mpService.getDraftService().addDraft(reqVO);
|
||||||
|
return success(mediaId);
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
throw exception(DRAFT_CREATE_FAIL, e.getError().getErrorMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
### 请求 /mp/free-publish/page 接口 => 成功
|
||||||
|
GET {{baseUrl}}/mp/free-publish/page?accountId=1&pageNo=1&pageSize=10
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
tenant-id: {{adminTenentId}}
|
||||||
|
|
||||||
|
### 请求 /mp/free-publish/submit 接口 => 成功
|
||||||
|
POST {{baseUrl}}/mp/free-publish/submit?accountId=1&mediaId=r6ryvl6LrxBU0miaST4Y-pEm50d1qKxNPkZVzrRZthSJHKCgiylCf4tARZfybZ_O
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
tenant-id: {{adminTenentId}}
|
||||||
|
|
||||||
|
{}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
package cn.iocoder.yudao.module.mp.controller.admin.news;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||||
|
import cn.iocoder.yudao.module.mp.controller.admin.news.vo.MpFreePublishPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.mp.framework.mp.core.MpServiceFactory;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishItem;
|
||||||
|
import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishList;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
// TODO 芋艿:权限
|
||||||
|
@Api(tags = "管理后台 - 公众号发布能力")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/mp/free-publish")
|
||||||
|
@Validated
|
||||||
|
public class MpFreePublishController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MpServiceFactory mpServiceFactory;
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("获得已发布的图文分页")
|
||||||
|
public CommonResult<PageResult<WxMpFreePublishItem>> getFreePublishPage(MpFreePublishPageReqVO reqVO) {
|
||||||
|
// 从公众号查询已发布的图文列表
|
||||||
|
WxMpService mpService = mpServiceFactory.getRequiredMpService(reqVO.getAccountId());
|
||||||
|
WxMpFreePublishList publicationRecords;
|
||||||
|
try {
|
||||||
|
publicationRecords = mpService.getFreePublishService().getPublicationRecords(
|
||||||
|
PageUtils.getStart(reqVO), reqVO.getPageSize());
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
throw exception(FREE_PUBLISH_LIST_FAIL, e.getError().getErrorMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回分页
|
||||||
|
return success(new PageResult<>(publicationRecords.getItems(), publicationRecords.getTotalCount().longValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/submit")
|
||||||
|
@ApiOperation("发布草稿")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "accountId", value = "公众号账号的编号", required = true,
|
||||||
|
example = "1024", dataTypeClass = Long.class),
|
||||||
|
@ApiImplicitParam(name = "mediaId", value = "要发布的草稿的 media_id", required = true,
|
||||||
|
example = "2048", dataTypeClass = String.class)
|
||||||
|
})
|
||||||
|
public CommonResult<String> submitFreePublish(@RequestParam("accountId") Long accountId,
|
||||||
|
@RequestParam("mediaId") String mediaId) {
|
||||||
|
WxMpService mpService = mpServiceFactory.getRequiredMpService(accountId);
|
||||||
|
try {
|
||||||
|
String publishId = mpService.getFreePublishService().submit(mediaId);
|
||||||
|
return success(publishId);
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
throw exception(FREE_PUBLISH_SUBMIT_FAIL, e.getError().getErrorMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package cn.iocoder.yudao.module.mp.controller.admin.news.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@ApiModel("管理后台 - 公众号草稿的分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class MpDraftPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "公众号账号的编号", required = true, example = "1024")
|
||||||
|
@NotNull(message = "公众号账号的编号不能为空")
|
||||||
|
private Long accountId;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package cn.iocoder.yudao.module.mp.controller.admin.news.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@ApiModel("管理后台 - 公众号已发布列表的分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class MpFreePublishPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "公众号账号的编号", required = true, example = "1024")
|
||||||
|
@NotNull(message = "公众号账号的编号不能为空")
|
||||||
|
private Long accountId;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue