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

jyhk-payment-sdk

v1.0.0

Published

简化支付SDK - 微信小程序支付、支付宝小程序支付、微信浏览器H5支付

Readme

JYHK Payment SDK

一个轻量级的跨平台支付SDK,支持微信小程序、支付宝小程序和微信H5支付。

功能特性

  • 微信小程序支付 - 支持微信小程序环境下的支付功能
  • 支付宝小程序支付 - 支持支付宝小程序环境下的支付功能
  • 微信H5支付 - 支持微信浏览器内的H5支付
  • 智能环境检测 - 自动检测当前运行环境并选择对应的支付方式
  • 统一API接口 - 提供简单易用的统一支付接口
  • 错误处理 - 完善的错误码映射和错误信息提示
  • 多模块格式 - 支持CommonJS、ES Module和UMD格式

安装

npm install jyhk-payment-sdk
# 或
yarn add jyhk-payment-sdk

快速开始

智能支付(推荐)

SDK会自动检测当前环境并选择最合适的支付方式:

import { smartPay } from 'jyhk-payment-sdk';

// 智能支付 - SDK会自动选择支付方式
smartPay({
  // 通用参数
  amount: 100, // 支付金额(分)
  orderId: '20231234567890', // 订单号
  
  // 微信支付参数
  timeStamp: '1631234567',
  nonceStr: '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
  package: 'prepay_id=wx201410272009395522657a690389285100',
  signType: 'MD5',
  paySign: 'C380BEC2BFD727A4B6845133519F3AD6',
  
  // 支付宝支付参数
  orderStr: '20231234567890'
}).then(result => {
  console.log('支付成功', result);
}).catch(error => {
  console.error('支付失败', error);
});

指定支付方式

如果您明确知道当前环境,可以直接调用特定的支付方法:

import { 
  wechatMiniProgramPay, 
  alipayMiniProgramPay, 
  wechatH5Pay 
} from 'jyhk-payment-sdk';

// 微信小程序支付
wechatMiniProgramPay({
  timeStamp: '1631234567',
  nonceStr: '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
  package: 'prepay_id=wx201410272009395522657a690389285100',
  signType: 'MD5',
  paySign: 'C380BEC2BFD727A4B6845133519F3AD6'
});

// 支付宝小程序支付
alipayMiniProgramPay({
  orderStr: '20231234567890'
});

// 微信H5支付
wechatH5Pay({
  timeStamp: '1631234567',
  nonceStr: '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
  package: 'prepay_id=wx201410272009395522657a690389285100',
  signType: 'MD5',
  paySign: 'C380BEC2BFD727A4B6845133519F3AD6'
});

API文档

smartPay(params)

智能支付方法,根据当前环境自动选择支付方式。

参数:

  • params (Object) - 支付参数对象
    • 通用参数:amount, orderId
    • 微信支付参数:timeStamp, nonceStr, package, signType, paySign
    • 支付宝支付参数:orderStr

返回值: Promise

wechatMiniProgramPay(params)

微信小程序支付方法。

参数:

  • params (Object) - 微信支付参数
    • timeStamp (string) - 时间戳
    • nonceStr (string) - 随机字符串
    • package (string) - 订单详情扩展字符串
    • signType (string) - 签名方式,默认'MD5'
    • paySign (string) - 签名

alipayMiniProgramPay(params)

支付宝小程序支付方法。

参数:

  • params (Object) - 支付宝支付参数
    • orderStr (string) - 订单信息字符串

wechatH5Pay(params)

微信H5支付方法。

参数:

  • params (Object) - 微信支付参数(同微信小程序支付)

getEnvironmentInfo()

获取当前环境信息。

返回值: Object

  • isWechatMiniProgram (boolean) - 是否微信小程序环境
  • isAlipayMiniProgram (boolean) - 是否支付宝小程序环境
  • isWechatBrowser (boolean) - 是否微信浏览器环境

getSupportedMethods()

获取当前环境支持的支付方式。

返回值: Array - 支持的支付方式列表

环境要求

  • 微信小程序:需要微信小程序环境,支持 wx.requestPayment API
  • 支付宝小程序:需要支付宝小程序环境,支持 my.tradePay API
  • 微信H5:需要在微信浏览器中运行,支持 WeixinJSBridge

开发

项目结构

src/
  ├── index.ts      # 主入口文件
  └── types.ts      # 类型定义
test/
  └── demo.js       # 测试示例
dist/               # 构建输出目录

构建

npm run build

测试

npm test

错误码

微信支付错误码

  • -1: 支付失败
  • -2: 用户取消支付

支付宝支付错误码

  • 4000: 订单支付失败
  • 5000: 重复请求
  • 6001: 用户中途取消
  • 6002: 网络连接出错
  • 6004: 支付结果未知
  • 8000: 正在处理中
  • 9000: 订单支付成功

许可证

MIT License

技术支持

如有问题请提交 Issue 或联系开发团队。