kxing 发表于 2013-6-21 05:48:24

_winhttp_getrespond提交中文乱码

本帖最后由 kxing 于 2013-6-21 19:54 编辑

该程序几乎成品了,可惜是发送中文字符就乱码。
在此贴上源码,新手拿去学习。望高人能解决这美中不足的地方。
希望 republican 等高人能出来解决,小弟不胜感激!!#include "winhttp_getrespond.au3"
_sms_main()
func _sms_main()
local $hOpen=_winhttpopen()

$phonenum=inputbox("手机号码","请输入接收验证码的手机号:")
if not stringregexp($phonenum,"^\d{11}$") then return msgbox(48,"提示","您输入的手机号码不正确!")
_sms_getcheckcode($hOpen,$phonenum)
$checkcode=inputbox("验证码","请输入手机接收到的验证码:")
if not stringregexp($checkcode,"^\d+$") then return msgbox(48,"提示","您输入的验证码不正确!")

$loginRes=_winhttp_getrespond($hOpen,"http://115.239.133.251:6090/imweb/codeLoginForSouGou.s?clientId=51&channel=51&account="&$phonenum&"&checkCode="&$checkcode,2)
if @error then
msgbox(48,"抱歉","连接服务器失败,请稍后再试!")
return false
else
$res=binarytostring($loginRes)
if stringinstr($res,"100") then
msgbox(64,"OK","登陆成功!")
else;判断错误码
if stringinstr($res,"101") then
msgbox(48,"提示","您已连续5次输错验证码,请半小时后再试")
elseif stringinstr($res,"102") then
msgbox(48,"提示","验证码错误")
elseif stringinstr($res,"103") then
msgbox(48,"提示","验证码失效,请重新获取")
elseif stringinstr($res,"802") then
msgbox(48,"提示","验证码错误")
else
msgbox(48,"提示","登录失败,请稍后再试")
endif
;return false
endif
endif


const $title="短信免费发"
if winexists("") then return winactivate("")


$hForm=guicreate($title,200,180)
guisetbkcolor(0x000000)
guictrlcreatelabel("对方手机:",10,10,60,20)
guictrlsetcolor(-1,0xffffff)
$hPhonenum=guictrlcreateinput("",70,10,100,20)
guictrlcreatelabel("发送内容:",0,0,0,0)
$hSendmsg=guictrlcreateedit("",0,40,200,100)
$hSendbut=guictrlcreatebutton("免费发送(Ctrl+回车)",30,150,140,20)
guisetstate()

while 1
switch guigetmsg()
case -3
_winhttpclosehandle($hOpen)
exit

case $hSendbut
$num=guictrlread($hPhonenum)
$text=guictrlread($hSendmsg)
_sms_sendmsg($hOpen,$num,$text,$checkcode)
endswitch
wend
endfunc;main

func _sms_getcheckcode($hOpen,$pNum)
$res=_winhttp_getrespond($hOpen,"http://115.239.133.251:6090/imweb/phoneCheckCode.s?sendPhone="&$pNum&"&methodType=getPhoneCode",2)
if @error then return false

$res=binarytostring($res)
if stringinstr($res,100) then
msgbox(64,"OK","验证码已经发送至您手机")
elseif stringinstr($res,103) then
msgbox(48,"提示","今天已经获取过10次已达上限")
elseif stringinstr($res,"104") then
msgbox(48,"提示","您获取验证码次数太频繁,请歇会再试")
elseif stringinstr($res,"105") then
msgbox(48,"提示","您已连续5次输错验证码,请半小时后再试")
else
msgbox(16,"错误","验证码获取失败")
endif
endfunc;getcheckcode

func _sms_sendmsg($hOpen,$num,$text,$chk)
$send="http://115.239.133.251:6090/imweb/smsPush.s?checkCode="&$chk&"&receivePhone="&$num&"&smsContent="&$text
$headers="x-requested-with: XMLHttpRequest"&@CRLF& _
"Accept-Language: zh-cn"&@CRLF& _
"Referer: http://115.239.133.251:6090/imweb/toSouGou/index.html"&@CRLF& _
"Accept: */*"&@CRLF& _
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"&@CRLF& _
"Accept-Encoding: gzip, deflate"&@CRLF& _
"Connection: Keep-Alive"&@CRLF& _
"Cache-Control: no-cache"&@CRLF&@CRLF

$sendres=_winhttp_getrespond($hOpen,$send,2,-1,$headers)

$res=binarytostring($sendres)
if stringinstr($res,100) then
msgbox(64,"OK","短信已成功发送!")
else
msgbox(16,"错误","短信发送失败,可能验证码已失效,请重新获取!")
endif
clipput($res)
endfunc;sendmsg

kxing 发表于 2013-6-21 05:56:27

我尝试过将短信内容用unicode编码过也是不行。

原POST抓包数据:

POST /imweb/smsPush.s?clientId=51 HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: zh-cn
Referer: http://115.239.133.251:6090/imweb/toSouGou/index.html
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)
Host: 115.239.133.251:6090
Content-Length: 193
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=A2AEDACC5D21AC6663C0D6AEF7EC9E60



-------------------------

checkCode=%E6%A0%A1%E9%AA%8C%E7%A0%81&receivePhone=11位手机号&smsContent=hello+123.%E3%80%82%E3%80%82%E5%93%A6%E5%8F%91%E7%BB%99%E8%B0%81&fileUrl=&fileSize=&fileName=&random=0.5231676247708166

邪恶海盗 发表于 2013-6-21 13:00:55

楼主高淫,帮顶了...

heavenm 发表于 2013-6-21 13:19:14

没实用价值! 只能发5条
还要手机验证码!

laomeng 发表于 2013-6-21 17:49:48

有想法不错

kxing 发表于 2013-6-22 09:03:52

顶起来,望高人看见。。。

Duvet 发表于 2013-6-22 16:02:17

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

Line 84 $text

轉成urlencoded(UTF-8)再發送出去

kxing 发表于 2013-6-23 17:43:00

回复 7# Duvet

试过了,还是乱码啊。。。

Duvet 发表于 2013-6-23 19:35:45

不是unicode编码

$send = "http://115.239.133.251:6090/imweb/smsPush.s?" & _
                "checkCode=" & $chk & _
                "&receivePhone=" & $num & _
                "&smsContent=" & _Encode($text)
                       
Func _Encode($sText)
        Local $oSC = ObjCreate("ScriptControl")
        If @error Then Return SetError(-1, 0, $sText)
        $oSC.language = "JavaScript"
        Return $oSC.eval("encodeURIComponent('" & $sText & "');")
EndFunc

kxing 发表于 2013-6-24 03:44:24

回复 9# Duvet


老兄,我用的就是此编码啊    ,不行哦。
难道你测试没问题??

lvjun215 发表于 2013-6-26 21:56:49

看看怎么样啊学习中···

republican 发表于 2013-6-26 23:04:13

好久没回了,周末看看。

其他大大都不在啦?

republican 发表于 2013-6-26 23:41:33

回复 1# kxing

请使用POST而非GET提交转义字符。

kxing 发表于 2013-6-27 01:52:33

本帖最后由 kxing 于 2013-6-27 01:54 编辑

post也试过了,一样乱码。

kxing 发表于 2013-6-30 05:26:08

高人们出来驻站下啊....
页: [1]
查看完整版本: _winhttp_getrespond提交中文乱码