目前相关模块已经同步至全部机器,对应python版本3。 html
python包依赖:click (pip3 install click)python
源码地址
阿里云短信:/usr/local/python36/lib/python3.6/site-packages/send_sms/sendsms.py,依赖两个阿里提供的sdk
/usr/local/python36/lib/python3.6/site-packages/aliyunsdkcore 和
/usr/local/python36/lib/python3.6/site-packages/aliyunsdkdysmsapic#
企业微信: /usr/local/python36/lib/python3.6/site-packages/weixin_qiye.pyapi
特色:均支持代码中引用以及命令行调用两种使用方式微信
在python代码中经过模块引入方式调用
阿里云短信ide
>>> from send_sms import sendsms >>> sendsms. sendsms.AcsClient( sendsms.PRODUCT_NAME sendsms.SendSmsRequest sendsms.const sendsms.send_sms( sendsms.uuid sendsms.DOMAIN sendsms.REGION sendsms.acs_client sendsms.region_provider sendsms.sys >>> help(sendsms.send_sms) Help on function send_sms in module send_sms.sendsms: send_sms(phone_numbers, sign_name, template_code, template_param=None) phone_numbers: String, 接收短信的手机号码, 支持对多个手机号码发送短信,手机号码之间以英文逗号(,)分隔。上限为1000个手机号码。批量调用相对于单条调用及时性稍有延迟 sign_name: String, 短信签名名称。请在控制台签名管理页面签名名称一列查看 template_code: String, 短信模板ID。请在控制台模板管理页面模板CODE一列查看 template_param: String, 短信模板变量对应的实际值,JSON格式 >>> phone_numbers = '15810xxxxxx' >>> sign_name = '公司' >>> template_code = 'SMS_14159xxxx' >>> template_param = '{"sysName":"nongye","modName":"","alarmInfo":"ljk test"}' >>> sendsms.send_sms(phone_numbers, sign_name, template_code, template_param).decode() '{"Message":"OK","RequestId":"5D9C9B11-A4C1-43B1-BCC9-2B2F0EBD4170","BizId":"920009151147346098^0","Code":"OK"}'
企业微信ui
import weixin_qiye >>> help(weixin_qiye.gettoken) Help on function gettoken in module weixin_qiye: gettoken(corpid, corpsecret) 获取access_token corpid: 企业ID corpsecret: 应用的凭证密钥 >>> help(weixin_qiye.senddata) Help on function senddata in module weixin_qiye: senddata(access_token, msg, touser='', toparty='', agentid=1) 经过企业微信发送文本消息 access_token: 调用接口凭证 msg: 文本消息 touser: 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊状况:指定为@all,则向该企业应用的所有成员发送 toparty: 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 agentid: 企业应用的id >>> token = weixin_qiye.gettoken('wx14f4b31', 'JynHsZm-pcuAel1ruG-5mbktKQea') >>> weixin_qiye.senddata(token, 'ljk test', 'LiKai') {'errcode': 0, 'errmsg': 'ok', 'invaliduser': ''}
做为脚本在Linux命令行运行 this
阿里云短信阿里云
ins01 ~]# cd /usr/local/python36/lib/python3.6/site-packages ins01 site-packages]# python3 send_sms/sendsms.py --help Usage: sendsms.py [OPTIONS] Options: --phone_numbers TEXT 接收短信的手机号码, 支持对多个手机号码发送短信,手机号码之间以英文逗号(,)分隔。上限为1000个手机号 码。批量调用相对于单条调用及时性稍有延迟 [required] --sign_name TEXT 短信签名名称。请在控制台签名管理页面签名名称一列查看 [required] --template_code TEXT 短信模板ID。请在控制台模板管理页面模板CODE一列查看 [required] --template_param TEXT 短信模板变量对应的实际值,JSON格式 [required] --help Show this message and exit. ins01 site-packages]# python3 send_sms/sendsms.py --phone_numbers 15810xxxxxx --sign_name 公司 --template_code SMS_14159xxxx --template_param '{"sysName":"nongye","modName":"","alarmInfo":"ljk test"}' {"Message":"OK","RequestId":"543E6ACF-5CDD-4BF7-B2D1-671FA45A3","BizId":"513316751727947^0","Code":"OK"}
企业微信命令行
ins01 site-packages]# python3 weixin_qiye.py --help Usage: weixin_qiye.py [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: gettoken 获取access_token senddata 经过企业微信发送文本消息 ins01 site-packages]# python3 weixin_qiye.py gettoken --help Usage: weixin_qiye.py gettoken [OPTIONS] 获取access_token Options: --corpid TEXT 企业ID [required] --corpsecret TEXT 应用的凭证密钥 [required] --help Show this message and exit. ins01 site-packages]# token=`python3 weixin_qiye.py gettoken --corpid wx4f4bbb --corpsecret JyryvHsZm-cuql1ruG-5mbktKJMntavh` ins01 site-packages]# python3 weixin_qiye.py senddata --access_token $token --msg 'test 1122334455' --touser='LiKai' {'errcode': 0, 'errmsg': 'ok', 'invaliduser': ''}