Code Monkey home page Code Monkey logo

use-alipay's Introduction

use-alipay

Unofficial Alipay SDK

Use Alipay

import {useAlipay} from "use-alipay";
import {readFileSync} from "fs";

const alipay = useAlipay({
    appId: "your_app_id",

    appPrivateKey: readFileSync("private_key.pem"),

    // If encrypt is enabled
    encryptKey: readFileSync("AES.txt"),

    // If you are using public key certification
    appPublicKey: readFileSync(path.join(alipayDir, "appCertPublicKey.crt")),
    alipayPublicKey: readFileSync(path.join(alipayDir, "alipayCertPublicKey_RSA2.crt")),
    alipayRootPublicKey: readFileSync(path.join(alipayDir, "alipayRootCert.crt")),
});

// Perform a trade query
const queryResponse = await alipay.request({
    "out_trade_no": "xxx"
})

Expose RESTful Alipay API with Expressjs

With Expressjs, you can expose RESTful Alipay service easy.

import {useAlipay} from "./use-alipay";

const express = require("express");

const app = express();
app.use(express.json());
app.use(express.raw());
app.use(express.urlencoded());

const alipay = useAlipay({
    appId: "your_app_id",
    // more alipay configurations
}, {
    expressApp: app,
    alipayMountPoint: "/alipay",
    unsafeMountPoint: "/unsafe/alipay"
});

app.listen(8080);

Now you can send a request via curl

$ curl -v -X POST -H "Content-Type: application/json" \
'http://localhost:8080/unsafe/alipay/submit/alipay.trade.query' \
-d '{"out_trade_no": "xxx"}' 

RESTful Endpoints

  • POST /unsafe/alipay/submit/:method Submit a request
  • POST /unsafe/alipay/sign/:method Sign a request
  • POST /alipay/ack/:method Receives asynchronous notify from Alipay
  • POST /alipay/encrypt Encrypt request body and response with base64 encoded text
  • POST /alipay/decrypt Decrypt request body

use-alipay's People

Contributors

shoukunhuai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.