下一节课程: Lbs开发(1342次播放)

5 秒后自动播放下一节
  重新观看
章节
笔记
提问
课件
反馈
捐赠
  • 推荐课程
  • 评论
  • 问答
  • 笔记
  • 课件下载
州平郡安

州平郡安

真正的很好!感谢分享!

3年前    添加回复 1

健康美丽喝撒呦

他的还是3G网络。这个视频该是多么的老

健康美丽喝撒呦 · 2020-04-13 14:32
回复
呵呵

呵呵

真正的很好!感谢分享!

2年前    添加回复 0

回复
对方正在输入...

对方正在输入...

2年前    添加回复 0

回复
zhi

zhi

<?php /** * wechat php test */ header('Content-type:text'); //define your token //定义TOKEN密钥 define("TOKEN", "zweixins"); //实例化微信对象 $wechatObj = new wechatCallbackapiTest(); //验证成功后注释掉valid方法 //$wechatObj->valid(); //开启自动回复功能 $wechatObj->responseMsg(); //定义类文件 class wechatCallbackapiTest { //实现valid验证方法:实现对接微信公众平台 public function valid() { //通过GET请求接收随机字符串 $echoStr = $_GET["echostr"]; //调用checkSignature方法进行用户(开发者)数字签名验证 //valid signature , option if($this->checkSignature()){ //如果成功,则返回接收到的随机字符串 echo $echoStr; //并退出 exit; } } public function responseMsg() { //get post data, May be due to the different environments //接收用户端(客户)发送过来的XML数据 $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data //判断XML数据是否为空 if (!empty($postStr)){ /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); //通过simplexml进行xml解析 PHP中有两大类可以完成对XML的解析,1.PHP的Dom模型2.通过simplexml模型 $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); //手机端 $fromUsername = $postObj->FromUserName; //微信公众平台 $toUsername = $postObj->ToUserName; //接收用户发送的关键词 $keyword = trim($postObj->Content); //接收用户消息类型 $msgType = $postObj->MsgType; //时间戳 $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>"; //音乐发送模块 $musicTpl = "<xml> <ToUserName>< ![CDATA[%s] ]></ToUserName> <FromUserName>< ![CDATA[%s] ]></FromUserName> <CreateTime>%s</CreateTime> <MsgType>< ![CDATA[%s] ]></MsgType> <Music> <Title>< ![CDATA[%s] ]></Title> <Description>< ![CDATA[%s] ]></Description> <MusicUrl>< ![CDATA[%s] ]></MusicUrl> <HQMusicUrl>< ![CDATA[%s] ]></HQMusicUrl> <ThumbMediaId>< ![CDATA[%S] ]></ThumbMediaId> </Music> </xml>"; if($msgType=='text'){ //判断用户发送关键词是否为空 if(!empty( $keyword )){ if($keyword=='智'){ //回复类型,如果为"text",代表文本类型 $msgType = "text"; //回复内容 $contentStr = "智哥你好哈"; //格式化字符串(对xml进行格式化操作,把里面相关的变量格式化成字符串) $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); //把XML数据返回给手机端 echo $resultStr; }elseif($keyword=='?' || $keyword=='?'){ //回复类型,如果为"text",代表文本类型 $msgType = "text"; //回复内容 $contentStr = "你想\n问\n什么"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); //把XML数据返回给手机端 echo $resultStr; }elseif($keyword=='音乐'){ //定义回复类型 $msgType = 'music'; //定义音乐标题 $title = '一生所爱'; //定义音乐描述 $desc = '《一生所爱》很好听的歌曲...'; //定义音乐链接 $url = 'https://music.163.com/outchain/player?type=2&id=25727660&auto=1&height=66'; //定义高清音乐链接 $hqurl = 'https://music.163.com/outchain/player?type=2&id=25727660&auto=1&height=66'; //格式化字符串 $resultStr = sprintf($musicTpl, $fromUsername, $toUsername, $time, $msgType, $title, $desc, $url, $hqurl); //返回XML数据到微信客户端 echo $resultStr; } } //如果用户发送的关键词为空,则返回下列字符串 else{ echo "Input something..."; } }elseif($msgType=='image'){ //回复类型,如果为"text",代表文本类型 $msgType = "text"; //回复内容 $contentStr = "你发送的是图片消息"; //格式化字符串(对xml进行格式化操作,把里面相关的变量格式化成字符串) $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); //把XML数据返回给手机端 echo $resultStr; } }else { echo ""; exit; } } //定义checkSignature方法 private function checkSignature() { // you must define TOKEN by yourself //判断TOKEN密钥是否定义 if (!defined("TOKEN")) { //如果没有定义则抛出异常,返回'TOKEN is not defined!'字符串 throw new Exception('TOKEN is not defined!'); } //接收微信加密签名 $signature = $_GET["signature"]; //接收时间戳信息 $timestamp = $_GET["timestamp"]; //接收随机数 $nonce = $_GET["nonce"]; //把TOKEN常量赋值给$token变量 $token = TOKEN; //把相关参数组装为数组(密钥文件、时间戳、随机数) $tmpArr = array($token, $timestamp, $nonce); // use SORT_STRING rule //通过字典法进行排序 sort($tmpArr, SORT_STRING); //把排序后的数组转化为字符串 $tmpStr = implode( $tmpArr ); //通过哈希算法对字符串进行加密操作 $tmpStr = sha1( $tmpStr ); //与加密签名进行对比 if( $tmpStr == $signature ){ return true; }else{ return false; } } } ?>

3年前 0

九现神龙111

九现神龙111

组装xml模板

3年前 0

九现神龙111

九现神龙111

for循环

3年前 0