微信公众号判断用户是否已关注php代码解析

网络编程 2021-07-05 09:10www.168986.cn编程入门
这篇文章主要大家详细解析了微信公众号判断用户是否已关注php代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

现在的活动,很多都引导用户关注公众号,才能参与到活动当中,那如何才能判断用户关注了公众号呢? 本文就为大家提供php代码,解决问题。

官方接口说明
获取用户基本信息(包括UnionID机制) 

http://mp.weixin.qq./wiki/14/bb5031008f1494a59c6f71fa0f319c66.html

1、只要有基础的aess_token和用户openid就可以判断用户是否关注该公众号
2、利用的接口url为:https://api.weixin.qq./cgi-bin/user/info?aess_token=$token&openid=$openid
3、判断接口返回的字段subscribe是否为1.【1关注,0未关注】

注:
1、判断用户登录的方式为静默授权,用户无感知,从而得到用户的openid;
2、判断用户登录,需要微信认证服务号的支持,订阅号不行; 

狼蚁网站SEO优化是代码案例

< ? php

$aess_token = $this - > _getAessToken();
$subscribe_msg = 'https://api.weixin.qq./cgi-bin/user/info?aess_token='.$aess_token.'&openid='.$_SESSION['wecha_id'];
$subscribe = json_decode($this - > curlGet($subscribe_msg));
$zyxx = $subscribe - > subscribe;

if ($zyxx !== 1) {
 echo'未关注!';
}
private function _getAessToken() {
 $where = array('token' = > $this - > token);
 $this - > thisWxUser = M('Wxuser') - > where($where) - > find();
 $url_get = 'https://api.weixin.qq./cgi-bin/token?grant_type=client_credential&appid='.$this - > thisWxUser['appid'].'&secret='.$this - > thisWxUser['appsecret'];
 $json = json_decode($this - > curlGet($url_get));
 if (!$json - > errmsg) {
 } else {
  $this - > error('获取aess_token发生错误:错误代码'.$json - > errcode.',微信返回错误信息:'.$json - > errmsg);
 }
 return $json - > aess_token;
}
? >

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by