• 微信接口测试


    ""
    用于向指定用户发送消息
    前提:
    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)
  • 相关阅读:
    Pygal之掷骰子
    pygal之掷骰子 2颗面数为6的骰子
    matplotlib之scatter
    使用Flash Builder 4 beta和FlexUnit进行Test Driven Development
    FlexUnit单元测试(第二章FlexUnit基本应用)
    FlexUnit单元测试(第三章FlexUnit事件断言)
    [Flex]Flex SDK 4(Gumbo)更方便的自定义样式、自定义SparkSkin(二)
    Flex开源项目
    Flex 4 : Chart 控件
    Flex SDK 4(Gumbo)更方便的自定义样式、自定义SparkSkin(三)
  • 原文地址:https://www.cnblogs.com/qunxiadexiaoxiangjiao/p/9470794.html
Copyright © 2020-2023  润新知