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

lazy-kit-weixin

v1.0.1

Published

> weixin quick toolkit based on Nodejs

Readme

lazy-kit-weixin

weixin quick toolkit based on Nodejs

Functions

interface WxAccessToken {
  access_token?: string;
  expires_in?: number;
  errcode?: number;
  errmsg?: string;
}
interface WxWebAccessToken {
  access_token?: string;
  expires_in?: number;
  refresh_token?: string;
  openid?: string;
  scope?: string;
  unionid?: string;
}
interface WxSession {
  openid?: string;
  session_key?: string;
  unionid?: string;
  errcode?: number;
  errmsg?: string;
}
interface WxPhone {
  phone_info?: {
    phoneNumber?: string;
    purePhoneNumber?: string;
    countryCode?: string;
    watermark?: {
      appid?: string;
      timestamp?: number;
    };
  };
  errcode?: number;
  errmsg?: string;
}
interface WxWebUserInfo {
  openid?: string;
  nickname?: string;
  sex?: number;
  province?: string;
  city?: string;
  country?: string;
  headimgurl?: string;
  privilege?: string[];
  unionid?: string;
}
interface NotifyParams {
  out_trade_no: string;
  transaction_id: string;
  trade_state: string;
  success_time: string;
}
interface MchOptions {
  id: string;
  serial_no: string;
  key_path: string;
  notify_url: string;
  prepay_url: string;
  v2?: string;
  v3?: string;
}
interface PrepayParams {
  appid: string;
  openid: string;
  amount: number;
  description: string;
  tradeno: string;
}
interface MsgTemplate {
  touser: string;
  template_id: string;
  page?: string;
  data: any;
  miniprogram_state: "developer" | "trial" | "formal";
  lang: "zh_CN";
}
interface AppSetting {
  appid: string;
  appSecret: string;
}

/**
 * [1] 授权认证
 */
namespace WeAuth {
  /**
   * 获取accessToken
   * @param appid
   * @param secret
   * @returns WxAccessTokenResult
   */
  function getAccessToken(
    appid: string,
    secret: string,
    options?: {
      url: string;
    }
  ): Promise<WxAccessToken>;

  /**
   * 获取session
   * @param appid
   * @param secret
   * @param code
   * @returns WxSessionResult
   */
  function getSession(
    appid: string,
    secret: string,
    code: string,
    options?: {
      url: string;
    }
  ): Promise<WxSession>;

  /**
   * 获取手机号
   * @param appid
   * @param secret
   * @param code
   * @returns WxPhoneResult
   */
  function getPhone(
    appid: string,
    secret: string,
    code: string,
    options?: {
      url: string;
    }
  ): Promise<WxPhone>;

  /**
   * 解密
   * @param encrypted_data
   * @param iv
   * @param appId
   * @param session_key
   * @returns encrypted JSON
   */
  function decrypt(
    encrypted_data: string,
    iv: string,
    appId: string,
    session_key: string
  ): any;

  /**
   * 获取微信QR扫码登陆页的访问地址
   * @param appid
   * @param redirect_uri query参数:CODE&SCOPE
   * @param scope snsapi_login
   * @param state
   * @param lang
   * @returns
   */
  function getScanPageURL(
    appid: string,
    redirect_uri: string,
    scope?: string,
    options?: {
      url: string;
      state?: string;
      lang?: string;
    }
  ): string;

  /**
   * 获取网页端的accessToken
   * @param appid
   * @param secret
   * @param code 网页端的redirect_uri返回的code
   * @returns
   */
  function getWebAccessToken(
    appid: string,
    secret: string,
    code: string,
    options?: {
      url: string;
    }
  ): Promise<WxWebAccessToken>;

  /**
   * 刷新网页端的Token
   * @param appid
   * @param refresh_token
   * @returns WxWebAccessTokenResult
   */
  function refreshWebAccessToken(
    appid: string,
    token: string,
    options?: {
      url: string;
    }
  ): Promise<WxWebAccessToken>;

