-
Notifications
You must be signed in to change notification settings - Fork 11
/
sgip_webserver.py
49 lines (39 loc) · 1.07 KB
/
sgip_webserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
SGIP Server, Http server, client->server->sgip(联通)
"""
import sys
from twisted.internet import reactor
from twisted.web.resource import Resource
from twisted.web.server import Site
from sgip_client import send_sms
reload(sys)
sys.setdefaultencoding('utf8')
try:
import json
except:
import simplejson as json
class SmsAPI(Resource):
def render_GET(self, request):
return 'error'
def render_POST(self, request):
res = {"code": 2}
try:
jsondata = request.content.getvalue()
data = json.loads(jsondata)
phone = data.get('phone', "")
message = data.get('message', "")
if phone and message:
code = send_sms(str(phone), message)
res["code"] = code
else:
code = 3
except Exception as e:
res["code"] = 3
return json.dumps(res)
root = Resource()
root.putChild("smsapi", SmsAPI())
factory = Site(root)
reactor.listenTCP(30059, factory)
reactor.run()