发布日期: 2023-09-20 人气指数: -
我们在开发过程中有时需要判断用户有没有关注我的公众号,下面的代码可以完美解决:
<?php $access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=您的appid&secret=您的secret"; $access_msg = json_decode(file_get_contents($access_token)); $token = $access_msg->access_token; $openid = '您的openid '; $subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$openid"; $subscribe = json_decode(file_get_contents($subscribe_msg)); $gzxx = $subscribe->subscribe; if($gzxx === 1){ echo "已关注"; }else{ echo "未关注"; } ?>