View Source WeChat.ServerMessage.EventHelper (wechat v0.15.1)

微信推送消息处理

API Docs

增加 saxy 依赖

注意: 公众号推送消息格式为 xml

def deps do
  [
    {:wechat, "~> x.x", hex: :wechat_sdk},
    {:saxy, "~> x.x"}
  ]
end

Summary

Types

@type data_type() :: :plaqin_text | :encrypted_xml | :encrypted_json
@type encrypt_content() :: String.t()
@type json() :: map()
@type json_string() :: String.t()
@type nonce() :: String.t()
@type signature() :: String.t()
@type status() :: Plug.Conn.status()
@type xml() :: map()
@type xml_string() :: String.t()

Functions

Link to this function

check_msg_signature?(encrypt_content, params, token)

View Source
@spec check_msg_signature?(encrypt_content(), params(), WeChat.token()) :: boolean()
Link to this function

check_signature?(params, token)

View Source
@spec check_signature?(params(), WeChat.token()) :: boolean()

验证消息的确来自微信服务器

Link to this function

decrypt_json_msg(encrypt_content, params, client)

View Source
@spec decrypt_json_msg(encrypt_content(), params(), WeChat.client()) ::
  {:ok, :encrypted, json_string()} | {:error, String.t()}
Link to this function

decrypt_json_msg(encrypt_content, params, appid, token, aes_key)

View Source
@spec decrypt_json_msg(
  encrypt_content(),
  params(),
  WeChat.appid(),
  WeChat.token(),
  WeChat.ServerMessage.Encryptor.aes_key()
) :: {:ok, :encrypted, json_string()} | {:error, String.t()}
Link to this function

decrypt_xml_msg(encrypt_content, params, client)

View Source
@spec decrypt_xml_msg(encrypt_content(), params(), WeChat.client()) ::
  {:ok, :encrypted, xml_string()} | {:error, String.t()}
Link to this function

decrypt_xml_msg(encrypt_content, params, appid, token, aes_key)

View Source
@spec decrypt_xml_msg(
  encrypt_content(),
  params(),
  WeChat.appid(),
  WeChat.token(),
  WeChat.ServerMessage.Encryptor.aes_key()
) :: {:ok, :encrypted, xml_string()} | {:error, String.t()}
Link to this function

encrypt_xml_msg(xml_string, timestamp, client)

View Source
@spec encrypt_xml_msg(xml_string(), timestamp(), WeChat.client()) :: String.t()
Link to this function

encrypt_xml_msg(xml_string, timestamp, client, agent)

View Source
@spec encrypt_xml_msg(
  xml_string(),
  timestamp(),
  WeChat.client(),
  WeChat.Work.Agent.t()
) :: String.t()
Link to this function

encrypt_xml_msg(xml_string, timestamp, appid, token, aes_key)

View Source
@spec encrypt_xml_msg(
  xml_string(),
  timestamp(),
  WeChat.appid(),
  WeChat.token(),
  WeChat.ServerMessage.Encryptor.aes_key()
) :: String.t()
Link to this function

handle_component_event(conn, client, message)

View Source

处理第三方平台推送通知

Link to this function

parse_json_event(params, body, client)

View Source
@spec parse_json_event(params(), body :: String.t(), WeChat.client()) ::
  {:ok, data_type(), json()} | {:error, String.t()}
Link to this function

parse_work_xml_event(params, body, client, agent)

View Source
@spec parse_work_xml_event(
  params(),
  body :: String.t() | map(),
  WeChat.client(),
  WeChat.Work.Agent.t()
) ::
  {:ok, data_type(), xml()} | {:error, String.t()}

parse xml format event message for work

Link to this function

parse_xml_event(params, body, client)

View Source
@spec parse_xml_event(params(), body :: String.t() | map(), WeChat.client()) ::
  {:ok, data_type(), xml()} | {:error, String.t()}

parse xml format event message for official_account

Link to this function

reply_msg(arg1, xml_string, timestamp, client, agent)

View Source
@spec reply_msg(
  data_type(),
  xml_string(),
  timestamp(),
  WeChat.client(),
  WeChat.Work.Agent.t()
) ::
  String.t()