WeChat.request
You're seeing just the function
request
, go back to WeChat module for more information.
Specs
request(method :: method(), options :: Keyword.t()) :: {:ok, term()} | {:error, WeChat.Error.t()}
Call WeChat's HTTP API functions in a explicit way.
We can defined a global module to assemble appid
, authorizer_appid
(only used for "component" application), and adapter_storage
.
For example:
defmodule MyClient do
use WeChat,
appid: "...",
adapter_storage: "..."
end
defmodule MyComponentClient do
use WeChat.Component,
appid: "...",
authorizer_appid: "...",
adapter_storage: "..."
end
And then we can use MyClient
or MyComponentClient
to call request/2
, as usual, there dose NOT need to pass the above parameters when invoke, but if needed you
input them to override.
We can directly use WeChat.request/2
as well, in this way, the appid
, authorizer_appid
(only used for "component" application), and adapter_storage
are required
for each invoke.
The method
parameter can be used as one of method/0
.
Options
:appid
, required, if you use a global module to assemble it, this value is optional. If you are using acommon
application,appid
means the application id of your WeChat Official Account; if you are acomponent
application,appid
means the application id of your WeChat Official Account third-party platform application.:authorizer_appid
, optional, if you are using acomponent
application, this value is required, the application id of your WeChat Official Account third-party platform application.:adapter_storage
, required, the predefined storage way to used foraccess_token
,jsapi_ticket
, andcard_ticket
, here provide a{:default, "MyHubURL"}
as option.:url
, required, the URL to call WeChat's HTTP API function, for example, "/cgi-bin/material/get_materialcount", also you can input a completed URL like this "https://api.weixin.qq.com/cgi-bin/material/get_materialcount".:host
, optional, the host of URI to call WeChat's HTTP API function, if you input a completed URL with host, this value is optional, by default it is "api.weixin.qq.com".:scheme
, optional, the scheme of URI to call WeChat's HTTP API function, if you input a completed URL with scheme, this value is optional, by default it is "https".:port
, optional, the port of URI to call WeChat's HTTP API function, if you input a completed URL with port, this value is optional, by default it is "443"(as integer).:body
, optional, a map, decided by your used WeChat's HTTP API functions, following WeChat official document to setup the body of the request.:query
, optional, a keyword, decided by your used WeChat's HTTP API functions, following WeChat official document to setup the query string of the request, this library will automatically appended a properaccess_token
into the query of each request, so we do NOT need to inputaccess_token
parameter.:opts
, optional, custom, per-request middleware or adapter options (exported fromTesla
)