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


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

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

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/26 15:22:00 [只看该作者]

试试这样处理

 

Dim req = System.Net.WebRequest.Create("http://www.baidu.com")
req.Method = "delete"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
Dim ck As new System.Net.Cookie("username", "123456")
req.CookieContainer.add(new Uri("http://www.baidu.com/"), 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  
msgbox(str)
stm.Dispose()


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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/26 18:04:00 [只看该作者]

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


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/26 18:29:00 [只看该作者]

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", "123456")
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)

[此贴子已经被作者于2018/7/26 18:29:24编辑过]

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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/28 20:55:00 [只看该作者]

增加了一个get方法,可以查收回复的上行短信,如何实现呀?


<!--[if !supportLists]-->1         <!--[endif]-->message

message资源供用户进行短信的发送和上行短信的查询,支持POSTGET方法。

POST

调用POST方法提交数据实现短信的发送,需首先登陆,并在request请求中附带登陆后的cookies使用。

按照模拟form表单提交方式调用。

POST所需form参数有desttermidcontentmode

desttermid为目标手机号码

content为短信内容,需采用utf-8编码传输

mode为短信类型,取值有012。其中0表示无需查询短信回执和回复,1表示无需查询短信回复,2表示需要查询短信回复。

返回json内容为一个字典,包含errorcodetaskid两个字段,errorcode为错误码,taskid为这一次短信发送的唯一标识,之后对回执和回复的查询都需要使用。

 

GET

需首先登陆,并在request请求中附带登陆后的cookies使用。

调用GET方法查询某个taskid对应短信的上行回复短信,无需额外参数,但url中需包含taskid信息。实际调用url为:

http://10.10.10.10:10/message/taskid/<taskid>

返回json内容为一个数组,其中每一个数组为一个字典,包含sourcetermidcontentreceivedtime三个字段。

sourcetermid为发送方号码。

content为短信内容,按照utf-8编码

receivedtime为短信接收时间。

[此贴子已经被作者于2018/7/28 21:01:39编辑过]

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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/28 21:01:00 [只看该作者]

用下面这串代码,和上面的delete方法一样,提示 没有登录,但实际上登陆是有返回TWIST_SESSION值的,应该是成功的
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
  16楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/28 21:13:00 [只看该作者]


此主题相关图片如下:1.png
按此在新窗口浏览图片

  <!--[endif]-->errorcode  = -20的意思对应:    ERROR_NOT_LOGGED_IN = -20


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  17楼 | 信息 | 搜索 | 邮箱 | 主页 | 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
  18楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


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

接口文档如下

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


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/7/29 16:45:00 [只看该作者]

以下是引用ycwk在2018/7/28 21:13:00的发言:

此主题相关图片如下:1.png
按此在新窗口浏览图片

  <!--[endif]-->errorcode  = -20的意思对应:    ERROR_NOT_LOGGED_IN = -20

 

提示是请先登录,说明你cookie值不对导致的,认真核对和测试。


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  20楼 | 信息 | 搜索 | 邮箱 | 主页 | 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()




 回到顶部
总数 41 上一页 1 2 3 4 5 下一页