WeChat (wechat v0.2.2)
WeChat SDK for Elixir
定义 Client
模块
公众号(默认):
defmodule YourApp.WeChatAppCodeName do
@moduledoc "CodeName"
use WeChat,
appid: "wx-appid",
appsecret: "appsecret"
end
小程序:
defmodule YourApp.WeChatAppCodeName do
@moduledoc "CodeName"
use WeChat,
app_type: :mini_program,
appid: "wx-appid",
appsecret: "appsecret"
end
第三方应用:
defmodule YourApp.WeChatAppCodeName do
@moduledoc "CodeName"
use WeChat,
by_component?: true,
app_type: :official_account | :mini_program, # 默认为 :official_account
appid: "wx-appid",
component_appid: "wx-third-appid", # 第三方 appid
end
参数说明
请看 options/0
接口调用
支持两种方式调用:
调用
client
方法YourApp.WeChatAppCodeName.Material.batch_get_material(:image, 2)
原生调用方法
WeChat.Material.batch_get_material(YourApp.WeChatAppCodeName, :image, 2)
Link to this section Summary
Types
client
的应用类型
公众号/小程序 应用id
应用秘钥
是否第三方平台开发
公众号/小程序 应用代码
第三方平台应用id
第三方平台应用秘钥
错误码
错误信息
OpenID 普通用户的标识,对当前公众号唯一
参数
服务器角色
服务器配置里的 token
值,在接收消息时用于校验签名
UnionID 不同应用下的唯一ID
Link to this section Types
Link to this type
app_type()
Specs
app_type() :: :official_account | :mini_program
client
的应用类型
:official_account
: 公众号:mini_program
: 小程序
Link to this type
appid()
Specs
appid() :: String.t()
公众号/小程序 应用id
Link to this type
appsecret()
Specs
appsecret() :: String.t()
应用秘钥
Link to this type
by_component?()
Specs
by_component?() :: boolean()
是否第三方平台开发
Link to this type
client()
Specs
client() :: module()
Link to this type
code_name()
Specs
code_name() :: String.t()
公众号/小程序 应用代码
Link to this type
component_appid()
Specs
component_appid() :: String.t()
第三方平台应用id
Link to this type
component_appsecret()
Specs
component_appsecret() :: String.t()
第三方平台应用秘钥
Link to this type
err_code()
Specs
err_code() :: non_neg_integer()
错误码
Link to this type
err_msg()
Specs
err_msg() :: String.t()
错误信息
Link to this type
openid()
Specs
openid() :: String.t()
OpenID 普通用户的标识,对当前公众号唯一
加密后的微信号,每个用户对每个公众号的 OpenID
是唯一的。对于不同公众号,同一用户的 OpenID
不同
Link to this type
options()
Specs
options() :: [ server_role: server_role(), by_component?: by_component?(), app_type: app_type(), storage: WeChat.Storage.Adapter.t(), appid: appid(), appsecret: appsecret(), component_appid: component_appid(), component_appsecret: component_appsecret(), encoding_aes_key: WeChat.ServerMessage.Encryptor.encoding_aes_key(), token: token(), requester: module() ]
参数
参数说明
appid
:appid/0
- 必填app_type
:app_type/0
by_component?
:by_component?/0
server_role
:server_role/0
storage
:t:WeChat.Storage.Adapter.t()
appsecret
:appsecret/0
- 仅在by_component?
设定为false
时才有效component_appid
:component_appid/0
- 仅在by_component?
设定为true
时才有效component_appsecret
:component_appsecret/0
- 仅在by_component?
设定为true
时才有效encoding_aes_key
:WeChat.ServerMessage.Encryptor.encoding_aes_key/0
- 在编译时会自动将encoding_aes_key
转换为aes_key
token
:token/0
requester
: 请求客户端 -module/0
默认参数:
server_role
::client
by_component?
:false
app_type
::official_account
storage
:WeChat.Storage.File
requester
:WeChat.Requester
- 其余参数皆为可选
Link to this type
requester()
Specs
requester() :: module()
Link to this type
response()
Specs
response() :: Tesla.Env.result()
Link to this type
server_role()
Specs
server_role() :: :client | :hub | :hub_client
服务器角色
:client
: 默认,刷新token
:hub
: 中控服务器,刷新token
:hub_client
: 逻辑服务器,获取token
Link to this type
token()
Specs
token() :: String.t()
服务器配置里的 token
值,在接收消息时用于校验签名
Link to this type
unionid()
Specs
unionid() :: String.t()
UnionID 不同应用下的唯一ID
同一用户,对同一个微信开放平台下的不同应用,UnionID
是相同的
Link to this section Functions
Link to this function
build_client(client, options)
Specs
动态构建 client
Link to this function
get_client_by_appid(appid)
Specs
根据 appid
获取 client