Current section

29 Versions

Jump to

Compare versions

24 files changed
+396 additions
-173 deletions
  @@ -1,16 +1,28 @@
1 1 # Change Log
2 2
3 - ## [v0.1.2](https://github.com/goofansu/wechat_elixir/tree/v0.1.2) (2016-08-03)
4 - [Full Changelog](https://github.com/goofansu/wechat_elixir/compare/v0.1.1...v0.1.2)
3 + ## [v0.1.3](https://github.com/goofansu/wechat-elixir/tree/v0.1.3) (2016-09-11)
4 + [Full Changelog](https://github.com/goofansu/wechat-elixir/compare/v0.1.2...v0.1.3)
5 +
6 + **Closed issues:**
7 +
8 + - unused variable in Wechat.Plugs.CheckMsgSignature.decrypt\_msg/3 [\#3](https://github.com/goofansu/wechat-elixir/issues/3)
5 9
6 10 **Merged pull requests:**
7 11
8 - - Add a Gitter chat badge to README.md [\#1](https://github.com/goofansu/wechat_elixir/pull/1) ([gitter-badger](https://github.com/gitter-badger))
12 + - Message [\#4](https://github.com/goofansu/wechat-elixir/pull/4) ([linjunpop](https://github.com/linjunpop))
13 + - Added floki to applications. [\#2](https://github.com/goofansu/wechat-elixir/pull/2) ([linjunpop](https://github.com/linjunpop))
9 14
10 - ## [v0.1.1](https://github.com/goofansu/wechat_elixir/tree/v0.1.1) (2016-07-28)
11 - [Full Changelog](https://github.com/goofansu/wechat_elixir/compare/v0.1.0...v0.1.1)
15 + ## [v0.1.2](https://github.com/goofansu/wechat-elixir/tree/v0.1.2) (2016-08-03)
16 + [Full Changelog](https://github.com/goofansu/wechat-elixir/compare/v0.1.1...v0.1.2)
12 17
13 - ## [v0.1.0](https://github.com/goofansu/wechat_elixir/tree/v0.1.0) (2016-07-27)
18 + **Merged pull requests:**
19 +
20 + - Add a Gitter chat badge to README.md [\#1](https://github.com/goofansu/wechat-elixir/pull/1) ([gitter-badger](https://github.com/gitter-badger))
21 +
22 + ## [v0.1.1](https://github.com/goofansu/wechat-elixir/tree/v0.1.1) (2016-07-28)
23 + [Full Changelog](https://github.com/goofansu/wechat-elixir/compare/v0.1.0...v0.1.1)
24 +
25 + ## [v0.1.0](https://github.com/goofansu/wechat-elixir/tree/v0.1.0) (2016-07-27)
14 26
15 27
16 28 \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\ No newline at end of file
  @@ -1,7 +1,5 @@
1 1 # Wechat
2 2
3 - [![Join the chat at https://gitter.im/goofansu/wechat_elixir](https://badges.gitter.im/goofansu/wechat_elixir.svg)](https://gitter.im/goofansu/wechat_elixir?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 -
5 3 Wechat API wrapper in Elixir.
6 4
7 5 ## Installation
  @@ -46,7 +44,7 @@ Wechat API wrapper in Elixir.
46 44 * user
47 45
48 46 ```elixir
49 - iex> Wechat.User.list
47 + iex> Wechat.User.get
50 48 %{count: 4,
51 49 data: %{openid: ["oi00OuFrmNEC-QMa0Kikycq6A7ys",
52 50 "oi00OuKAhA8bm5okpaIDs7WmUZr4", "oi00OuOdjK0TicVUmovudbSP5Zq4",
  @@ -1,36 +1,39 @@
1 1 {<<"app">>,<<"wechat">>}.
2 2 {<<"build_tools">>,[<<"mix">>]}.
3 - {<<"description">>,<<"Wechat API wrapper.">>}.
4 - {<<"elixir">>,<<"~> 1.3">>}.
3 + {<<"description">>,<<"Wechat API wrapper in Elixir.">>}.
4 + {<<"elixir">>,<<"~> 1.5">>}.
5 5 {<<"files">>,
6 - [<<"lib/wechat.ex">>,<<"lib/wechat/access_token.ex">>,
7 - <<"lib/wechat/api_base.ex">>,<<"lib/wechat/api_file.ex">>,
8 - <<"lib/wechat/cipher.ex">>,<<"lib/wechat/media.ex">>,
9 - <<"lib/wechat/message/custom.ex">>,<<"lib/wechat/message/template.ex">>,
6 + [<<"lib/wechat.ex">>,<<"lib/wechat/api.ex">>,<<"lib/wechat/application.ex">>,
7 + <<"lib/wechat/cipher.ex">>,<<"lib/wechat/http.ex">>,
8 + <<"lib/wechat/media.ex">>,<<"lib/wechat/message/custom.ex">>,
9 + <<"lib/wechat/message/template.ex">>,<<"lib/wechat/mp.ex">>,
10 10 <<"lib/wechat/msg_parser.ex">>,
11 11 <<"lib/wechat/plugs/check_msg_signature.ex">>,
12 - <<"lib/wechat/plugs/check_url_signature.ex">>,<<"lib/wechat/signature.ex">>,
13 - <<"lib/wechat/user.ex">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE.md">>,
14 - <<"CHANGELOG.md">>]}.
12 + <<"lib/wechat/plugs/check_url_signature.ex">>,<<"lib/wechat/qrcode.ex">>,
13 + <<"lib/wechat/signature.ex">>,<<"lib/wechat/tags.ex">>,
14 + <<"lib/wechat/tags/members.ex">>,<<"lib/wechat/ticket.ex">>,
15 + <<"lib/wechat/user.ex">>,<<"lib/wechat/workers/access_token.ex">>,
16 + <<"lib/wechat/workers/jsapi_ticket.ex">>,<<"mix.exs">>,<<"README.md">>,
17 + <<"LICENSE.md">>,<<"CHANGELOG.md">>]}.
15 18 {<<"licenses">>,[<<"MIT">>]}.
16 19 {<<"links">>,[{<<"Github">>,<<"https://github.com/goofansu/wechat-elixir">>}]}.
17 20 {<<"maintainers">>,[<<"goofansu">>]}.
18 21 {<<"name">>,<<"wechat">>}.
19 22 {<<"requirements">>,
20 - [[{<<"app">>,<<"plug">>},
21 - {<<"name">>,<<"plug">>},
22 - {<<"optional">>,false},
23 - {<<"requirement">>,<<"~> 1.0">>}],
24 - [{<<"app">>,<<"poison">>},
23 + [[{<<"app">>,<<"poison">>},
25 24 {<<"name">>,<<"poison">>},
26 25 {<<"optional">>,false},
27 - {<<"requirement">>,<<"~> 2.0">>}],
26 + {<<"requirement">>,<<"~> 3.1">>}],
28 27 [{<<"app">>,<<"httpoison">>},
29 28 {<<"name">>,<<"httpoison">>},
30 29 {<<"optional">>,false},
31 - {<<"requirement">>,<<"~> 0.9.0">>}],
30 + {<<"requirement">>,<<"~> 0.12">>}],
32 31 [{<<"app">>,<<"floki">>},
33 32 {<<"name">>,<<"floki">>},
34 33 {<<"optional">>,false},
35 - {<<"requirement">>,<<"~> 0.9.0">>}]]}.
36 - {<<"version">>,<<"0.1.3">>}.
34 + {<<"requirement">>,<<"~> 0.17.0">>}],
35 + [{<<"app">>,<<"plug">>},
36 + {<<"name">>,<<"plug">>},
37 + {<<"optional">>,false},
38 + {<<"requirement">>,<<"~> 1.0">>}]]}.
39 + {<<"version">>,<<"0.2.0">>}.
  @@ -1,43 +1,43 @@
1 1 defmodule Wechat do
2 - @moduledoc """
3 - Assemble config and provide access to access_token.
4 - """
2 + @moduledoc false
3 +
4 + alias Wechat.Workers.AccessToken
5 + alias Wechat.Workers.JSAPITicket
5 6
6 7 def config do
7 - default_config
8 - |> Keyword.merge(Application.get_env(:wechat, Wechat, []))
8 + Keyword.merge(default_config(), Application.get_env(:wechat, Wechat))
9 + end
10 +
11 + def appid do
12 + config()[:appid] |> get_env
13 + end
14 +
15 + def secret do
16 + config()[:secret] |> get_env
17 + end
18 +
19 + def token do
20 + config()[:token] |> get_env
21 + end
22 +
23 + def encoding_aes_key do
24 + config()[:encoding_aes_key] |> get_env
9 25 end
10 26
11 27 defp default_config do
12 - [token_file: "/tmp/access_token"]
28 + [
29 + api_host: "https://api.weixin.qq.com/cgi-bin",
30 + mp_host: "https://mp.weixin.qq.com/cgi-bin"
31 + ]
13 32 end
14 33
15 - def access_token do
16 - token_info = read_token_from_file
17 - token_info =
18 - case access_token_expired?(token_info) do
19 - true -> refresh_access_token
20 - false -> token_info
34 + defp get_env({:system, env_var}) do
35 + System.get_env(env_var)
21 36 end
22 - token_info.access_token
37 + defp get_env(val) do
38 + val
23 39 end
24 40
25 - defp read_token_from_file do
26 - case File.read(config[:token_file]) do
27 - {:ok, binary} -> Poison.decode!(binary, keys: :atoms)
28 - {:error, _reason} -> refresh_access_token
29 - end
30 - end
31 -
32 - defp refresh_access_token do
33 - now = DateTime.to_unix(DateTime.utc_now)
34 - token_info = Map.merge(Wechat.AccessToken.token, %{refreshed_at: now})
35 - File.write(config[:token_file], Poison.encode!(token_info))
36 - token_info
37 - end
38 -
39 - defp access_token_expired?(token_info) do
40 - now = DateTime.utc_now |> DateTime.to_unix
41 - now >= (token_info.refreshed_at + token_info.expires_in)
42 - end
41 + defdelegate access_token, to: AccessToken, as: :get
42 + defdelegate jsapi_ticket, to: JSAPITicket, as: :get
43 43 end
  @@ -1,14 +0,0 @@
1 - defmodule Wechat.AccessToken do
2 - @moduledoc """
3 - AccessToken API.
4 - """
5 -
6 - import Wechat.ApiBase
7 -
8 - def token do
9 - get "token",
10 - grant_type: "client_credential",
11 - appid: Wechat.config[:appid],
12 - secret: Wechat.config[:secret]
13 - end
14 - end
Loading more files…