微信公众号二次开发
2017-03-30 10:49
183 查看
<?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </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> </Music> </xml>"; $newsTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>1</ArticleCount> <Articles> <item> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <PicUrl><![CDATA[%s]]></PicUrl> <Url><![CDATA[%s]]></Url> </item> </Articles> </xml>"; //关注事件回复 if($postObj->MsgType == 'event'){ if($postObj->Event == 'subscribe'){ $msgType = 'news'; $title = '三月三!!!!'; $des = '好日子,欢迎你的到来!!!!'; $picurl = 'http://boolceshi.ittun.com/xie.jpg'; $url = 'http://www.zixue.it'; $resultful = sprintf($newsTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$picurl,$url); echo $resultful; }elseif($postObj->Event == 'CLICK'){ if($postObj->EventKey == '音乐'){ $msgType = 'music'; $title = '许嵩'; $des = '好听,唯美'; $url = 'http://boolceshi.ittun.com/22.mp3'; $resultful = sprintf($musicTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$url,$url); echo $resultful; } } } //关键词自动回复 if($postObj->MsgType == "text" ){ if($postObj->Content == '1'){ $content = '你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '你好'){ $content = '欢迎你来到布尔教育!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($keywords == '音乐'){ $msgType = 'music'; $title = '许嵩'; $des = '好听,唯美'; $url = 'http://boolceshi.ittun.com/22.mp3'; $resultful = sprintf($musicTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$url,$url); echo $resultful; }elseif($keywords == '图文'){ $msgType = 'news'; $title = '微信公开课!!!'; $des = '好听,好学,好玩!!!'; $picurl = 'http://boolceshi.ittun.com/bool.jpg'; $url = 'http://www.baidu.com'; $resultful = sprintf($newsTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$picurl,$url); echo $resultful; }else{ $content = '你好你好你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } }elseif($postObj->MsgType == 'image'){ $url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'; $data = [ 'api_key'=>'AWHXLEMVlhTju6raJrlAJS5R4gPe8jX_', 'api_secret'=>'j3etjvp-DZsz_SJpXdZNN0IOovVgO1KK', 'image_url'=>$postObj->PicUrl, 'return_landmark'=>'1', 'return_attributes'=>'age,gender', ]; $curl = curl_init(); //设置参数 curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER,0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //发送请求信息 $da = curl_exec($curl); //关闭请求资源 curl_close($curl); $arr = json_decode($da,true); $num = count($arr['faces']); if($num == '0'){ $content = '你的图片真好看!!!'; }else{ $content = '你的图片中有'.$num.'个人'; } $msgType = 'text'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'voice'){ $msgType = 'text'; $content = '你的声音真好听!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'location'){ $msgType = 'text'; $location_x = $postObj->Location_X; $location_y = $postObj->Location_Y; $url = 'http://api.map.baidu.com/place/v2/search?query=%E5%8E%95%E6%89%80&location=' . $location_x .','. $location_y .'&scope=2&radius=2000&output=json&ak=88H9M1sNCCGGWVz7A3VZjq6xCSLx6Va5'; $json = file_get_contents($url); $arr = json_decode($json,true); $content = ''; foreach($arr['results'] as $k => $v){ $content .= $v['name'] . '在' . $v['address'] . ',' . '距离你有' . $v['detail_info']['distance'] ."米,\n"; } $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } ?>
<?php echo $_GET['echostr']; exit; /*//微信服务器发送get请求到我们的服务器 //token、timestamp、nonce,signature $token = 'kaituozhe'; $timestamp = $_GET['timestamp']; $nonce = $_GET['nonce']; $signature = $_GET['signature']; //将token、timestamp、nonce三个参数进行字典序排序 $arr = array($token,$timestamp,$nonce); sort($array, SORT_STRING); //将三个参数字符串拼接成一个字符串进行sha1加密 $arr = implode($arr); $arr = sha1($arr); //开发者获得加密后的字符串可与signature对比,标识该请求来源于微信 if($arr == $signature){ $echostr = $_GET['echostr']; echo $echostr; exit; }*/ //--------------------------写文件(接收xml数据)--------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $a = $postObj->Content; file_put_contents('./a.txt', $a) //--------------------------回复消息--------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $textTpl = "<xml> <ToUserName><![CDATA[$fromuserName]]></ToUserName> <FromUserName><![CDATA[qq87080912]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[欢迎你好]]></Content> </xml>"; echo $textTpl; //--------------------------关键词回复--------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; if($postObj->MsgType == "text" ){ if($postObj->Content == '你好'){ $content = '你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '大帅是傻逼吗'){ $content = '大帅确实是傻逼!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }else{ $content = '不用问了大帅是傻逼'; 4000 $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } } //--------------------------接收不同类型的消息--------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; if($postObj->MsgType == "text" ){ if($postObj->Content == '你好'){ $content = '你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '大帅是傻逼吗'){ $content = '大帅确实是傻逼!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }else{ $content = '不用问了大帅是傻逼'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } }elseif($postObj->MsgType == 'image'){ $msgType = 'text'; $content = '你的图片真好看!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'voice'){ $msgType = 'text'; $content = '你的声音真美妙!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } //--------------------------布尔教育--11--LBS厕即送--------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"; if($postObj->MsgType == "text" ){ if($postObj->Content == '你好'){ $content = '你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '大帅是傻逼吗'){ $content = '大帅确实是傻逼!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }else{ $content = '不用问了大帅是傻逼'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } }elseif($postObj->MsgType == 'image'){ $msgType = 'text'; $content = '你的图片真好看!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'voice'){ $msgType = 'text'; $content = '你的声音真美妙!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'location'){ $msgType = 'text'; $location_x = $postObj->Location_X; $location_y = $postObj->Location_Y; $url = 'http://api.map.baidu.com/place/v2/search?query=%E5%8E%95%E6%89%80&location=' . $location_x .','. $location_y .'&scope=2&radius=2000&output=json&ak=ke9uqA3l6BgVgj7bCmiexVBt1FylWTL4'; $json = file_get_contents($url); $arr = json_decode($json,true); $content = ''; foreach($arr['results'] as $k => $v){ $content .= $v['name'] . '在' . $v['address'] . ',' . '距离你有' . $v['detail_info']['distance'] ."米,\n"; } $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } //--------------------------布尔教育--11--音乐恢复--------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </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> </Music> </xml>"; if($postObj->MsgType == "text" ){ if($postObj->Content == '你好'){ $content = '你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '大帅是傻逼吗'){ $content = '大帅确实是傻逼!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($keywords == '音乐'){ $msgType = 'music'; $title = '告别气球-周杰伦'; $des = '好听,唯美'; $url = 'http://v.150643.com/22.mp3'; $resultful = sprintf($musicTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$url,$url); echo $resultful; }else{ $content = '不用问了大帅是傻逼'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } }elseif($postObj->MsgType == 'image'){ $msgType = 'text'; $content = '你的图片真好看!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'voice'){ $msgType = 'text'; $content = '你的声音真美妙!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'location'){ $msgType = 'text'; $location_x = $postObj->Location_X; $location_y = $postObj->Location_Y; $url = 'http://api.map.baidu.com/place/v2/search?query=%E5%8E%95%E6%89%80&location=' . $location_x .','. $location_y .'&scope=2&radius=2000&output=json&ak=ke9uqA3l6BgVgj7bCmiexVBt1FylWTL4'; $json = file_get_contents($url); $arr = json_decode($json,true); $content = ''; foreach($arr['results'] as $k => $v){ $content .= $v['name'] . '在' . $v['address'] . ',' . '距离你有' . $v['detail_info']['distance'] ."米,\n"; } $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } //--------------------------布尔教育--11--人脸识别Face++-------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </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> </Music> </xml>"; if($postObj->MsgType == "text" ){ if($postObj->Content == '你好'){ $content = '你好!!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '大帅是傻逼吗'){ $content = '大帅确实是傻逼!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($keywords == '音乐'){ $msgType = 'music'; $title = '告别气球-周杰伦'; $des = '好听,唯美'; $url = 'http://v.150643.com/22.mp3'; $resultful = sprintf($musicTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$url,$url); echo $resultful; }else{ $content = '不用问了大帅是傻逼'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } }elseif($postObj->MsgType == 'image'){ $url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'; $data = [ 'api_key'=>'WrYx9bJJY5jjtPO2doK9mgLk1Rp2Aqi3', 'api_secret'=>'G4qM--7D_agRXSUnNly46roH_bb-SFX6', 'image_url'=>$postObj->PicUrl, 'return_landmark'=>'1', 'return_attributes'=>'age,gender', ]; $curl = curl_init(); //设置参数 curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER,0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //发送请求信息 $da = curl_exec($curl); //关闭请求资源 curl_close($curl); $arr = json_decode($da,true); $num = count($arr['faces']); if($num == '0'){ $content = '你的图片真好看!!!'; }else{ $content = '你的图片中有'.$num.'个人'; } $msgType = 'text'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'voice'){ $msgType = 'text'; $content = '你的声音真美妙!!!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'location'){ $msgType = 'text'; $location_x = $postObj->Location_X; $location_y = $postObj->Location_Y; $url = 'http://api.map.baidu.com/place/v2/search?query=%E5%8E%95%E6%89%80&location=' . $location_x .','. $location_y .'&scope=2&radius=2000&output=json&ak=ke9uqA3l6BgVgj7bCmiexVBt1FylWTL4'; $json = file_get_contents($url); $arr = json_decode($json,true); $content = ''; foreach($arr['results'] as $k => $v){ $content .= $v['name'] . '在' . $v['address'] . ',' . '距离你有' . $v['detail_info']['distance'] ."米,\n"; } $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } //--------------------------布尔教育--图文++-------------------------------- <?php /*echo $_GET['echostr']; exit;*/ //接收xml数据 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; //把xml数据转化成对象 $postObj = simplexml_load_string($postStr); $fromuserName = $postObj->FromUserName; $touserName = $postObj->ToUserName; $time = time(); $msgType = $postObj->MsgType; $keywords = $postObj->Content; $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </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> </Music> </xml>"; $newsTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>1</ArticleCount> <Articles> <item> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <PicUrl><![CDATA[%s]]></PicUrl> <Url><![CDATA[%s]]></Url> </item> </Articles> </xml>"; if($postObj->MsgType == "text" ){ if($postObj->Content == '你好'){ $content = '谢谢,你也好!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->Content == '你叫什么'){ $content = '我的名字叫:小帅!'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($keywords == '音乐'){ $msgType = 'music'; $title = '告别气球-周杰伦'; $des = '好听,唯美'; $url = 'http://v.150643.com/22.mp3'; $resultful = sprintf($musicTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$url,$url); echo $resultful; }elseif($keywords == '图文'){ $msgType = 'news'; $title = '微信公开课!!!'; $des = '好听,好学,好玩!!!'; $picurl = 'http://v.150643.com/22.jpg'; $url = 'http://www.baidu.com'; $resultful = sprintf($newsTpl,$fromuserName,$touserName,$time,$msgType,$title,$des,$picurl,$url); echo $resultful; }else{ $content = '你可以跟我说:你好,你叫什么,音乐。也可以跟我送图片、语音。'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } }elseif($postObj->MsgType == 'image'){ $url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'; $data = [ 'api_key'=>'WrYx9bJJY5jjtPO2doK9mgLk1Rp2Aqi3', 'api_secret'=>'G4qM--7D_agRXSUnNly46roH_bb-SFX6', 'image_url'=>$postObj->PicUrl, 'return_landmark'=>'1', 'return_attributes'=>'age,gender', ]; $curl = curl_init(); //设置参数 curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER,0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //发送请求信息 $da = curl_exec($curl); //关闭请求资源 curl_close($curl); $arr = json_decode($da,true); $num = count($arr['faces']); if($num == '0'){ $content = '你的图片真好看,怎么没有人?!'; }else{ $content = '你的图片中有'.$num.'个人'; } $msgType = 'text'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'voice'){ $msgType = 'text'; $content = '听到你的声音真是太好了。'; $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; }elseif($postObj->MsgType == 'location'){ $msgType = 'text'; $location_x = $postObj->Location_X; $location_y = $postObj->Location_Y; $url = 'http://api.map.baidu.com/place/v2/search?query=%E5%8E%95%E6%89%80&location=' . $location_x .','. $location_y .'&scope=2&radius=2000&output=json&ak=ke9uqA3l6BgVgj7bCmiexVBt1FylWTL4'; $json = file_get_contents($url); $arr = jso a1d6 n_decode($json,true); $content = ''; foreach($arr['results'] as $k => $v){ $content .= $v['name'] . '在' . $v['address'] . ',' . '距离你有' . $v['detail_info']['distance'] ."米,\n"; } $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); echo $resultful; } //--------------------------布尔教育--用户关注消息++--------------------------------
相关文章推荐
- 【2018最新】基于java的微信公众号二次开发视频教程
- 微信公众号二次开发
- 微信公众号二次开发
- 适合新手学习的laravel接入微信接口,实现微信公众号二次开发
- 微信公众号二次开发(一)-申请微信公众帐号及简单介绍
- 微信公众号二次开发
- 微信公众号二次开发 新浪云应用SAE Token验证失败
- 微信公众号二次开发(三)-介绍tortoisesvn开发工具
- 微信公众号二次开发(1)
- 微信公众号二次开发
- 微信公众号二次开发
- 微信公众号二次开发(二)-注册新浪SAE
- 微信公众号二次开发流程
- 微信公众号二次开发
- 微信公众号二次开发
- 配置微信公众号二次开发接口java代码
- 微信公众号二次开发之消息回复
- 微信公众号二次开发
- java二次开发微信公众号授权
- 微信公众号二次开发