我们每个人都在使用微信,那订阅号,公众号中的机器人以及关键字是如何实现的呢?
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use function Couchbase\defaultDecoder;
class ApiController extends Controller{
/*此处开始为机器人以及关键字回复*/
public function robot(){
define("TOKEN", "mengxianglei");
$wechatObj = new ApiController();
if(!isset($_GET['echostr'])){
$wechatObj->responseMsg();
}else{
$wechatObj->valid();
}
}
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 = file_get_contents("php://input");
// var_dump($postStr);die;
//extract post data
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLEle