Home  >  Article  >  Backend Development  >  How to verify whether the user has followed the official account during WeChat activities in php

How to verify whether the user has followed the official account during WeChat activities in php

不言
不言Original
2018-08-20 15:59:073360browse

The content of this article is about how to verify whether the user has followed the public account during PHP WeChat activities. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

When we do WeChat activities, some activities require users to follow the official account before they can continue the activity or send gifts. Here we are required to verify whether the user has paid attention, so we need to use WeChat's ---- Get basic user information interface

Get basic user information (including UnionID mechanism)

Developers can obtain basic user information through OpenID. Please use https protocol.

接口调用请求说明
http请求方式: GET
https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN

Parameter Description

Parameter Is it necessary Description
access_token is calling interface credentials
openid is The identification of ordinary users, unique to the current public account
lang No Return to the country and region language version, zh_CN simplified, zh_TW traditional, en English

This interface only needs to pass in the token of your official account and the user's openid to obtain the user's basic information

##subscribe_sceneReturn to the source of channels that users follow, ADD_SCENE_SEARCH public account search, ADD_SCENE_ACCOUNT_MIGRATION public account migration, ADD_SCENE_PROFILE_CARD business card sharing, ADD_SCENE_QR_CODE scan QR code, ADD_SCENEqr_scenetwo-dimensional Code scanning scene (developer customization) qr_scene_strQR code scanning scene description (developer customization)
Parameter Description
subscribe Whether the user subscribes to the public account ID, when the value is 0, It means that this user has not followed the official account and cannot retrieve other information.
openid The user’s identifier, unique to the current public account
nickname The user’s nickname
sex The gender of the user, when the value is 1, it is male, when the value is 2, it is female, when the value is 0, it is unknown
city The city where the user is located
country The country where the user is located
province Province where the user is located
language The user’s language, simplified Chinese is zh_CN
headimgurl User avatar, the last value represents the square avatar size (0, 46, 64, 96, 132 values ​​are available, 0 represents a 640*640 square avatar), this item is empty when the user does not have an avatar. If the user changes their avatar, the original avatar URL will be invalid.
subscribe_time The time the user pays attention to is the timestamp. If the user has followed multiple times, the last follow time
unionid will only appear after the user binds the official account to the WeChat open platform account. field.
remark Remarks from public account operators to fans. Public account operators can add comments to fans in the WeChat public platform user management interface
groupid The group ID of the user (compatible with the old user group interface)
tagid_list The tag the user is tagged with ID list
PROFILE LINK Click on the name in the graphic page, ADD_SCENE_PROFILE_ITEM menu in the upper right corner of the graphic page, ADD_SCENE_PAID and follow after payment, ADD_SCENE_OTHERS Others
One of the columns is the subscribe field, which we can use to verify whether the user has followed the condition. When subscribe is 1, it proves that the user has followed our official account and can continue. When it is 0, it means that the user has not followed the relevant activities. At this time, we need to guide the user to follow the relevant public account (but we still need to master the relevant guidance skills to avoid being warned by WeChat. We can implicitly guide, such as receiving awards. Contact customer service or something like that)

If your event needs to be verified every time, it is not recommended to do caching to avoid users paying attention and then canceling to get the wool. But if your activity does not have much restrictions on whether the user will pay attention in the future, it is recommended to store it in the database or throw it into the redis permanent cache.

The specific method of obtaining token and curl will not be explained in detail in this chapter. You can just look at the relevant codes in the previous chapters. After all, it is very simple. Just use the code to obtain the user's openid and the relevant public account. information to obtain the token, and finally curl the above address to obtain the user information.

Related recommendations:

php implements WeChat public platform account custom menu class, public account

php implements WeChat public Unlimited mass sending of accounts, mass sending of php letters to the public

The above is the detailed content of How to verify whether the user has followed the official account during WeChat activities in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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