微信接口测试

news/2024/6/29 10:29:44
""
用于向指定用户发送消息
前提:
1. 申请账号
"appid": 'wx65d37317efb972e0',
"secret": 'f59dc1e2f5e3641145a213027fb122cc',
2. 知道用户的微信ID
othEL0hlOrdBIRLLXuX0BA8frGZE





"""
import json
import requests

# 1. 伪造浏览器向 https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential... 发送GET请求,并获取token
r1 = requests.get(
url="https://api.weixin.qq.com/cgi-bin/token",
params={
"grant_type": "client_credential",
"appid": 'wxef0ccb22d20e98fe',
"secret": '16b49b6dbdb332dba4286c254c9ce433',
}
)

access_token = r1.json().get('access_token')

# 2. 给指定用户发送普通消息消息:access_token/
"""
wx_id = 'o6xWq1WAoD4vWJ8lYcMFEc8PCjfM'

body = {
"touser": wx_id,
"msgtype": "text",
"text": {
"content": '骑兵步兵'
}
}

r2 = requests.post(
url="https://api.weixin.qq.com/cgi-bin/message/custom/send",
params={
'access_token': access_token
},
data=bytes(json.dumps(body,ensure_ascii=False),encoding='utf-8')
)

print(r2.text)
"""
# 3. 给指定用户发送模板消息:access_token/
#
wx_id = 'o6xWq1WAoD4vWJ8lYcMFEc8PCjfM'

body = {
"touser": wx_id,
"template_id": 'kiAQoj1dbd3Ybjw8inuLwwfB-KlhzTPcMgRkBbmV-9M',
"data": {
"user": {
"value": "付萍女士",
"color": "#173177"
}
}
}

r2 = requests.post(
url="https://api.weixin.qq.com/cgi-bin/message/template/send",
params={
'access_token': access_token
},
data=json.dumps(body)
)

print(r2.text)

# response = requests.post(
# url="https://api.weixin.qq.com/cgi-bin/message/custom/send",
# params={
# 'access_token': access_token
# },
# data=bytes(json.dumps(body, ensure_ascii=False), encoding='utf-8')
# )
# # 这里可根据回执code进行判定是否发送成功(也可以根据code根据错误信息)
# result = response.json()
# print(result)

转载于:https://www.cnblogs.com/qunxiadexiaoxiangjiao/p/9470794.html


http://www.niftyadmin.cn/n/3018941.html

相关文章

嵌入式linux学习笔记---TCP立即发出 以及 TCP的keep alive

事情的起因是公司的产品的某一个功能存在的bug,所以就有了本次的探索。 需求: 产品在某一个端口上 定时的向外发送1440 字节的数据包,该数据包包含了产品当前的各种状态。 需求2 : 产品本身绑定一个本地的端口 接收来自外部的字符…

Flink Sort-Shuffle写简析

文章目录1、配置2、初始创建3、成员变量4、写shuffle文件4.1、获取SortBuffer4.2、追加数据4.3、buffer不足的处理4.4、buffer不足数据未读完5、关于排序5.1、segment申请5.2、writeIndex5.2.1、获取当前可用segment5.2.2、写入index到segment5.2.3、更新partition最后数据的索…

Flink Sort-Shuffle读简析

文章目录1、SortMergeResultPartition的创建使用2、PartitionedFileReader2.1、moveToNextReadableRegion2.2、readCurrentRegion2.3、hasRemaining3、读操作的调用4、数据返回4.1、读入缓存4.2、buffersRead读取1、SortMergeResultPartition的创建使用 首先是一个读过程的一个…

信息社会

消息 通知 公告(简报) 新闻(深度分析文章) 历史(沉淀形成知识) 各部门的信息系统 陕西省住房和城乡建设厅 陕西省建筑市场监管平台陕西省质量安全监管信息系统陕西省标准定额协同管理平台陕西省房地产市场监管信息系统陕西省城市园林绿化企业信息管理系统陕西省执业资格注册人员…

java 实现方法_java常见代码(1)------常见实现方法

1.equals 和 hashcode方法class Students {String name;int age;byte[] idSequence;Overridepublic boolean equals(Object obj) {if (!(obj instanceof Students))return false;Students other (Students) obj;return name.equals(other.name)&& age other.age&…

JdbcSink 简析

文章目录1、JdbcSink1.1、参数1.2、返回2、JdbcBatchingOutputFormat2.1、参数2.2、open方法2.2.1、连接数据库2.2.2、JdbcExec2.2.3、scheduler2.3、writeRecord方法2.3.1、缓存数据2.3.2、flush1、JdbcSink 用于DataStream增加Jdbc的Sink输出,主要两个接口&#x…

机器学习(1)_R与神经网络之Neuralnet包

本篇博客将会介绍R中的一个神经网络算法包:Neuralnet,通过模拟一组数据,展现其在R中是如何使用,以及如何训练和预测。在介绍Neuranet之前,我们先简单介绍一下神经网络算法。 人工神经网络(ANN),简称神经网络…

C# List.ForEach 方法

C#中List.ForEach 方法是对 List 的每个元素执行指定操作。 示例: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace AppExample {class Program{static void Main(string[] args){…