npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cn-open-sdk

v1.0.1

Published

SDK for Chinese open platforms

Readme

cn-open-sdk

一个用于调用中国开放平台 API 的 TypeScript SDK,支持淘宝开放平台和支付宝开放平台。 为满足自用需求,随缘更新。

安装

npm install cn-open-sdk
# 或
pnpm add cn-open-sdk
# 或
yarn add cn-open-sdk

使用方法

淘宝开放平台

  1. 初始化客户端
import { OpenClient } from "cn-open-sdk";

// 创建淘宝开放平台客户端
const client = new OpenClient("taobao", {
  appkey: "YOUR_APP_KEY",
  appsecret: "YOUR_APP_SECRET",
  // 可选:自定义网关URL 默认为正式环境
  // gatewayUrl: "https://gw.api.taobao.com/router/rest"
});
  1. 调用 API 接口
// 调用淘宝API示例
try {
  const response = await client.execute("taobao.item.get", {
    fields: "num_iid,title,price",
    num_iid: "123456789",
  });
  console.log("API响应:", response);
} catch (error) {
  console.error("API调用失败:", error);
}

支付宝开放平台

注意:支付宝平台使用 RSA2(SHA256WithRSA)算法进行签名,需要提供私钥(PEM 格式)

  1. 初始化客户端
import { OpenClient } from "cn-open-sdk";

// 创建支付宝开放平台客户端
const client = new OpenClient("alipay", {
  appid: "YOUR_APP_ID",
  privateKey: "YOUR_PRIVATE_KEY", // RSA私钥(PEM格式)
  // 可选:自定义网关URL 默认为正式环境
  // gatewayUrl: "https://openapi.alipay.com/gateway.do"
});
  1. 调用 API 接口

支付宝 API 支持两种调用方式:

方式一:有 biz_content 参数的时候(适用于大部分接口)

// 使用biz_content参数的API调用示例
try {
  const response = await client.execute("alipay.trade.create", {
    biz_content: JSON.stringify({
      out_trade_no: "2023111100001",
      total_amount: "0.01",
      subject: "测试商品",
      product_code: "FAST_INSTANT_TRADE_PAY",
    }),
  });
  console.log("API响应:", response);
} catch (error) {
  console.error("API调用失败:", error);
}

方式二:直接传递业务参数(适用于部分简单接口)

// 直接传递业务参数的API调用示例
try {
  const response = await client.execute("alipay.trade.query", {
    out_trade_no: "2023111100001",
  });
  console.log("API响应:", response);
} catch (error) {
  console.error("API调用失败:", error);
}

说明:SDK 会根据是否包含biz_content参数自动选择请求方式:

  • 包含biz_content时:使用 POST 请求,业务参数放在 body 中
  • 不包含biz_content时:使用 GET 请求,所有参数放在 URL 查询参数中

支持的平台

  • ✅ 淘宝开放平台 (taobao)
  • ✅ 支付宝开放平台 (alipay)

API 文档

OpenClient 类

构造函数

new OpenClient(platform: string, params: Record<string, any>)
  • platform: 平台名称,支持 taobao 和 alipay
  • params: 平台参数
    • 淘宝平台:需要包含 appkey 和 appsecret,可选 gatewayUrl
    • 支付宝平台:需要包含 appid 和 privateKey(RSA 私钥,PEM 格式),可选 gatewayUrl
      • 支付宝使用 RSA2(SHA256WithRSA)算法进行签名
      • 私钥格式应为标准 PEM 格式,包含-----BEGIN RSA PRIVATE KEY-----和-----END RSA PRIVATE KEY-----标记

execute 方法

async execute(method: string, params: Record<string, any>): Promise<any>
  • method: API 方法名(如 taobao.item.get 或 alipay.trade.query)
  • params: API 请求参数
  • 返回: Promise,解析为 API 响应数据

错误处理

API 调用可能会抛出错误,包括但不限于:

  • 平台不支持错误
  • 参数缺失或格式错误
  • API 调用失败

建议使用 try/catch 捕获并处理这些错误。

许可证

MIT