接收xml数据-回复消息-关键词回复-接收不同类型的消息-LBS厠即送-回复音乐消息-Face++-回复图文-关注事件回复-了解自定义菜单-自定义菜单创建-自定义菜单整合项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
/*-------------------------*******微信开发*****----------------------------------*/ <?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 = '不用问了大帅是傻逼'; $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; } //----------------------------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; } //----------------------------音乐恢复--------------------------------- <?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; } //--------------------------人脸识别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 = 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 == '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; } ?> |

我的微信
把最实用的经验,分享给最需要的读者,希望每一位来访的朋友都能有所收获!
2017年3月30日 下午4:26 1F
代码大师
2017年4月2日 下午11:41 2F
支持楼主,赞赞