zoukankan      html  css  js  c++  java
  • getaccesstoken方法

    通过appid和appsecret获取access_token的定义函数

    这里用的是memcache缓存存储用户信息7000秒

    <?php
    function getAccessToken($appid,$appsecret) 
    {
    $mem = new CacheMemcache(); $acc = $mem->get('access_token_'.$appid); if (!$acc)
    {
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $result = https_request($url); $jsoninfo = json_decode($result, true); $access_token = $jsoninfo['access_token']; if ($access_token)
    {
    $expire = time() + 7000; $mem = new CacheMemcache(); $mem->set('access_token_'.$appid,$access_token,$expire); } }
    else
    {
    $access_token = $acc; } return $access_token; }
    ?>
  • 相关阅读:
    UVA756
    SP30906
    SP32900
    CF940F
    洛谷P5030
    洛谷P5142
    洛谷P2569
    网络流 24 题做题记录
    矩阵
    二分图
  • 原文地址:https://www.cnblogs.com/lizhaoyao/p/5640897.html
Copyright © 2011-2022 走看看