python -- detect whether the user pays attention to the official account (UID mechanism)

class Followofficial(object):
    '''检测是否关注公众号'''

    def _get_access_token(self):
        url = 'https://api.weixin.qq.com/cgi-bin/token?appid=&secret=&grant_type=client_credential'
        result = requests.get(url).json()
        print(f'获取token:【{result}】')
        return result.get('access_token')


    def detection(self, openid: str):
        '''检测是否关注公众号'''
        access_token = self._get_access_token()
        url = f'https://api.weixin.qq.com/cgi-bin/user/info?access_token={access_token}&openid={openid}&lang=zh_CN'
        result = requests.get(url).json()
        print(f'获取用户信息:【{result}】')
        return result.get('subscribe')!

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44634704/article/details/131946727