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