This article introduces the content is about the public development of a complete tutorial three, has a certain reference value, now share to everyone, the need for friends can refer to
because of the needs of the work, this two years of public numbers and small procedures, project production more. That's why I'm going to write a full-fledged tutorial, of course, the best tutorial is the documentation for the work platform. I'm just here to tell you about the production process in my work. All relevant articles of the source, I hosted on my own GitHub above, welcome to the attention: address click Open Link . Next, we'll start our tutorial.
For development, in fact, the most important thing is to read the developer documentation, and carefully write and replace variables, there will be meticulous debugging errors, slowly achieve their own requirements. The second article refers to the Baidu map and Turing person, we this section describes:
First look at the effect: Turing robot
Use of Baidu Map:
In this section we begin to explain the use of custom menus: Tell the story, start talking about Baidu and Turing robot
1. Customize the Menu
The Documentation:
Types of buttons for custom menus:
Interface Description:
The code is as follows: (can be tested locally)
Public Function Creatmenu () {//The URL address of the assembly request = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=". $ this->accesstoken; $data = Array (//button for each element "button" =>array (//First one-level menu array (' type ' = ' = ' click ', "name" = > "Profile", "Key" and "info", Array ("name" = "Language Rank", "Sub_button" =>array ("name" = "Product List", "type" = > "View", ' url ' = + ' Http://xiaoziheng.club/home/demo/demo4 '), Array (' name ' = ' C + + ', ' type ' = ' = ' pic_ Sysphoto ', ' key ' = ' Sysptoto '), Array (' name ' = = ' java ', ' type ' = ' pic_weixin ', ' key ' = ' pic_weixin ')), Array (' type ' = = ' click ', ' name ' = ' xxxx ', ' key ' = ' content '));// convert data to JSON format $data = Json_encode ($data, Json_unescaped_unicode); $result = Http_curl ($url, $data, ' post ');d UMP ($result);}
The results are as follows:
2. Custom Menu Query:
Code:
Gets the custom menu public Function GetMenu () {$url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=". $this Accesstoken, $res =http_curl ($url); Var_dump ($res);}
Result: The array is displayed (slightly unusual here, but the result is no problem)
3. Custom Menu Removal:
Code:
Delete custom menu Public Function Delmenu () {$url = ' https://api.weixin.qq.com/cgi-bin/menu/delete?access_token= '. $this Accesstoken, $res =http_curl ($url);d UMP ($res);}
Results:
4. Push the events in the custom menu:
Document:
Code:
The results are as follows:
5. Follow the reply:
Document
The code is as follows:
The results are as follows:
6. Use of the database (use of the Turing device person):
We can build the data table of the keyword in the database, so that the content that the followers reply to can be controlled by us.
If no content is found, then we use a Turing device to help us:
First enter the official website:
Create a robot: I have applied for a
Get access to key:
To view the use of a document:
Code:
The equality match is based on the fields in the Keyword table $info = db (' Keyword ')->where (Array (' Keyword ' = $keyword))->find (); if (! $info) {// Use robot reply to "http://www.tuling123.com/openapi/api?key=96308475006241449b53013d66f8e387&info=" for non-matching keywords . $keyword; $result = file_get_contents ($url), $result = Json_decode ($result, true); if ($result [' C Ode '] = = 100000) {//reply text message $resultstr = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, ' text ', $result [' text ']);} ElseIf ($result [' code '] = = 200000) {$str = ' <a href= '. $result [' url ']. ' " > '. $result [' text ']. ' </a> ';//robot is differentiated as link $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, ' text ', $str);} ElseIf ($result [' Code '] ==302000) {//news $data in robot = $result [' list '];for ($i =0; $i <8; $i + +) {$Articles = "<item> <title><! [cdata[{$data [$i] [' article ']}]]></title> <description><! [cdata[{$data [$i] [' article ']}]]></descriPtion> <picurl><! [cdata[{$data [$i] [' Icon ']}]]></picurl> <url><! [cdata[{$data [$i] [' Detailurl ']}]]></url> </item> ';} $count = 1; $resultStr = sprintf ($newsTpc, $fromUsername, $toUsername, $time, ' News ', $count, $Articles); }else{//reply text Message $resultstr = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, ' text ', ' hug Sorry for not understanding, say again the question ');} echo $resultStr;//File_put_contents (' 2 ', 33333); exit;}
The effect is the same as my above.
7. Use of Baidu Map:
Geolocation-based location services, locating the specific address of a user based on latitude and longitude
LBS(locationBasedservice): geolocation-based services
$longitude Longitude
$latitude Latitude
Access to the interface:
The code is as follows:
The results are as of the beginning of the article.
The next section describes the development of Web page authorization ....
Related recommendations:
Public number Development Complete Tutorial II
Public number Development Complete tutorial One