Skip to content

Instantly share code, notes, and snippets.

@fanyer
Forked from lihongjie0209/sms.py
Created October 4, 2018 12:28
Show Gist options
  • Save fanyer/ffb5ef25417f12af36b38f563f80e2e5 to your computer and use it in GitHub Desktop.
Save fanyer/ffb5ef25417f12af36b38f563f80e2e5 to your computer and use it in GitHub Desktop.

Revisions

  1. @lihongjie0209 lihongjie0209 created this gist Oct 4, 2018.
    27 changes: 27 additions & 0 deletions sms.py
    Original 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)