Foxtable(狐表)用户栏目专家坐堂 → 短信接口中请在request请求中附带登出后的cookies使用,这是什么意思?


  共有4109人关注过本帖树形打印复制链接

主题:短信接口中请在request请求中附带登出后的cookies使用,这是什么意思?

帅哥哟,离线,有人找我吗?
ycwk
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/28 21:19:00 [显示全部帖子]

Dim str_name As String="王"
Dim str_sign As String="信"
'Dim str_SearchTable As String=args(2)
Dim str_tel As String="15311111111"
Dim str_content As String="上行短信第9遍"
Dim str_status As Boolean=True   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
      


Dim str_cookies As String
Dim user As String = "yc"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@X" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化


Dim hc As New HttpClient("http://10.10.10.10:10/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)

For Each key As String In hc.rCookies.Keys
   msgbox(key)                   'TWISTED_SESSION
   msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
   str_cookies= hc.rCookies(key)
Next



'接收回复
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")  '代表接收短信后的id
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
req.CookieContainer.add(new Uri("http://10.10.10.10"), ck)
Dim pos = req.GetResponse()
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm,encoding.utf8)
Dim str As String = reader.ReadToEnd
stm.Dispose()


msgbox(str)


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  12楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/28 21:22:00 [显示全部帖子]

接口文档如下

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:接口文档.rar


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  13楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/29 19:07:00 [显示全部帖子]

cookies应该没有问题吧,下面这段代码,发短信和查收回复 都是用的str_cookies ,如果有问题,为什么登陆后的发短信是成功的呢?

Dim str_name As String="王昆"
Dim str_sign As String="信息科"
'Dim str_SearchTable As String=args(2)
Dim str_tel As String="15327667745"
Dim str_content As String="上行短信第3遍"
Dim str_status As Boolean=True   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
      


Dim str_cookies As String
Dim user As String = "yc_yyy_xmgl"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@XfW1K4WA7&p0Y&tg4&4" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化


