In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the Wechat public platform message interface development from the Hello2BizUser text to the subscribe event example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
I. handling of old events in Hello2BizUser
In the old concern incident, after the user followed the Wechat public platform account, the system sent a Hello2BizUser text to the public account for the user. In the public account backend development mode, the welcome word was sent by judging the word Hello2BizUser.
The code example is as follows:
If ($keyword = = "Hello2BizUser") {$contentStr = ""; $resultStr = $this- > transmitText ($object, $contentStr, $funcFlag); return $resultStr;}
If you make changes on the underlying interface, it will affect everyone. Generally speaking, such changes will not be made easily.
Why does Wechat want to modify this event? the disadvantage of this method is that if the user does not judge the event, then there will be no welcome words. It doesn't matter, and it doesn't matter if there is no welcome words. But many people's program code, all the process is directly to judge the key words. For example, we have seen the Wechat account of a hospital, and the user sends the registered number, which shows how many people are arranged in front of it, but the background program does not make a distinction. The Hello2BizUser is also sent as a registration ticket, and the Hello2BizUser registration is not found. I do not know how many people are in front of us, which makes the user strange and strange. In addition, if users take the initiative to send a Hello2BizUser, they will get the same content as the welcome message, although very few users will send it.
On the other hand, turning users' attention into events is more conducive to the realization of statistical functions. Using this event, we can more easily determine the number of followers and unsubscribers, while the original Hello2BizUser text push judgment may be inaccurate, because users can send it manually to form false follow statistics.
Second, "subscribe" subscription event judgment
Subscribe is a new event. We need to make a judgment on the event type first. We added the judgment to this event in the official example and modified it as follows:
$postObj = simplexml_load_string ($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $RX_TYPE = trim ($postObj- > MsgType); switch ($RX_TYPE) {case "text": $resultStr = $this- > receiveText ($postObj); break; case "event": $resultStr = $this- > receiveEvent ($postObj); break; default: $resultStr = "unknow msg type:". $RX_TYPE; break;}
Then determine the subscription event in the event receive handler function:
Private function receiveEvent ($object) {$contentStr = ""; switch ($object- > Event) {case "subscribe": $contentStr = "Hello, welcome to Fangbi Studio. New feeling, new experience!" ; break;} $resultStr = $this- > transmitText ($object, $contentStr); return $resultStr;}
This completes the processing under the subscription event of "subscribe".
2. Complete code
Thank you for reading this article carefully. I hope the article "sample Analysis of Wechat Public platform message Interface Development from Hello2BizUser text to subscribe events" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.