知识点
相关文章
更多最近更新
更多ACCESS TOKEN
2019-03-02 00:56|来源: 网路
Access Token
在微信公众平台接口开发中,Access Token占据了一个很重要的地位,相当于进入各种接口的钥匙,拿到这个钥匙才有调用其他各种特殊接口的权限。
access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。正常情况下access_token有效期为7200秒,重复获取将导致上次获取的access_token失效。
公众号可以使用AppID和AppSecret调用本接口来获取access_token。AppID和AppSecret可在开发模式中获得(需要已经成为开发者,且帐号没有异常状态)。注意调用所有微信接口时均需使用https协议。
接口调用请求说明
http请求方式: GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
参数说明
参数 |
是否必须 |
说明 |
grant_type |
是 |
获取access_token填写client_credential |
appid |
是 |
第三方用户唯一凭证 |
secret |
是 |
第三方用户唯一凭证密钥,既appsecret |
返回说明
正常情况下,微信会返回下述JSON数据包给公众号:
{"access_token":"ACCESS_TOKEN","expires_in":7200}
参数 |
说明 |
access_token |
获取到的凭证 |
expires_in |
凭证有效时间,单位:秒 |
错误时微信会返回错误码等信息,JSON数据包示例如下(该示例为AppID无效错误):
{"errcode":40013,"errmsg":"invalid appid"}
代码实现
$appid = "wxbad0b4x543aa0b5e"; $appsecret = "ed222a84da15cd24c4bdfa5d9adbabf2"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); $access_token = $jsoninfo["access_token"];
特别说明
在OAuth2.0认证中,我们会看到另一种Access Token,请注意区别。
转自:http://www.cnblogs.com/pondbay/p/3486351
相关问答
更多-
电脑二级考试 是考access 还是VPF[2022-06-08]
access -
如果我有他/她的oauth_token,如何获得用户access_token?(How to get user access_token if I have his/her oauth_token?)[2023-03-17]
您正在谈论的oauth_token也是用户access_token,它们应该完全相同。 要检查用户权限,您可以对/ me / permissions进行GET调用,这应该返回类似于下面的数据数组 { "data": [ { "installed": 1, "read_stream": 1, "manage_notifications": 1, "manage_pages": 1, "user_likes": 1, ... -
在oauth端点进行射击将始终为您提供长寿命令牌,这与短命令牌不同。 Firing at the oauth endpoint will always give you the long lived token, which is different than the short lived one.
-
grant_type应为“ refresh_token ”而不是“ access_token ” 尝试这个: RestClient.post 'https://accounts.google.com/o/oauth2/token', :refresh_token => refresh_token, :client_id => client_id, :client_secret => client_secret, :grant_type => 'refresh_token' grant_type shoul ...
-
如何使用访问令牌?(How to use the access token?)[2022-06-19]
喜欢这个: FB.getLoginStatus(function(response) { if (response.status === 'connected') { FB.api('/me', function(response) { alert('Your name is ' + response.name); }); } else if (response.status === 'not_authorized') { // the user is lo ... -
你必须重定向到你的本地主机 。 You must be just redirect to your localhost.
-
access_token无效(The access_token invalid)[2023-07-16]
关闭了这个问题。 我找到了问题。 我的服务器访问令牌名称是“accessToken”,但oltu默认名称是“access_token”。 因此,需要继承OAuthBearerClientRequest并重新编码所有方法。 Closed this question. I found issue. my server access Token name is "accessToken", but oltu default name is "access_token". So, need to inheritan ... -
无法获得access_token(Not able to get access_token)[2023-05-12]
如果你使用cURL来调用url,你应该像下面这样调用它 curl -v -D https://org-name.okta.com/oauth2/v1/authorize 如果你使用REST客户端来调用这个URL,那么是的,它会返回重定向URI。 因为这是从浏览器调用的隐式流。 当你从浏览器调用这个URL(JavaScript或复制粘贴URL并按下回车键)时,你将被重定向到redirectUri并且令牌(id令牌和/或访问令牌)将位于重定向应用程序的url中,如下所示。 http:// localhost:/ ... -
OAUTH access_token TTL(OAUTH access_token TTL)[2024-02-29]
颁发令牌的授权服务器负责为其分配到期时间。 客户端可以使用标准化授权请求参数来指示首选TTL。 授权服务器基于可以基于客户端标识符和关联/配置的“许可”或“信任”的策略来决定,授权请求中可用的参数(例如scope )和其他上下文数据,例如HTTP请求参数,时间一天等 The Authorization Server that issues the token is responsible for assigning an expiry time to it. There's no standardized ... -
您是否在硬编码时编码令牌? | 应该是%7C。 不能想到目前可能出现的任何其他问题 Did you encode the token while hard coding? | should be %7C . Cant think of anything else that might have gone wrong for the moment