微信开发中,access_token的获取是一种非常常见的功能,通过公众号的appid和appsecret来向微信公众平台请求一个临时通行凭证:access_token。公众平台上的绝大部分操作都会需要这个临时通行凭证的授权,以php为例,access_token的获取方法:

<?php
define("APPID", $appid);
define("APPSECRET", $appsecret);
 
// 获取access_token
$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&app> APPSECRET;
$res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容
$result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result['access_token'];
?>

返回的参数中除了我们需要的access_token以外,还会有一个这个临时通行凭证的有效期。由于每天向公众平台获取access_token的次数是有限的,所以建议将获取的access_token存入数据里,超出有效期了再进行请求获取。

相关文章:

  • 2021-12-04
  • 2021-10-26
  • 2021-08-28
  • 2021-10-17
  • 2021-12-25
  • 2021-11-03
  • 2021-12-04
  • 2021-12-10
猜你喜欢
  • 2021-12-04
  • 2021-12-04
  • 2021-07-31
  • 2021-12-14
  • 2021-12-04
  • 2021-12-04
  • 2021-05-01
  • 2022-01-03
相关资源
相似解决方案