ex_wechat v0.1.8 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.aes/0

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

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

access_token()

Get the access_token

add_kf_account(body)

Add the kf_account

add_kf_account(body, callback)
add_kf_account(body, callback, extra)
add_other_permanent(body)

add other permanent image

add_other_permanent(body, callback)
add_other_permanent(body, callback, extra)
add_permanent_image(body)

add permanent image

add_permanent_image(body, callback)
add_permanent_image(body, callback, extra)
add_permanent_news(body)

add forever news

add_permanent_news(body, callback)
add_permanent_news(body, callback, extra)
aes()

See Wechat.Api.aes/0.

appid()

See Wechat.Api.appid/0.

batch_update_group_member(body)

Batch update group member

batch_update_group_member(body, callback)
batch_update_group_member(body, callback, extra)
cancel_blacklist(body)

Cancel user in blacklist

cancel_blacklist(body, callback)
cancel_blacklist(body, callback, extra)
create_group(body)

Create user group

create_group(body, callback)
create_group(body, callback, extra)
create_menu(body)

Create the menu

create_menu(body, callback)
create_menu(body, callback, extra)
create_qrcode_ticket(body)

Generate qrcode ticket.

create_qrcode_ticket(body, callback)
create_qrcode_ticket(body, callback, extra)
create_special_menu(body)

Special menu create

create_special_menu(body, callback)
create_special_menu(body, callback, extra)
create_user_tag(body)

create user tag

create_user_tag(body, callback)
create_user_tag(body, callback, extra)
delete_group(body)

Delete the users in group

delete_group(body, callback)
delete_group(body, callback, extra)
delete_kf_account(body)

Delete the kf_account

delete_kf_account(body, callback)
delete_kf_account(body, callback, extra)
delete_menu()

Delete the menu

delete_menu(callback)
delete_menu(callback, extra)
delete_permanent(body)

delete permanent resource

delete_permanent(body, callback)
delete_permanent(body, callback, extra)
delete_special_menu(body)

Delete special menu

delete_special_menu(body, callback)
delete_special_menu(body, callback, extra)
delete_user_tag(body)

delete user tag

delete_user_tag(body, callback)
delete_user_tag(body, callback, extra)
get_access_token()

Get the access_token from wechat server

get_access_token(callback)
get_access_token(callback, extra)
get_all_kf_account()

Get all the kf_account

get_all_kf_account(callback)
get_all_kf_account(callback, extra)
get_blacklist(body)

Get users in blacklists

get_blacklist(body, callback)
get_blacklist(body, callback, extra)
get_groups()

Get groups

get_groups(callback)
get_groups(callback, extra)
get_jsapi_ticket()

Get the jsapi ticket from wechat server

get_jsapi_ticket(callback)
get_jsapi_ticket(callback, extra)
get_media()

get media, added_params(media_id)

get_media(callback)
get_media(callback, extra)
get_media_list(body)

get media list

get_media_list(body, callback)
get_media_list(body, callback, extra)
get_menu()

Get the menu that are using.

get_menu(callback)
get_menu(callback, extra)
get_menu_conf()

Get all the menu config

get_menu_conf(callback)
get_menu_conf(callback, extra)
get_params(param)

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(body)

get permanent resource

get_permanent(body, callback)
get_permanent(body, callback, extra)
get_permanent_resources_count()

get permanent resources count

get_permanent_resources_count(callback)
get_permanent_resources_count(callback, extra)
get_qrcode()

Get qrcode with ticket.

get_qrcode(callback)
get_qrcode(callback, extra)
get_server_ip()

Get the wechat server ip.

get_server_ip(callback)
get_server_ip(callback, extra)
get_short_url(body)

Get the short url

get_short_url(body, callback)
get_short_url(body, callback, extra)
get_tags_on_user(body)

Get user’s tag

get_tags_on_user(body, callback)
get_tags_on_user(body, callback, extra)
get_user_info()

Get user info, added_params(openid)

get_user_info(callback)
get_user_info(callback, extra)
get_user_list()

Get user list

get_user_list(callback)
get_user_list(callback, extra)
get_user_tag()

Get user tags

get_user_tag(callback)
get_user_tag(callback, extra)
get_users_in_tag(body)

Get uses in tag

get_users_in_tag(body, callback)
get_users_in_tag(body, callback, extra)
get_users_info(body)

Get users info

get_users_info(body, callback)
get_users_info(body, callback, extra)
get_wxcard_ticket()

Get the wxcard ticket from wechat server

get_wxcard_ticket(callback)
get_wxcard_ticket(callback, extra)
jsapi_ticket()

Get the jsapi_ticket

put_blacklist(body)

Put users in blacklist

put_blacklist(body, callback)
put_blacklist(body, callback, extra)
renew_access_token()

Refresh the access_token

renew_jsapi_ticket()

Refresh the jsapi_ticket

renew_wxcard_ticket()

Refresh the wxcard_ticket

secret()

See Wechat.Api.secret/0.

send_custom_message(body)

Send custom message to user.

send_custom_message(body, callback)
send_custom_message(body, callback, extra)
send_mass_message(body)

Send Mass message to user.

send_mass_message(body, callback)
send_mass_message(body, callback, extra)
send_template_message(body)

Send Template message to user.

send_template_message(body, callback)
send_template_message(body, callback, extra)
start(type, args)

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 node node.
  • {:failover, node} - used if the application is distributed and is started on the current node because of a failover on node node, 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.

tag_at_users(body)

tag at user

tag_at_users(body, callback)
tag_at_users(body, callback, extra)
token()

See Wechat.Api.token/0.

untag_at_users(body)

untag user

untag_at_users(body, callback)
untag_at_users(body, callback, extra)
update_group_member(body)

Update group member

update_group_member(body, callback)
update_group_member(body, callback, extra)
update_kf_account(body)

Edit the kf_account

update_kf_account(body, callback)
update_kf_account(body, callback, extra)
update_kf_account_avatar(body)

Change the avatar of kf_account, added_params(kf_account)

update_kf_account_avatar(body, callback)
update_kf_account_avatar(body, callback, extra)
update_permanent_news(body)

update permanent news

update_permanent_news(body, callback)
update_permanent_news(body, callback, extra)
update_user_remark(body)

update user remark

update_user_remark(body, callback)
update_user_remark(body, callback, extra)
update_user_tag(body)

update user tag

update_user_tag(body, callback)
update_user_tag(body, callback, extra)
upload_media(body)

upload media, needed_params(type)

upload_media(body, callback)
upload_media(body, callback, extra)
wxcard_ticket()

Get the wxcard_ticket