php微信開發(fā)之圖片回復(fù)功能
更新時(shí)間:2018年06月14日 10:17:17 作者:qiphon3650
這篇文章主要為大家詳細(xì)介紹了php微信開發(fā)之圖片回復(fù)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了php微信圖片回復(fù)功能的具體代碼,供大家參考,具體內(nèi)容如下
<?php
/**
* wechat php test
*/
//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
//$wechatObj->valid();
$wechatObj->responseMsg();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$type = $postObj->MsgType;
$customrevent = $postObj->Event;
$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($type=="event" and $customrevent=="subscribe"){
$contentStr = "33333333333";
$msgType = "text";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
if($type=="image" ){
$contentStr = "你的圖片很棒!";
$msgType = "text";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
if(!empty( $keyword ))
{
$msgType = "text";
if($keyword=="1"){
$contentStr = "333";}
if($keyword=="2"){
$contentStr = "444
if($keyword=="3"){
$contentStr = "11";}
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else{
echo "Input something...";
}
}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;
}
}
}
?>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- php微信開發(fā)之音樂回復(fù)功能
- php微信開發(fā)之關(guān)鍵詞回復(fù)功能
- php微信公眾號(hào)開發(fā)(4)php實(shí)現(xiàn)自定義關(guān)鍵字回復(fù)
- php版微信開發(fā)之接收消息,自動(dòng)判斷及回復(fù)相應(yīng)消息的方法
- php版微信公眾平臺(tái)回復(fù)中文出現(xiàn)亂碼問題的解決方法
- 微信公眾號(hào)開發(fā)之文本消息自動(dòng)回復(fù)php代碼
- 驗(yàn)證token、回復(fù)圖文\文本、推送消息的實(shí)用微信類php代碼
- PHP微信開發(fā)之模板消息回復(fù)
- PHP微信開發(fā)之文本自動(dòng)回復(fù)
- PHP微信開發(fā)之微信消息自動(dòng)回復(fù)下所遇到的坑
相關(guān)文章
Yii2框架制作RESTful風(fēng)格的API快速入門教程
Yii提供了一整套用來簡(jiǎn)化實(shí)現(xiàn)RESTful風(fēng)格的WebService服務(wù)的API。這篇文章主要介紹了Yii2框架制作RESTful風(fēng)格的API快速入門教程的相關(guān)資料,需要的朋友可以參考下2016-11-11
php處理靜態(tài)頁(yè)面:頁(yè)面設(shè)置緩存時(shí)間實(shí)例
本篇文章主要介紹了php處理靜態(tài)頁(yè)面:頁(yè)面設(shè)置緩存時(shí)間實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
Smarty最簡(jiǎn)單實(shí)現(xiàn)列表奇偶變色的方法
這篇文章主要介紹了Smarty最簡(jiǎn)單實(shí)現(xiàn)列表奇偶變色的方法,實(shí)例分析了Smarty屬性與方法的相關(guān)使用技巧,需要的朋友可以參考下2015-07-07
Laravel框架文件上傳功能實(shí)現(xiàn)方法示例
這篇文章主要介紹了Laravel框架文件上傳功能實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Laravel框架文件上傳相關(guān)步驟,包括配置、上傳功能實(shí)現(xiàn)技巧及相關(guān)注意事項(xiàng),需要的朋友可以參考下2019-04-04
PHP使用數(shù)組依次替換字符串中匹配項(xiàng)
這篇文章主要介紹了PHP使用數(shù)組依次替換字符串中匹配項(xiàng)的相關(guān)資料,需要的朋友可以參考下2016-01-01
thinkPHP批量刪除的實(shí)現(xiàn)方法分析
這篇文章主要介紹了thinkPHP批量刪除的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了thinkPHP實(shí)現(xiàn)批量刪除數(shù)據(jù)的數(shù)據(jù)庫(kù)及模板操作相關(guān)技巧,需要的朋友可以參考下2016-11-11

