WeChat public platform development interface (3) and Wechat development interface

Source: Internet
Author: User

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:

 
 
  1. <? Php
  2. Define ("TOKEN", "weixin ");
  3. $ WechatObj = new wechatCallbackapiTest ();
  4. $ WechatObj-> weixin_run ();
  5.  
  6. Class wechatCallbackapiTest {
  7.  
  8. Private $ fromUsername;
  9. Private $ toUsername;
  10. Private $ times;
  11. Private $ keyword;
  12. Private $ MsgType;
  13.  
  14. Public function responseMsg (){
  15. $ PostStr = $ GLOBALS ["HTTP_RAW_POST_DATA"];
  16. If (! Empty ($ postStr )){
  17. $ PostObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA );
  18. $ This-> fromUsername = $ postObj-> FromUserName;
  19. $ This-> toUsername = $ postObj-> ToUserName;
  20. $ This-> keyword = trim ($ postObj-> Content );
  21. $ This-> time = time ();
  22. $ This-> MsgType = $ postObj-> MsgType;
  23. } Else {
  24. Echo "Pay attention to <a href = 'HTTP: // {$ _ SERVER ['HTTP _ host']} '> http: // {$ _ SERVER ['HTTP _ host']} </a>, thanks! ";
  25. Exit;
  26. }
  27. }
  28.  
  29. Public function weixin_run (){
  30. $ This-> responseMsg ();
  31. If ($ this-> MsgType! = 'Event') {// attention
  32. $ Data = $ this-> getData ();
  33. $ This-> fun_xml ("news", $ data, count ($ data ));
  34. } Else {
  35. $ Data = $ this-> getWelData ();
  36. $ This-> fun_xml ("text", $ data, 1 );
  37. }
  38. }
  39.  
  40. // Type: text type, news text type
  41. // Text, array (content), array (ID)
  42. // News, array (title, Introduction, image, hyperlink),... smaller than 10), number of items
  43. Private function fun_xml ($ type, $ value_arr, $ count ){
  44. $ Con = "<xml>
  45. <ToUserName> <! [CDATA [{$ this-> fromUsername}]> </ToUserName>
  46. <FromUserName> <! [CDATA [{$ this-> toUsername}]> </FromUserName>
  47. <CreateTime >{$ this-> times} </CreateTime>
  48. <MsgType> <! [CDATA [{$ type}]> </MsgType> ";
  49. Switch ($ type ){
  50. Case "text ":
  51. $ Con. = "<Content> <! [CDATA [$ value_arr]> </Content> ";
  52. Break;
  53. Case "news ":
  54. $ Con. = "<ArticleCount >{$ count} </ArticleCount>
  55. <Articles> ";
  56. Foreach ($ value_arr as $ key => $ v ){
  57. $ Con. = "<item>
  58. <Title> <! [CDATA [{$ v [0]}]> </Title>
  59. <Description> <! [CDATA [{$ v [1]}]> </Description>
  60. <PicUrl> <! [CDATA [{$ v [2]}]> </PicUrl>
  61. <Url> <! [CDATA [{$ v [3]}]> </Url>
  62. </Item> ";
  63. }
  64. $ Con. = "</Articles> ";
  65. Break;
  66. }
  67. Echo $ con. "</xml> ";
  68. }
  69.  
  70. Private function getData (){
  71. // The database queries an article by keyword
  72.  
  73. //............
  74. //............
  75.  
  76. // Returns an array of article results
  77. Return $ data;
  78. }
  79.  
  80. Private function getWelData (){
  81. $ Data = "thank you for choosing AndyYang personal blog assistant. \ R \ n ".
  82. "Reply [1] Back to two latest articles \ r \ n ".
  83. "Reply [2] Return two popular articles \ r \ n ".
  84. "Reply [3] Return two hot comments \ r \ n ".
  85. "Reply [4] Back to two latest technical articles \ r \ n ".
  86. "Reply [5] Back to two latest writing articles \ r \ n ".
  87. "Reply to two other articles that return the search keyword \ r \ n ".
  88. "For more information, see <a href = 'HTTP: // www.webyang.net/mobile.php'> www.webyang.net </a>. Thank you for your support ~ ";
  89. ;
  90. Return $ data;
  91. }
  92. }

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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.