elixir_wechat v0.1.2 WeChat.Adapter.Storage.Hub behaviour
The storage adapter specification for WeChat common application.
Since we need to storage(cache) some key data(e.g. access_token
) for invoking WeChat APIs, this module
is used for customizing the persistence when use this library in a :hub
side of WeChat common application.
Notice: In the :hub
scenario, we need to implement the completed functions to maintain the persistence.
Writing custom storage adapter
Example for WeChat Official Account Platform application
defmodule MyApp.Storage.Hub do
@behaviour WeChat.Adapter.Storage.Hub
@impl true
def get_secret_keya(appid) do
secret_key = "Get secret_key by appid from your persistence..."
secret_key
end
@impl true
def get_access_token(appid) do
access_token = "Get access_token by appid from your persistence..."
access_token
end
@impl true
def save_access_token(appid, access_token) do
# Save access_token by appid to your persistence
end
@impl true
def refresh_access_token(appid, access_token) do
# Refresh access_token by appid from your persistence
end
end
Link to this section Summary
Callbacks
Get access_token of WeChat common application
Get secret_key of WeChat common application
Refresh access_token of WeChat common application
Save access_token of WeChat common application
Link to this section Callbacks
Link to this callback
get_access_token(appid)
Get access_token of WeChat common application.
Example
get_access_token(appid)
Link to this callback
get_secret_key(appid)
Get secret_key of WeChat common application.
Link to this callback
refresh_access_token(appid, access_token)
Refresh access_token of WeChat common application.
Example
refresh_access_token(appid, access_token)
Link to this callback
save_access_token(appid, access_token)
Save access_token of WeChat common application.
Example
save_access_token(appid, access_token)