增加获取小程序临时素材接口
This commit is contained in:
parent
579c9803c1
commit
55fad9e54b
|
|
@ -86,6 +86,9 @@ export declare class WechatMpInstance {
|
|||
filename: string;
|
||||
filetype: string;
|
||||
}): Promise<any>;
|
||||
getTemporaryMaterial(options: {
|
||||
mediaId: string;
|
||||
}): Promise<any>;
|
||||
sendServeMessage(options: ServeMessageOption): Promise<any>;
|
||||
private isJson;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,6 +213,26 @@ export class WechatMpInstance {
|
|||
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/media/upload?access_token=${token}&type=${type}`, myInit);
|
||||
return result;
|
||||
}
|
||||
// 获取临时素材
|
||||
async getTemporaryMaterial(options) {
|
||||
const { mediaId } = options;
|
||||
const myInit = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
media_id: mediaId,
|
||||
}),
|
||||
};
|
||||
const token = await this.getAccessToken();
|
||||
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/media/get?access_token=${token}`, myInit);
|
||||
if (this.isJson(result)) {
|
||||
return result;
|
||||
}
|
||||
const arrayBuffer = await result.arrayBuffer();
|
||||
return arrayBuffer;
|
||||
}
|
||||
async sendServeMessage(options) {
|
||||
const { openId, type } = options;
|
||||
const myInit = {
|
||||
|
|
|
|||
|
|
@ -663,7 +663,11 @@ export class WechatPublicInstance {
|
|||
};
|
||||
const token = await this.getAccessToken();
|
||||
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/media/get?access_token=${token}`, myInit);
|
||||
return result;
|
||||
if (this.isJson(result)) {
|
||||
return result;
|
||||
}
|
||||
const arrayBuffer = await result.arrayBuffer();
|
||||
return arrayBuffer;
|
||||
}
|
||||
async getTicket() {
|
||||
const myInit = {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ export declare class WechatMpInstance {
|
|||
filename: string;
|
||||
filetype: string;
|
||||
}): Promise<any>;
|
||||
getTemporaryMaterial(options: {
|
||||
mediaId: string;
|
||||
}): Promise<any>;
|
||||
sendServeMessage(options: ServeMessageOption): Promise<any>;
|
||||
private isJson;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,6 +217,26 @@ class WechatMpInstance {
|
|||
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/media/upload?access_token=${token}&type=${type}`, myInit);
|
||||
return result;
|
||||
}
|
||||
// 获取临时素材
|
||||
async getTemporaryMaterial(options) {
|
||||
const { mediaId } = options;
|
||||
const myInit = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
media_id: mediaId,
|
||||
}),
|
||||
};
|
||||
const token = await this.getAccessToken();
|
||||
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/media/get?access_token=${token}`, myInit);
|
||||
if (this.isJson(result)) {
|
||||
return result;
|
||||
}
|
||||
const arrayBuffer = await result.arrayBuffer();
|
||||
return arrayBuffer;
|
||||
}
|
||||
async sendServeMessage(options) {
|
||||
const { openId, type } = options;
|
||||
const myInit = {
|
||||
|
|
|
|||
|
|
@ -667,7 +667,11 @@ class WechatPublicInstance {
|
|||
};
|
||||
const token = await this.getAccessToken();
|
||||
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/media/get?access_token=${token}`, myInit);
|
||||
return result;
|
||||
if (this.isJson(result)) {
|
||||
return result;
|
||||
}
|
||||
const arrayBuffer = await result.arrayBuffer();
|
||||
return arrayBuffer;
|
||||
}
|
||||
async getTicket() {
|
||||
const myInit = {
|
||||
|
|
|
|||
|
|
@ -135,11 +135,11 @@ export class WechatMpInstance {
|
|||
const json = JSON.parse(data);
|
||||
if (typeof json.errcode === 'number' && json.errcode !== 0) {
|
||||
if ([40001, 42001].includes(json.errcode)) {
|
||||
if (fresh) {
|
||||
throw new OakServerProxyException(
|
||||
'刚刷新的token不可能马上过期,请检查是否有并发刷新token的逻辑'
|
||||
);
|
||||
}
|
||||
if (fresh) {
|
||||
throw new OakServerProxyException(
|
||||
'刚刷新的token不可能马上过期,请检查是否有并发刷新token的逻辑'
|
||||
);
|
||||
}
|
||||
return this.refreshAccessToken(url, init);
|
||||
}
|
||||
throw new OakExternalException(
|
||||
|
|
@ -375,6 +375,30 @@ export class WechatMpInstance {
|
|||
return result;
|
||||
}
|
||||
|
||||
// 获取临时素材
|
||||
async getTemporaryMaterial(options: { mediaId: string }) {
|
||||
const { mediaId } = options;
|
||||
const myInit = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
media_id: mediaId,
|
||||
}),
|
||||
};
|
||||
const token = await this.getAccessToken();
|
||||
const result = await this.access(
|
||||
`https://api.weixin.qq.com/cgi-bin/media/get?access_token=${token}`,
|
||||
myInit
|
||||
);
|
||||
if (this.isJson(result)) {
|
||||
return result;
|
||||
}
|
||||
const arrayBuffer = await result.arrayBuffer();
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
async sendServeMessage(options: ServeMessageOption) {
|
||||
const { openId, type } = options;
|
||||
const myInit = {
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ export class WechatPublicInstance {
|
|||
expireSeconds: result.expire_seconds,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async sendTemplateMessage(options: {
|
||||
openId: string;
|
||||
templateId: string;
|
||||
|
|
@ -916,7 +916,11 @@ export class WechatPublicInstance {
|
|||
`https://api.weixin.qq.com/cgi-bin/media/get?access_token=${token}`,
|
||||
myInit
|
||||
);
|
||||
return result;
|
||||
if (this.isJson(result)) {
|
||||
return result;
|
||||
}
|
||||
const arrayBuffer = await result.arrayBuffer();
|
||||
return arrayBuffer;
|
||||
}
|
||||
|
||||
async getTicket() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue