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

微信推送消息处理

API Docs

增加 saxy 依赖

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

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

Summary

Types

data_type()

@type data_type() :: :plaqin_text | :encrypted_xml | :encrypted_json

encrypt_content()

@type encrypt_content() :: String.t()

json()

@type json() :: map()

json_string()

@type json_string() :: String.t()

nonce()

@type nonce() :: String.t()

signature()

@type signature() :: String.t()

status()

@type status() :: Plug.Conn.status()

xml()

@type xml() :: map()

xml_string()

@type xml_string() :: String.t()

Functions

check_msg_signature?(encrypt_content, params, token)

@spec check_msg_signature?(encrypt_content(), params(), WeChat.token()) :: boolean()

check_signature?(params, token)

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

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

decrypt_json_msg(encrypt_content, params, client)

@spec decrypt_json_msg(encrypt_content(), params(), WeChat.client()) ::
  {:ok, :encrypted, json_string()} | {:error, String.t()}

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

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

decrypt_xml_msg(encrypt_content, params, client)

@spec decrypt_xml_msg(encrypt_content(), params(), WeChat.client()) ::
  {:ok, :encrypted, xml_string()} | {:error, String.t()}

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

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

encrypt_xml_msg(xml_string, timestamp, client)

@spec encrypt_xml_msg(xml_string(), timestamp(), WeChat.client()) :: String.t()

encrypt_xml_msg(xml_string, timestamp, client, agent)

@spec encrypt_xml_msg(
  xml_string(),
  timestamp(),
  WeChat.client(),
  WeChat.Work.Agent.t()
) :: String.t()

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

@spec encrypt_xml_msg(
  xml_string(),
  timestamp(),
  WeChat.appid(),
  WeChat.token(),
  WeChat.ServerMessage.Encryptor.aes_key()
) :: String.t()

handle_component_event(conn, client, message)

处理第三方平台推送通知

parse_json_event(params, body, client)

@spec parse_json_event(params(), body :: String.t(), WeChat.client()) ::
  {:ok, data_type(), json()} | {:error, String.t()}

parse_work_xml_event(params, body, client, agent)

@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

parse_xml_event(params, body, client)

@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

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

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