<?php namespace app\index\controller; class Index { public function index(){ if(isset($_GET['echostr'])){ $timestamp=$_GET['timestamp']; $nonce=$_GET['nonce']; $token='xiaofeng'; $signature=$_GET['signature']; $echostr=$_GET['echostr']; $array=array($timestamp,$nonce,$token); sort($array); $tmpstr=sha1(implode('',$array)); if($tmpstr==$signature && $echostr){ //第一次接入微信api接口时 header('content-type:text'); echo $echostr; exit; } }else{ $this->reponseMsg(); } } public function reponseMsg(){ //1.获取到微信推送过来post数据(xml格式) $postArr = file_get_contents("php://input") ; //2.处理消息类型,并设置回复类型和内容 /*<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]><
微信公众号接入代码
最新推荐文章于 2024-08-26 12:31:39 发布