PHP public development notes (1) are written on Evernote first and sorted out when there is no problem at night.
PHP public development Notes Series
Date: 2014.9.1
Today, we officially started to provide developer services for public platforms in the class. Because it was the first time to do this, and I didn't know much about PHP, so I learned how to organize a public platform while learning PHP.
After logging on to the public platform, the developer center is at the bottom of the functional area on the left:
There is nothing in it before you start the developer service. After the service is enabled, the automatic reply function edited on the website is canceled, and the interaction information between the user and the public platform is transferred to the function accessed by the developer. To enable the developer function, you need to configure the server configuration:
I have already configured it here, mainly including two information: URL and Token. One link and one verification tag. What is the URL of our server? (How can this be described ?), Here I use SAE to create an application, mainly because it is free (500 Yundou is provided for registration, which is said to be sufficient for common users). The registration link is as follows: http://sae.sina.com.cn/after registration, you can do bad things.
1. start configuring server information:
1. after creating the SAE account, we will start to create our application (can the server be understood as an application? This is really unfamiliar, Cainiao), my homepage-console-Application Management-create a new application:
Click create:
The second-level domain name is the URL link we will use at that time;
Application Name-enter the description;
Select php for the development language;
Select web application for the application type;
The independent security password will be verified during the creation process. this is set during registration, not the password used for logon.
2. after the code is created, go to the next step and upload the code.
First, click the application we created and select code management in the functional area on the left:
The operations shown in the left-side operation area are as follows:
Click the operation button and select Upload code-delete. Select Upload code. In this step, the server is like this, and then we need to sort out the code we want to upload.
II. PHP code
The simplest of course is to download the sample code provided in the Developer Documentation: http://mp.weixin.qq.com/mpres/htmledition/res/wx_sample.20140819.zip this link is directly downloaded.
Code start:
Define ("TOKEN", "weixin") shows the TOKEN we need to fill in when configuring the developer service. set it here and enter the correct TOKEN in the configuration. Because we need to perform verification before starting the developer service, the code execution at the beginning is as follows:
$ WechatObj = new wechatCallbackapiTest ();
$ WechatObj-> valid ();
In the sample code, we can see that the valid function executes the detection task. after the detection, this is not needed. Instead, we need to change the corresponding response information, so after we have successfully verified it, after the developer service function is enabled, you need to modify this code:
$ WechatObj-> responseMsg ();
This function corresponds to the operation for executing the response.
Jump to the responseMsg function. PHP syntax cannot be understood, but the function is relatively simple. you can get a general idea:
This section shows that welcome to wechat world is about to respond to user input messages. msgType = "text" indicates that the user sends the text information type, then the welcome message is returned. You can use this php file to upload the created SAE application, and then check the effect.
Here I also have some questions: I renamed this php file xxx.php and compressed it into a xxx.zip package. after performing the upload code operation mentioned above, I set the developer's URL and TOKEN, prompting that the server did not respond to the operation, I tried it several times but it didn't work. then I clicked to edit the code:
Then, we need to name the php file index. php. According to this modification, it was indeed successful, but why?
After setting, check-send a text message to the public account, and then return the set response information. So far, the developer service is successfully started, and further difficulties will begin.