python --检测用户是否关注公众号(UID机制)

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')!

python --检测用户是否关注公众号(UID机制)_第1张图片

你可能感兴趣的:(python,开发语言)