This article describes in detail the php public platform configuration interface development program, which has some reference value, interested friends can refer to the following preparations before reading this article:
1. Register a subscription number (via public platform https://mp.weixin.qq.com /);
2. Register Sina Cloud and real-name authentication http://sae.sina.com.cn/
3. create a cloud application after real-name authentication of Sina Cloud.
4. you need to know basic php knowledge.
I. verification interface
1. log on to our public account. then click to enter the developer tool, in the lower left corner of the page after logon.
2. click to enter the Developer Documentation. then click start development, and click Access Guide. we will see it as shown in.
Note:In the code, $ token is different from each other. we need to fill in our own code. click the developer tool, and there is a public platform test account on the right. click to enter. then we will see the interface configuration, copy the Token to the code.
Copy the code to the PHP file of the SAE we just created, save it (remember to save it), and then click access through URL,
If an error is reported (the error message is a number), please click in the developer documentation and read it before clicking it. there is an interface return code description. let's take a look at the error, note: 0 indicates that the request is successful.
2. get access_token
Tip: access_token is the globally unique interface call credential of the public account. access_token is required when the public account calls each interface. as developers, we need to properly store the access_token. The validity period of the access_token is currently 2 hours and needs to be refreshed regularly. repeated access_token acquisition will invalidate the access_token obtained last time.
Step 1,Click the developer documentation, click start development, and click GET access_token to see the http request method: GET, and then a URL. we need to use this URL, as shown in,
E0204D74-2EA6-4943-B93F-7E7C1E2FA88A.png
Step 2:We write the GET request function to GET the access_token.
AppID} & secret = {$ this-> appsecret} "; // return $ this-> httpGet ($ url ); // json string $ json = $ this-> httpGet ($ url); // parse json $ obj = json_decode ($ json); return $ obj-> access_token ;} function httpGet ($ url) {// 1. initialize $ curl = curl_init (); // Configure curl curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true ); // execute curl $ res = curl_exec ($ curl); // close curl curl_close ($ curl); return $ res ;}} $ Wx = new Weixin (); echo $ wx-> getAccessToken ();/* get access_token method get method */?>
Note:In the code, $ appID and $ appsecret are different from each other. we need to fill in our own code. click the developer tool, and then there is a public platform test account on the right. click to enter, then we will see the test number information. then copy it to the code.
Step 3: Copy the code to the SAEphp file and right-click to access it through URL. if {"access_token": "ACCESS_TOKEN", "expires_in": 7200} is returned, the token is successfully obtained. if an error is reported unfortunately, it doesn't matter if we look for an error. click the development document, and you must read it before clicking Start. click the interface return code description. let's take a look at it and find the error as prompted.
Here, our configuration interface is complete. in the next section, we will continue to develop the custom menu creation interface.
The above describes how to use php to develop the interface program for public platform configuration. For more information, see other related articles on php Chinese network!