From c7f207034f54650fe2a11f190618c21791f328ab Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Fri, 30 May 2025 20:51:03 +0800 Subject: [PATCH] feat: mp api --- apps/web-antd/src/api/mp/account/index.ts | 59 +++++++++++++ apps/web-antd/src/api/mp/autoReply/index.ts | 49 +++++++++++ apps/web-antd/src/api/mp/draft/index.ts | 59 +++++++++++++ apps/web-antd/src/api/mp/freePublish/index.ts | 45 ++++++++++ apps/web-antd/src/api/mp/material/index.ts | 43 ++++++++++ apps/web-antd/src/api/mp/menu/index.ts | 58 +++++++++++++ apps/web-antd/src/api/mp/message/index.ts | 54 ++++++++++++ apps/web-antd/src/api/mp/statistics/index.ts | 84 +++++++++++++++++++ apps/web-antd/src/api/mp/tag/index.ts | 62 ++++++++++++++ apps/web-antd/src/api/mp/user/index.ts | 57 +++++++++++++ 10 files changed, 570 insertions(+) create mode 100644 apps/web-antd/src/api/mp/account/index.ts create mode 100644 apps/web-antd/src/api/mp/autoReply/index.ts create mode 100644 apps/web-antd/src/api/mp/draft/index.ts create mode 100644 apps/web-antd/src/api/mp/freePublish/index.ts create mode 100644 apps/web-antd/src/api/mp/material/index.ts create mode 100644 apps/web-antd/src/api/mp/menu/index.ts create mode 100644 apps/web-antd/src/api/mp/message/index.ts create mode 100644 apps/web-antd/src/api/mp/statistics/index.ts create mode 100644 apps/web-antd/src/api/mp/tag/index.ts create mode 100644 apps/web-antd/src/api/mp/user/index.ts diff --git a/apps/web-antd/src/api/mp/account/index.ts b/apps/web-antd/src/api/mp/account/index.ts new file mode 100644 index 000000000..918c80202 --- /dev/null +++ b/apps/web-antd/src/api/mp/account/index.ts @@ -0,0 +1,59 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpAccountApi { + /** 公众号账号信息 */ + export interface Account { + id?: number; + name: string; + account: string; + appId: string; + appSecret: string; + token: string; + aesKey?: string; + qrCodeUrl?: string; + remark?: string; + createTime?: Date; + } +} + +/** 查询公众号账号列表 */ +export function getAccountPage(params: PageParam) { + return requestClient.get>( + '/mp/account/page', + { + params, + }, + ); +} + +/** 查询公众号账号详情 */ +export function getAccount(id: number) { + return requestClient.get(`/mp/account/get?id=${id}`); +} + +/** 新增公众号账号 */ +export function createAccount(data: MpAccountApi.Account) { + return requestClient.post('/mp/account/create', data); +} + +/** 修改公众号账号 */ +export function updateAccount(data: MpAccountApi.Account) { + return requestClient.put('/mp/account/update', data); +} + +/** 删除公众号账号 */ +export function deleteAccount(id: number) { + return requestClient.delete(`/mp/account/delete?id=${id}`); +} + +/** 生成公众号账号二维码 */ +export function generateAccountQrCode(id: number) { + return requestClient.post(`/mp/account/generate-qr-code?id=${id}`); +} + +/** 清空公众号账号 API 配额 */ +export function clearAccountQuota(id: number) { + return requestClient.post(`/mp/account/clear-quota?id=${id}`); +} diff --git a/apps/web-antd/src/api/mp/autoReply/index.ts b/apps/web-antd/src/api/mp/autoReply/index.ts new file mode 100644 index 000000000..d72e5a0cb --- /dev/null +++ b/apps/web-antd/src/api/mp/autoReply/index.ts @@ -0,0 +1,49 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpAutoReplyApi { + /** 自动回复信息 */ + export interface AutoReply { + id?: number; + accountId: number; + type: number; + keyword: string; + content: string; + status: number; + remark?: string; + createTime?: Date; + } +} + +/** 查询自动回复列表 */ +export function getAutoReplyPage(params: PageParam) { + return requestClient.get>( + '/mp/auto-reply/page', + { + params, + }, + ); +} + +/** 查询自动回复详情 */ +export function getAutoReply(id: number) { + return requestClient.get( + `/mp/auto-reply/get?id=${id}`, + ); +} + +/** 新增自动回复 */ +export function createAutoReply(data: MpAutoReplyApi.AutoReply) { + return requestClient.post('/mp/auto-reply/create', data); +} + +/** 修改自动回复 */ +export function updateAutoReply(data: MpAutoReplyApi.AutoReply) { + return requestClient.put('/mp/auto-reply/update', data); +} + +/** 删除自动回复 */ +export function deleteAutoReply(id: number) { + return requestClient.delete(`/mp/auto-reply/delete?id=${id}`); +} diff --git a/apps/web-antd/src/api/mp/draft/index.ts b/apps/web-antd/src/api/mp/draft/index.ts new file mode 100644 index 000000000..435f13e0b --- /dev/null +++ b/apps/web-antd/src/api/mp/draft/index.ts @@ -0,0 +1,59 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpDraftApi { + /** 草稿文章信息 */ + export interface Article { + title: string; + author: string; + digest: string; + content: string; + contentSourceUrl: string; + thumbMediaId: string; + showCoverPic: number; + needOpenComment: number; + onlyFansCanComment: number; + } + + /** 草稿信息 */ + export interface Draft { + id?: number; + accountId: number; + mediaId: string; + articles: Article[]; + createTime?: Date; + } +} + +/** 查询草稿列表 */ +export function getDraftPage(params: PageParam) { + return requestClient.get>('/mp/draft/page', { + params, + }); +} + +/** 创建草稿 */ +export function createDraft(accountId: number, articles: MpDraftApi.Article[]) { + return requestClient.post('/mp/draft/create', articles, { + params: { accountId }, + }); +} + +/** 更新草稿 */ +export function updateDraft( + accountId: number, + mediaId: string, + articles: MpDraftApi.Article[], +) { + return requestClient.put('/mp/draft/update', articles, { + params: { accountId, mediaId }, + }); +} + +/** 删除草稿 */ +export function deleteDraft(accountId: number, mediaId: string) { + return requestClient.delete('/mp/draft/delete', { + params: { accountId, mediaId }, + }); +} diff --git a/apps/web-antd/src/api/mp/freePublish/index.ts b/apps/web-antd/src/api/mp/freePublish/index.ts new file mode 100644 index 000000000..bc50efe96 --- /dev/null +++ b/apps/web-antd/src/api/mp/freePublish/index.ts @@ -0,0 +1,45 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpFreePublishApi { + /** 自由发布文章信息 */ + export interface FreePublish { + id?: number; + accountId: number; + mediaId: string; + articleId: string; + title: string; + author: string; + digest: string; + content: string; + thumbUrl: string; + status: number; + publishTime?: Date; + createTime?: Date; + } +} + +/** 查询自由发布文章列表 */ +export function getFreePublishPage(params: PageParam) { + return requestClient.get>( + '/mp/free-publish/page', + { + params, + }, + ); +} + +/** 删除自由发布文章 */ +export function deleteFreePublish(accountId: number, articleId: string) { + return requestClient.delete('/mp/free-publish/delete', { + params: { accountId, articleId }, + }); +} + +/** 发布自由发布文章 */ +export function submitFreePublish(accountId: number, mediaId: string) { + return requestClient.post('/mp/free-publish/submit', null, { + params: { accountId, mediaId }, + }); +} diff --git a/apps/web-antd/src/api/mp/material/index.ts b/apps/web-antd/src/api/mp/material/index.ts new file mode 100644 index 000000000..73ca899ee --- /dev/null +++ b/apps/web-antd/src/api/mp/material/index.ts @@ -0,0 +1,43 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +/** 素材类型枚举 */ +export enum MaterialType { + IMAGE = 1, // 图片 + THUMB = 4, // 缩略图 + VIDEO = 3, // 视频 + VOICE = 2, // 语音 +} + +export namespace MpMaterialApi { + /** 素材信息 */ + export interface Material { + id?: number; + accountId: number; + type: MaterialType; + mediaId: string; + url: string; + name: string; + size: number; + remark?: string; + createTime?: Date; + } +} + +/** 查询素材列表 */ +export function getMaterialPage(params: PageParam) { + return requestClient.get>( + '/mp/material/page', + { + params, + }, + ); +} + +/** 删除永久素材 */ +export function deletePermanentMaterial(id: number) { + return requestClient.delete('/mp/material/delete-permanent', { + params: { id }, + }); +} diff --git a/apps/web-antd/src/api/mp/menu/index.ts b/apps/web-antd/src/api/mp/menu/index.ts new file mode 100644 index 000000000..a8ae0833b --- /dev/null +++ b/apps/web-antd/src/api/mp/menu/index.ts @@ -0,0 +1,58 @@ +import { requestClient } from '#/api/request'; + +/** 菜单类型枚举 */ +export enum MenuType { + CLICK = 'click', // 点击推事件 + LOCATION_SELECT = 'location_select', // 发送位置 + MEDIA_ID = 'media_id', // 下发消息 + MINIPROGRAM = 'miniprogram', // 小程序 + PIC_PHOTO_OR_ALBUM = 'pic_photo_or_album', // 拍照或者相册发图 + PIC_SYSPHOTO = 'pic_sysphoto', // 系统拍照发图 + PIC_WEIXIN = 'pic_weixin', // 微信相册发图 + SCANCODE_PUSH = 'scancode_push', // 扫码推事件 + SCANCODE_WAITMSG = 'scancode_waitmsg', // 扫码带提示 + VIEW = 'view', // 跳转URL + VIEW_LIMITED = 'view_limited', // 跳转图文消息URL +} + +export namespace MpMenuApi { + /** 菜单按钮信息 */ + export interface MenuButton { + type: MenuType; + name: string; + key?: string; + url?: string; + mediaId?: string; + appId?: string; + pagePath?: string; + subButtons?: MenuButton[]; + } + + /** 菜单信息 */ + export interface Menu { + accountId: number; + menus: MenuButton[]; + } +} + +/** 查询菜单列表 */ +export function getMenuList(accountId: number) { + return requestClient.get('/mp/menu/list', { + params: { accountId }, + }); +} + +/** 保存菜单 */ +export function saveMenu(accountId: number, menus: MpMenuApi.MenuButton[]) { + return requestClient.post('/mp/menu/save', { + accountId, + menus, + }); +} + +/** 删除菜单 */ +export function deleteMenu(accountId: number) { + return requestClient.delete('/mp/menu/delete', { + params: { accountId }, + }); +} diff --git a/apps/web-antd/src/api/mp/message/index.ts b/apps/web-antd/src/api/mp/message/index.ts new file mode 100644 index 000000000..cfb2dbacc --- /dev/null +++ b/apps/web-antd/src/api/mp/message/index.ts @@ -0,0 +1,54 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +/** 消息类型枚举 */ +export enum MessageType { + IMAGE = 'image', // 图片消息 + MPNEWS = 'mpnews', // 公众号图文消息 + MUSIC = 'music', // 音乐消息 + NEWS = 'news', // 图文消息 + TEXT = 'text', // 文本消息 + VIDEO = 'video', // 视频消息 + VOICE = 'voice', // 语音消息 + WXCARD = 'wxcard', // 卡券消息 +} + +export namespace MpMessageApi { + /** 消息信息 */ + export interface Message { + id?: number; + accountId: number; + type: MessageType; + openid: string; + content: string; + mediaId?: string; + status: number; + remark?: string; + createTime?: Date; + } + + /** 发送消息请求 */ + export interface SendMessageRequest { + accountId: number; + openid: string; + type: MessageType; + content: string; + mediaId?: string; + } +} + +/** 查询消息列表 */ +export function getMessagePage(params: PageParam) { + return requestClient.get>( + '/mp/message/page', + { + params, + }, + ); +} + +/** 发送消息 */ +export function sendMessage(data: MpMessageApi.SendMessageRequest) { + return requestClient.post('/mp/message/send', data); +} diff --git a/apps/web-antd/src/api/mp/statistics/index.ts b/apps/web-antd/src/api/mp/statistics/index.ts new file mode 100644 index 000000000..e36073820 --- /dev/null +++ b/apps/web-antd/src/api/mp/statistics/index.ts @@ -0,0 +1,84 @@ +import type { PageParam } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpStatisticsApi { + /** 统计查询参数 */ + export interface StatisticsQuery extends PageParam { + accountId: number; + beginDate: string; + endDate: string; + } + + /** 消息发送概况数据 */ + export interface UpstreamMessage { + refDate: string; + msgType: string; + msgUser: number; + msgCount: number; + } + + /** 用户增减数据 */ + export interface UserSummary { + refDate: string; + userSource: number; + newUser: number; + cancelUser: number; + cumulateUser: number; + } + + /** 用户累计数据 */ + export interface UserCumulate { + refDate: string; + cumulateUser: number; + } + + /** 接口分析数据 */ + export interface InterfaceSummary { + refDate: string; + callbackCount: number; + failCount: number; + totalTimeCost: number; + maxTimeCost: number; + } +} + +/** 获取消息发送概况数据 */ +export function getUpstreamMessage(params: MpStatisticsApi.StatisticsQuery) { + return requestClient.get( + '/mp/statistics/upstream-message', + { + params, + }, + ); +} + +/** 获取用户增减数据 */ +export function getUserSummary(params: MpStatisticsApi.StatisticsQuery) { + return requestClient.get( + '/mp/statistics/user-summary', + { + params, + }, + ); +} + +/** 获取用户累计数据 */ +export function getUserCumulate(params: MpStatisticsApi.StatisticsQuery) { + return requestClient.get( + '/mp/statistics/user-cumulate', + { + params, + }, + ); +} + +/** 获取接口分析数据 */ +export function getInterfaceSummary(params: MpStatisticsApi.StatisticsQuery) { + return requestClient.get( + '/mp/statistics/interface-summary', + { + params, + }, + ); +} diff --git a/apps/web-antd/src/api/mp/tag/index.ts b/apps/web-antd/src/api/mp/tag/index.ts new file mode 100644 index 000000000..3cf677e7d --- /dev/null +++ b/apps/web-antd/src/api/mp/tag/index.ts @@ -0,0 +1,62 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpTagApi { + /** 标签信息 */ + export interface Tag { + id?: number; + name: string; + accountId: number; + createTime?: Date; + } + + /** 标签分页查询参数 */ + export interface TagPageQuery extends PageParam { + accountId?: number; + name?: string; + } +} + +/** 创建公众号标签 */ +export function createTag(data: MpTagApi.Tag) { + return requestClient.post('/mp/tag/create', data); +} + +/** 更新公众号标签 */ +export function updateTag(data: MpTagApi.Tag) { + return requestClient.put('/mp/tag/update', data); +} + +/** 删除公众号标签 */ +export function deleteTag(id: number) { + return requestClient.delete('/mp/tag/delete', { + params: { id }, + }); +} + +/** 获取公众号标签 */ +export function getTag(id: number) { + return requestClient.get('/mp/tag/get', { + params: { id }, + }); +} + +/** 获取公众号标签分页 */ +export function getTagPage(params: MpTagApi.TagPageQuery) { + return requestClient.get>('/mp/tag/page', { + params, + }); +} + +/** 获取公众号标签精简信息列表 */ +export function getSimpleTagList() { + return requestClient.get('/mp/tag/list-all-simple'); +} + +/** 同步公众号标签 */ +export function syncTag(accountId: number) { + return requestClient.post('/mp/tag/sync', null, { + params: { accountId }, + }); +} diff --git a/apps/web-antd/src/api/mp/user/index.ts b/apps/web-antd/src/api/mp/user/index.ts new file mode 100644 index 000000000..e34573a1a --- /dev/null +++ b/apps/web-antd/src/api/mp/user/index.ts @@ -0,0 +1,57 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace MpUserApi { + /** 用户信息 */ + export interface User { + id?: number; + accountId: number; + openid: string; + nickname: string; + avatar: string; + sex: number; + country: string; + province: string; + city: string; + language: string; + subscribe: boolean; + subscribeTime?: Date; + remark?: string; + tagIds?: number[]; + createTime?: Date; + } + + /** 用户分页查询参数 */ + export interface UserPageQuery extends PageParam { + accountId?: number; + nickname?: string; + tagId?: number; + } +} + +/** 更新公众号粉丝 */ +export function updateUser(data: MpUserApi.User) { + return requestClient.put('/mp/user/update', data); +} + +/** 获取公众号粉丝 */ +export function getUser(id: number) { + return requestClient.get('/mp/user/get', { + params: { id }, + }); +} + +/** 获取公众号粉丝分页 */ +export function getUserPage(params: MpUserApi.UserPageQuery) { + return requestClient.get>('/mp/user/page', { + params, + }); +} + +/** 同步公众号粉丝 */ +export function syncUser(accountId: number) { + return requestClient.post('/mp/user/sync', null, { + params: { accountId }, + }); +}