├── .gitignore ├── LICENSE ├── README.md ├── bin └── message ├── data └── mysql │ └── init │ └── init.sql ├── docker-compose.yaml ├── dockerfile ├── es │ ├── Dockerfile │ └── readonlyrest.yml └── message │ └── Dockerfile └── source ├── entrypoint.py ├── kibana.png ├── message_api.py ├── message_controller.py ├── message_main.py ├── process.png └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### 短信发送小助手 2 | 3 | - 项目使用: 4 | - 下载项目代码 git clone https://github.com/Brightest08/message 5 | - 修改docker-compose.yaml文件,配置es、mysql、账号密码,也可以使用默认配置直接启动 6 | - docker-compose up -d 将自动下载镜像并启动服务,使用到的镜像有: 7 | - 1、elasticsearch - 用于收集短信发送日志,便于分析短信接口是否异常,和统计用户短信发送情况 8 | - 2、mysql - 存储短信接口信息、用户信息 9 | - 3、redis - 从mysql中读取并保存短信接口信息,用于缓存,保存用户登录信息 10 | - 4、kibana - 图形化展示es中的数据 11 | - 5、message - 短信发送镜像 12 | - 登录验证,默认用户名密码为admin,可以在首次启动MySQL时修改data/mysql/init/init.sql默认值 13 | ``` 14 | [root@host message]# ./bin/message 15 | 未登录或登录信息已过期 16 | 请输入用户名:admin 17 | 请输入密码: 18 | 登陆成功,请继续使用 19 | ``` 20 | - 运行测试 21 | ``` 22 | [root@host message]# ./bin/message -m 手机号码 -c 短信发送条数 23 | 2019-07-22 21:58:49 morequick {"ret":1,"data":"ok"} 24 | ``` 25 | - 登录kibana查看发送日志,登录需要用户认证,默认用户名密码为message,可以在docker-compose.yaml中进行修改 26 | 27 | ![image](https://github.com/Brightest08/message/blob/master/source/kibana.png) 28 | 29 | - 目录对应说明 30 | - bin - 短信发送脚本 31 | - data - 各个数据库数据存放位置,还有mysql的初始化建表sql 32 | - dockerfile - 构建镜像的dockerfile 33 | - source - 源代码存放位置 34 | 35 | - 流程图 36 | - ![image](https://github.com/Brightest08/message/blob/master/source/process.png) 37 | 38 | - 项目声明: 39 | - 本项目只供学习交流使用,务作为非法用途 40 | -------------------------------------------------------------------------------- /bin/message: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | docker exec -it message python message_main.py $@ 3 | -------------------------------------------------------------------------------- /data/mysql/init/init.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `available_url`; 2 | CREATE TABLE `available_url` ( 3 | `id` int(11) NOT NULL AUTO_INCREMENT, 4 | `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 5 | `domain` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 6 | `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 7 | `maximum` int(10) NULL DEFAULT NULL, 8 | `interval` int(10) NULL DEFAULT NULL, 9 | `black` int(10) NULL DEFAULT 0, 10 | `remark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, 11 | PRIMARY KEY (`id`) USING BTREE, 12 | UNIQUE INDEX `name`(`name`) USING BTREE, 13 | INDEX `url`(`url`) USING BTREE, 14 | INDEX `domain`(`domain`) USING BTREE 15 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci; 16 | 17 | DROP TABLE IF EXISTS `user`; 18 | CREATE TABLE `user` ( 19 | `id` int(10) NOT NULL AUTO_INCREMENT, 20 | `username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 21 | `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 22 | `available_count` int(10) NOT NULL, 23 | `send_count` int(10) NOT NULL, 24 | PRIMARY KEY (`id`) USING BTREE, 25 | INDEX `username`(`username`) USING BTREE 26 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci; 27 | 28 | INSERT INTO `message`.`available_url`(`name`, `domain`, `url`, `maximum`, `interval`, `black`, `remark`) VALUES ('chaoxing', 'passport2.chaoxing.com', 'http://passport2.chaoxing.com/register3', 3, 60, 0, NULL); 29 | INSERT INTO `message`.`available_url`(`name`, `domain`, `url`, `maximum`, `interval`, `black`, `remark`) VALUES ('happigo', 'www.happigo.com', 'https://www.happigo.com/register/', 3, 60, 0, NULL); 30 | INSERT INTO `message`.`available_url`(`name`, `domain`, `url`, `maximum`, `interval`, `black`, `remark`) VALUES ('pailixiang', 'heimaohui.pailixiang.com', 'http://heimaohui.pailixiang.com/register.html', 10, 60, 0, NULL); 31 | INSERT INTO `message`.`available_url`(`name`, `domain`, `url`, `maximum`, `interval`, `black`, `remark`) VALUES ('morequick', 'itv.morequick.net', 'https://itv.morequick.net/register.html', 3, 60, 0, NULL); 32 | INSERT INTO `message`.`available_url`(`name`, `domain`, `url`, `maximum`, `interval`, `black`, `remark`) VALUES ('asprova', 'www.asprova.cn', 'http://www.asprova.cn/register.html', 15, 30, 0, NULL); 33 | /* 34 | 默认用户名密码为admin:admin 35 | */ 36 | INSERT INTO `message`.`user`(`id`, `username`, `password`, `available_count`, `send_count`) VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 1000, 0); 37 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "2.2" 2 | services: 3 | message: 4 | container_name: message 5 | image: registry.cn-hongkong.aliyuncs.com/brightest/message 6 | environment: 7 | - es_user=message 8 | - es_passwd=message 9 | - mysql_user=message 10 | - mysql_passwd=message 11 | - mysql_db=message 12 | restart: on-failure 13 | depends_on: 14 | - es 15 | - mysql 16 | - redis 17 | es: 18 | image: registry.cn-hongkong.aliyuncs.com/brightest/elasticsearch:message 19 | environment: 20 | - es_user=message 21 | - es_passwd=message 22 | - xpack.security.enabled=false 23 | - discovery.type=single-node 24 | - bootstrap.memory_lock=true 25 | - "ES_JAVA_OPTS=-Xms512m -Xmx512m" 26 | volumes: 27 | - ./data/es:/usr/share/elasticsearch/data 28 | mysql: 29 | image: mysql:5.7 30 | environment: 31 | MYSQL_ROOT_PASSWORD: root 32 | MYSQL_USER: message 33 | MYSQL_PASSWORD: message 34 | MYSQL_DATABASE: message 35 | restart: on-failure 36 | mem_limit: 500m 37 | cpus: '0.5' 38 | volumes: 39 | - ./data/mysql/db:/var/lib/mysql 40 | - ./data/mysql/init:/docker-entrypoint-initdb.d 41 | redis: 42 | image: redis 43 | restart: on-failure 44 | volumes: 45 | - ./data/redis:/data 46 | kibana: 47 | image: docker.elastic.co/kibana/kibana:7.2.0 48 | environment: 49 | - ELASTICSEARCH_HOSTS=["http://es:9200"] 50 | - ELASTICSEARCH_USERNAME=message 51 | - ELASTICSEARCH_PASSWORD=message 52 | - SERVER.HOST=0.0.0.0 53 | - TIMELION_ENABLED=true 54 | - I18N_LOCALE="zh-CN" 55 | ports: 56 | - "5601:5601" 57 | -------------------------------------------------------------------------------- /dockerfile/es/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.elastic.co/elasticsearch/elasticsearch:7.2.0 2 | 3 | COPY readonlyrest-1.18.2_es7.2.0.zip /plugins/readonlyrest-1.18.2_es7.2.0.zip 4 | 5 | COPY readonlyrest.yml /usr/share/elasticsearch/config/readonlyrest.yml 6 | 7 | RUN sed '2 ased -i "s/message:message/$es_user:$es_passwd/g" /usr/share/elasticsearch/config/readonlyrest.yml' -i /usr/local/bin/docker-entrypoint.sh && \ 8 | echo -e "y" | /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///plugins/readonlyrest-1.18.2_es7.2.0.zip 9 | -------------------------------------------------------------------------------- /dockerfile/es/readonlyrest.yml: -------------------------------------------------------------------------------- 1 | readonlyrest: 2 | access_control_rules: 3 | - name: "Require HTTP Basic Auth" 4 | type: allow 5 | auth_key: message:message 6 | -------------------------------------------------------------------------------- /dockerfile/message/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7-slim as message_base 2 | COPY source/requirements.txt /requirements.txt 3 | RUN apt-get update && \ 4 | apt-get install gcc -y && \ 5 | pip install -r /requirements.txt && \ 6 | cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 7 | 8 | FROM message_base 9 | add source /message 10 | WORKDIR /message 11 | ENTRYPOINT ["python3","entrypoint.py"] 12 | -------------------------------------------------------------------------------- /source/entrypoint.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | from elasticsearch import Elasticsearch 3 | import os 4 | 5 | mapping = { 6 | "mappings": { 7 | "properties": { 8 | "ip": { 9 | "type": "text", 10 | "fields": { 11 | "keyword": { 12 | "type": "keyword", 13 | "ignore_above": 256 14 | } 15 | } 16 | }, 17 | "message": { 18 | "type": "text", 19 | "fields": { 20 | "keyword": { 21 | "type": "keyword", 22 | "ignore_above": 256 23 | } 24 | } 25 | }, 26 | "mobile": { 27 | "type": "text", 28 | "fields": { 29 | "keyword": { 30 | "type": "keyword", 31 | "ignore_above": 256 32 | } 33 | } 34 | }, 35 | "respond": { 36 | "type": "text", 37 | "fields": { 38 | "keyword": { 39 | "type": "keyword", 40 | "ignore_above": 256 41 | } 42 | } 43 | }, 44 | "time": { 45 | "type": "date", 46 | "format": "yyyy-MM-dd HH:mm:ss" 47 | }, 48 | "user": { 49 | "type": "text", 50 | "fields": { 51 | "keyword": { 52 | "type": "keyword", 53 | "ignore_above": 256 54 | } 55 | } 56 | } 57 | } 58 | } 59 | } 60 | es_user = os.getenv('es_user', 'es_user') 61 | es_passwd = os.getenv('es_passwd', 'es_passwd') 62 | es = Elasticsearch(hosts=['es:9200'], http_auth=(es_user, es_passwd)) 63 | if not es.indices.exists('m_success_log'): 64 | es.indices.create('m_success_log', body=mapping) 65 | es.indices.create('m_error_log', body=mapping) 66 | os.system('echo "message is running" && touch /message/success.log && tail -f /message/success.log') 67 | -------------------------------------------------------------------------------- /source/kibana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brightest08/message/b85ea410d02e036bafe1fac9fdb2a683e2f1d1cf/source/kibana.png -------------------------------------------------------------------------------- /source/message_api.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import re 3 | import requests 4 | import json 5 | from message_controller import success, failure 6 | from message_controller import yundama as yundama 7 | from hashlib import md5 8 | import codecs 9 | import time 10 | import execjs 11 | 12 | headers = { 13 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' 14 | } 15 | 16 | def chaoxing(fun, mobile): 17 | s = requests.session() 18 | s.headers = headers 19 | r = s.get('http://passport2.chaoxing.com/num/phonecode?phone=%s&needcode=false' % (mobile)) 20 | if r.json()['result']: 21 | return success(fun, r.text) 22 | failure(fun, r.text) 23 | 24 | def asprova(fun, mobile): 25 | g = requests.get('http://www.asprova.cn/register.html', headers=headers) 26 | token = re.findall('false\|async\|(.*?)\.split', g.text)[0][:-1] 27 | data = {'appid': '24653', 'to': mobile, 'project': 'L4hZT2', 'signature': token} 28 | r = requests.post('https://api.mysubmail.com/message/xsend', headers=headers, data=data) 29 | if r.json()['status'] == 'success': 30 | return success(fun, r.text) 31 | failure(fun, r.text) 32 | 33 | def morequick(fun, mobile): 34 | data = {'item': 'get', 'type': '5', 'tel': mobile} 35 | r = requests.post('https://itv.morequick.net/webapi/sms_code', data=data, headers=headers) 36 | if r.json() == {"ret": 1, "data": "ok"}: 37 | return success(fun, r.text) 38 | failure(fun, r.text) 39 | 40 | def pailixiang(fun, mobile): 41 | s = requests.session() 42 | headers['Referer'] = 'http://heimaohui.pailixiang.com/register.html' 43 | s.headers = headers 44 | s.get('http://heimaohui.pailixiang.com/register.html') 45 | data = {'mobile': mobile} 46 | r = s.post('http://heimaohui.pailixiang.com/Services/SendSms.ashx?t=1&rid=reqlfd6ocg3a1ug', data=data) 47 | if r.json()['Code'] == 1: 48 | return success(fun, r.text) 49 | failure(fun, r.text) 50 | 51 | def happigo(fun, mobile): 52 | s = requests.session() 53 | s.headers = headers 54 | g = s.get('https://www.happigo.com/register/') 55 | send_mobile_key = re.findall('',g.text)[0] 56 | m = s.get('https://ecimg.happigo.com/resource/web/js/md5.js') 57 | ctx = execjs.compile(m.text) 58 | send_mobile_token = ctx.call('hex_md5',send_mobile_key+mobile) 59 | data = {'token':'ok','mobile':mobile,'send_mobile_key':send_mobile_key,'send_mobile_token':send_mobile_token,'v':'1.0','t':str(int(time.time()*1000))} 60 | s.headers['referer'] = 'https://www.happigo.com/register/' 61 | s.headers['x-requested-with'] = 'XMLHttpRequest' 62 | s.headers['x-tingyun-id'] = 'JEZ7HInwfsc;r=747473032' 63 | s.cookies['traceguid'] = 'webportalef19626169fd56134181bae74abdfd59' 64 | r = s.post('https://www.happigo.com/shop/index.php?act=login&op=send_auth_code&type=2',data=data) 65 | decoded_data = codecs.decode(bytes(r.text,encoding='utf-8'), 'utf-8-sig') 66 | if json.loads(decoded_data)['state'] == 'true': 67 | return success(fun, r.text) 68 | failure(fun, r.text) 69 | -------------------------------------------------------------------------------- /source/message_controller.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import json 3 | import time 4 | import datetime 5 | import redis 6 | from hashlib import md5 7 | import requests 8 | import pymysql 9 | import getpass 10 | import re 11 | import os 12 | import sys 13 | from tempfile import gettempdir 14 | import chardet 15 | import psutil 16 | from DBUtils.SteadyDB import connect 17 | from elasticsearch import Elasticsearch 18 | 19 | 20 | es = Elasticsearch('es:9200',http_auth=(os.getenv('es_user'), os.getenv('es_passwd'))) 21 | 22 | ip = re.findall('window.sohu_user_ip="(.*?)"', requests.get('http://txt.go.sohu.com/ip/soip').text)[0] 23 | pool = redis.ConnectionPool(host='redis', port=6379, decode_responses=True) 24 | r = redis.Redis(connection_pool=pool) 25 | 26 | already_send = 0 27 | set_of_times = 0 28 | mobile = '' 29 | user_name = '' 30 | headers = { 31 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' 32 | } 33 | 34 | 35 | def message_info(debug=True): 36 | last_m_sql = 'SELECT name FROM available_url WHERE id = (SELECT MAX(id) FROM `available_url` where black=0 and maximum is not NULL and `interval` is not NULL)' 37 | last_m = mysql(last_m_sql)[0][0]['name'] 38 | all_m_sql = "SELECT `name`,`maximum`,`interval` FROM `available_url` WHERE maximum is not NULL and `interval` is not NULL and black=0" 39 | if not r.hget('message',last_m): 40 | ret = mysql(all_m_sql)[0] 41 | r.delete('message') 42 | for m in ret: 43 | r.hset('message', m['name'], '{"maximum":%s,"interval":%s}' % (m['maximum'], m['interval'])) 44 | all_message_info = r.hgetall('message') 45 | for m_name, m_info in all_message_info.items(): 46 | all_message_info[m_name] = json.loads(m_info) 47 | return all_message_info 48 | 49 | 50 | def check_available(mg): 51 | sql = "SELECT available_count from `user` WHERE username = '%s'" % (user_name) 52 | _available_count = mysql(sql)[0][0]['available_count'] 53 | if _available_count < set_of_times: 54 | print('用户:%s,账户剩余短信发送数为:%d,请充值' % (user_name, _available_count)) 55 | sys.exit(-1) 56 | m_info = json.loads(r.hget(mobile, mg)) 57 | if not m_info.get('last_time'): 58 | return True 59 | if not m_info['remainder']: 60 | return False 61 | interval = m_info['interval'] 62 | last_send_time = datetime.datetime.strptime(m_info.get('last_time'), '%Y-%m-%d %H:%M:%S') 63 | now_time = datetime.datetime.strptime(get_now_time(), '%Y-%m-%d %H:%M:%S') 64 | delta = now_time - last_send_time 65 | # 可用发送数大于0 发送间隔 66 | if m_info['remainder'] > 0 and delta.seconds > interval: 67 | return True 68 | 69 | 70 | def local_img(content): 71 | with open('img.png', 'wb') as f: 72 | f.write(content) 73 | 74 | 75 | def login(): 76 | print('未登录或登录信息已过期') 77 | while True: 78 | user = input('请输入用户名:') 79 | passwd = getpass.getpass('请输入密码:') 80 | sql = "SELECT password from `user` WHERE username = '%s'" % (passwd) 81 | if mysql(sql)[0]: 82 | p = mysql(sql)[0][0]['password'] 83 | else: 84 | p = '' 85 | if p == md5(bytes(passwd, encoding='utf-8')).hexdigest(): 86 | token = md5(bytes(user + passwd + get_now_time(), encoding='utf-8')).hexdigest() 87 | r.hmset(user, {'token': token, 'ip': ip, 'login_time': get_now_time()}) 88 | with open(os.path.join(gettempdir(), 'login.json'), 'w') as f: 89 | data = '{"user_name":"%s","token":"%s"}' % (user, token) 90 | json.dump(data, f) 91 | print('登陆成功,请继续使用') 92 | sys.exit(0) 93 | print('账号或密码输入错误') 94 | 95 | 96 | def check_login(): 97 | global user_name 98 | if os.path.exists(os.path.join(gettempdir(), 'login.json')): 99 | try: 100 | login_file = open(os.path.join(gettempdir(), 'login.json'), 'r') 101 | login_info = json.loads(json.load(login_file)) 102 | if r.exists(login_info['user_name']): 103 | local_token = login_info['token'] 104 | r_token = r.hget(login_info['user_name'], 'token') 105 | if local_token == r_token: 106 | user_name = login_info['user_name'] 107 | return True 108 | except Exception: 109 | pass 110 | login() 111 | 112 | 113 | def init_mobile(m, s_time): 114 | global mobile, set_of_times 115 | mobile = m 116 | set_of_times = s_time 117 | if not r.exists(mobile): 118 | all_msg_info = message_info() 119 | for mg in all_msg_info: 120 | _m = all_msg_info[mg] 121 | m_info = '{"remainder": %s,"interval":%s}' % (_m['maximum'], _m['interval']) 122 | r.hset(mobile, mg, m_info) 123 | 124 | 125 | def write_log(status, content): 126 | with open(status + '.log', 'a+') as f: 127 | f.write(content) 128 | f.close() 129 | 130 | 131 | def get_now_time(): 132 | return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) 133 | 134 | 135 | def failure(mg, text): 136 | if chardet.detect(bytes(text, encoding='utf-8'))['encoding'] != 'utf-8': 137 | text = text.encode('utf-8').decode('unicode_escape') 138 | now = get_now_time() 139 | body = {"user": user_name, "message": mg, "mobile": mobile, "ip": ip, "time": get_now_time(), "respond": text} 140 | write_log('error', now + ' ' + mg + ' ' + mobile + ' ' + text + ' ' + '\n') 141 | es.index(index='m_error_log', body=body) 142 | if not r.exists(user_name): 143 | print('你被强制下线,如有疑问请联系管理员') 144 | p = psutil.Process(os.getpid()) 145 | p.terminate() 146 | sys.exit(-1) 147 | 148 | 149 | def success(mg, text): 150 | # 发送短信成功后把当前短信接口的可用数减一,和设置的发送短信数加一,及更新最后一次成功的时间 151 | if chardet.detect(bytes(text, encoding='utf-8'))['encoding'] != 'utf-8': 152 | text = text.encode('utf-8').decode('unicode_escape') 153 | mobile_incr = '%s_%d' % (mobile, set_of_times) 154 | r.incr(mobile_incr) 155 | now = get_now_time() 156 | body = {"user": user_name, "message": mg, "mobile": mobile, "ip": ip, "time": now, "respond": text} 157 | es.index(index='m_success_log', body=body) 158 | print(now, mg, text) 159 | write_log('success', now + ' ' + mg + ' ' + mobile + ' ' + text + ' ' + '\n') 160 | m_info = json.loads(r.hget(mobile, mg)) 161 | m_info['remainder'] = m_info['remainder'] - 1 162 | m_info['last_time'] = get_now_time() 163 | r.hset(mobile, mg, json.dumps(m_info)) 164 | sql = "update user set send_count=send_count+1 where username = '%s'" % (user_name) 165 | mysql(sql) 166 | sql = "update user set available_count=available_count-1 where username = '%s'" % (user_name) 167 | mysql(sql) 168 | if not r.exists(user_name): 169 | print('你被强制下线,如有疑问请联系管理员') 170 | p = psutil.Process(os.getpid()) 171 | p.terminate() 172 | sys.exit(-1) 173 | return True 174 | 175 | 176 | def mysql(sql): 177 | data, result = "", "" 178 | host = "mysql" 179 | user = os.getenv('mysql_user') 180 | pw = os.getenv('mysql_passwd') 181 | db = os.getenv('mysql_db') 182 | port = 3306 183 | # 使用连接池 184 | connection = connect( 185 | creator=pymysql,host=host, 186 | user=user, password=pw, database=db, 187 | autocommit=True, charset='utf8', port=port, 188 | cursorclass=pymysql.cursors.DictCursor) 189 | try: 190 | with connection.cursor() as cursor: 191 | cursor.execute(sql) 192 | connection.commit() 193 | if "select" or "show" in sql: 194 | data = cursor.fetchall() 195 | except Exception as e: 196 | print(e) 197 | connection.rollback() 198 | else: 199 | result = True 200 | 201 | finally: 202 | connection.close() 203 | 204 | return data, result 205 | 206 | 207 | def fateadm(url=None, s=requests, code_type=4, debug=False): 208 | try: 209 | get_code_type = str([30100, 30200, 30300, 30400, 30500][code_type - 1]) 210 | except Exception: 211 | get_code_type = str(code_type) 212 | img = s.get(url) 213 | img_content = img.content 214 | timestamp = str(int(time.time())) 215 | pd_id = '' 216 | pd_key = '' 217 | 218 | app_id = '313198' 219 | app_key = 'oIwP/WtbJZhyLz4b5y6f7dpB6ZZM6AV+' 220 | _sign = md5(bytes(timestamp + pd_key, encoding='utf-8')).hexdigest() 221 | sign = md5(bytes(pd_id + timestamp + _sign, encoding='utf-8')).hexdigest() 222 | _asign = md5(bytes(timestamp + app_key, encoding='utf-8')).hexdigest() 223 | asign = md5(bytes(app_id + timestamp + _asign, encoding='utf-8')).hexdigest() 224 | files = { 225 | 'img_data': ('img_data', img_content) 226 | } 227 | data = {'user_id': pd_id, 228 | 'timestamp': timestamp, 229 | 'sign': sign, 230 | 'asign': asign, 231 | 'up_type': 'mt', 232 | 'predict_type': get_code_type, 233 | } 234 | r = requests.post('http://pred.fateadm.com/api/capreg', 235 | data=data, headers=headers, files=files) 236 | if r.json()['RetCode'] == '0': 237 | if debug: 238 | with open('img.png', 'wb') as f: 239 | f.write(img_content) 240 | print(json.loads(r.json()['RspData'])['result']) 241 | return json.loads(r.json()['RspData'])['result'] 242 | return False 243 | 244 | 245 | def yundama(url=None, s=requests, code_type=4, debug=False): 246 | get_code_type = [1001, 1002, 1003, 1004, 1005][code_type - 1] 247 | username = '' 248 | password = '' 249 | appid = 1 250 | appkey = '22cc5376925e9387a23cf797cb9ba745' 251 | api_url = 'http://api.yundama.com/api.php' 252 | codetype = get_code_type 253 | timeout = 60 254 | data = {'method': 'upload', 'username': username, 'password': password, 'appid': appid, 'appkey': appkey, 255 | 'codetype': str(codetype), 'timeout': str(timeout)} 256 | img = s.get(url, headers=headers) 257 | img_content = img.content 258 | files = {'file': img_content} 259 | ret = requests.post(api_url, files=files, data=data) 260 | cid = str(ret.json()['cid']) 261 | ret_url = 'http://api.yundama.com/api.php?cid=%s&method=result' % cid 262 | while True: 263 | ret = requests.get(ret_url) 264 | data = ret.json() 265 | if data.get('text'): 266 | if debug: 267 | with open('img.png', 'wb') as f: 268 | f.write(img_content) 269 | print(data.get('text')) 270 | return data['text'] 271 | -------------------------------------------------------------------------------- /source/message_main.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | import argparse 3 | from message_api import * 4 | from message_controller import check_available, init_mobile, r, message_info,check_login 5 | import queue 6 | import sys 7 | from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED, as_completed 8 | import time 9 | import random 10 | 11 | 12 | def sed_msg(mobile, set_of_times, interval_time, remainder): 13 | init_mobile(mobile, set_of_times) 14 | available_msg = [] 15 | while len(available_msg) < remainder: 16 | m = random.choice(all_message_info) 17 | if check_available(m): 18 | available_msg.append(m) 19 | pool = ThreadPoolExecutor(500) 20 | SHARE_Q = queue.Queue(remainder) 21 | while SHARE_Q.qsize() < remainder: 22 | SHARE_Q.put(random.choice(available_msg)) 23 | all_task = [] 24 | for t in range(SHARE_Q.qsize()): 25 | mg = SHARE_Q.get() 26 | try: 27 | all_task.append(pool.submit(eval(mg), mg, mobile)) 28 | except KeyboardInterrupt: 29 | r.delete('%s_%d' % (mobile, set_of_times)) 30 | sys.exit(0) 31 | if interval_time: 32 | time.sleep(interval_time) 33 | wait(all_task, return_when=ALL_COMPLETED) 34 | 35 | 36 | def main(mobile, set_of_times, interval_time): 37 | mobile_incr = '%s_%d' % (mobile, set_of_times) 38 | while True: 39 | if r.get(mobile_incr): 40 | sed_count = int(r.get(mobile_incr)) 41 | else: 42 | sed_count = 0 43 | if sed_count >= set_of_times: 44 | break 45 | if sed_count: 46 | remainder = set_of_times - sed_count 47 | else: 48 | remainder = set_of_times 49 | sed_msg(mobile, set_of_times, interval_time, remainder) 50 | r.delete(mobile_incr) 51 | 52 | 53 | if __name__ == '__main__': 54 | check_login() 55 | parser = argparse.ArgumentParser() 56 | parser.add_argument('-m', required=True, type=int, dest='m', metavar='Mobile', help='接收短信的手机号码') 57 | parser.add_argument('-c', required=True, type=int, dest='c', metavar='Count', help='发送短信数量') 58 | parser.add_argument('-s', required=False, type=int, dest='s', metavar='Seconds', help='设置每条短信发送的时间间隔,默认为连续发送') 59 | args = parser.parse_args() 60 | mobile = str(args.m) 61 | if len(mobile) < 11 or not mobile.startswith('1'): 62 | sys.exit('手机号码格式错误') 63 | set_of_times = args.c 64 | interval_time = args.s 65 | all_message_info = [m for m in message_info()] 66 | try: 67 | main(mobile, set_of_times, interval_time) 68 | except KeyboardInterrupt: 69 | r.delete('%s_%d' % (mobile, set_of_times)) 70 | sys.exit(0) 71 | -------------------------------------------------------------------------------- /source/process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brightest08/message/b85ea410d02e036bafe1fac9fdb2a683e2f1d1cf/source/process.png -------------------------------------------------------------------------------- /source/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.22.0 2 | PyMySQL==0.9.3 3 | chardet==3.0.4 4 | psutil==5.6.3 5 | DBUtils==1.3 6 | kafka-python==1.4.6 7 | redis==3.2.1 8 | beautifulsoup4==4.6.0 9 | PyExecJS==1.5.1 10 | elasticsearch==7.0.2 11 | --------------------------------------------------------------------------------