<?php //小程序appid $appid = 'wx79d7c348d19f010c'; //小程序 APPSecret 密钥 $appsecret = 'd624aca86d0350eec824cde1baec36cb'; $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret; $token_json = file_get_contents($url); //可以将转换的数组保存到数据库中,token有效时长2小时内不用重新获取了 $token_arr = json_decode($token_json,true); echo $token_json;exit; //返回json数据例: //{"access_token":"16_i3UvTXusBfyAfRBDWF2jGws9fyuPoWr5ZZXoc91wjoZAutkGC9b5wKkpPal-B5tBu3Jhd0oMJ3hCqJhigPtUo1SKikolPH6-jFFIMkb2U7A0TMU8sp04hm_F2gSV_txj50oOgZ-OXfiho-2SKMQeAHAFHL","expires_in":7200}