python3微信企业号 发送图文

  • 时间:
  • 浏览:0

    post_data['touser'= UserID

    json_post_data1 = json.dumps(post_data1,False,False)

def get_token():  

UserID = "hequan2011"

def  send_tu(path):  

    return dict_result['access_token']

    Gtoken = get_token()

send_text("123-何全")  

Secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

    gurl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(ID, Secret)

    return request_post

    request_post = urllib.request.urlopen(purl2,json_post_data1.encode(encoding='UTF8'))

    post_data['msgtype'= 'text'

AppID = 0  

    post_data = {}

    msg_content1 = {}

ID="xxxxxxxxxxxx"  

    post_data['agentid'= AppID

    post_data1['msgtype'= 'image'

    purl1="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(Gtoken)

send_tu("1.png")  

    return request_post

    = requests.post(img_url, files=files)

    post_data1 = {}

    files = {'image'open(path, 'rb')}

    post_data1['touser'= UserID

def  send_text(text):  

PartyID=17  

    msg_content = {}

    Gtoken = get_token()

    post_data['text'= msg_content

    post_data1['image'= msg_content1

    request_post = urllib.request.urlopen(purl,json_post_data.encode(encoding='UTF8'))

def get_media_ID(path):  

    r=requests.get(gurl)

import requests

    dict_result= (r.json())

    re = json.loads(r.text)

    img_id = get_media_ID(path)

    post_data1['toparty'= PartyID

    purl2="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(Gtoken)

    post_data1['safe'= '0'

    post_data['toparty'= PartyID

    post_data1['agentid'= AppID

    Gtoken = get_token()

    post_data['safe'= '0'  

    return re['media_id']

    json_post_data = json.dumps(post_data,False,False)

    msg_content['content'= text  

import urllib.request

    msg_content1['media_id'= img_id

    img_url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={}&type=image".format(Gtoken)

import json

本例 只适用于企业号,公众号没试,可自行测试,妙招差很多。有事找官网开发文档。