1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import requests
- import json
- import sys
- import time
- reload(sys)
- sys.setdefaultencoding( "utf-8" )
- date_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
- tmp_date_time=time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
- tmp_date=time.strftime('%Y-%m-%d',time.localtime(time.time()))
- tmp_time=time.strftime('%H:%M:%S',time.localtime(time.time()))
- f=open("/opt/matrix/agent/bin/alert_cmd/send_sms.log", "a+")
- data1=sys.argv[1]
- data2=sys.argv[2]
- #hjson1= json.loads(data1.decode('utf-8'))
- hjson1= json.loads(data1)
- ipaddress=hjson1['netgate']['address']
- port=hjson1['netgate']['port']
- protocol=hjson1['netgate']['protocol']
- brNo=hjson1['netgate']['brNo']
- chanNo=hjson1['netgate']['chanNo']
- srvId=hjson1['netgate']['srvId']
- svcId=hjson1['netgate']['svcId']
- print(hjson1['jdbc']['driver'])
- #hjson2= json.loads(data2.decode('utf-8'))
- hjson2= json.loads(data2)
- #f.write(date_time+" "+hjson1+" "+hjson2+"\n")
- for msg in hjson2:
- message=msg['msg']
- for names in msg['to']:
- touser=names['mobile']
- #url=protocol+'://'+ipaddress+':'+port+'/'
- url=protocol+'://'+str(ipaddress)+':'+str(port)+'/'
- body='<?xml version="1.0" encoding="UTF-8"?>' \
- '<reqt>' \
- '<appHdr>' \
- '<reqDt>'+tmp_date+'</reqDt>' \
- '<reqTm>'+tmp_time+'</reqTm>' \
- '<svcId>'+svcId+'</svcId>' \
- '</appHdr>' \
- '<appBody>' \
- '<srvId>'+srvId+'</srvId>' \
- '<chanNo>'+chanNo+'</chanNo>' \
- '<brNo>'+brNo+'</brNo>' \
- '<objAddr>'+touser+'</objAddr>' \
- '<msgCont>'+message+'</msgCont>' \
- '<ordTm>'+tmp_date_time+'</ordTm>' \
- '<accNo>null</accNo>' \
- '<custNo>null</custNo>' \
- '</appBody>' \
- '</reqt>'
- #r = requests.post(url,data=body.decode("gbk").encode("utf-8"))
- r = requests.post(url,data=body.encode("utf-8"))
- #f.write(date_time+" "+url+" "+body+"\n")
- f.write(date_time+" "+touser+" "+message+r.text+"\n")
- #f.write(date_time+" "+touser+" "+message+"\n")
- f.close()
- #print(hjson1)
|