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');
    }
}
上一篇:双方API交互:签名及验证-- (AK/SK)认证的实现


下一篇:【新冠疫苗预约】Fiddler抓包新冠疫苗预约接口及脚本实现