🚀
TypeScript 优先
完整的类型定义,提供卓越的开发体验和类型安全保障,支持智能提示和错误检查
npm install goofish-clientyarn add goofish-clientpnpm add goofish-clientimport { Goofish, LogLevel } from "goofish-client";
// 创建客户端实例
const client = new Goofish({
cookie: "cookie2=xxxx",
level: LogLevel.INFO,
});
// 获取首页Feed数据
const feedData = await client.api.mtop.home.getFeed({
pageSize: 20,
pageNumber: 1,
});
console.log(`获取到 ${feedData.data.cardList.length} 个商品`);
// 搜索商品
const results = await client.api.mtop.search.search({
keyword: "iPhone 14",
pageNumber: 1,
rowsPerPage: 20,
});
console.log(`找到 ${results.data.resultList.length} 个商品`);
// 获取商品详情
const itemDetail = await client.api.mtop.item.getDetail({
itemId: "95xxxxxxxxx334",
});
console.log(`商品标题: ${itemDetail.data.itemDO.title}`);
// 获取收藏列表
const favorList = await client.api.mtop.favor.getAllFavorItems();
console.log(`收藏商品数量: ${favorList.data.items.length}`);
// 获取订单列表
const orderList = await client.api.mtop.order.getAllOrders();
console.log(`订单数量: ${orderList.data.items.length}`);WsClient,支持自动重连、心跳保活、消息队列/r/Conversation/listNewestPagination 获取最新会话列表npm install goofish-client选择以下任一方式获取认证:
import { Goofish, LogLevel } from "goofish-client";
// 方式1: 使用已有Cookie
const client = new Goofish({
cookie: "your_existing_cookie",
});
// 方式2: 二维码登录
const client = new Goofish({});
const loginResult = await client.api.passport.qr.generate();
// 扫描二维码后获取Cookie...// 获取首页推荐
const feedData = await client.api.mtop.home.getFeed({
pageSize: 30,
pageNumber: 1,
});
// 搜索商品
const products = await client.api.mtop.search.search({
keyword: "MacBook Pro",
filter: {
priceRange: { from: 5000, to: 15000 },
},
});
// 获取商品详情
const itemDetail = await client.api.mtop.item.getDetail({
itemId: "95xxxxxxxxx334",
});
// 获取用户信息
const userInfo = await client.api.mtop.user.getUserNav();
// 获取收藏商品
const favorItems = await client.api.mtop.favor.getAllFavorItems();
// (可选)初始化 IM:获取 Token、连接 WebSocket 并注册
const tokenRes = await client.api.mtop.im.getLoginToken();
await client.wsClientIm.connect();
await client.api.im.auth.register({ token: tokenRes.data.accessToken });
// 监听格式化后的消息
client.api.im.message.onFormattedMessage((msg) => {
console.log("收到 IM 消息:", msg);
});重要声明
本 Client 为第三方开发工具,仅供学习研究使用。使用前请确保遵守相关平台的服务条款。
TypeScript 类型定义主要覆盖成功响应场景,错误处理请参考官方文档。