Web Short Message安卓短信接口

;Autohotkey+Web Short Message(com.wangtai.smstwoman)短信接口
;Thinkai@2015-01-05

;注意每次运行APP的管理网址都不一样
ManageUrl = http://192.168.1.106:1984/8119

;获取参数
RegExMatch(ManageUrl,"^(http://.*:d*/)(d{4})",parameter)
global parameter1
global parameter2



;运用实例

;发短信
if (SendMsg(10001,7)=1)
	MsgBox, 64, 提示, 短信发送成功

;接收回复
NewMessage := GetNewMsg()
From :=  NewMessage[1]["person"] ? NewMessage[1]["person"] "(" NewMessage[1]["address"] ")" : "未知(" NewMessage[1]["address"] ")"
MsgBox % "From:" From "`n" NewMessage[1]["body"]

;获取联系人
Contact := GetContacts()
for k,v in Contact
{
	MsgBox, 64, 提示, 第一个联系人是%v%`,号码是%k%
	Return
}

;获取新消息函数(调用后收到的)
GetNewMsg(){
;返回数组说明
;数组[1]:
;	_id:消息ID
;	address:号码
;	body:短信正文
;	date:收信Uinx时间戳
;	person:联系人
	Loop
	{
		res := URLDownloadToVar(parameter1 "get_new_msg/" parameter2 "/", "utf-8","POST") ;获取最新短信的JSON数据
		if (strlen(res)>2)
			Return json_toobj(res)
		Sleep, 100
	}
}

;获取联系人函数
GetContacts(){
obj := {} ;初始数组
res := URLDownloadToVar(parameter1 "get_contacts/" parameter2 "/", "utf-8","POST") ;获取联系人的JSON数据
;处理格式问题
StringTrimLeft, res, res, 1
StringTrimRight, res, res, 1
StringSplit, var, res, `,
loop % var0
{
	tmp_var := var%A_index%
	RegExMatch(tmp_var,"""(.*)"":""(.*)""",m)
	m1 := RegExReplace(m1,"s","")
	m1 := RegExReplace(m1,"+86","")
	obj["" m1] := m2 ;注意此处数组key的类型
}
Return obj ;返回数组  obj[电话号码] := 联系人姓名
}

;发短信函数
SendMsg(to,msg){ ;号码,消息
msg := urlencode(msg)
Return URLDownloadToVar(parameter1 "send/" parameter2 "/" to "/", "utf-8","POST","msg=" msg)
}



URLDownloadToVar(url, Encoding = "",Method="GET",postData=""){ ;网址,编码,请求方式,post数据
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	if Method = GET
	{
		hObject.Open("GET",url)
		Try
			hObject.Send()
		catch e
			return -1
	}
	else if Method = POST
	{
		hObject.Open("POST",url,False)
		hObject.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
		Try
			hObject.Send(postData)
		catch e
			return -1
	}

	if Encoding
	{
		oADO := ComObjCreate("adodb.stream")
		oADO.Type := 1
		oADO.Mode := 3
		oADO.Open()
		oADO.Write(hObject.ResponseBody)
		oADO.Position := 0
		oADO.Type := 2
		oADO.Charset := Encoding
		return oADO.ReadText(), oADO.Close()
	}
	return hObject.ResponseText
}


urlencode(string){
string := Ansi2UTF8(string)
StringLen, len, string
Loop % len
{
SetFormat, IntegerFast, hex ;运算结果为HEX
StringMid, out, string, %A_Index%, 1
hex := Asc(out) ;获取单字节ascii值
hex2 := hex ;另存变量
StringReplace, hex, hex, 0x, , All
SetFormat, IntegerFast, d
hex2 := hex2 ;十进制化
;判断是否可见单字节字符 是则直接连接 否则编码
If (hex2==33 || (hex2>=39 && hex2 =48 && hex2=65 && hex2=97 && hex2 1
		} ; Loop Parse, str, % "[{"

		If !--nest
			Break

		; Insert the newly closed object into the one on top of the stack, then pop the stack
		pbj := obj
		obj := objs.remove()
		obj[key := keys.remove()] := pbj
		If ( isarray := isarrays.remove() )
			key++

	} ; Loop Parse, str, % "]}"

	Return obj
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他案例

浮岛拼图|将window键盘的CTRL,WIN,ALT改为mac键盘布局

2020-3-11 22:59:16

其他

01_安装电脑软件的步骤批处理脚本.bat

2020-3-15 19:55:18

个人中心
购物车
优惠劵
有新私信 私信列表
搜索