md5_test.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import hashlib
  2. import urllib
  3. import datetime
  4. import json
  5. import requests
  6. def generate_mengwang_pwd(userid, pwd, timestamp):
  7. """
  8. add by zhouhl 2017-07-25
  9. 对梦网的用户密码加密
  10. """
  11. constant_string = '00000000'
  12. tmp_string = ''.join([userid.upper(), constant_string, pwd, timestamp])
  13. print(tmp_string)
  14. md5 = hashlib.md5()
  15. md5.update(tmp_string.encode())
  16. return md5.hexdigest()
  17. def md5test():
  18. timestamp = datetime.datetime.strftime(
  19. datetime.datetime.now(), '%m%d%H%M%S')
  20. ciphertext_pwd = generate_mengwang_pwd('JS5112', '858965', timestamp)
  21. # 梦网的content需要先GBK编码,再urlencode
  22. multimt = []
  23. tmp_i = {}
  24. tmp_i['mobile'] = '18665318962'
  25. content = '今天天气转凉,大家请注意防寒保暖。'.encode('GBK')
  26. tmp_content = urllib.parse.urlencode({'content': content})
  27. tmp_i['content'] = tmp_content.split('=')[-1]
  28. multimt.append(tmp_i)
  29. data = {
  30. 'userid': 'JS5112',
  31. 'pwd': ciphertext_pwd,
  32. 'multimt': multimt,
  33. 'timestamp': timestamp,
  34. }
  35. jsonStr = json.dumps(data)
  36. print(jsonStr)
  37. try:
  38. response = requests.post(
  39. 'http://61.145.229.28:7902/sms/v2/std/multi_send',
  40. headers={'Content-Type': 'application/json'},
  41. data=jsonStr,
  42. )
  43. print(response.content.decode('utf-8'))
  44. except Exception as e:
  45. print(e)
  46. md5test()