Merge branch 'dev' of codeup.aliyun.com:61c14a7efa282c88e103c23f/oak-external-sdk into dev

This commit is contained in:
wangwenchen 2023-10-11 15:17:21 +08:00
commit 3774ebe8bd
9 changed files with 274 additions and 7 deletions

View File

@ -246,13 +246,19 @@ export class QiniuCloudInstance {
throw new OakNetworkException();
}
const responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
// qiniu如果返回空结果类型也是application/json(delete kodo file)
const contentLength = response.headers.get('Content-Length') || response.headers.get('content-length');
if (Number(contentLength) === 0) {
return;
}
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
const json = await response.json();
if (response.status > 299) {
// 七牛服务器返回异常根据文档一定是json实测发现返回和文档不一样
// https://developer.qiniu.com/kodo/3928/error-responses
// qiniu的status是重要的返回信息
const { error_code, error } = json;
return new OakExternalException('qiniu', error_code, error);
throw new OakExternalException('qiniu', error_code, error, { status: response.status });
}
return json;
}

View File

@ -69,6 +69,12 @@ export declare class WechatPublicInstance {
deleteTag(tag: {
id: number;
}): Promise<any>;
getTagUsers(tagid: number): Promise<any>;
batchtagging(openid_list: string[], tagid: number): Promise<any>;
batchuntagging(openid_list: string[], tagid: number): Promise<any>;
getUsers(nextOpenId: string): Promise<any>;
getUserTags(openid: string): Promise<any>;
getSubscribedUserInfo(openid: string): Promise<any>;
getCurrentMenu(): Promise<any>;
getMenu(): Promise<any>;
createMenu(menuConfig: any): Promise<any>;

View File

@ -190,7 +190,76 @@ export class WechatPublicInstance {
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 getTagUsers(tagid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ tagid, next_openid: "" })
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=${token}`, undefined, myInit);
return result;
}
async batchtagging(openid_list, tagid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ openid_list, tagid })
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=${token}`, undefined, myInit);
return result;
}
async batchuntagging(openid_list, tagid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ openid_list, tagid })
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=${token}`, undefined, myInit);
return result;
}
async getUsers(nextOpenId) {
const myInit = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/user/get?access_token=${token}${nextOpenId ? `&next_openid=${nextOpenId}` : ''}`, undefined, myInit);
return result;
}
async getUserTags(openid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ openid }),
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=${token}`, undefined, myInit);
return result;
}
async getSubscribedUserInfo(openid) {
const myInit = {
methods: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/user/info?access_token=${token}&openid=${openid}&lang=zh_CN`, undefined, myInit);
return result;
}
async getCurrentMenu() {
const myInit = {

View File

@ -250,13 +250,19 @@ class QiniuCloudInstance {
throw new Exception_1.OakNetworkException();
}
const responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
// qiniu如果返回空结果类型也是application/json(delete kodo file)
const contentLength = response.headers.get('Content-Length') || response.headers.get('content-length');
if (Number(contentLength) === 0) {
return;
}
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
const json = await response.json();
if (response.status > 299) {
// 七牛服务器返回异常根据文档一定是json实测发现返回和文档不一样
// https://developer.qiniu.com/kodo/3928/error-responses
// qiniu的status是重要的返回信息
const { error_code, error } = json;
return new Exception_1.OakExternalException('qiniu', error_code, error);
throw new Exception_1.OakExternalException('qiniu', error_code, error, { status: response.status });
}
return json;
}

View File

@ -69,6 +69,12 @@ export declare class WechatPublicInstance {
deleteTag(tag: {
id: number;
}): Promise<any>;
getTagUsers(tagid: number): Promise<any>;
batchtagging(openid_list: string[], tagid: number): Promise<any>;
batchuntagging(openid_list: string[], tagid: number): Promise<any>;
getUsers(nextOpenId: string): Promise<any>;
getUserTags(openid: string): Promise<any>;
getSubscribedUserInfo(openid: string): Promise<any>;
getCurrentMenu(): Promise<any>;
getMenu(): Promise<any>;
createMenu(menuConfig: any): Promise<any>;

View File

@ -194,7 +194,76 @@ class WechatPublicInstance {
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 getTagUsers(tagid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ tagid, next_openid: "" })
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=${token}`, undefined, myInit);
return result;
}
async batchtagging(openid_list, tagid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ openid_list, tagid })
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=${token}`, undefined, myInit);
return result;
}
async batchuntagging(openid_list, tagid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ openid_list, tagid })
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=${token}`, undefined, myInit);
return result;
}
async getUsers(nextOpenId) {
const myInit = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/user/get?access_token=${token}${nextOpenId ? `&next_openid=${nextOpenId}` : ''}`, undefined, myInit);
return result;
}
async getUserTags(openid) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ openid }),
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=${token}`, undefined, myInit);
return result;
}
async getSubscribedUserInfo(openid) {
const myInit = {
methods: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/cgi-bin/user/info?access_token=${token}&openid=${openid}&lang=zh_CN`, undefined, myInit);
return result;
}
async getCurrentMenu() {
const myInit = {

View File

@ -15,7 +15,6 @@
],
"scripts": {
"test": "ts-node test/test.ts",
"testqiniu": "ts-node test/testqiniu.ts",
"build": "tsc -p tsconfig.json && tsc -p tsconfig.es.json"
},
"license": "ISC",

View File

@ -341,14 +341,20 @@ export class QiniuCloudInstance {
const responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
// qiniu如果返回空结果类型也是application/json(delete kodo file)
const contentLength = response.headers.get('Content-Length') || response.headers.get('content-length');
if (Number(contentLength) === 0) {
return;
}
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
const json = await response.json();
if (response.status > 299) {
// 七牛服务器返回异常根据文档一定是json实测发现返回和文档不一样
// https://developer.qiniu.com/kodo/3928/error-responses
// qiniu的status是重要的返回信息
const { error_code, error } = json;
return new OakExternalException('qiniu', error_code, error);
throw new OakExternalException('qiniu', error_code, error, { status: response.status });
}
return json;
}

View File

@ -290,7 +290,107 @@ export class WechatPublicInstance {
undefined,
myInit
);
return result;;
return result;
}
async getTagUsers(tagid: number) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({tagid, next_openid: ""})
};
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=${token}`,
undefined,
myInit
);
return result;
}
async batchtagging(openid_list: string[], tagid: number) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({openid_list, tagid})
};
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=${token}`,
undefined,
myInit
);
return result;
}
async batchuntagging(openid_list: string[], tagid: number) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({openid_list, tagid})
};
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=${token}`,
undefined,
myInit
);
return result;
}
async getUsers(nextOpenId: string) {
const myInit = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/cgi-bin/user/get?access_token=${token}${nextOpenId ? `&next_openid=${nextOpenId}` : ''}`,
undefined,
myInit
);
return result;
}
async getUserTags(openid: string) {
const myInit = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({openid}),
};
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=${token}`,
undefined,
myInit
);
return result;
}
async getSubscribedUserInfo(openid: string) {
const myInit = {
methods: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/cgi-bin/user/info?access_token=${token}&openid=${openid}&lang=zh_CN`,
undefined,
myInit
);
return result
}
async getCurrentMenu() {