View Source WeChat.Pay (wechat v0.13.0)
微信支付(V3版)
注意 未经上线测试,请谨慎使用
定义 Client 模块
defmodule YourApp.WeChatAppCodeName do
@moduledoc "CodeName"
use WeChat.Pay,
mch_id: "mch_id",
api_secret_key: "api_secret_key",
client_serial_no: "client_serial_no",
client_cert: "client_cert",
client_key: "client_key"
end
定义参数说明请看 options/0
初始化平台证书
WeChat.Pay.init_cacerts(YourApp.WeChatAppCodeName)
启动支付 Client 进程
defmodule YourApp.Application do
def start(_type, _args) do
children = [
# ...
YourApp.WeChatAppCodeName,
# or
{YourApp.WeChatAppCodeName, start_options},
# ...
]
Supervisor.start_link(children, strategy: :one_for_one, name: YourApp.Supervisor)
end
end
启动参数说明请看 start_options/0
处理回调消息
Summary
Types
API v3密钥 - 官方文档
商户 API 证书 - 官方文档
商户 API 私钥 - 官方文档
商户API 证书序列号 - 官方文档
商户号
构建参数
平台 证书序列号 - 官方文档
证书的序列号
启动参数
Types
@type api_secret_key() :: binary() | WeChat.env_option()
API v3密钥 - 官方文档
@type cacerts() :: [binary()]
平台证书列表 - 官方文档
@type client() :: module()
@type client_cert() :: pem_file()
商户 API 证书 - 官方文档
@type client_key() :: pem_file()
商户 API 私钥 - 官方文档
@type client_serial_no() :: serial_no()
商户API 证书序列号 - 官方文档
@type mch_id() :: binary()
商户号
@type options() :: [ mch_id: mch_id(), api_secret_key: binary(), client_serial_no: client_serial_no(), client_cert: client_cert(), client_key: client_key(), requester: module(), storage: module() ]
构建参数
参数说明
mch_id
:mch_id/0
- 必填api_secret_key
:binary/0
- 必填client_serial_no
:client_serial_no/0
- 必填client_cert
:client_cert/0
- 必填client_key
:client_key/0
- 必填storage
:t:WeChat.Storage.Adapter.t()
requester
: 请求客户端 -module/0
默认参数:
storage
:WeChat.Storage.PayFile
requester
:WeChat.Requester.Pay
@type platform_serial_no() :: serial_no()
平台 证书序列号 - 官方文档
@type requester_id() :: :A | :B
@type requester_opts() :: %{id: requester_id(), name: atom()}
@type serial_no() :: binary()
证书的序列号
@type start_options() :: [{:refresher, module()}]
启动参数
refresher
: 刷新器 -module/0
, 可选, 默认值:WeChat.Refresher.Pay
Functions
动态构建 client
初始化平台证书