亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home WeChat Applet WeChat Development Introduction to how to use PHP to develop WeChat to receive messages, automatically judge and reply to corresponding messages

Introduction to how to use PHP to develop WeChat to receive messages, automatically judge and reply to corresponding messages

Mar 20, 2017 pm 02:37 PM
php WeChat development

This article mainly introduces the development of the PHP version of WeChatreceiving messages, the method of automatically judging and replying to the corresponding messages, and involves the related operation skills of calling based on the WeChat message processinginterface, Friends in need can refer to

This article describes the example of the PHP version of WeChat development on how to receive messages, automatically judge and reply to corresponding messages. I share it with you for your reference. The details are as follows:

WeChat’s api is now powerful enough that you can freely call the content of our website or designated database to automatically reply and push messages, here Let me introduce you to a WeChat development note.

Send 1, 2, 3, 7 test corresponding messages, the menu mode needs to be upgraded to a service account, or the number of subscribers exceeds 500.

1. The messages sent by users are received through the developer URL submitted by you. You can get it by subscribing here. The data sent is in the xml format and needs to be parsed. The code is as follows:

$data?=?$GLOBALS["HTTP_RAW_POST_DATA"];
if?(!emptyempty($data))?{//接收消息并處理
$xml?=?(array)simplexml_load_string($data,?‘SimpleXMLElement',?LIBXML_NOCDATA);
return?$xml;
}

The reply also needs to return XML data format.

2. Actively send messages to users, query user information, and create custom menu (subscription accounts can also be used now), As well as some advanced functions, you need to obtain the appid and AppSecret in order to obtain the access_token.

Access_token is used by every interface in addition to receiving information. The access_token expires in 7200 milliseconds and needs to be obtained again.

Currently, I have implemented it, receiving messages, automatically judging and replying to the corresponding news, creating a custom menu, and performing corresponding operations after clicking on the custom menu, such as user lists. I feel that there is no difference between the current development model and the subscription model.

Here is a test example of testing the reply, the code is as follows:

<?php
/**
 * wechat php test
 */
//define your token
define("TOKEN", "你的申請(qǐng)上的token");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
class?wechatCallbackapiTest
{
?public?function?valid()
??{
????$echoStr?=?$_GET["echostr"];
????//valid?signature?,?option
????if($this->checkSignature()){
?????$this->responseMsg();
?????exit;
????}
??}
??public?function?responseMsg()
??{
?//get?post?data,?May?be?due?to?the?different?environments
?$postStr?=?$GLOBALS["HTTP_RAW_POST_DATA"];
????//extract?post?data
?if?(!emptyempty($postStr)){
????????$postObj?=?simplexml_load_string($postStr,?'SimpleXMLElement',?LIBXML_NOCDATA);
????????$fromUsername?=?$postObj->FromUserName;
????????$toUsername?=?$postObj->ToUserName;
????????$keyword?=?trim($postObj->Content);
????????$time?=?time();
??$msgType?=?"text";
????????$textTpl?=?"<xml>
????<ToUserName><![CDATA[%s]]></ToUserName>
????<FromUserName><![CDATA[%s]]></FromUserName>
????<CreateTime>%s</CreateTime>
????<MsgType><![CDATA[%s]]></MsgType>
????<Content><![CDATA[%s]]></Content>
????<FuncFlag>0</FuncFlag>
????</xml>";
??if(!emptyempty(?$keyword?))
????????{
?????????$contentStr?=?$this->keyrep($keyword);
???if(?emptyempty($contentStr)?)
???{
???$contentStr?="你是故意的吧,沒(méi)文化真可怕";//你是故意的吧,沒(méi)文化真可怕;
???}
???//$contentStr?=?@iconv('UTF-8','gb2312',$keyword);
?????????$resultStr?=?sprintf($textTpl,?$fromUsername,?$toUsername,?$time,?$msgType,?$contentStr);
?????????echo?$resultStr;
????????}else{
?????????$contentStr?=?'沒(méi)文化真可怕,居然不會(huì)打字!';//$this->keyrep($keyword);
?????????//$contentStr?=?@iconv('UTF-8','gb2312',$keyword);
???$resultStr?=?sprintf($textTpl,?$fromUsername,?$toUsername,?$time,?$msgType,?$contentStr);
?????????echo?$resultStr;
????????}
????}else?{
?????echo?"";
?????exit;
????}
??}
?private?function?checkSignature()
?{
????$signature?=?$_GET["signature"];
????$timestamp?=?$_GET["timestamp"];
????$nonce?=?$_GET["nonce"];
?$token?=?TOKEN;
?$tmpArr?=?array($token,?$timestamp,?$nonce);
?sort($tmpArr);
?$tmpStr?=?implode(?$tmpArr?);
?$tmpStr?=?sha1(?$tmpStr?);
?if(?$tmpStr?==?$signature?){
??return?true;
?}else{
??return?false;
?}
?}
?function?keyrep($key)
?{
?//return?$key;
?if(?$key=='嗨'?||?$key=='在嗎'?||?$key=='你好'?){
??$mt?=?mt_rand(1,17);
??$array?=?array(1=>'自殺中,稍后再說(shuō)...',2=>'有事找我請(qǐng)大叫!',3=>'我正在裸奔,已奔出服務(wù)區(qū)',4=>'我現(xiàn)在位置:WC;?姿勢(shì):下蹲;?臉部:抽搐;?狀態(tài):用力中。。。。',5=>'去吃飯了,如果你是帥哥,請(qǐng)一會(huì)聯(lián)系我,如果你是美女...............就算你是美女,我也要先吃飽肚子啊',6=>'
洗澡中~謝絕旁觀?。_^0',7=>'有熊出?],我去誘捕,盡快回來(lái)。',8=>'你好,我是500,請(qǐng)問(wèn)你是250嗎?',9=>'喂!亂碼啊,再發(fā)',10=>'
不是我不理你,只是時(shí)間難以抗拒!',11=>'你剛才說(shuō)什么,我沒(méi)看清楚,請(qǐng)?jiān)僬f(shuō)一遍!',12=>'發(fā)多幾次啊~~~發(fā)多幾次我就回你。',13=>'此人已死,有事燒紙!',14=>'乖,不急哦…',15=>'你好.我去殺幾個(gè)人,很快回來(lái).',16=>'本人已成仙?有事請(qǐng)發(fā)煙?佛說(shuō)有煙沒(méi)火成不了正果?有火沒(méi)煙成不了仙。',17=>'
你要和我說(shuō)話?你真的要和我說(shuō)話?你確定自己想說(shuō)嗎?你一定非說(shuō)不可嗎?那你說(shuō)吧,這是自動(dòng)回復(fù),反正我看不見(jiàn)其實(shí)我在~就是不回你拿我怎么著?'
);
??return?$array[$mt];
?}
?if(?$key=='靠'?||?$key=='啊'?||?$key=='阿'?)
?{
??$mt?=?mt_rand(1,19);
??$array?=?array(1=>'人之初?性本善?玩心眼?都滾蛋。',2=>'今后的路?我希望你能自己好好走下去?而我?坐車(chē)',3=>'笑話是什么?就是我現(xiàn)在對(duì)你說(shuō)的話。',4=>'人人都說(shuō)我丑?其實(shí)我只是美得不明顯。',5=>'A;豬是怎么死的?B;你還沒(méi)死我怎么知道',6=>'
奧巴馬已經(jīng)干掉和他同姓的兩個(gè)人?奧特曼你要小心了。?',7=>'有的人活著?他已經(jīng)死了?有的人活著?他早該死了。',8=>'"妹妹你坐船頭?哥哥我岸上走"據(jù)說(shuō)很傻逼的人看到都是唱出來(lái)的。',9=>'我這輩子只有兩件事不會(huì)?這也不會(huì)?那也不會(huì)。',10=>'
過(guò)了這個(gè)村?沒(méi)了這個(gè)店?那是因?yàn)橛蟹值辍?,11=>'我以為你只是個(gè)球?沒(méi)想到?你真是個(gè)球。',12=>'你終于來(lái)啦,我找你N年了,去火星干什么了?我現(xiàn)在去冥王星,回頭跟你說(shuō)個(gè)事,別走開(kāi)啊',13=>'你有權(quán)保持沉默,你所說(shuō)的一切都將被作為存盤(pán)記錄。你可以請(qǐng)代理服務(wù)器,如果請(qǐng)不起網(wǎng)絡(luò)會(huì)為你分配一個(gè)。',14=>'本人正在被國(guó)際刑警組織全球范圍內(nèi)通緝,如果您有此人的消息,請(qǐng)撥打當(dāng)?shù)貓?bào)警電話',15=>'洗澡中~謝絕旁觀?。_^0',16=>'嘀,這里是移動(dòng)秘書(shū),?美眉請(qǐng)?jiān)侔l(fā)一次,我就與你聯(lián)系;姐姐請(qǐng)?jiān)侔l(fā)兩次,我就與你聯(lián)系;哥哥、弟弟就不要再發(fā)了,因?yàn)榘l(fā)了也不和你聯(lián)系!',17=>'
其實(shí)我在~就是不回你拿我怎么著?',18=>'你剛才說(shuō)什么,我沒(méi)看清楚,請(qǐng)?jiān)僬f(shuō)一遍!',19=>'乖,不急。。。');
??return?$array[$mt];
?}
?if(?$key?=='請(qǐng)問(wèn)'?)
?{
??$mt?=?mt_rand(1,5);
??$array?=?array(1=>'"我臉油嗎"反光??反正我不清楚',2=>'走,我請(qǐng)你吃飯',3=>'此人已死,有事燒紙!',4=>'喂!什么?。y碼啊,再發(fā)',5=>'笑話是什么??就是我現(xiàn)在對(duì)你說(shuō)的話。');
??return?$array[$mt];
?}
?return?"";
?}
?function?keylist()
?{
?$array?=?array(1=>'嗨',2=>'你好',3=>'靠',4=>'在嗎',5=>'請(qǐng)問(wèn)');
?}
}
?>

