Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alipay-sdk

Package Overview
Dependencies
Maintainers
6
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alipay-sdk

蚂蚁金服开放平台 SDK

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8K
decreased by-7.98%
Maintainers
6
Weekly downloads
 
Created
Source

Alipay SDK

蚂蚁金服开放平台 SDK

使用步骤

1. 注册支付宝开放平台(https://open.alipay.com/),并创建账号

2. 生成密钥

  1. 下载 RSA密钥工具:https://docs.open.alipay.com/291/106097/

  2. 切换到生成秘钥 tab,秘钥格式选择“PKCS1(非JAVA适用)” Differences between “BEGIN RSA PRIVATE KEY” and “BEGIN PRIVATE KEY”

    img

  3. 新建 private-key.pem 保存私钥,文件格式如下:

    -----BEGIN RSA PRIVATE KEY-----
    // 粘贴上一步生成的私钥到这里(不需要换行)
    -----END RSA PRIVATE KEY-----
    

    完整的 private-key.pem 文件例子:

    -----BEGIN RSA PRIVATE KEY-----
    MIIEpQIBAAKCAQEAqATL9/w/B5Siq/C0mKO8CoUqxX9gv2Fxs2Xz8n0Ce2O3qk+zzQxxwpgG77TMQ5JRaFZ8f1hA2Ax8DQVp9NLi5hqX3cZUpt8snWvc2Jz3hNWv81GqTDZCsMQD/HqgLURZxyw1yVHA2sayFcm8Exn1gqd1bNMSdy/VxhtfwKRxBq/vTNtfKus2E15/bQKB+l/mvroYrR5qYOAInEQt0HoTDFKL2+kvq3TD24gT/VbsfpJoy8FU3lT33LkYAOhHridveugXLbd7eK9e4iC02KV1loQBbL7R+UKdvh+5RZQfRIbQfKhDaSwQqTY0l+2u0b7W80BV8M1iMwQ8errtyUuWKQIDAQABAoIBAEcB5/XA7B5XCbyiuKA9qm3Dw8S9xXR8SSIpN0TG4jKlfOyETJee58D2oQ/TF/SCtNbkni7vbFAiTpbuL85hBbV7ja0TcZkofmF1QVtm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vBzJmQNXd8qpR8smzPqbcYwYHZG39l7lZ+lx/h1+qDiEcMRu/r8h3gv04lMxA=
    -----END RSA PRIVATE KEY-----
    

3. 设置应用公钥

  1. 复制 2.2 中生成的应用公钥

    img

  2. 登录开放平台设置应用公钥

    注意: 1.0.x 只支持 RSA(SHA1WithRSA) 方式的签名,请务必设置 RSA 秘钥

    img

4. 保存支付宝公钥

“支付宝公钥”用于开放平台返回值的进行验签

  1. 开放平台“应用概览”页面中复制“支付宝公钥”

    img

  2. 新建 public-key.pem 保存私钥,文件格式如下:

    -----BEGIN PUBLIC KEY-----
    // 粘贴上一步复制的“支付宝公钥”到这里(不需要换行)
    -----END PUBLIC KEY-----
    

    完整的 public-key.pem 文件例子:

    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqATL9/w/B5Siq/C0mKO8CoUqxX9gv2Fxs2Xz8n0Ce2O3qk+zzQxxwpgG77TMQ5JRaFZ8f1hA2Ax8DQVp9NLi5hqX3cZUpt8snWvc2Jz3hNWv81GqTDZCsMQD/HqgLURZxyw1yVHA2sayFcm8Exn1gqd1bNMSdy/VxhtfwKRxBq/vTNtfKus2E15/bQKB+l/mvroYrR5qYOAInEQt0HoTDFKL2+kvq3TD24gT/VbsfpJoy8FU3lT33LkYAOhHridveugXLbd7eK9e4iC02KV1loQBbL7R+UKdvh+5RZQfRIbQfKhDaSwQqTY0l+2u0b7W80BV8M1iMwQ8errtyUuWKQIDAQAB
    -----END PUBLIC KEY-----
    

调用 SDK

Exp:

const AlipaySdk = require('alipay-sdk');

const sdk = new AlipaySdk({
  appId: '2016101300678716',
  privateKey: fs.readFileSync('./private-key.pem', 'ascii'),
  alipayPublicKey: fs.readFileSync('./public-key.pem', 'ascii'),
});

sdk.execute(method, bizContent)
  .then(ret => {
    // console.log(ret);
  })
  .catch(() => {
    // ...
  });
  • alipaySDKConfig 配置参数

    • 必选参数
      • appId: String 开放平台上创建应用时生成的 appId
      • privateKey: String 应用私钥
      • alipayPublicKey: String 支付宝公钥
    • 可选参数
      • timeout: Number 网关超时时间
      • camelcase: Boolean 是否把服务端返回的数据下划线转驼峰
  • execute 方法参数列表

    • 必选参数
      • method: String 调用的 Api,比如 koubei.marketing.campaign.tags.query
      • bizContext: Object Api 的请求参数(文档中的“请求参数“)

        注: 某些 Api 可能没有请求参数

    • 可选参数
      • publicArgs: String Api 的公共请求参数(系统会自动处理公共请求参数,某些 Api 有自己特殊的公共请求参数时,请在这里设置)
      • validateSign: String 是否对返回值验签(依赖3.2中配置的”支付宝公钥“)
      • log: Log 对象,存在时会调用 info 方法写执行日志

FAQs

Package last updated on 03 May 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc