define("token",?"leo2012");
$wechatobj?=?new?test;
if?(isset($_get['echostr']))?{
????$wechatobj->valid();
}else{
????$wechatobj->responsemsg();
}
class?test
{
????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?=?"
????????????????????????
????????????????????????
????????????????????????
????????????????????????
????????????????????????
????????????????????????
????????????????????????
????????????if($keyword?==?"qqq"?||?$keyword?==?"ccc")
????????????{
????????????????$msgtype?=?"text";
????????????????$contentstr?=?date("y-m-d?h:i:s",time())."aaaaa";
????????????????$resultstr?=?sprintf($texttpl,?$fromusername,?$tousername,?$time,?$msgtype,?$contentstr);
????????????????echo?$resultstr;
????????????}
????????}else{
????????????echo?"";
????????????exit;
????????}
????}
}
?>
上面是代碼,輸入ccc或qqq后沒有自動(dòng)回復(fù),這是為什么?
你在else下面的echo?輸出一個(gè)字符串調(diào)試就明白了。
?$wechatObj->valid();
}else{
????$wechatObj->responseMsg();
}
class?Test???{}
兄弟!?你這個(gè)程序在哪里copy的,能不能仔細(xì)的看看??你的微信類和測(cè)試類?是什么鬼。。。。。。。。兩個(gè)類都不一樣?你怎么調(diào)方法
我看錯(cuò)了?不好意思?是我沒仔細(xì)看。。。。。。。
微信是一款手機(jī)通信軟件,支持通過手機(jī)網(wǎng)絡(luò)發(fā)送語音短信、視頻、圖片和文字。微信可以單聊及群聊,還能根據(jù)地理位置找到附近的人,帶給大家全新的移動(dòng)溝通體驗(yàn),有需要的小伙伴快來保存下載體驗(yàn)吧!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)