python傳送微信訊息和企業號訊息

2022-08-23 19:03:11 字數 2853 閱讀 2399

bot = bot(cache_path=true)可以保持登陸狀態

embed()# 堵塞執行緒可以一直不掉線

**如下:

from wxpy import *bot = bot(cache_path=true)

#定位好友

boss = bot.search('

好友名字

')[0]

boss.send(""

)#堵塞執行緒

embed()

傳送群把好友名改成群名就行,以上指令碼參考自網上

實際使用時發現效果不好,可以改成使用企業號推送

註冊企業號

下面是4個引數:

傳送指令碼**

修改後適應py3

#

!/usr/bin/env python

#-*- coding: utf-8 -*-

#@time : 2018/4/25 17:06

#@author : zms

#@site :

#@file : wechat.py

#@software: pycharm community edition

#!/usr/bin/env python

#coding:utf-8

#file wechat.py

import

time

import

requests

import

json

import

sysclass

wechat:

def__init__

(self):

self.corpid = '

企業號'

self.corpsecret = '

應用號見圖2箭頭2

' # 應用加密字串

self.agentid = '

1000002

' # 應用號

self.touser = "

聯絡人1|聯絡人2|聯絡人3

"def

_get_access_token(self):

url = '

'values =

req = requests.post(url, params=values)

data =json.loads(req.text)

#print(data)

return data["

access_token"]

defget_access_token(self):

try:

with open(

'../common/tmp/access_token.conf

', 'r'

) as f:

t, access_token =f.read().split()

#print(access_token)

except

: with open(

'./tmp/access_token.conf

', 'w'

) as f:

access_token =self._get_access_token()

cur_time =time.time()

f.write('\t

'.join([str(cur_time), access_token]))

return

access_token

else

: cur_time =time.time()

if 0 < cur_time - float(t) < 7260:

return

access_token

else

: with open(

'./access_token.conf

', 'w'

) as f:

access_token =self._get_access_token()

f.write('\t

'.join([str(cur_time), access_token]))

return

access_token

defsend_data(self,msg):

send_url = '

' +self.get_access_token()

send_values =,

"safe

": "0"

} send_data = '

}' %(

self.agentid, self.touser, msg)

r = requests.post(send_url, json=send_values)

#print r.content

return

r.content

if__name__ == '

__main__':

wx =wechat()

wx.send_data(

'測試中文

C 微信企業號 傳送訊息

企業可以主動發訊息給成員,訊息量不受限制。呼叫介面時,使用https協議 json資料報格式,資料報不需做加密處理。首先我們看下,介面文件 https請求方式 post 引數必須 說明access token 是呼叫介面憑證 收件人必須處於應用的可見範圍內,並且管理組對應用有使用許可權 對收件人有檢...

微信傳送訊息

from future import unicode literals from threading import timer from wxpy import import requests 首先import wxpy這個模組和request這個模組 def get news url 這個是英文心...

微信企業號傳送監控訊息 php

1 定時任務檢測異常訊息 2將訊息存入redis佇列 3定時處理佇列異常訊息 簡單的來說,只需要兩個步驟即可 1獲取accesstoken 2 傳送訊息到對應的專案部門組 一 獲取accesstoken accesstoken是企業號的全域性唯一票據,呼叫介面時需攜帶accesstoken。acce...