Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to handle subscription events in the development of php Wechat public platform

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to deal with subscription events in the development of php Wechat public platform. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

I. brief introduction

New users following the Wechat public platform will generate a subscription event, the subscribe event, which is not responded to in the default code.

After new users follow the public platform, they may want to know what features the platform provides and how to use it, which is, to put it more colloquially, the "instruction manual" for the platform.

This article will describe in detail the handling process of subscribe events and reply to the corresponding information to improve interactivity.

Second, train of thought analysis

Wechat currently provides five message types, which are:

Text message (text)

Picture message (image)

Geolocation message (location)

Link message (link)

Event push (event)

After receiving the message, you first need to judge the message type, and then deal with different types of messages. In the event push, there are three event types: subscribe (subscription), unsubscribe (unsubscribe) and CLICK (custom menu click event), which need to be judged again; after judging as the subscribe event, reply to the user according to the set welcome message.

Third, judge the type of message

$postObj = simplexml_load_string ($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $RX_TYPE = trim ($postObj- > MsgType); switch ($RX_TYPE) {case "text": $resultStr = $this- > handleText ($postObj); break; case "event": $resultStr = $this- > handleEvent ($postObj); break; default: $resultStr = "Unknow msg type:". $RX_TYPE; break;}

Description:

$RX_TYPE = trim ($postObj- > MsgType); get message type; case "text": $resultStr = $this- > handleText ($postObj); use handleText () function to process text messages; case "event": $resultStr = $this- > handleEvent ($postObj); use handleEvent () function to handle event push

Fourth, judge the type of event

Switch ($object- > Event) {case "subscribe": $contentStr = "Thank you for following [Zhuojin Suzhou]."\ n "WeChat account: zhuojinsz". "\ n". Excellent Beautiful City Suzhou, we provide you with Suzhou local life guide, Suzhou related information query, to be the best Suzhou Wechat platform. " . "\ n". At present, the functions of the platform are as follows: "."\ n "." [1] check the weather, such as input: Suzhou Weather. "\ n". "[2] check bus, such as input: Suzhou bus 178". "\ n". "[3] translation, such as input: translation I love you."\ n "." [4] Suzhou information query, such as input: Suzhou Guanqian Street. "\ n". For more information, please look forward to...; break; default: $contentStr = "Unknow Event:". $object- > Event; break;}

Description:

If it is a subscribe event, set the reply as "Thank you for your interest [Zhuojin Suzhou]."

5. Complete code

This is the end of the article on "how to deal with subscription events in the development of php Wechat public platform". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report