日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

php 企业号文本消息推送,Python如何实现微信企业号文本消息推送功能的示例

發(fā)布時(shí)間:2025/4/16 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 企业号文本消息推送,Python如何实现微信企业号文本消息推送功能的示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這篇文章主要介紹了Python編程實(shí)現(xiàn)微信企業(yè)號(hào)文本消息推送功能,結(jié)合實(shí)例形式分析了Python微信企業(yè)號(hào)文本消息推送接口的調(diào)用相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python微信企業(yè)號(hào)文本消息推送功能。分享給大家供大家參考,具體如下:

企業(yè)號(hào)的創(chuàng)建、企業(yè)號(hào)應(yīng)用的創(chuàng)建、組、tag、part就不贅述了,一搜一大堆,但是網(wǎng)上拿的那些個(gè)腳本好多都不好使,所以自己修了一個(gè)

坦率的講,這個(gè)腳本是用來(lái)作為zabbix的通知媒介腳本的,本人是個(gè)菜鳥(niǎo),如果哪里不對(duì),大神們不要笑話,python也處于學(xué)習(xí)階段,如果有哪些地方不合理,很希望可以不吝賜教,廢話不多說(shuō),腳本奉上:

#!/usr/bin/python

# _*_coding:utf-8 _*_

import urllib2

import json

import sys

reload(sys)

sys.setdefaultencoding('utf-8')

def gettoken(corpid, corpsecret):

gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret

try:

token_file = urllib2.urlopen(gettoken_url)

except urllib2.HTTPError as e:

print e.code

print e.read().decode("utf8")

sys.exit()

token_data = token_file.read().decode('utf-8')

token_json = json.loads(token_data)

token_json.keys()

token = token_json['access_token']

return token

def senddata(access_token, user, party, agent, subject, content):

send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token

send_values = "{\"touser\":\"" + user + "\",\"toparty\":\"" + party + "\",\"totag\":\"\",\"msgtype\":\"text\",\"agentid\":\"" + agent + "\",\"text\":{\"content\":\"" + subject + "\n" + content + "\"},\"safe\":\"0\"}"

send_request = urllib2.Request(send_url, send_values)

response = json.loads(urllib2.urlopen(send_request).read())

print str(response)

if __name__ == '__main__':

user = str(sys.argv[1]) # 參數(shù)1:發(fā)送給用戶的賬號(hào),必須關(guān)注企業(yè)號(hào),并對(duì)企業(yè)號(hào)有發(fā)消息權(quán)限

party = str(sys.argv[2]) # 參數(shù)2:發(fā)送給組的id號(hào),必須對(duì)企業(yè)號(hào)有權(quán)限

agent = str(sys.argv[3]) # 參數(shù)3:企業(yè)號(hào)中的應(yīng)用id

subject = str(sys.argv[4]) # 參數(shù)4:標(biāo)題【消息內(nèi)容的一部分】

content = str(sys.argv[5]) # 參數(shù)5:文本具體內(nèi)容

corpid = 'CorpID' # CorpID是企業(yè)號(hào)的標(biāo)識(shí)

corpsecret = 'corpsecretSecret' # corpsecretSecret是管理組憑證密鑰

try:

accesstoken = gettoken(corpid, corpsecret)

senddata(accesstoken, user, party, agent, subject, content)

except Exception, e:

print str(e) + "Error Please Check \"corpid\" or \"corpsecret\" Config"

總結(jié)

以上是生活随笔為你收集整理的php 企业号文本消息推送,Python如何实现微信企业号文本消息推送功能的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。