phone.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from email import header
  2. #!/usr/bin/env python
  3. # -*- encoding: utf-8 -*-
  4. '''
  5. @Contact : liuyuqi.gov@msn.cn
  6. @Time : 2022/11/26 19:59:03
  7. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  8. @Desc : 获取手机号,手机验证码
  9. '''
  10. import json,re,sys,logging,requests
  11. from twitter_account_creator.models import api
  12. class Phone(object):
  13. def __init__(self, apiKey):
  14. pass
  15. def getBalance(self):
  16. res = json.loads(requests.get(api.getBalance).text)
  17. if res["response"] == "error":
  18. return {"balance": res["error_msg"]}
  19. if res["response"] == "1":
  20. return {"balance": res["balance"]}
  21. return {"balance": "something went wrong :/"}
  22. def getNumber(self):
  23. try:
  24. res = json.loads(requests.get(api.getNumber).text)
  25. number = res["number"]
  26. _id = res["id"]
  27. return number, _id
  28. except:
  29. return "error_number", "error_id"
  30. def getSMS(self, id):
  31. try:
  32. res = json.loads(requests.get(api.getSms).text)
  33. if res["sms"] != None:
  34. return res["sms"]
  35. except:
  36. return "error_code"