在编写微信机器人的时候需要用到自定义API,并返回JOSON格式的数据,可以根据URL访问的指定参数来执行PHP函数。
比如请求地址为:
index.php?token=7fea03c63ac806607fea03c63ac80660&domain=baidu.com。
访问编写好的PHP页面index.php,需要获取到RUL中的参数&domain参数值:baidu.com,这个参数是PHP构造的时候固定的参数。
页面访问效果:

PHP获取访问URL指定参数值源代码:
<?php$requset_url=$_SERVER["REQUEST_URI"];$pattern="~&domain=(.*)~";$match=[];preg_match($pattern, $requset_url, $match);$url_sub=$match[1];echo $url_sub;?>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号