1、把普通的IP访问改为自己的域名,例如我们希望的域名是mywebsocket.test.com,那么前端页面配置的地址如下
// ws协议,注意,域名后面的/webSocket自己随意起,但是要和后台保持一直,别访问不到了
ws://mywebsocket.test.com/webSocket
// wss协议,需要SSL证书,也就是你的域名必须要支持HTTPS
wss://app116386.eapps.dingtalkcloud.com/webSocket
2、页面的DEMO如下,比较简单
var wesocketServer = "wss://mywebsocket.test.com/webSocket";
var myWebSocket = new WebSocket(wesocketServer);
myWebSocket.onopen = function () {
var loginMessage = {
authorization: publicWechatToken,
event: "AUTHORIZATION",
source: "WE_CHAT"
};
myWebSocket.send(JSON.stringify(loginMessage));
myWebSocketInterval = setInterval(function(){
va