-
-
Save fanyer/ffb5ef25417f12af36b38f563f80e2e5 to your computer and use it in GitHub Desktop.
Revisions
-
lihongjie0209 created this gist
Oct 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ from androidhelper import Android from time import sleep import json import urllib2 d = Android() url = "youserver/sms/notify" while(True): messages = d.smsGetMessages(False) for i in messages.result: body = i["body"] phone = i["address"] # if not json, just pass if (len(body)==0): continue # 简单判断是否为json if body.strip()[0:1]=="{": try: request = urllib2.Request(url, body, headers={"from" : phone, "via_device":"python-app"}) f = urllib2.urlopen(request) d.smsDeleteMessage(i["_id"]) print("send {0} to {1} with response {2}".format(body, url, f.read())) except Exception, e: print("send {0} to {1} fail: {0}".format(body, url, str(e))) # print(i["_id"] + ":" + i["address"] + ":" + ) sleep(1)