Socket
Book a DemoInstallSign in
Socket

alipay-open-new

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alipay-open-new

alipay open api wrap

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

##0、注意事项

  • AliPayClient和AliPayRequest内部封装了请求签名和返回验证签名方法,会自动位请求带上签名,并且验证返回的签名

##1、创建请求客户端

const fs = require('fs');
const alipay = require('alipay-open-new');
const debug = true;

const client = new alipay.AliPayClient({
    appId: '2016090900473171',
    appPrivateKey: fs.readFileSync('app private key pem path'),
    appPublicKey: fs.readFileSync('app public key pem path'),
    aliPayPublicKey: fs.readFileSync('alipay public key path'),
    appAESKey: 'app aes key',
}, debug);

##2、创建请求

 let accessTokenRequest = new alipay.auth.AccessTokenRequest();
    
 accessTokenRequest.setBizContent({
        grant_type: 'authorization_code',
        code: 'auth_code_***'
 });

##3、发送请求或者执行跳转

const fs = require('fs');
const alipay = require('alipay-open-new');
const debug = true;

const client = new alipay.AliPayClient({
    appId: '2016090900473171',
    appPrivateKey: fs.readFileSync('app private key pem path'),
    appPublicKey: fs.readFileSync('app public key pem path'),
    aliPayPublicKey: fs.readFileSync('alipay public key path'),
    appAESKey: 'app aes key',
}, debug);

let webLogin = function() {
  let accessTokenRequest = new alipay.auth.AccessTokenRequest();
      
  accessTokenRequest.setBizContent({
          grant_type: 'authorization_code',
          code: 'auth_code_***'
  });
  
  client.request(accessTokenRequest, function (err, body) {
      if(err){
          return next(err);
      }
      
      let userInfoRequest = new alipay.auth.UserInfoRequest();
      
      userInfoRequest.setAccessToken(body.access_token);
      
      client.request(userInfoRequest, function (err, body) {
          if(err){
              return next(err);
          }
          
          console.log(body);
      });
  });
};

Keywords

alipay

FAQs

Package last updated on 18 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.