WeChat.WebPage (wechat v0.4.0)
网页开发
API Docs
Link to this section Summary
Types
JS API的临时票据类型
授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
授权范围
重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
Link to this section Types
Link to this type
access_token()
Specs
access_token() :: String.t()
Link to this type
card_config()
Specs
card_config() :: %{cardId: WeChat.Card.card_id(), cardExt: card_ext()}
Link to this type
card_ext()
Specs
card_ext() :: String.t()
Link to this type
code()
Specs
code() :: String.t()
Link to this type
js_api_ticket()
Specs
js_api_ticket() :: ticket()
Link to this type
js_api_ticket_type()
Specs
js_api_ticket_type() :: String.t()
JS API的临时票据类型
"jsapi"
- JS-SDK Config"wx_card"
- 微信卡券
Link to this type
js_sdk_config()
Specs
js_sdk_config() :: %{ appId: WeChat.appid(), signature: signature(), timestamp: timestamp(), nonceStr: nonce_str() }
Link to this type
nonce_str()
Specs
nonce_str() :: String.t()
Link to this type
redirect_uri()
Specs
redirect_uri() :: String.t()
授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
Link to this type
refresh_token()
Specs
refresh_token() :: String.t()
Link to this type
scope()
Specs
scope() :: String.t()
授权范围
"snsapi_base"
- 静默授权"snsapi_userinfo"
- 用户的基本信息(无须关注)
Link to this type
signature()
Specs
signature() :: String.t()
Link to this type
state()
Specs
state() :: String.t()
重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
Link to this type
ticket()
Specs
ticket() :: String.t()
Link to this type
timestamp()
Specs
timestamp() :: non_neg_integer()
Link to this type
url()
Specs
url() :: String.t()
Link to this type
wx_card_ticket()
Specs
wx_card_ticket() :: ticket()
Link to this section Functions
Link to this function
add_card_config(client, card_id, outer_str)
Specs
add_card_config(WeChat.client(), WeChat.Card.card_id(), outer_str :: String.t()) :: card_config()
生成微信卡券配置 - 添加卡券
API Docs
Link to this function
add_card_config(client, card_id, outer_str, openid)
Specs
add_card_config( WeChat.client(), WeChat.Card.card_id(), outer_str :: String.t(), WeChat.openid() ) :: map()
生成微信卡券配置 - 添加卡券(绑定openid
)
API Docs
Link to this function
auth(requester \\ Requester, openid, access_token)
网页授权 - 检验授权凭证(access_token
)是否有效 -
官方文档
Link to this function
code2access_token(client, code)
Specs
code2access_token(WeChat.client(), code()) :: WeChat.response()
网页授权 - 通过code
换取access_token
官方文档:
Link to this function
get_ticket(client, type)
Specs
get_ticket(WeChat.client(), js_api_ticket_type()) :: WeChat.response()
获取api_ticket
-
官方文档
Link to this function
js_sdk_config(client, url)
Specs
js_sdk_config(WeChat.client(), url()) :: js_sdk_config()
生成JS-SDK配置 - 官方文档
Link to this function
oauth2_authorize_url(client, redirect_uri, scope \\ "snsapi_base", state \\ "")
Specs
oauth2_authorize_url(WeChat.client(), redirect_uri(), scope(), state()) :: url()
网页授权 - 请求code
官方文档:
关于网页授权回调域名的说明
- 在微信公众号请求用户网页授权之前,开发者需要先到公众平台官网中的 “
开发
-接口权限
-网页服务
-网页帐号
-网页授权获取用户基本信息
” 的配置选项中, 修改授权回调域名。请注意,这里填写的是域名(是一个字符串),而不是URL,因此请勿加http://
等协议头; - 授权回调域名配置规范为全域名,比如需要网页授权的域名为:
www.qq.com
,配置以后此域名下面的页面http://www.qq.com/music.html
、http://www.qq.com/login.html
都可以进行OAuth2.0
鉴权。但http://pay.qq.com
、http://music.qq.com
、http://qq.com
无法进行OAuth2.0
鉴权 - 如果公众号登录授权给了第三方开发者来进行管理,则不必做任何设置,由第三方代替公众号实现网页授权即可
Link to this function
refresh_token(client, refresh_token)
Specs
refresh_token(WeChat.client(), refresh_token()) :: WeChat.response()
网页授权 - 刷新access_token
由于access_token
拥有较短的有效期,当access_token
超时后,可以使用refresh_token
进行刷新,
refresh_token
有效期为30天,当refresh_token
失效之后,需要用户重新授权。
官方文档:
Link to this function
sign_card(list)
Specs
卡券签名 - 官方文档
Link to this function
sign_card(wx_card_ticket, card_id)
Specs
sign_card(wx_card_ticket(), WeChat.Card.card_id()) :: map()
See sign_card/1
Link to this function
sign_card(wx_card_ticket, card_id, openid)
Specs
sign_card(wx_card_ticket(), WeChat.Card.card_id(), WeChat.openid()) :: map()
See sign_card/1
Link to this function
sign_jssdk(jsapi_ticket, url, appid)
Specs
sign_jssdk(js_api_ticket(), url(), WeChat.appid()) :: js_sdk_config()
生成JS-SDK配置(by ticket) - 官方文档
Link to this function
user_info(openid, access_token)
Specs
user_info(WeChat.openid(), access_token()) :: WeChat.response()
网页授权 - 拉取用户信息(需scope
为snsapi_userinfo
) -
官方文档
如果网页授权作用域为snsapi_userinfo
,则此时开发者可以通过access_token和openid拉取用户信息了.
Link to this function
user_info(requester, openid, access_token)
Specs
user_info(WeChat.requester(), WeChat.openid(), access_token()) :: WeChat.response()
user_info(WeChat.openid(), access_token(), WeChat.User.lang()) :: WeChat.response()
See user_info/2
Link to this function
user_info(requester, openid, access_token, lang)
Specs
user_info( WeChat.requester(), WeChat.openid(), access_token(), WeChat.User.lang() ) :: WeChat.response()
See user_info/2