elixir_wechat v0.1.2 WeChat.Adapter.Storage.Client 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 :client side of WeChat common application.

Notice: In the :client scenario, we only need to implement the minimum functions to automatically append the required parameters from the persistence.

Writing custom storage adapter

Example for WeChat Official Account Platform application

defmodule MyApp.Storage.Client do
  @behaviour WeChat.Adapter.Storage.Client

  @impl true
  def get_access_token(appid) do
    access_token = "Get access_token by appid from your persistence..."
    access_token
  end

  @impl true
  def refresh_access_token(appid, access_token) do
    # Refresh access_token by appid from your persistence
    :ok
  end

end

Link to this section Summary

Callbacks

Get access_token of WeChat common application

Refresh access_token of WeChat common application via configured Hub servers

Link to this section Callbacks

Link to this callback

get_access_token(appid)
get_access_token(appid :: String.t()) ::
  %WeChat.Token{access_token: term(), refresh_token: term()}
  | nil
  | %WeChat.Error{
      __exception__: term(),
      errcode: term(),
      message: term(),
      reason: term()
    }

Get access_token of WeChat common application.

Example

get_access_token(appid)
Link to this callback

refresh_access_token(appid, access_token)
refresh_access_token(appid :: String.t(), access_token :: String.t()) ::
  String.t()

Refresh access_token of WeChat common application via configured Hub servers

Example

refresh_access_token(appid, access_token)