亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

首頁 微信小程式 微信開發(fā) python3開發(fā)微信企業(yè)號(hào)傳送圖文方法

python3開發(fā)微信企業(yè)號(hào)傳送圖文方法

Mar 22, 2017 pm 01:53 PM

這篇文章介紹python3開發(fā)微信企業(yè)號(hào)發(fā)送圖文方法

本例 只適用于企業(yè)號(hào),公眾號(hào)沒試,可自行測(cè)試,方法差不多。有事找官網(wǎng)開發(fā)文檔。
 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import urllib.request
 
ID="xxxxxxxxxxxx"  
Secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
 
UserID = "hequan2011"##成員ID列表(消息接收者,多個(gè)接收者用'|'分隔,最多支持1000個(gè))。特殊情況:指定為@all,則向關(guān)注該企業(yè)應(yīng)用的全部成員發(fā)送
PartyID=17  ##部門ID列表,多個(gè)接收者用‘|’分隔,最多支持100個(gè)。當(dāng)touser為@all時(shí)忽略本參數(shù)
AppID = 0  ##應(yīng)用ID,默認(rèn)是 企業(yè)小助手  企業(yè)應(yīng)用的id,整型。可在應(yīng)用的設(shè)置頁面查看
 
 
 
def get_token():  ##獲取TOKEN
    gurl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(ID, Secret)
    r=requests.get(gurl)
    dict_result= (r.json())
    return dict_result['access_token']
def get_media_ID(path):  ##上傳到臨時(shí)素材  圖片ID
    Gtoken = get_token()
    img_url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={}&type=image".format(Gtoken)
    files = {'image': open(path, 'rb')}
    r = requests.post(img_url, files=files)
    re = json.loads(r.text)
    return re['media_id']
##
 
 
  
def  send_text(text):  ##發(fā)送文字
    post_data = {}
    msg_content = {}
    msg_content['content'] = text  ## 消息內(nèi)容,最長(zhǎng)不超過2048個(gè)字節(jié)
    post_data['touser'] = UserID
    post_data['toparty'] = PartyID
    post_data['msgtype'] = 'text'
    post_data['agentid'] = AppID
    post_data['text'] = msg_content
    post_data['safe'] = '0'  #表示是否是保密消息,0表示否,1表示是,默認(rèn)0
    Gtoken = get_token()
    purl1="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(Gtoken)
    json_post_data = json.dumps(post_data,False,False)
    request_post = urllib.request.urlopen(purl,json_post_data.encode(encoding='UTF8'))
    return request_post
     
     
     
def  send_tu(path):  ##發(fā)送圖片
    img_id = get_media_ID(path)
    post_data1 = {}
    msg_content1 = {}
    msg_content1['media_id'] = img_id
    post_data1['touser'] = UserID
    post_data1['toparty'] = PartyID
    post_data1['msgtype'] = 'image'
    post_data1['agentid'] = AppID
    post_data1['image'] = msg_content1
    post_data1['safe'] = '0'
    Gtoken = get_token()
    purl2="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(Gtoken)
    json_post_data1 = json.dumps(post_data1,False,False)
    request_post = urllib.request.urlopen(purl2,json_post_data1.encode(encoding='UTF8'))
    return request_post
     
     
     
send_tu("1.png")  ##圖片目錄
send_text("123-何全")  ##文字內(nèi)容

以上是python3開發(fā)微信企業(yè)號(hào)傳送圖文方法的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門話題

Laravel 教程
1597
29
PHP教程
1488
72