websocket版 websocket连接不上

开发接入

(snlijianpu) #1

wss://apigwws.open.rokid.com/api?key=195A9C1092F749DA89CBA6651F0D93C8&device_type_id=646046030C4C4C309066F4A77DFA1B3E&device_id=rock&service=asr&version=2.0&time=1518343331&sign=8BFC710C41BF4D8A69C733E3E536B731 error>>>>>>>>>>>>>>>>>>>>>> Connection is already closed. error<<<<<<<<<<<<<<<<<<<<<<

closed

websock 是通过这种方式连接,一直就没有连接上呢?


(大发) #2

是在进行哪一个步骤的时候报错的呢?


(snlijianpu) #3

是在 AuthRequest 时,返回结果为result: AUTH_FAILED, 签名字符串是 key=195A9C1092F749DA89CBA6651F0D93C8&device_type_id=646046030C4C4C309066F4A77DFA1B3E&device_id=rock&service=asr&version=2.0&time=1519265603&secret={secret} 其中{secret}是我们的秘钥 签名结果为:3Jcuyq1W7TiyJADxBfoQEw==


(yam.zhang) #4

service=speech,您试试这个呢


(snlijianpu) #5

key=195A9C1092F749DA89CBA6651F0D93C8&device_type_id=646046030C4C4C309066F4A77DFA1B3E&device_id=rock&service=speech&version=2.0&time=1519281068&secret=DB0AD79952064DCBA56F167874B779D0

sign=nhQIxTmvujZDgvMFgTm1aA==

结果还是result: AUTH_FAILED


(yam.zhang) #6

您的sign是错的,我们要求是md5的呢


(616941303) #7

你好。sign是对一串字符串的md5,可以参考如下代码:

func generateSign(now, version, secret, key, deviceTypeID, deviceID, service string) string {
	src := "key=" + key + "&device_type_id=" + deviceTypeID + "&device_id=" + 
         deviceID + "&service=" + service + "&version=" +
         version + "&time=" + now + "&secret=" + secret
	fmt.Println("sign source:", src)
	sign := strings.ToUpper(makeMD5(src))
	return sign
}

(snlijianpu) #8

result: SUCCESS

AuthRequest返回成功了,谢谢各位