View Source AlipayKit.V3 (alipay_kit v0.1.0)
A kit for Alipay OpenAPI V3.
Endpoints
- Production:
"https://openapi.alipay.com/v3"
- Sandbox:
"https://openapi-sandbox.dl.alipaydev.com/v3"
Methods for signing
Alipay officially supports two methods:
- Keys (密钥)
- Certificates (证书)
But, this module only supports Keys method for now.
Explore available API
Visit https://open.alipay.com/api.
Usage
Build a signed request and send it via an HTTP request
- build a
%HTTPSpec.Request{}
. - sign the request with
sign_request!/2
. - send the requset.
When building the request, don't forget adding required headers:
Content-Type: application/json; charset=UTF-8
Accept: application/json
And it's better to add a header for request id:
alipay-request-id: <32 characters>
More
I don't want to repeat what the official documentation already covers. For more information, please refer to the following materials:
Summary
Types
The Alipay's public key in PEM format, such as
The app's RSA private key in PEM format, such as
Functions
Signs a request.
Verifies a response returned by Alipay, and returns the verified and decoded body.
Types
@type alipay_public_key() :: String.t()
The Alipay's public key in PEM format, such as:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlHcsKzSFSoYkHionHPwo
<truncated>
-----END PUBLIC KEY-----
@type app_id() :: String.t()
@type app_private_key() :: String.t()
The app's RSA private key in PEM format, such as:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAlHcsKzSFSoYkHionHPwocwlgpX1iS9Fg+ZadVZMHiKrXvHUW
<truncated>
-----END RSA PRIVATE KEY-----
or:
-----BEGIN PRIVATE KEY-----
MIIEowIBAAKCAQEAlHcsKzSFSoYkHionHPwocwlgpX1iS9Fg+ZadVZMHiKrXvHUW
<truncated>
-----END PRIVATE KEY-----
@type nonce() :: String.t()
@type sign_request_opt() :: {:app_id, app_id()} | {:app_private_key, app_private_key()} | {:sign_type, sign_type()} | {:nonce, nonce()} | {:timestamp, timestamp()}
@type sign_request_opts() :: [sign_request_opt()]
@type sign_type() :: :SHA256withRSA | :SM3withSM2
@type timestamp() :: String.t()
@type verify_response_opt() :: {:alipay_public_key, alipay_public_key()} | {:sign_type, sign_type()}
@type verify_response_opts() :: [verify_response_opt()]
Functions
@spec sign_request!(HTTPSpec.Request.t(), sign_request_opts()) :: HTTPSpec.Request.t()
Signs a request.
Examples
References
@spec verify_response(HTTPSpec.Response.t(), verify_response_opts()) :: {:ok, map()} | {:error, :bad_response | :bad_signature}
Verifies a response returned by Alipay, and returns the verified and decoded body.