Public platform development interface (3): Development Interface
I haven't written any article about the public account for a long time, and my research has come to an end, but I still share the complete code of some of my only functions. Hope everyone can make progress together:
- <? Php
- Define ("TOKEN", "weixin ");
- $ WechatObj = new wechatCallbackapiTest ();
- $ WechatObj-> weixin_run ();
-
- Class wechatCallbackapiTest {
-
- Private $ fromUsername;
- Private $ toUsername;
- Private $ times;
- Private $ keyword;
- Private $ MsgType;
-
- Public function responseMsg (){
- $ PostStr = $ GLOBALS ["HTTP_RAW_POST_DATA"];
- If (! Empty ($ postStr )){
- $ PostObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA );
- $ This-> fromUsername = $ postObj-> FromUserName;
- $ This-> toUsername = $ postObj-> ToUserName;
- $ This-> keyword = trim ($ postObj-> Content );
- $ This-> time = time ();
- $ This-> MsgType = $ postObj-> MsgType;
- } Else {
- Echo "Pay attention to <a href = 'HTTP: // {$ _ SERVER ['HTTP _ host']} '> http: // {$ _ SERVER ['HTTP _ host']} </a>, thanks! ";
- Exit;
- }
- }
-
- Public function weixin_run (){
- $ This-> responseMsg ();
- If ($ this-> MsgType! = 'Event') {// attention
- $ Data = $ this-> getData ();
- $ This-> fun_xml ("news", $ data, count ($ data ));
- } Else {
- $ Data = $ this-> getWelData ();
- $ This-> fun_xml ("text", $ data, 1 );
- }
- }
-
- // Type: text type, news text type
- // Text, array (content), array (ID)
- // News, array (title, Introduction, image, hyperlink),... smaller than 10), number of items
- Private function fun_xml ($ type, $ value_arr, $ count ){
- $ Con = "<xml>
- <ToUserName> <! [CDATA [{$ this-> fromUsername}]> </ToUserName>
- <FromUserName> <! [CDATA [{$ this-> toUsername}]> </FromUserName>
- <CreateTime >{$ this-> times} </CreateTime>
- <MsgType> <! [CDATA [{$ type}]> </MsgType> ";
- Switch ($ type ){
- Case "text ":
- $ Con. = "<Content> <! [CDATA [$ value_arr]> </Content> ";
- Break;
- Case "news ":
- $ Con. = "<ArticleCount >{$ count} </ArticleCount>
- <Articles> ";
- Foreach ($ value_arr as $ key => $ v ){
- $ Con. = "<item>
- <Title> <! [CDATA [{$ v [0]}]> </Title>
- <Description> <! [CDATA [{$ v [1]}]> </Description>
- <PicUrl> <! [CDATA [{$ v [2]}]> </PicUrl>
- <Url> <! [CDATA [{$ v [3]}]> </Url>
- </Item> ";
- }
- $ Con. = "</Articles> ";
- Break;
- }
- Echo $ con. "</xml> ";
- }
-
- Private function getData (){
- // The database queries an article by keyword
-
- //............
- //............
-
- // Returns an array of article results
- Return $ data;
- }
-
- Private function getWelData (){
- $ Data = "thank you for choosing AndyYang personal blog assistant. \ R \ n ".
- "Reply [1] Back to two latest articles \ r \ n ".
- "Reply [2] Return two popular articles \ r \ n ".
- "Reply [3] Return two hot comments \ r \ n ".
- "Reply [4] Back to two latest technical articles \ r \ n ".
- "Reply [5] Back to two latest writing articles \ r \ n ".
- "Reply to two other articles that return the search keyword \ r \ n ".
- "For more information, see <a href = 'HTTP: // www.webyang.net/mobile.php'> www.webyang.net </a>. Thank you for your support ~ ";
- ;
- Return $ data;
- }
- }
To be honest, I really want to get a service number for fun. The custom menu has no technical content, but the only service of the service number, such as payment, is worth trying...
I also hope that you can use the "webyangnet" support code.
More please support: http://www.webyang.net/Html/web/article_118.html
What are the areas for public platform interface development?
I have this course and can send it to you.
Highlight 1: Message Interaction
The message interface of the public platform provides developers with the ability to exchange messages with users. For a public account that successfully accesses the message interface, when a user sends a message to the public account, the public platform server uses an http request to push messages to the accessed URL, A third-party server can reply to a message through a response packet.
Highlight 2: New Mobile Service Forms
Open the public platform of the API, so that the public account has a larger space to play. Currently, querying bank balances, translating English words, booking hotels, booking movie tickets, Food Recommendations, dressing recommendations, and so on has sprung up to address the needs of different users.
Lecture 1st: Demonstration of public platform development models and Analysis of business models
And public platforms
Demonstration of message interface program based on public platform
Six business models
2nd Lecture: Principle Analysis of public platform interfaces, application for message interfaces, and verification of encrypted signatures
Public platform interface Principle Analysis
How to register a public account and apply for a message interface
Verify the request by verifying signature
Lecture 3rd: Introduction to the message interface of the public platform to implement the Hello world Entry Program
Introduction to message interfaces on the public platform
Compile the Hello world Entry Program
Write an event push program that welcomes new users to subscribe (subscription)
Lecture 4th: application example of the public platform "text message" and "Reply text message" interface (I)
Query students' scores
5th Lecture: application example of the public platform "text message" and "Reply text message" interface (below)
Implement calendar huangdaojiri Query
Lecture 6th: application example of the "geographic location message" interface on the public platform
Introduction to poi
Poi search
Lecture 7th: application example of the "Reply music message" API on the public platform
Online karaoke System
Lecture 8th: application example of the public platform "image message" and "Reply text message" interface (I)
Receives image messages and displays the path where the image is saved on the server.
Static Image Display and display of dynamic image information read from the database
Lecture 9th: application example of the public platform "image message" and "Reply text message" interface (lower)
Implement the Platform ordering system
Lecture 10th: Cross-Server query and other application instance analysis based on third-party information on the public platform
Weather forecast API provided by the National Meteorological Administration
Regional search POI service interface provided by Baidu Map
Baidu map coordinate conversion interface
Baidu map API ?? Web Service API --> Geocoding API v2.0
CURL transmission and retrieval in PHP
Implement the weather forecast query interface, latitude and longitude ?? Geographic address query interface and regional Search POI Service
How can I upload an application for interface development on a public platform to make the port respond?
Haha. If you do not understand this, you must rely on others to develop and learn more. Follow our public account binguome