300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 支付宝小程序服务器要求 支付宝小程序:支付宝服务端SDK

支付宝小程序服务器要求 支付宝小程序:支付宝服务端SDK

时间:2020-03-12 20:35:02

相关推荐

支付宝小程序服务器要求 支付宝小程序:支付宝服务端SDK

支付宝 OpenAPI SDK

Yet Another Alipay OpenAPI Smart Development Kit

主要功能

OOP风格化的,可弹性扩容的,支付宝OpenAPI SDK

低依赖,目前仅依赖Axios

使用Node原生代码实现支付宝OpenAPI的AES(aes-128-cbc)加/解密功能

使用Node原生代码实现支付宝OpenAPI的RSA(sha1WithRSAEncryption)及RSA2(sha256WithRSAEncryption)签名、验签功能

SDK约定

使用method({请求参数}[, {公共请求参数}[, {特殊头参数}]])作为HTTP接口驱动,释义如下:

接口定义中公共请求参数的method,即作为本SDK标准方法链,弹性扩容,示例使用方法如下,详细审查见文末

接口定义中的请求参数,以Object对象作为第一个入参

接口定义中的公共请求参数,以Object对象作为第二个入参

特别的,对于图片/视频上传,需要定义multipart/form-data头信息,以Object对象作为第三个入参,见如下示例

特别的,对于页面表单提交型,即所谓的page类接口,第三参数须定义为Formatter.page,返回结果可直接作为页面/接口输出,说明用法见如下示例

请求数据签名以及返回数据验签均自动完成,开发者仅需关注业务代码即可;特别地,对于验签结果有依赖的情况,可以从返回值的头部获取:

headers[x-alipay-verified]为验签结果,值可能为ok,undefined

headers[x-alipay-signature]为源返回数据签名值,值可能为undefined

headers[x-alipay-responder]为源返回值字段名转译,值可能为undefined,error或者实际请求的method值

使用手册

certHelper 命令行工具

./node_modules/.bin/certHelper -h

Usage: cert.js [command] [options]nnCommands:n cert.js SN Get the certificatie(s) `SN` [default]n cert.js extract Extract the chained certificate(s)nnOptions:n -f, --file The certificate(s) file path [required]n -p, --pattern The algo prefix or suffix, dot(.) for alln -h, --help Show help [boolean]n -V, --version Show version number [boolean]nnExamples:n cert.js SN -f alipayRootCert.crtget the `sha256`(default) certificate `SN`n cert.js SN -f alipayRootCert.crt -p ec get the signatureAlgorithm whose contains `ec` words

certificate `SN`n cert.js SN -f alipayRootCert.crt -p . get all chained certificate(s) `SN`n cert.js extract -f alipayRootCert.crt extract the `sha256`(default) certificaten cert.js extract -f alipayRootCert.crt -p sha1 extract the `sha1` certificaten cert.js extract -f alipayRootCert.crt -p .extract all chained certificate(s)n cert.js extract -f alipayRootCert.crt -p sha1 | openssl x509 piped openssl x509 commandn -noout -textn cert.js extract -f alipayRootCert.crt -p sha1 > tmp.pem save to a file

此命令行工具,主要是用来计算并获取 公钥证书模式 所需的 应用公钥证书SN(app_cert_sn)及 支付宝公钥证书SN(alipay_root_cert_sn)。

./bin/cert.js SN -f /path/your/app_cert.crt

./bin/cert.js SN -f /path/your/alipay_root_cert.crt -p RSAEncryption

而SN命令是Helpers.SN的语法糖,可从测试用例tests/lib/helpers.test.js查看更详细用法

初始化

const {readFileSync} = require('fs')nconst {Alipay} = require('whats-alipay')nn//应用app_idnconst app_id = '072300007148'nn//商户私钥证书,须完整格式,同时支持 `PKCS#1` `PKCS#8` 格式nconst privateKey = readFileSync('/your/openapi/private_key.pem')nn//支付宝公钥证书,须完整格式,同时支持 `PKCS#1` `PKCS#8` 格式nconst publicCert = readFileSync('/the/alipay/public_cert.pem')nnconst whats = new Alipay({ privateKey, publicCert, params: { app_id, } })

统一收单线下交易查询

whatsn .alipay.trade.query({out_trade_no})n .then(({headers,data}) => ({headers,data}))n .catch(({response: {data}}) => data)n .then(console.log)

console.log sample result

{n headers: {

server: 'Tengine/2.1.0',

date: 'Fri, 25 Sep 03:27:32 GMT',

'content-type': 'text/html;charset=utf-8',

'content-length': '829',

connection: 'close',

'set-cookie': [

'JSESSIONID=6FF6F65BB1EC785992117C95EA7C27BB; Path=/; HttpOnly',

'spanner=ubOmkyHGnYLtouOsffShT4n70pJgSji6Xt2T4qEYgj0=;path=/;secure;'

],

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。