ex_wechat v0.1.7 Wechat
An elixir Wechat api. Functional and clear.
This sdk will read api definition from definition files. then it will automaticlly add all the function you define in these definition files.
All the methods in definition file are like this:
You also can add your own api definition files.
Set the api definition folder in config.exs
,
then you can use the api you define.
For example:
# config/config.exs
config :ex_wechat, Wechat,
appid: System.get_env("WECHAT_APPID"),
secret: System.get_env("WECHAT_APPSECRET"),
token: System.get_env("WECHAT_TOKEN"),
access_token_cache: "/tmp/access_token"
api_definition_files: Path.join(__DIR__, "lib/demo/apis")
# lib/demo/apis/simple_user
use Mix.Config
config :create_user_tag,
doc: "create user tag"
endpoint: "https://api.weixin.qq.com/cgi-bin",
path: "/tags/create",
http: :post,
params: [access_token: nil]
# web/controller/user_controller.ex
defmodule Demo.UserController do
use Demo.Web, :controller
use Wechat.Api
@api [:simple_user] # file name of the api definition file
end
Normally, when you add:
use Wechat.Api
to your module, this module will read all the api definition files,
define and import all the medthod you put in api definition file,
each method is a get
or post
http request.
All the Http methods use HTTPosion
for request.
defmodule MenuController do
use Wechat.Api
@api [:menu]
# post method
create_menu(post_body, extra_params \\ [])
# get method
get_menu(extra_params \\ [])
end
You can only import the menu api by add:
@api [:menu]
When use a post
method, it is you responsibility to offer
the right data(Elixir Map), when post data,
it will convert to json by the api.
Summary
Functions
Get the access_token
Add the kf_account
add other permanent image
add permanent image
add forever news
See Wechat.Api.appid/0
Batch update group member
Cancel user in blacklist
Create user group
Create the menu
Generate qrcode ticket
Special menu create
create user tag
Delete the users in group
Delete the kf_account
Delete the menu
delete permanent resource
Delete special menu
delete user tag
Get the access_token from wechat server
Get all the kf_account
Get users in blacklists
Get groups
Get the jsapi ticket from wechat server
get media, added_params(media_id)
get media list
Get the menu that are using
Get all the menu config
This method can be used in you own defined module. You can add this method in your module and afford the needed params
get permanent resource
get permanent resources count
Get qrcode with ticket
Get the wechat server ip
Get the short url
Get user’s tag
Get user info, added_params(openid)
Get user list
Get user tags
Get uses in tag
Get users info
Get the wxcard ticket from wechat server
Get the jsapi_ticket
Put users in blacklist
Refresh the access_token
Refresh the jsapi_ticket
Refresh the wxcard_ticket
See Wechat.Api.secret/0
Send custom message to user
Send Mass message to user
Send Template message to user
Called when an application is started
tag at user
See Wechat.Api.token/0
untag user
Update group member
Edit the kf_account
Change the avatar of kf_account, added_params(kf_account)
update permanent news
update user remark
update user tag
upload media, needed_params(type)
Get the wxcard_ticket
Functions
This method can be used in you own defined module. You can add this method in your module and afford the needed params.
Called when an application is started.
This function is called when an the application is started using
Application.start/2
(and functions on top of that, such as
Application.ensure_started/2
). This function should start the top-level
process of the application (which should be the top supervisor of the
application’s supervision tree if the application follows the OTP design
principles around supervision).
start_type
defines how the application is started:
:normal
- used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another mode and the application specification key:start_phases
is:undefined
.{:takeover, node}
- used if the application is distributed and is started on the current node because of a failover on the nodenode
.{:failover, node}
- used if the application is distributed and is started on the current node because of a failover on nodenode
, and the application specification key:start_phases
is not:undefined
.
start_args
are the arguments passed to the application in the :mod
specification key (e.g., mod: {MyApp, [:my_args]}
).
This function should either return {:ok, pid}
or {:ok, pid, state}
if
startup is successful. pid
should be the PID of the top supervisor. state
can be an arbitrary term, and if omitted will default to []
; if the
application is later stopped, state
is passed to the stop/1
callback (see
the documentation for the c:stop/1
callback for more information).
use Application
provides no default implementation for the start/2
callback.
Callback implementation for Application.start/2
.