WeChat public account development WeChat public account determines whether the user has paid attention to PHP code analysis

PHP中文网
Release: 2016-07-28 08:28:52
Original
1524 people have browsed it

Many of today’s activities guide users to follow public accounts in order to participate in the activities. So how can we judge that users have followed public accounts? This article will provide you with php code to solve the problem.

Official interface description
Get basic user information (including UnionID mechanism)

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

1. As long as there is a basic access_token and user openid It can be judged whether the user follows the official account
2. The interface URL used is: https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$openid3. Determine the fields returned by the interface Whether subscribe is 1. [1 following, 0 not following]

Note:
1. To determine that the user login method is silent authorization, the user is unaware, and thus get the user's openid;
2. To determine the user's login, WeChat authentication is required Service account support, subscription account does not work;

The following is a code example

< ? php

$access_token = $this - > _getAccessToken();
$subscribe_msg = &#39;https://api.weixin.qq.com/cgi-bin/user/info?access_token=&#39;.$access_token.&#39;&openid=&#39;.$_SESSION[&#39;wecha_id&#39;];
$subscribe = json_decode($this - > curlGet($subscribe_msg));
$zyxx = $subscribe - > subscribe;

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

The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above introduces the development of WeChat public account. WeChat public account determines whether the user has paid attention to PHP code analysis, including the content of WeChat public account development. I hope it will be helpful to friends who are interested in PHP tutorials.


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template