  /**
   * 获取用户信息
   * @param access_token
   * @param openid
   * @returns
   */
  function getWebUserInfo(
    access_token: string,
    openid: string,
    options?: {
      url: string;
    }
  ): Promise<WxWebUserInfo>;
}

/**
 * [2] 商家支付
 */
namespace WePay {
  /**
   * 统一下单
   * @param params PrepayParams
   * @param mch MchOptions
   * @returns payment 小程序支付参数
   */
  function prepay(params: PrepayParams, mch: MchOptions): Promise<any>;

  /**
   * 统一订单参数
   * @param mch_id
   * @param notify_url
   * @param appid
   * @param openid
   * @param out_trade_no
   * @param description
   * @param amount 分
   * @param currency "CNY"
   * @returns
   */
  function getPrePayArgs(
    mch_id: string,
    notify_url: string,
    appid: string,
    openid: string,
    out_trade_no: string,
    description: string,
    amount: number,
    currency?: string
  ): any;

  /**
   * 获取小程序调用支付参数
   * @param appid
   * @param mchKey
   * @param prepay_id
   * @returns
   */
  function getPaymentArgs(
    appid: string,
    mchKey: string | Buffer,
    prepay_id: string
  ): any;

  /**
   * 支付完成回调 [POST]
   * @param req_body 请求参数
   * @param apiv3
   * @param callback (params: NotifyParams)=>void 后处理函数
   * @returns 通知参数
   */
  function onNotify(
    req_body: any,
    apiv3: string,
    callback?: (params: NotifyParams) => void
  ): Promise<NotifyParams>;

  /**
   * 获取支付回调参数
   * @param body
   * @returns NotifyParams
   */
  function getNotifyParams(body: any, apiv3: string): NotifyParams;

  /**
   * 参数解密
   * @param resource
   * @param apiv3
   * @returns any 通知回调参数
   */
  function decode(resource: any, apiv3: string): any;
}

/**
 * [3] 消息推送
 */
namespace WeMsg {
  /**
   * 发送消息
   * @param template MsgTemplate 消息模板
   * @param app AppSetting 小程序参数
   * @returns 推送回执
   */
  function send(
    template: MsgTemplate,
    app: AppSetting,
    options?: {
      url: string;
    }
  ): Promise<any>;
}


  /**
   * [4] 商家退款
   */
  namespace Refund {
    interface MchOptions {
      id: string;
      serial_no: string;
      key_path: string;
      refund_url: string; // 2024/11/21 新增退款模块时添加,默认 https://api.mch.weixin.qq.com/v3/refund/domestic/refunds
    }
    interface RefundParams {
      transaction_id?: string;    // 微信支付订单号
      out_trade_no?: string;      // 商户订单号
      out_refund_no: string;      // 商户退款单号
      reason?: string;            // 退款原因
      amount: {
        refund: number;           // 退款金额(分)
        total: number;            // 原订单金额(分)
        currency: string;         // 货币类型
      };
    }
    interface RefundResult {
      refund_id: string;          // 微信支付退款号
      out_refund_no: string;      // 商户退款单号
      transaction_id: string;     // 微信支付订单号
      out_trade_no: string;       // 商户订单号
      channel: string;            // 退款渠道
      user_received_account: string; // 退款入账账户
      success_time: string;       // 退款成功时间
      create_time: string;        // 退款创建时间
      status: string;             // 退款状态:SUCCESS/CLOSED/PROCESSING/ABNORMAL
      amount: {
        refund: number;           // 退款金额
        total: number;            // 原订单金额
        payer_total: number;      // 用户支付金额
        settlement_refund: number;// 应结退款金额
        settlement_total: number; // 应结订单金额
        discount_refund: number;  // 优惠退款金额
        currency: string;         // 退款币种
      }
    }
    function apply(params: RefundParams, mch: MchOptions): Promise<RefundResult>;
    function queryStatus(outRefundNo: string, mch: MchOptions): Promise<RefundResult>;
  }