The above is the detailed content of Introduction to how to use PHP to develop WeChat to receive messages, automatically judge and reply to corresponding messages. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
PHP calls AI intelligent voice assistant PHP voice interaction system construction PHP calls AI intelligent voice assistant PHP voice interaction system construction Jul 25, 2025 pm 08:45 PM

User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

How to use PHP to build social sharing functions PHP sharing interface integration practice How to use PHP to build social sharing functions PHP sharing interface integration practice Jul 25, 2025 pm 08:51 PM

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

How to use PHP combined with AI to achieve text error correction PHP syntax detection and optimization How to use PHP combined with AI to achieve text error correction PHP syntax detection and optimization Jul 25, 2025 pm 08:57 PM

To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

PHP creates a blog comment system to monetize PHP comment review and anti-brush strategy PHP creates a blog comment system to monetize PHP comment review and anti-brush strategy Jul 25, 2025 pm 08:27 PM

1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

How to use PHP to combine AI to generate image. PHP automatically generates art works How to use PHP to combine AI to generate image. PHP automatically generates art works Jul 25, 2025 pm 07:21 PM

PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

PHP realizes commodity inventory management and monetization PHP inventory synchronization and alarm mechanism PHP realizes commodity inventory management and monetization PHP inventory synchronization and alarm mechanism Jul 25, 2025 pm 08:30 PM

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

Beyond the LAMP Stack: PHP's Role in Modern Enterprise Architecture Beyond the LAMP Stack: PHP's Role in Modern Enterprise Architecture Jul 27, 2025 am 04:31 AM

PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

PHP integrated AI speech recognition and translator PHP meeting record automatic generation solution PHP integrated AI speech recognition and translator PHP meeting record automatic generation solution Jul 25, 2025 pm 07:06 PM

Select the appropriate AI voice recognition service and integrate PHPSDK; 2. Use PHP to call ffmpeg to convert recordings into API-required formats (such as wav); 3. Upload files to cloud storage and call API asynchronous recognition; 4. Analyze JSON results and organize text using NLP technology; 5. Generate Word or Markdown documents to complete the automation of meeting records. The entire process needs to ensure data encryption, access control and compliance to ensure privacy and security.

See all articles