Method 1 to obtain Access Token:
You can modify it manually here:
https://api.weixin .qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
The appid and secret we want to use here can be obtained in the test, as shown in the figure below :
Then modify it manually:
Then ask the question, you can see that he returns a json format data
{"access_token":"fNNeJ5DpjmpE8SkZnyeByVP4x pqnZRMRkwlhZ7HZemT_WiULJ2YnpsNr4UgTG4zoJo5uMeOA2hFy2rlzOg-U9hnSpHuUuZMZRgI4ZhDK6KN_OIbNxHvfvdl4_wbW775oWKIdAAAIWU","expires_in": 7200}
Method 2 to obtain Access Token:
Call the program get_token.php, and then upload the file to your own WeChat server and browse By calling get_token.php in the server, you can also get the value of the access token.
get_token.php The code is as follows:
<?php //原理,就是使用curl函数,发出http请求,获取access_token $appid = 'wxed89d8f74fa6fc51'; $appsecret = 'd4624c36b6795d1d99dcf0547af5443d'; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}"; //我们使用curl函数 //初始化 $ch = curl_init(); //设置变量 curl_setopt($ch, CURLOPT_URL,$url); //这意思是,设置好发送的url地址发送到那 //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,$url); 这样的意思是对方要不要验证,如果不用则按照下面的即可 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE); //如果不用验证,这样即可 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE); //如果不用验证HOST主机这样即可 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //将curl_exec()获取的信息以文件流的形式返回,而不是直接输出 //执行 $output = curl_exec($ch); //返回来的值是一个json格式的值 //对返回的json结果要将他转为一个数组 $jsoninfo = json_decode($output,true); //测试以下,看下是否拿到返的回数组 //var_dump($jsoninfo); $access_token = $jsoninfo['access_token'];
For more articles related to WeChat development and obtaining access_token, please pay attention to the PHP Chinese website!