Based on thinkPHP3.2, thinkphp3.2token is used to access and query the token value.
This example describes how to access and query the token Value Based on thinkPHP3.2. We will share this with you for your reference. The details are as follows:
1. Configure the TOKEN, APPID, and APPSECRET values in the con. fig file.
2. Controller WeixinController code:
<? Php/*** parent class Controller * @ author Songle **/namespace Weixin \ Controller; use Think \ Controller; class WeixinController extends Controller {private $ last_time = null; private $ appid = null; private $ appsecret = null; function _ construct () {parent ::__ construct (); $ token = C ('Token '); $ this-> appid = C ('appid '); $ this-> appsecret = C ('appsecret '); // obtain the four parameters of the Server GET request $ signature = I ('signature'); $ timestamp = I ('timestamp'); $ Nonce = I ('nonce '); $ echostr = I ('chostr'); if (! Empty ($ echostr )&&! Empty ($ signature )&&! Empty ($ nonce) {// defines an array and stores three parameters: timestamp, nonce, and token $ tempArr = array ($ nonce, $ timestamp, $ token); // sort ($ tempArr, SORT_STRING); // convert the array to a string $ tmpStr = implode ($ tempArr ); // perform the sha1 encryption algorithm $ tmpStr = sha1 ($ tmpStr); // determine whether the request is from the server. Compare $ tmpStr and $ signature if ($ tmpStr = $ signature) {echo $ echostr;} exit () ;}/ *** get tooken value */public function getTooken () {$ this-> last_time = 1448012924; $ access_t Oken = "fill in the last token value"; // replace it with your own if (time ()> ($ this-> last_time + 7200 )) {// GET request url $ url = "https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid ={$ this-> appid} & secret ={$ this-> appsecret} "; $ access_token_Arr = $ this-> https_request ($ url ); $ this-> last_time = time (); return $ access_token_Arr ['Access _ token'];} return $ access_token;} // https request (GET and POST are supported) public function https_request ($ url, $ data = null) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); if (! Empty ($ data) {curl_setopt ($ ch, CURLOPT_POST, 1); // simulate POST curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data ); // POST content} $ outopt = curl_exec ($ ch); curl_close ($ ch); $ outopt = json_decode ($ outopt, true); return $ outopt ;}}