91在线公开视频_全黄特一级_www.亚洲天堂网_杏导航aⅴ福利网站_久久久综合网_大又大粗又爽又黄少妇毛片

18842388900

網站建設 APP開發 小程序

Article/文章

記錄成長點滴 分享您我感悟

您當前位置>首頁 > 知識 > 軟件開發

小程序下如何獲取access_token(代碼示例)

發表時間:2019-05-20 08:50:31

文章來源:沈陽網站建設

標簽:access_token

分享:

瀏覽次數:0

本篇文章給大家帶來的內容是關于小程序下如何獲取access_token(代碼示例),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。



<button bindtap="token">獲取token</button>
// pages/token/token.jsPage({  data: {  },  token:function(){    wx.request({      url: 'xxxx',      data:{},      success:function(res){        console.log(res.data);        //這里我是用的新浪云的sae,所以存在讀寫權限問題,打印出來的信息會存在告警      }    });  }})
<?php exit();?>{"access_token":"","expire_time":0}
<?php  //驗證  function getToken(){    $timestamp = $_GET["timestamp"];    $nonce =$_GET["nonce"];    $token="hello hqtoken";    $signature=$_GET["signature"];    $array=array($timestamp,$nonce,$token);    sort($array);    $tmpstr=implode("",$array);    $tmpstr=sha1($tmpstr);    if($tmpstr == $signature){      echo $_GET["echostr"];      exit;    }  }  //獲取AccessToken  function getAccessToken(){    $appid="你的appid";    $appsecret = "你的appsecret";    //文件存儲    $data=json_decode(get_php_file("access_token.php"));    if($data->expire_time<time()){      $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;      $res=json_decode(httpGet($url));      $access_token=$res->access_token;      if($access_token){        $data->expire_time=time()+7000;        $data->access_token=$access_token;        set_php_file("access_token.php",json_encode($data));      }    }else{      $access_token=$data->access_token;    }    return $access_token;  }  //公共的curl方法  function httpGet($url){    $curl = curl_init();    curl_setopt($curl,CURLOPT_URL,$url);    curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);    //如果用的是https,ssl安全驗證    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);    $res =curl_exec($curl);    curl_close($curl);    return $res;  }  function get_php_file($filename){    return trim(substr(file_get_contents($filename),15));  }  function set_php_file($filename,$content){    $fp=fopen($filename,"w");    fwrite($fp,"<?php exit()沈陽軟件開發

<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>沈陽<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>軟件開發</a></a>,<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>沈陽<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>軟件公司</a></a>

;?>".$content); fclose($fp); } echo getAccessToken();?>

以上就是小程序下如何獲取access_token(代碼示例)的詳細內容,更多請關注沈陽網站建設其它相關文章!

access_token

相關案例查看更多

主站蜘蛛池模板: 江油市| 姚安县| 米脂县| 澜沧| 灵璧县| 河间市| 杭州市| 潜山县| 乌苏市| 南汇区| 滕州市| 来凤县| 开原市| 浪卡子县| 金门县| 新乡县| 浦东新区| 高雄县| 大关县| 留坝县| 宜州市| 蚌埠市| 同德县| 集贤县| 阿瓦提县| 公主岭市| 邛崃市| 敦化市| 奉节县| 灵川县| 福泉市| 镇坪县| 合川市| 湘潭市| 温泉县| 丽水市| 申扎县| 成安县| 大洼县| 淮阳县| 毕节市|