TP5微信小程序获取access_token

2021/6/21 12:26:05

本文主要是介绍TP5微信小程序获取access_token,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

protected $appid = 'xxxxxxxxxxxxxxxxx';
protected $appsecrt = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
public function getSessionKey()
{
    //获取access_token
    //获取openID
    $code = $this->request->param('code');
    if($code) {
        $token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->appsecrt;
        $str_token = file_get_contents($token);
        $json_token = json_decode($str_token);
        $arr_token = get_object_vars($json_token);
        $this->success('获取成功',['access_token'=>$arr_token['access_token']],'20000');
    }else{
        $this->error('获取失败,code不存在','','20001');
    }
}


这篇关于TP5微信小程序获取access_token的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程