


WeChat public platform message interface development and enable interface
Feb 21, 2017 pm 04:30 PMIn this WeChat public platform development tutorial, we assume that you already have the basics of PHP language program, MySQL database, computer network communication, and HTTP/XML/CSS/JS.
We will use the WeChat public account Fangbei Studio as an example to explain. See the QR code at the bottom.
This series of tutorials will guide you to complete the following tasks:
Apply for Baidu Cloud Platform resources
Enable WeChat public platform development Mode
##First article applying for server resources
Create Baidu Cloud Application
Apply for an account
Log in to http://developer .baidu.com/bae, use your email or mobile phone to register an account. Registration requires binding your mobile phone and verifying your email.Create application
After successful registration and login, click on the upper right side, and the following window will pop up.
說明:在以下的教程中,您可以將所有我填寫為pondbay的地方改為你的一個相應(yīng)的名稱,如果您沒有想好名稱,最簡單的方法就是qq這兩個字符+qq號碼,比如方倍工作室的QQ是1354386063,那么就將"pondbay"改為"qq1354386063"
注意:此處填寫的域名將要在下面填寫URL時用到??梢韵缺4嫦聛?。
Original text: http://ipnx.cn/
Create version
Original text: http://ipnx.cn/
Upload code
Change the token in the following code Change it to your name and save as index.php.注意:此處填寫的Token將要在下面填寫URL時用到??梢韵缺4嫦聛?。
<?php/* CopyRight 2013 www.doucube.com All Rights Reserved*/define("TOKEN", "pondbay");$wechatObj = new wechatCallbackapiTest();if (isset($_GET['echostr'])) { $wechatObj->valid(); }else{????$wechatObj->responseMsg(); }class?wechatCallbackapiTest {????public?function?valid() ????{????????$echoStr?=?$_GET["echostr"];????????if($this->checkSignature()){????????????echo?$echoStr;????????????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; ????????} ????}????public?function?responseMsg() ????{????????$postStr?=?$GLOBALS["HTTP_RAW_POST_DATA"];????????if?(!empty($postStr)){????????????$postObj?=?simplexml_load_string($postStr,?'SimpleXMLElement',?LIBXML_NOCDATA);????????????$fromUsername?=?$postObj->FromUserName;????????????$toUsername?=?$postObj->ToUserName;????????????$keyword?=?trim($postObj->Content);????????????$time?=?time();????????????$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($keyword?==?"?"?||?$keyword?==?"?") ????????????{????????????????$msgType?=?"text";????????????????$contentStr?=?date("Y-m-d?H:i:s",time());????????????????$resultStr?=?sprintf($textTpl,?$fromUsername,?$toUsername,?$time,?$msgType,?$contentStr);????????????????echo?$resultStr; ????????????} ????????}else{????????????echo?"";????????????exit; ????????} ????} }?>
, as shown below.
百度云應(yīng)用的創(chuàng)建就成功了。
?
第二篇 啟用開發(fā)模式
微信公眾平臺開發(fā)模式
高級功能
微信公眾平臺地址:https://mp.weixin.qq.com?
登錄微信公眾平臺后臺,選擇高級功能,進(jìn)入后就看到兩種模式
我們需要先關(guān)閉編輯模式。點擊編輯模式的進(jìn)入
滑動關(guān)閉
?
開發(fā)模式
進(jìn)入開發(fā)模式里面
?點擊成為開發(fā)者
彈出URL和Token填寫框
此處的URL為創(chuàng)建百度云應(yīng)用的域名,包括后面的duapp.com,而Token為index.php中定義的值。在這篇教程中如下:
URL:?????http://pondbay.duapp.com Token:??pondbay
填寫如下圖,
?提交成功
再滑動右上角啟用按鈕。
恭喜,你成功啟用開發(fā)模式。
?
自動回復(fù)
在上面的例子中,實現(xiàn)了一個發(fā)送“?”就能回復(fù)當(dāng)前時間的功能。
效果如下:
至此,你的微信公眾平臺賬號已經(jīng)實現(xiàn)自動回復(fù)了。
更多微信公眾平臺消息接口開發(fā) 啟用接口?相關(guān)文章請關(guān)注PHP中文網(wǎng)!
?

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)