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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ycnt/wechatpay

v1.1.4

Published

a Wechat payment library

Downloads

8

Readme

Build Status Coverage Status MIT license

安装

npm i -S @ycnt/wechatpay

yarn add @ycnt/wechatpay

使用方法

配置

import { Wechatpay } from '@ycnt/wechatpay';

const wechatpay = new Wechatpay({
  appid: 'xxxx',
  mch_id: 'xxxx',
  apiKey: 'xxxx', // 微信商户平台API密钥
  pfx: readFileSync(resolve('xxxx/apiclient_cert.p12')),
});

创建订单

const orderParams: IOrderParams = {
  body: '支付测试', // 商品或支付单简要描述
  out_trade_no: 'xxx', // 商户系统内部的订单号,32个字符内、可包含字母
  total_fee: 100, // 价格单位为分
  spbill_create_ip: '127.0.0.1', // 客户IP地址
  notify_url: 'http://wxpayment_notify_url', // 回调通知接口URL
  trade_type: 'APP', // APP, JSAPI, NATIVE etc.
};

const order = await wechatpay.createUnifiedOrder(orderParams);

创建支付对象

支付对象是客户端用于发起支付的凭据

const payment = wechatpay.configForPayment(order);

查寻订单

const queryOrder = await wechatpay.queryOrder({
  out_trade_no: 'xxx',
});

关闭订单

const closeOrder = await wechatpay.closeOrder({
  out_trade_no: 'xxx',
});

退款

const refundOrder = await wechatpay.refund({
  out_trade_no: 'xxx',
  out_refund_no: 'xxx', // 退款流水号,同一流水号多次退款只会处理一次
  total_fee: 100, // 订单总额
  refund_fee: 100, // 退款金额
});

退款查寻

const queryRefund = await wechatpay.queryRefund({
  out_trade_no: 'xxx',
});

反馈信息验证

支付成功后微信给后台反馈的信息为XML格式。 为了安全,我们需要对信息进行验证。

const xml = `微信通知的内容`
const obj = `转xml为Object`
const isSignOk = wechatpay.signVerify(obj);

给微信返回结果

微信反馈信息后,我们需要回复成功或失败,格式为XML。 不然微信会持续发送反馈信息。 下面两个方法会创建XML格式的回复信息。

const success: string = wechatpay.success(); // 成功XML信息
const fail: string = wechatpay.fail(); // 失败XML信息