Dim hc As New HttpClient("http://10.27.254.6:9527/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)

For Each key As String In hc.rCookies.Keys
   'msgbox(key)                   'TWISTED_SESSION
   'msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
   str_cookies= hc.rCookies(key)
Next

'msgbox(4)
'在提交的时候附带cookies
Dim hc_send As New HttpClient("http://10.27.254.6:9527/message")    '发短信
hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
hc_send.FormData.Add("desttermid",str_tel)
hc_send.FormData.Add("content",str_content)
hc_send.FormData.Add("mode","2")  '表示需要查收回复
Dim ret_send As String = hc_send.getData()

Dim jo_send As JObject= JObject.Parse(ret_send)
msgbox(jo_send("errorcode").ToString)
msgbox(jo_send("taskid").ToString)


'接收回复
'Dim str_reply As String ="http://sms.yc.hb.cegn.cn:9527/message/taskid/" & 
'Dim hc_send As New HttpClient("http://10.27.254.6:9527/message")    '发短信
'hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
'hc_send.FormData.Add("desttermid",str_tel)
'hc_send.FormData.Add("content",str_content)
'hc_send.FormData.Add("mode","2")   


'msgbox(5)
 ' 接收发送后的返回信息
 Dim dr_receipt As Row = Tables("短信通知回执表").AddNew
 dr_receipt("returnstatus") = jo_send("errorcode")
         
If str_status=True Then   '如果需要弹出提醒则弹,否则不弹
   If jo_send("errorcode") ="0"  Then   '如果返回发送成功信息
      MessageBox.Show("发送成功")
   Else 
      MessageBox.Show("发送失败")
   End If
End If
 dr_receipt("taskID") = jo_send("taskID")
 dr_receipt("回执时间") = Date.Now
 dr_receipt("发送号码") = str_tel
 dr_receipt("发送内容") = str_content
 dr_receipt("姓名")= str_name    '保存发送对象的姓名在通知回执里
 dr_receipt.Save     ' 保存回执



'Functions.Execute("智慧宜昌短信平台",dr("任务_责任人"),"计算机中心","人员联系方式字典",str_content,True )) 

Dim str_name As String="王"
Dim str_sign As String="信科"
'Dim str_SearchTable As String=args(2)
Dim str_tel As String="15311111111"
Dim str_content As String="上行短信第3遍"
Dim str_status As Boolean=True   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
      


Dim str_cookies As String
Dim user As String = "yc_yy"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化


Dim hc As New HttpClient("http://10.10.10.10:10/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)

For Each key As String In hc.rCookies.Keys
   'msgbox(key)                   'TWISTED_SESSION
   'msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
   str_cookies= hc.rCookies(key)
Next

'msgbox(4)
'在提交的时候附带cookies
Dim hc_send As New HttpClient("http://10.10.10.10:10/message")    '发短信
hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
hc_send.FormData.Add("desttermid",str_tel)
hc_send.FormData.Add("content",str_content)
hc_send.FormData.Add("mode","2")  '表示需要查收回复
Dim ret_send As String = hc_send.getData()

Dim jo_send As JObject= JObject.Parse(ret_send)
msgbox(jo_send("errorcode").ToString)
msgbox(jo_send("taskid").ToString)



 ' 接收发送后的返回信息
 Dim dr_receipt As Row = Tables("短信通知回执表").AddNew
 dr_receipt("returnstatus") = jo_send("errorcode")
         
If str_status=True Then   '如果需要弹出提醒则弹,否则不弹
   If jo_send("errorcode") ="0"  Then   '如果返回发送成功信息
      MessageBox.Show("发送成功")
   Else 
      MessageBox.Show("发送失败")
   End If
End If
 dr_receipt("taskID") = jo_send("taskID")
 dr_receipt("回执时间") = Date.Now
 dr_receipt("发送号码") = str_tel
 dr_receipt("发送内容") = str_content
 dr_receipt("姓名")= str_name    '保存发送对象的姓名在通知回执里
 dr_receipt.Save     ' 保存回执




'查收回复   
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
req.CookieContainer.add(new Uri("http://10.10.10.10"), ck)
Dim pos = req.GetResponse()
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm,encoding.utf8)
Dim str As String = reader.ReadToEnd
stm.Dispose()




 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  14楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/29 19:17:00 [显示全部帖子]



Dim str_name As String="王"
Dim str_sign As String="信"
'Dim str_SearchTable As String=args(2)
Dim str_tel As String="15321111111"
Dim str_content As String="上行短信第13遍"
Dim str_status As Boolean=True   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
      


Dim str_cookies As String
Dim user As String = "yc_yy"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@X" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化


Dim hc As New HttpClient("http://10.10.10.10:10/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)

For Each key As String In hc.rCookies.Keys
   'msgbox(key)                   'TWISTED_SESSION
   'msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
   
   str_cookies= hc.rCookies(key)
   msgbox(str_cookies) 
Next

'msgbox(4)
'在提交的时候附带cookies
Dim hc_send As New HttpClient("10.10.10.10:10/message")    '发短信
hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
hc_send.FormData.Add("desttermid",str_tel)
hc_send.FormData.Add("content",str_content)
hc_send.FormData.Add("mode","2")  '表示需要查收回复
Dim ret_send As String = hc_send.getData()

Dim jo_send As JObject= JObject.Parse(ret_send)
msgbox(jo_send("errorcode").ToString)
msgbox(jo_send("taskid").ToString)


'接收回复
'Dim str_reply As String ="http://10.10.10.10:10/message/taskid/" & 
'Dim hc_send As New HttpClient("10.10.10.10:10/message")    '发短信
'hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
'hc_send.FormData.Add("desttermid",str_tel)
'hc_send.FormData.Add("content",str_content)
'hc_send.FormData.Add("mode","2")   


'msgbox(5)
 ' 接收发送后的返回信息
Dim dr_receipt As Row = Tables("短信通知回执表").AddNew
 dr_receipt("returnstatus") = jo_send("errorcode")
         
If str_status=True Then   '如果需要弹出提醒则弹,否则不弹
   If jo_send("errorcode") ="0"  Then   '如果返回发送成功信息
      MessageBox.Show("发送成功")
   Else 
      MessageBox.Show("发送失败")
   End If
End If
 dr_receipt("taskID") = jo_send("taskID")
 dr_receipt("回执时间") = Date.Now
 dr_receipt("发送号码") = str_tel
 dr_receipt("发送内容") = str_content
 dr_receipt("姓名")= str_name    '保存发送对象的姓名在通知回执里
 dr_receipt.Save     ' 保存回执


msgbox(str_cookies) 
'查收回复   
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
req.CookieContainer.add(new Uri("http://10.10.10.10:10"), ck)
Dim pos = req.GetResponse()
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm,encoding.utf8)
Dim str As String = reader.ReadToEnd
stm.Dispose()
msgbox(str)


用上面的代码,依次弹出如下提示,短信是成功收到了的。证明每次的cookies都是一样的
1178c55d833f3a3febb66e8c4223d10f        'cookies
41d6d7847652d5dc1a62d210167d            'taskid
1178c55d833f3a3febb66e8c4223d10f        'cookies
1178c55d833f3a3febb66e8c4223d10f         'cookies
{"errorcode": -20, "result": "\u8bf7\u5148\u767b\u5f55"}




 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  15楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/29 21:31:00 [显示全部帖子]

delete方法也不能执行,我咨询了平台厂家的,他们是正常的呀

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  16楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/30 11:10:00 [显示全部帖子]

这段代码能用httpclient  实现吗?   get方法的


msgbox(str_cookies) 
'查收回复   
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
req.CookieContainer.add(new Uri("http://10.10.10.10:10"), ck)
Dim pos = req.GetResponse()
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm,encoding.utf8)
Dim str As String = reader.ReadToEnd
stm.Dispose()
msgbox(str)

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  17楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/8/4 21:19:00 [显示全部帖子]

