博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
订阅号功能----音乐
阅读量:7294 次
发布时间:2019-06-30

本文共 6268 字,大约阅读时间需要 20 分钟。

hot3.png

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;            $type =$postObj->MsgType;   $customevent=$postObj->Event;            $latitude=$postObj->Location_X;            $longitude=$postObj->Location_Y;   $keyword = trim($postObj->Content);   $time = time();   $textTpl = "
      
      
      
%s
      
      
      
0
      
";        $musicTpl="
        
        
          
%s
           
           
                
<![CDATA[%s]]>              
                
                
                   
        
";             if($type=="event" )//and $customrevent=="subscribe")            {                 $msgType = "text";                    $contentStr="感谢您的关注\n 回复1可查看联系方式 \n 回复2可还钱 \n 回复3可查看各种小吃";                  $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                 echo $resultStr;            }            else    {                switch($type)                {                    case "text":                 {                      $msgType = "text";                     if(!empty( $keyword ))                     {                                                                           if($keyword=="1")                         {                             $contentStr="广东工业大学工二馆,联系方式:18790652159,联系人:张星星";                         }                         else if($keyword=="2")                         {                             $contentStr="请将钱打入工行卡88888888,于五个工作日内,谢谢配合";                         }                         else if($keyword=="3")                         {                             $contentStr="饿了吗?河南小吃,广东小吃,台湾小吃,各种美味等着你哦";                         }                         else                             $contentStr = "hi,感谢您的关注!您的请求不正确,请重新申请。祝您每天生活愉快,牙齿天天晒------熳熳";                          }                     else                     {                         $contentStr= "Input something...";                     }                      $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                                          if($keyword=="音乐")                     {                        $Title="纯真年代";                        $Description="离婚前规则主题曲";                        $MusicUrl="http://1.zhangxuman.sinaapp.com/music/1.mp3";                        $HQMusicUrl= $MusicUrl;                        $msgType="music";                    $resultStr = sprintf($musicTpl, $fromUsername, $toUsername, $time, $msgType,$Title,$Description,$MusicUrl,$HQMusicUrl);                                                 }                                             break;                      }                                       case "voice":                    {                        $msgType = "text";                        $contentStr="语音功能尚未完善,请输入文本信息";                        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                        break;                    }                    case "image":                    {                        $msgType = "text";                        $contentStr="你的图片很漂亮";                        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                        break;                    }                                        case "location":                    {                        $msgType = "text";                        $contentStr="你的纬度是{$latitude},经度是{$longitude},我们已经锁定!";                        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                        break;                    }                    case "link":                    {                        $msgType = "text";                        $contentStr="你的链接有病毒吧!";                        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                        break;                    }                                        default :                    {                        $msgType = "text";                        $contentStr="此功能尚未开发";                        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                        break;                    }                }                   }             echo $resultStr;  }                              else         {         exit;        } }         function replymusic()       //回复音乐 {    $musicTpl="
    
    
    
12345678
    
    
    
<![CDATA[纯真年代]]>    
    
    
    
    
    
";     $resultStr = sprintf($musicTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);     echo $resultStr; }     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;  }  }}?>

比上一篇博文多了一个“音乐”的功能,当输入“音乐”,就会回复“纯真年代”

转载于:https://my.oschina.net/zhangxuman/blog/340747

你可能感兴趣的文章
设计模式(十)享元模式Flyweight(结构型)
查看>>
有图有真相!同是滑屏,荣耀Magic2不只比小米MIX3缝隙小,还更稳定
查看>>
AI+云 华为开启智能时代新纪元
查看>>
就是好骑!骑ofo小黄蜂和舒畅早晨say hi,跟闹心堵车say bye
查看>>
张旭豪:外卖概念的三点进化
查看>>
只用来保存JQuery lightbox图片用的
查看>>
C#学习笔记——MDI窗体(多文档界面)
查看>>
C++命名空间 namespace的作用和使用解析
查看>>
如果觉得职业看不到头,趁早换工作吧
查看>>
httpClient学习的初步认识
查看>>
SpringMVC 中整合JSON、XML视图一
查看>>
android151 笔记
查看>>
upload size of asp.net
查看>>
《算法设计手册》面试题解答 第三章:数据结构
查看>>
Windows Phone笔记(3)触摸简介
查看>>
Django使用心得(二)
查看>>
13个JavaScript图表图形绘制插件
查看>>
面状县级行政区划转地级行政区划,并关联属性字段
查看>>
用Session和唯一索引字段实现通用Web分页功能
查看>>
升级 Visual Studio 2015 CTP 5 的坑、坑、坑
查看>>