diff --git a/es/service/wechat/WechatPublic.d.ts b/es/service/wechat/WechatPublic.d.ts index 162da3f..387341b 100644 --- a/es/service/wechat/WechatPublic.d.ts +++ b/es/service/wechat/WechatPublic.d.ts @@ -53,16 +53,23 @@ export declare class WechatPublicInstance { gender: string | undefined; avatar: string; }>; - createTag(tag: { + createTag(params: { name: string; }): Promise; getTags(): Promise; - editTag(tag: {}): Promise; + editTag(tag: { + id: number; + name: string; + }): Promise; + deleteTag(tag: { + id: number; + }): Promise; getCurrentMenu(): Promise; getMenu(): Promise; createMenu(menuConfig: any): Promise; createConditionalMenu(menuConfig: any): Promise; deleteConditionalMenu(menuId: number): Promise; + deleteMenu(): Promise; private refreshAccessToken; getQrCode(options: { sceneId?: number; diff --git a/es/service/wechat/WechatPublic.js b/es/service/wechat/WechatPublic.js index 5852505..a5c04b7 100644 --- a/es/service/wechat/WechatPublic.js +++ b/es/service/wechat/WechatPublic.js @@ -131,18 +131,18 @@ export class WechatPublicInstance { avatar: headimgurl, }; } - async createTag(tag) { + async createTag(params) { const myInit = { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ tag }), + body: JSON.stringify({ tag: params }), }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/create?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { + const { tag } = result; + if (tag) { return Object.assign({ success: true }, result); } return Object.assign({ success: false }, result); @@ -158,7 +158,32 @@ export class WechatPublicInstance { const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/get?access_token=${token}`, undefined, myInit); return result; } - async editTag(tag) { } + async editTag(tag) { + const myInit = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tag }), + }; + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/update?access_token=${token}`, undefined, myInit); + return result; + ; + } + async deleteTag(tag) { + const myInit = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tag }), + }; + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=${token}`, undefined, myInit); + return result; + ; + } async getCurrentMenu() { const myInit = { method: 'GET', @@ -191,11 +216,7 @@ export class WechatPublicInstance { }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; } async createConditionalMenu(menuConfig) { const myInit = { @@ -207,11 +228,7 @@ export class WechatPublicInstance { }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; } async deleteConditionalMenu(menuId) { const myInit = { @@ -225,11 +242,15 @@ export class WechatPublicInstance { }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; + } + async deleteMenu() { + const myInit = { + method: 'GET', + }; + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=${token}`, undefined, myInit); + return result; } async refreshAccessToken(url, init) { const result = this.externalRefreshFn diff --git a/lib/service/wechat/WechatPublic.d.ts b/lib/service/wechat/WechatPublic.d.ts index 162da3f..387341b 100644 --- a/lib/service/wechat/WechatPublic.d.ts +++ b/lib/service/wechat/WechatPublic.d.ts @@ -53,16 +53,23 @@ export declare class WechatPublicInstance { gender: string | undefined; avatar: string; }>; - createTag(tag: { + createTag(params: { name: string; }): Promise; getTags(): Promise; - editTag(tag: {}): Promise; + editTag(tag: { + id: number; + name: string; + }): Promise; + deleteTag(tag: { + id: number; + }): Promise; getCurrentMenu(): Promise; getMenu(): Promise; createMenu(menuConfig: any): Promise; createConditionalMenu(menuConfig: any): Promise; deleteConditionalMenu(menuId: number): Promise; + deleteMenu(): Promise; private refreshAccessToken; getQrCode(options: { sceneId?: number; diff --git a/lib/service/wechat/WechatPublic.js b/lib/service/wechat/WechatPublic.js index afc0b21..c13c005 100644 --- a/lib/service/wechat/WechatPublic.js +++ b/lib/service/wechat/WechatPublic.js @@ -135,18 +135,18 @@ class WechatPublicInstance { avatar: headimgurl, }; } - async createTag(tag) { + async createTag(params) { const myInit = { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ tag }), + body: JSON.stringify({ tag: params }), }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/create?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { + const { tag } = result; + if (tag) { return Object.assign({ success: true }, result); } return Object.assign({ success: false }, result); @@ -162,7 +162,32 @@ class WechatPublicInstance { const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/get?access_token=${token}`, undefined, myInit); return result; } - async editTag(tag) { } + async editTag(tag) { + const myInit = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tag }), + }; + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/update?access_token=${token}`, undefined, myInit); + return result; + ; + } + async deleteTag(tag) { + const myInit = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tag }), + }; + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=${token}`, undefined, myInit); + return result; + ; + } async getCurrentMenu() { const myInit = { method: 'GET', @@ -195,11 +220,7 @@ class WechatPublicInstance { }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; } async createConditionalMenu(menuConfig) { const myInit = { @@ -211,11 +232,7 @@ class WechatPublicInstance { }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; } async deleteConditionalMenu(menuId) { const myInit = { @@ -229,11 +246,15 @@ class WechatPublicInstance { }; const token = await this.getAccessToken(); const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=${token}`, undefined, myInit); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; + } + async deleteMenu() { + const myInit = { + method: 'GET', + }; + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=${token}`, undefined, myInit); + return result; } async refreshAccessToken(url, init) { const result = this.externalRefreshFn diff --git a/src/service/wechat/WechatPublic.ts b/src/service/wechat/WechatPublic.ts index 9aadc22..98d6d10 100644 --- a/src/service/wechat/WechatPublic.ts +++ b/src/service/wechat/WechatPublic.ts @@ -205,13 +205,13 @@ export class WechatPublicInstance { }; } - async createTag(tag: { name: string }) { + async createTag(params: { name: string }) { const myInit = { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ tag }), + body: JSON.stringify({ tag: params }), }; const token = await this.getAccessToken(); const result = await this.access( @@ -219,8 +219,8 @@ export class WechatPublicInstance { undefined, myInit ); - const { errcode } = result; - if (errcode === 0) { + const { tag } = result; + if (tag) { return Object.assign({ success: true }, result); } return Object.assign({ success: false }, result); @@ -242,7 +242,39 @@ export class WechatPublicInstance { return result; } - async editTag(tag: {}) {} + async editTag(tag: { id: number, name: string }) { + const myInit = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tag }), + }; + const token = await this.getAccessToken(); + const result = await this.access( + `https://api.weixin.qq.com/cgi-bin/tags/update?access_token=${token}`, + undefined, + myInit + ); + return result;; + } + + async deleteTag(tag: { id: number }) { + const myInit = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ tag }), + }; + const token = await this.getAccessToken(); + const result = await this.access( + `https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=${token}`, + undefined, + myInit + ); + return result;; + } async getCurrentMenu() { const myInit = { @@ -290,11 +322,7 @@ export class WechatPublicInstance { undefined, myInit ); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; } async createConditionalMenu(menuConfig: any) { @@ -311,11 +339,7 @@ export class WechatPublicInstance { undefined, myInit ); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; } async deleteConditionalMenu(menuId: number) { @@ -334,11 +358,20 @@ export class WechatPublicInstance { undefined, myInit ); - const { errcode } = result; - if (errcode === 0) { - return Object.assign({ success: true }, result); - } - return Object.assign({ success: false }, result); + return result; + } + + async deleteMenu() { + const myInit = { + method: 'GET', + }; + const token = await this.getAccessToken(); + const result = await this.access( + `https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=${token}`, + undefined, + myInit + ); + return result; } private async refreshAccessToken(url?: string, init?: RequestInit) {