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