资源简介
![](http://www.nz998.com/pic/33904.jpg)
代码片段和文件信息
# -*- coding: utf-8 -*-
import urllib2
from urllib import urlencode
import simplejson
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8‘)#wx only adapt utf-8 (no unicodeno encoding and stay what it looks like)
Debug = True
IsMyQYH = True
def getTokenIntime(CorpIdSecret):
res = urllib2.urlopen(‘https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s‘%(CorpIdSecret))
res_dict = simplejson.loads(res.read())
token = res_dict.get(‘access_token‘False)
if not token:
with open(r‘./wx_log.txt‘‘ab‘) as f:
f.write(u‘异常: 无法取得token‘)
return token
def getToken():
with open(r‘./wx_token.txt‘) as f:
t = f.read()
return t
def sendTxtMsg(tokencontentto_user=“@all“to_party=““to_tag=““application_id=0safe=0):
try:
data = {
“touser“: to_user
“toparty“: to_party
“totag“: to_tag
“msgtype“: “text“
“agentid“: application_id
“text“: {
“content“: content
}
“safe“:safe
}
data = simplejson.dumps(dataensure_ascii=False)
if Debug:
with open(r‘./wx_data.txt‘‘ab‘) as f:
f.write(data+‘\r\n‘)
req = urllib2.Request(‘https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s‘%(token))
resp = urllib2.urlopen(reqdata)
msg = u‘返回值:‘ + resp.read()
except Exceptionex:
msg = u‘异常:‘ + str(ex)
finally:
with open(r‘./wx_log.txt‘‘ab‘) as f:
f.write(msg+‘\r\n‘)
def sendNews(tokentitledescriptionurlpic_urlto_user=“@all“to_party=““to_tag=““application_id=0safe=0):
try:
data = {
“touser“: to_user
“toparty“: to_party
“totag“: to_tag
“msgtype“: “news“
“agentid“: application_id
“news“: {
“articles“:[
{
“title“: title
“description“: description
“url“: url
“picurl“: pic_url
}
]
}
}
data = simplejson.dumps(dataensure_ascii=False)
if Debug:
with open(r‘./wx_data.txt‘‘ab‘) as f:
f.write(data+‘\r\n‘)
req = urllib2.Request(‘https://qyapi.weixin.qq.com/cgi-bin/message/send?debug=1&access_token=%s‘%(token))
resp = urllib2.urlopen(reqdata)
msg = u‘返回值:‘ + resp.read()
except Exceptionex:
msg = u‘异常:‘ + str(ex)
finally:
with open(r‘./wx_log.txt‘‘ab‘) as f:
f.write(msg + ‘\r\n‘)
def send_btn(tokenapplication_id=0):
try:
req = urllib2.Request(‘https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token=%s&agentid=%s‘%(tokenapplication_id))
data = {
“button
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11981 2014-10-09 20:54 wx_data.txt
文件 4761 2014-10-09 20:54 IWeixin.py
----------- --------- ---------- ----- ----
16742 2
- 上一篇:SEO常用数据分析表格模板
- 下一篇:用Proteus仿真的sht11电路
相关资源
- 随机森林R语言代码
- R语言新冠肺炎疫情可视化分析
- scratch垃圾分类源码(最终版本).sb
- zoj 分类加题解(浙大ACM)
- Iris数据集分类,查看几种分类方法的
- EM算法,能够比较准确的实现对二维数
- Scratch 垃圾分类.sb3
- 基于pytorch的UNet_demo实现及训练自己的
- 什么是容灾系统及系统分类
- 中微子质量模型:新的分类和与模型
- 深度学习卷积神经网络可检测和分类
- 基于动态分类器集成选择和GM(21)
- 基于三角图法的矿业城市人地系统脆
- 釉质发育不全的临床分类和治疗
- 基于字符串/ M理论隐藏扇区的暗物质
- BoW|Pyramid BoW+SVM进行图像分类
- R环境和RStudio
- 朴素贝叶斯分类模型完整代码
- 网站分析实战
- dataset-resized.zip
- V5快递单号生成器 v9.5.zip
- 广告报价助手 v2.02 官方免费版.zip
- 基于k-means聚类的财务欺诈类型分类
- opencv_traincascade训练分类器,手势识别
- 新闻分类语料
- 基于决策树和朴素贝叶斯算法对Adul
- 统计用产品分类目录2012
- 电信运营商企业级数据分类体系介绍
- 基于最小错误率的贝叶斯手写数字分
- R语言预测实战(完整版).pdf
评论
共有 条评论