官方提供的SDK只有一個文本消息功能,我們將所有消息的消息類型及事件響應都整理了進來,並且加入日志記錄,代碼如下:
<? ("TOKEN", "weixin" = (!(['echostr' -> } -> = ["echostr" (-> = ["signature" = ["timestamp" = ["nonce" = = (, , (, = ( = ( ( == } = ["HTTP_RAW_POST_DATA" (!( ->logger("R ". = (, 'SimpleXMLElement', = (-> ( "event": = ->receiveEvent( "text": = ->receiveText( "image": = ->receiveImage( "location": = ->receiveLocation( "voice": = ->receiveVoice( "video": = ->receiveVideo( "link": = ->receiveLink( : = "unknow msg type: ". ->logger("T ". } "" receiveEvent( = "" (-> "subscribe": = "歡迎關注方倍工作室 " .= (!(->EventKey))?("\n來自二維碼場景 ".("qrscene_","",->EventKey)):"" "unsubscribe": = "取消關注" "SCAN": = "掃描場景 ".-> "CLICK": (-> "COMPANY": = "方倍工作室提供互聯網相關產品與服務。" : = "點擊菜單:".-> "LOCATION": = "上傳位置:緯度 ".->Latitude.";經度 ".-> : = "receive a new event: ".-> = ->transmitText(, receiveText( = (-> ( "文本": = "這是個文本消息" "圖文": "單圖文": [] = ("Title"=>"單圖文標題", "Description"=>"單圖文內容", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958" "多圖文": [] = ("Title"=>"多圖文1標題", "Description"=>"", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958" [] = ("Title"=>"多圖文2標題", "Description"=>"", "PicUrl"=>"http://d.hiphotos.bdimg.com/wisegame/pic/item/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958" [] = ("Title"=>"多圖文3標題", "Description"=>"", "PicUrl"=>"http://g.hiphotos.bdimg.com/wisegame/pic/item/18cb0a46f21fbe090d338acc6a600c338644adfd.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958" "音樂": = ("Title"=>"最炫民族風", "Description"=>"歌手:鳳凰傳奇", "MusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3", "HQMusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3" : = "當前時間:".("Y-m-d H:i:s", (( (([0]['PicUrl' = ->transmitNews(, } ((['MusicUrl' = ->transmitMusic(, } = ->transmitText(, receiveImage( = ("MediaId"=>-> = ->transmitImage(, receiveLocation( = "你發送的是位置,緯度為:".->Location_X.";經度為:".->Location_Y.";縮放級別為:".->Scale.";位置為:".-> = ->transmitText(, receiveVoice( ((-> = ("MediaId"=>-> = ->transmitVoice(, } = "你剛才說的是:".-> = ->transmitText(, receiveVideo( = ("MediaId"=>->MediaId, "ThumbMediaId"=>->ThumbMediaId, "Title"=>"", "Description"=>"" = ->transmitVideo(, receiveLink( = "你發送的是鏈接,標題為:".->Title.";內容為:".->Description.";鏈接地址為:".-> = ->transmitText(, transmitText(, = " </xml>" = (, ->FromUserName, ->ToUserName, (), transmitImage(, = " </Image>" = (, ['MediaId' = " </xml>" = (, ->FromUserName, ->ToUserName, transmitVoice(, = " </Voice>" = (, ['MediaId' = " </xml>" = (, ->FromUserName, ->ToUserName, transmitVideo(, = " </Video>" = (, ['MediaId'], ['ThumbMediaId'], ['Title'], ['Description' = " </xml>" = (, ->FromUserName, ->ToUserName, transmitNews(, (!( = " " = "" ( .= (, ['Title'], ['Description'], ['PicUrl'], ['Url' = " </xml>" = (, ->FromUserName, ->ToUserName, (), ( transmitMusic(, = " </Music>" = (, ['Title'], ['Description'], ['MusicUrl'], ['HQMusicUrl' = " </xml>" = (, ->FromUserName, ->ToUserName, logger( ((['HTTP_APPNAME'])){ sae_set_display_errors( sae_debug( sae_set_display_errors( } (['REMOTE_ADDR'] != "127.0.0.1"){ = 10000 = "log.xml" (() and ((()) > )){( (, ('H:i:s')." ".."\r\n", ?>