In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to realize the development of Wechat public platform and cancel the attention to events". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
The specific analysis is as follows:
When users follow or cancel their official account, Wechat will push the event to the URL filled in by the developer, making it convenient for the developer to send a welcome message to the user or unbind the account.
The following is an example of following and canceling followers on Wechat public platform. The code is as follows:
The copy code is as follows:
Define ("TOKEN", "w3note"); / / define the identification code
$wechatObj = new wechatCallbackapiTest (); / / instantiate the wechatCallbackapiTest class
If (! isset ($_ GET ["echostr"])) {
$wechatObj- > responseMsg ()
} else {
$wechatObj- > valid ()
}
Class wechatCallbackapiTest
{
Public function valid ()
{
$echoStr = $_ GET ["echostr"]
If ($this- > checkSignature ()) {
Echo $echoStr
Exit
}
}
Public function responseMsg () / / execute the receiver method
{
$postStr = $GLOBALS ["HTTP_RAW_POST_DATA"]
If (! emptyempty ($postStr)) {
$postObj = simplexml_load_string ($postStr, 'SimpleXMLElement', LIBXML_NOCDATA)
$RX_TYPE = trim ($postObj- > MsgType)
Switch ($RX_TYPE) {
Case "event":
$result = $this- > receiveEvent ($postObj)
Breadk
}
Echo $result
} else {
Echo ""
Exit
}
}
Private function receiveEvent ($object) {
$content = ""
Switch ($postObj- > Event) {
Case "subscribe":
$content = "Welcome to follow the blog"; / / here are the tips sent to followers
Break
Case "unsubscribe":
$content = ""
Break
}
$result = $this- > transmitText ($object,$content)
Return $result
}
Private function transmitText ($object,$content) {
$textTpl = "
% s
0
"
$result = sprintf ($textTpl, $object- > FromUserName, $object- > $ToUserName, time (), $content)
Return $result
}
Private function checkSignature ()
{
$signature = $_ GET ["signature"]
$timestamp = $_ GET ["timestamp"]
$nonce = $_ GET ["nonce"]
$token = TOKEN
$tmpArr = array ($token, $timestamp, $nonce)
Sort ($tmpArr, SORT_STRING)
$tmpStr = implode ($tmpArr)
$tmpStr = sha1 ($tmpStr)
If ($tmpStr = = $signature) {
Return true
} else {
Return false
}
}
}
Code related parameters description:
Parameter description ToUserName developer WeChat account (an OpenID) CreateTime message creation time (integer) MsgType message type, eventEvent event type, subscribe (subscription), unsubscribe (unsubscription) "how to achieve Wechat public platform development attention and unfollow events" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.