delete函数的  demo来了:

   [WebMethod(EnableSession = true, BufferResponse = true, Description = "发短信注销")]
        public string SMSOut()
        {
            if (Session["cookie"] != null)
            {
                cookie = (CookieContainer)Session["cookie"];
            }

            string res = Utily.HttpDelete(cookie);

            string resStr = "";

            if (!string.IsNullOrEmpty(res))
            {
                ResultMsg rm = JsonHelper.DeserializeJsonToObject<ResultMsg>(res);

                string err = rm.errorcode;
                resStr = rm.result;
            }

            return resStr;
        }






        /// GET请求与获取结果  
        /// </summary> 
        public static string HttpDelete(CookieContainer cookie)
        {
            string url = "http://10.10.10.10:10/session";
     
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            
         
            webRequest.Method = "DELETE";
            webRequest.C;
            webRequest.Timeout = 60000;
            webRequest.CookieContainer = cookie;


            //4. 读取服务器的返回信息
            HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string res = sr.ReadToEnd();
            return res;
        }
[此贴子已经被作者于2018/8/4 21:41:31编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  18楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/8/4 22:37:00 [显示全部帖子]

使用下面的代码注销时始终提示 已经登出, 我怀疑是注销时没有成功把cookies传给服务器

Dim str_name As String="王"
Dim str_sign As String="心"
Dim str_tel As String="15311111111"
Dim str_content As String="你有新任务"
Dim str_ReplyMessage As String=""   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
        


Dim str_cookies As String
'Dim cookieCon = new System.Net.CookieContainer


Dim user As String = "yc_yy"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@XfW1K4W" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化
'msgbox(auth)
'msgbox(3)
Dim hc As New HttpClient("http://10.10.10.10:10/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)
'msgbox(jo("errorcode").ToString)    '可以正确弹出
'msgbox(jo("result").ToString)     '可以正确弹出
For Each key As String In hc.rCookies.Keys
   msgbox(key)                   'TWISTED_SESSION
   msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
  ' cookieCon.Headers.add(hc.rCookies(key))
   str_cookies=hc.rCookies(key)
Next


Dim wb As New WeUI
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/session")
req.Method = "DELETE"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
'Dim ck As new System.Net.Cookie("TWIST_SESSION", str_ )
wb.AppendCookie("TWIST_SESSION",str_cookies) 
req.CookieContainer.add(new Uri("http://10.10.10.10"), wb)
Dim pos = req.GetResponse()
Dim stm As System.IO.Stream = pos.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm,encoding.utf8)
Dim str As String = reader.ReadToEnd
stm.Dispose()
msgbox(str)




 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  19楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/8/5 22:34:00 [显示全部帖子]

没太看懂老师和贴子上说的意思,能否给个delete的代码?

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  20楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/8/6 8:00:00 [显示全部帖子]

自己试了一下,还是不行,把别人的demo要来了,在下面,请老师帮忙提供一下代码
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:发短信.rar


 回到顶部
总数 25 上一页 1 2 3 下一页