s.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import requests
  4. import json
  5. import sys
  6. import time
  7. reload(sys)
  8. sys.setdefaultencoding( "utf-8" )
  9. date_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
  10. tmp_date_time=time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
  11. tmp_date=time.strftime('%Y-%m-%d',time.localtime(time.time()))
  12. tmp_time=time.strftime('%H:%M:%S',time.localtime(time.time()))
  13. f=open("/opt/matrix/agent/bin/alert_cmd/send_sms.log", "a+")
  14. data1=sys.argv[1]
  15. data2=sys.argv[2]
  16. #hjson1= json.loads(data1.decode('utf-8'))
  17. hjson1= json.loads(data1)
  18. ipaddress=hjson1['netgate']['address']
  19. port=hjson1['netgate']['port']
  20. protocol=hjson1['netgate']['protocol']
  21. brNo=hjson1['netgate']['brNo']
  22. chanNo=hjson1['netgate']['chanNo']
  23. srvId=hjson1['netgate']['srvId']
  24. svcId=hjson1['netgate']['svcId']
  25. print(hjson1['jdbc']['driver'])
  26. #hjson2= json.loads(data2.decode('utf-8'))
  27. hjson2= json.loads(data2)
  28. #f.write(date_time+" "+hjson1+" "+hjson2+"\n")
  29. for msg in hjson2:
  30. message=msg['msg']
  31. for names in msg['to']:
  32. touser=names['mobile']
  33. #url=protocol+'://'+ipaddress+':'+port+'/'
  34. url=protocol+'://'+str(ipaddress)+':'+str(port)+'/'
  35. body='<?xml version="1.0" encoding="UTF-8"?>' \
  36. '<reqt>' \
  37. '<appHdr>' \
  38. '<reqDt>'+tmp_date+'</reqDt>' \
  39. '<reqTm>'+tmp_time+'</reqTm>' \
  40. '<svcId>'+svcId+'</svcId>' \
  41. '</appHdr>' \
  42. '<appBody>' \
  43. '<srvId>'+srvId+'</srvId>' \
  44. '<chanNo>'+chanNo+'</chanNo>' \
  45. '<brNo>'+brNo+'</brNo>' \
  46. '<objAddr>'+touser+'</objAddr>' \
  47. '<msgCont>'+message+'</msgCont>' \
  48. '<ordTm>'+tmp_date_time+'</ordTm>' \
  49. '<accNo>null</accNo>' \
  50. '<custNo>null</custNo>' \
  51. '</appBody>' \
  52. '</reqt>'
  53. #r = requests.post(url,data=body.decode("gbk").encode("utf-8"))
  54. r = requests.post(url,data=body.encode("utf-8"))
  55. #f.write(date_time+" "+url+" "+body+"\n")
  56. f.write(date_time+" "+touser+" "+message+r.text+"\n")
  57. #f.write(date_time+" "+touser+" "+message+"\n")
  58. f.close()
  59. #print(hjson1)