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

direct-alipay

v3.0.0

Published

alipay direct pay nodejs api client

Downloads

8

Readme

Npm Package Npm Downloads Dependency Status

支付宝 即时到账 NodeJS包 demo

集成到你的项目

1.安装

    npm install direct-alipay

2.配置支付宝参数

    var directAlipay = require('direct-alipay');
    directAlipay.config({
        seller_email: '[email protected]',
        partner: '2088911275465084',
        key: 'tws3ri4d3sg8ohc4t7k9dnj8kumvia05',
        return_url: 'http://127.0.0.1:3000/return'
    }); 

参数说明见支付宝官方文档    

3.传入订单参数,生成支付跳转URL

    var url = directAlipay.buildDirectPayURL({
        out_trade_no: Date.now().toString() + Math.random(),//业务侧需要为每个订单生成一个唯一订单号
        subject: '给华中师范大学贫困学生的捐赠',//订单标题
        body: 'body',
        total_fee: '1'//订单金额,单位元
    });

 

4.引导用户跳转到获得的URL,跳转到支付宝支付界面

    window.location.href = url;

5.用户支付完毕后,会跳转到第2步配置的return_url,在这里来判断订单是否成功支付

    app.get('/return', function (req, res) {
        var params = req.query;
        directAlipay.verity(params).then(function() {
                  //该通知是来自支付宝的合法通知
        }).catch(function(err) {
            console.error(err);
        });
    });

支付宝回调通知见官方文档

运行Demo

仔细npm start后,用浏览器打开http://localhost:3000

文档

directAlipay

所有方法的入口

    var directAlipay = require('direct-alipay');
directAlipay.config(params)

配置支付宝基础配置,在使用前先配置.

    directAlipay.config({
        //签约支付宝账号或卖家收款支付宝帐户
        seller_email: '[email protected]',
        //合作身份者ID,以2088开头由16位纯数字组成的字符串
        partner: '2088911275465084',
        //交易安全检验码,由数字和字母组成的32位字符串
        key: 'tws3ri4d3sg8ohc4t7k9dnj8kumvia05',
        //支付宝服务器通知的页面
        notify_url: 'http://127.0.0.1:3000/notify',
        //支付后跳转后的页面
        return_url: 'http://127.0.0.1:3000/'
    }); 

其它配置参数见官方文档

directAlipay.buildDirectPayURL(params)

使用订单参数构造一个支付请求

    directAlipay.buildDirectPayURL({
        out_trade_no: '你的网站订单系统中的唯一订单号匹配',
        subject: '订单名称显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里',
        body: '订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里',
        total_fee: '订单总金额'
    });

返回支付宝支付请求URL 浏览器跳转到该url支付

directAlipay.verity(params)

验证来自支付宝的通知是否合法

    app.get('/notify', function (req, res) {
        var params = req.body;
        directAlipay.verity(params).then(function() {
          //该通知是来自支付宝的合法通知
        }).catch(function(err) {
          console.error(err);
        })
    });