chaojiying.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import requests
  2. from hashlib import md5
  3. class Chaojiying_Client(object):
  4. def __init__(self, username, password, soft_id):
  5. self.username = username
  6. password = password.encode('utf8')
  7. self.password = md5(password).hexdigest()
  8. self.soft_id = soft_id
  9. self.base_params = {
  10. 'user': self.username,
  11. 'pass2': self.password,
  12. 'softid': self.soft_id,
  13. }
  14. self.headers = {
  15. 'Connection': 'Keep-Alive',
  16. 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
  17. }
  18. def PostPic(self, im, codetype):
  19. """
  20. im: 图片字节
  21. codetype: 题目类型 参考 http://www.chaojiying.com/price.html
  22. """
  23. params = {
  24. 'codetype': codetype,
  25. }
  26. params.update(self.base_params)
  27. files = {'userfile': ('ccc.jpg', im)}
  28. r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
  29. return r.json()
  30. def PostPic_base64(self, base64_str, codetype):
  31. """
  32. im: 图片字节
  33. codetype: 题目类型 参考 http://www.chaojiying.com/price.html
  34. """
  35. params = {
  36. 'codetype': codetype,
  37. 'file_base64':base64_str
  38. }
  39. params.update(self.base_params)
  40. r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, headers=self.headers)
  41. return r.json()
  42. def ReportError(self, im_id):
  43. """
  44. im_id:报错题目的图片ID
  45. """
  46. params = {
  47. 'id': im_id,
  48. }
  49. params.update(self.base_params)
  50. r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
  51. return r.json()
  52. # if __name__ == '__main__':
  53. # chaojiying = Chaojiying_Client('15985724690', 'a520520a', '923160') #用户中心>>软件ID 生成一个替换 96001
  54. # im = open('a.jpg', 'rb').read() #本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
  55. # print(chaojiying.PostPic(im, 1005)) #1902 验证码类型 官方网站>>价格体系 3.4+版 print 后要加()
  56. # #print chaojiying.PostPic(base64_str, 1902) #此处为传入 base64代码