以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- api接口请求,报签名错误,怎么回事? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=105404) |
-- 作者:zcl -- 发布时间:2017/8/18 15:18:00 -- api接口请求,报签名错误,怎么回事? 各位大师,我是一菜鸟,在做一个api接口请求的时候,报签名错误,怎么回事? {"success":false,"errorCode":"Base Param error","subErrorCode":"ErrorSign","errorDesc":"基本参数错误","subErrorDesc":"签名错误","requestMethod":null} api接口提供的说明如下: http://gop.guanyierp.com/interface/gy.erp.introd.htm 我的代码: Dim jo As New JObject jo("appkey") = "APPKEy" jo("sessionkey") = "会话密钥" jo("method") = "gy.erp.trade.get" jo("page_no")="1" jo("page_size")="10" jo("start_date") = "2017-08-16 00:00:00" jo("end_date") = "2017-08-16 24:00:00" jo("date_type") =2 \'jo("order_state") = 2 \'jo("shop_code") = 2 Dim postjsonstring As String = jo.ToString Dim secret As String = "安全密钥" Dim sign As String = secret & postjsonstring & secret sign = MD5Encrypt(sign) jo("sign") = sign.ToUpper postjsonstring= jo.ToString \'定义接口url Dim url As String = String.Format("http://v2.api.guanyierp.com/rest/erp_open/") \'Json序列化到内存流 Using ms As New System.IO.MemoryStream() Dim bytes = ConvertHelper.EncodingToBytes(postjsonstring , System.Text.Encoding.UTF8) ms.Write(bytes, 0, bytes.Length) ms.Seek(0, System.IO.SeekOrigin.Begin) Dim jsonString = Functions.Execute("HttpPost",url, ms) Dim mresult = ConvertHelper.FromJson(Of MmsgResult)(jsonString) e.Form.Controls("TextBox1").Text = jsonString 问题出在哪里呢?
|
-- 作者:有点蓝 -- 发布时间:2017/8/18 15:31:00 -- 加密试试 …… Dim sign As String = secret & postjsonstring & secret Using md5Hash As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create() Dim data As Byte() = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(sign )) Dim sBuilder As New StringBuilder() Dim i As Integer For i = 0 To data.Length - 1 sBuilder.Append(data(i).ToString("x2")) Next i jo("sign") = sBuilder.ToString().ToUpper End Using …… |
-- 作者:zcl -- 发布时间:2017/8/18 15:41:00 -- 蓝大侠,修改以后签名错误没有,但是说"用户输入参数格式有误“,我已经核对了,应该没有问题呀 { "appkey": "用户ID", "sessionkey": "1055403fe6ad4c7381ec4bed0cd16a61", "method": "gy.erp.trade.get", "page_no": "1", "page_size": "10", "start_date": "2017-08-16 00:00:00", "end_date": "2017-08-16 24:00:00", "date_type": 2, "sign": "2C23049415224C1E49527EFAE7A5A080" } 返回值: {"success":false,"errorCode":"500","subErrorCode":"","errorDesc":"用户输入参数格式有误","subErrorDesc":"","requestMethod":""} |
-- 作者:有点蓝 -- 发布时间:2017/8/18 16:00:00 -- 应该是数据类型不一致,比如page_no是整数,不是字符串 jo("page_no")=1
|
-- 作者:zcl -- 发布时间:2017/8/18 16:17:00 -- 他给的例子是字符呀,而且使用数字,也不行 [此贴子已经被作者于2017/8/18 16:18:32编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/8/18 16:38:00 -- 看不出其它问题,试试这种方式post数据 Dim hc As New HttpClient("http://v2.api.guanyierp.com/rest/erp_open/") hc.Content = postjsonstring Dim ret As String = hc.GetData() msgbox(ret)
|
-- 作者:zcl -- 发布时间:2017/8/18 16:41:00 -- 用这种办法又回到一开始 的哪个问题了,签名错误: {"success":false,"errorCode":"Base Param error","subErrorCode":"ErrorSign","errorDesc":"基本参数错误","subErrorDesc":"签名错误","requestMethod":null}
|
-- 作者:有点蓝 -- 发布时间:2017/8/18 16:49:00 -- 问问官方客服有没有.net的连接例子,看看是怎么连的。 |