File size: 1,373 Bytes
6e41657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**

 * 获取合集数据接口

 */

import { proxyMpRequest } from '~/server/utils/proxy-request';

interface AppMsgAlbumQuery {
  fakeid: string;
  album_id: string;
  is_reverse?: string;
  count?: number;
  begin_msgid?: string;
  begin_itemidx?: string;
}

export default defineEventHandler(async event => {
  const query = getQuery<AppMsgAlbumQuery>(event);
  const fakeid = query.fakeid;
  const album_id = query.album_id;
  const isReverse = query.is_reverse || '0';
  const begin_msgid = query.begin_msgid;
  const begin_itemidx = query.begin_itemidx;
  const count: number = query.count || 20;

  const params: Record<string, string | number | undefined> = {
    action: 'getalbum',
    __biz: fakeid,
    album_id: album_id,
    begin_msgid: begin_msgid,
    begin_itemidx: begin_itemidx,
    count: count,
    is_reverse: isReverse,
    f: 'json',
  };

  // misc 目录下的接口虽然也是用 proxyMpRequest 方法,但是其实不需要透传公众号的 cookie
  // 只是为了方法复用
  return proxyMpRequest({
    event: event,
    method: 'GET',
    endpoint: 'https://mp.weixin.qq.com/mp/appmsgalbum',
    query: params,
    parseJson: true,
  }).catch(e => {
    return {
      base_resp: {
        ret: -1,
        err_msg: '获取合集接口失败,请重试',
      },
    };
  });
});