{"id":13435918,"url":"https://github.com/elixir-wechat/wechat","last_synced_at":"2026-02-22T05:35:35.818Z","repository":{"id":48333025,"uuid":"63943791","full_name":"elixir-wechat/wechat","owner":"elixir-wechat","description":"Wechat API wrapper in Elixir","archived":false,"fork":false,"pushed_at":"2021-08-01T01:15:33.000Z","size":306,"stargazers_count":74,"open_issues_count":6,"forks_count":17,"subscribers_count":7,"default_branch":"main","last_synced_at":"2026-01-29T10:18:41.808Z","etag":null,"topics":["elixir","wechat","wechat-sdk","weixin","weixin-sdk"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/wechat","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-wechat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-22T10:03:08.000Z","updated_at":"2024-11-12T05:37:34.000Z","dependencies_parsed_at":"2022-08-27T21:12:37.411Z","dependency_job_id":null,"html_url":"https://github.com/elixir-wechat/wechat","commit_stats":null,"previous_names":["goofansu/wechat-elixir"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/elixir-wechat/wechat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-wechat%2Fwechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-wechat%2Fwechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-wechat%2Fwechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-wechat%2Fwechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-wechat","download_url":"https://codeload.github.com/elixir-wechat/wechat/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-wechat%2Fwechat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29705536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T03:17:42.375Z","status":"ssl_error","status_checked_at":"2026-02-22T03:17:31.622Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","wechat","wechat-sdk","weixin","weixin-sdk"],"created_at":"2024-07-31T03:00:40.753Z","updated_at":"2026-02-22T05:35:35.787Z","avatar_url":"https://github.com/elixir-wechat.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# Wechat\nWechat API wrapper in Elixir.\n\n[![CI](https://github.com/elixir-wechat/wechat/workflows/CI/badge.svg?branch=master)](https://github.com/elixir-wechat/wechat/actions?query=workflow%3ACI)\n[![Hex.pm](https://img.shields.io/hexpm/v/wechat.svg)](https://hex.pm/packages/wechat)\n![Hex.pm](https://img.shields.io/hexpm/dt/wechat.svg)\n\n## Installation\n\n```elixir\ndef deps do\n  [{:wechat, \"~\u003e 0.4.0\"}]\nend\n```\n\n## Configuration (optional)\n\n```elixir\nconfig :wechat,\n  adapter_opts: {Wechat.Adapters.Redis, [\"redis://localhost:6379/0\"]},\n  httpoison_opts: [recv_timeout: 300_000]\n```\n\n## Create a client to call APIs\n\n```elixir\niex(1)\u003e client = Wechat.Client.new(appid: \"WECHAT_APPID\", secret: \"WECHAT_SECRET\")\n%Wechat.Client{\n  appid: \"WECHAT_APPID\",\n  secret: \"WECHAT_SECRET\",\n  endpoint: \"https://api.weixin.qq.com/\"\n}\n\niex(2)\u003e Wechat.User.get(client)\n{:ok,\n  %{\n    \"count\" =\u003e 1,\n    \"data\" =\u003e %{\"openid\" =\u003e [\"oi00OuKAhA8bm5okpaIDs7WmUZr4\"]},\n    \"next_openid\" =\u003e \"oi00OuKAhA8bm5okpaIDs7WmUZr4\",\n    \"total\" =\u003e 1\n  }}\n```\n\n## Create a Wechat implementation\n\nYou can implement the `Wechat` module to simplify the usage.\n\nFirst, create an implementation by `use Wechat` :\n\n```elixir\ndefmodule MyApp.Wechat do\n  use Wechat, otp_app: :my_app\n\n  def users do\n    client() |\u003e Wechat.User.get()\n  end\nend\n```\n\nConfig the implementation with Wechat credentials:\n\n```elixir\nconfig :my_app, MyApp.Wechat,\n  appid: \"APP_ID\",\n  secret: \"APP_SECRET\",\n  token: \"TOKEN\",\n  encoding_aes_key: \"ENCODING_AES_KEY\" # Required if you enabled the encrypt mode\n```\n\n## Wechat implementation examples\n\n### JS-SDK\n\n[https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html)\n\n```html\n\u003cscript type=\"text/javascript\" src=\"//res.wx.qq.com/open/js/jweixin-1.4.0.js\"\u003e\u003c/script\u003e\n\u003c%= raw MyApp.Wechat.wechat_config_js(@conn, debug: false, api: ~w(previewImage closeWindow)) %\u003e\n\n\u003cscript\u003e\n$(function() {\n  var urls = [];\n  $('img').map(function(){\n    url = window.location.origin + $(this).attr('src'),\n    urls.push(url);\n  });\n\n  $('img').click(function(e) {\n    wx.previewImage({\n      current: window.location.origin + $(this).attr('src'),\n      urls: urls\n    });\n  })\n});\n\u003c/script\u003e\n```\n\n### Process message in Phoenix\n\n[https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_standard_messages.html](https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_standard_messages.html)\n\n- router.ex\n\n```elixir\ndefmodule MyApp.Router do\n  scope \"/wechat\", MyApp do\n    resources \"/\", WechatController, [:index, :create]\n  end\nend\n```\n\n- wechat_controller.ex\n\n```elixir\ndefmodule MyApp.WechatController do\n  use MyApp.Web, :controller\n\n  # Validate signature param\n  plug Wechat.Plugs.RequestValidator, module: MyApp.Wechat\n\n  # Parse message\n  plug Wechat.Plugs.MessageParser, [module: MyApp.Wechat] when action in [:create]\n\n  def index(conn, %{\"echostr\" =\u003e echostr}) do\n    text conn, echostr\n  end\n\n  def create(conn, _params) do\n    %{\"ToUserName\" =\u003e to, \"FromUserName\" =\u003e from, \"Content\" =\u003e content} = conn.body_params\n    reply = %{from: to, to: from, content: content}\n\n    msg = Phoenix.View.render_to_string(EvercamWechatWeb.WechatView, \"text.xml\", reply: reply)\n\n    # Return encrypted message if possible\n    case Wechat.encrypt_message(msg) do\n      {:ok, reply} -\u003e\n        render(conn, \"encrypt.xml\", reply: reply)\n\n      {:error, _} -\u003e\n        text(conn, msg)\n    end\n  end\nend\n```\n\n- text.xml.eex\n\n```xml\n\u003cxml\u003e\n  \u003cMsgType\u003e\u003c![CDATA[text]]\u003e\u003c/MsgType\u003e\n  \u003cContent\u003e\u003c![CDATA[\u003c%= @reply.content %\u003e]]\u003e\u003c/Content\u003e\n  \u003cToUserName\u003e\u003c![CDATA[\u003c%= @reply.to %\u003e]]\u003e\u003c/ToUserName\u003e\n  \u003cFromUserName\u003e\u003c![CDATA[\u003c%= @reply.from %\u003e]]\u003e\u003c/FromUserName\u003e\n  \u003cCreateTime\u003e\u003c%= DateTime.to_unix(DateTime.utc_now) %\u003e\u003c/CreateTime\u003e\n\u003c/xml\u003e\n```\n\n- encrypt.xml.eex\n\n```xml\n\u003cxml\u003e\n  \u003cEncrypt\u003e\u003c![CDATA[\u003c%= @reply.msg_encrypt %\u003e]]\u003e\u003c/Encrypt\u003e\n  \u003cMsgSignature\u003e\u003c![CDATA[\u003c%= @reply.msg_signature %\u003e]]\u003e\u003c/MsgSignature\u003e\n  \u003cTimeStamp\u003e\u003c%= @reply.timestamp %\u003e\u003c/TimeStamp\u003e\n  \u003cNonce\u003e\u003c![CDATA[\u003c%= @reply.nonce %\u003e]]\u003e\u003c/Nonce\u003e\n\u003c/xml\u003e\n```\n\n## Users\n\n* [evercam_wechat](https://github.com/evercam/evercam_wechat)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-wechat%2Fwechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-wechat%2Fwechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-wechat%2Fwechat/lists"}