收藏
回答

"errcode":48001,"errmsg":"api unauthorized rid:

https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.htmlhttps://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html

import requests

import json


# 替换为您自己的AppID和AppSecret

app_id = 'AppID'

app_secret = 'AppSecret'


# 获取access_token

token_url = f'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={app_id}&secret={app_secret}'

response = requests.get(token_url)

access_token = json.loads(response.text)['access_token']


# 替换为您自己的公众号的openid

openid = 'openid'


# 发送文本消息

send_url = f'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={access_token}'

data = {

    "touser": openid,

    "msgtype": "text",

    "text": {

        "content": "Hello, 微信公众号!"

    }

}

response = requests.post(send_url, data=json.dumps(data,ensure_ascii=False), headers={'Content-Type': 'application/json'})

print(response.text)

print(access_token)

报标题所示错误

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容