Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 推送程序无效签名:应为的HMAC SHA256十六进制摘要_Java_Javascript_Pusher - Fatal编程技术网

Java 推送程序无效签名:应为的HMAC SHA256十六进制摘要

Java 推送程序无效签名:应为的HMAC SHA256十六进制摘要,java,javascript,pusher,Java,Javascript,Pusher,我在一个HTML文件中有JavaScript代码,从中调用服务器进行身份验证: <html> <script> <head> var options = { authEndpoint: "api/pusher.json?socket_id=9900&channel_name=presence-channel" } var pusher = new Pusher('98384343434343434', options); pus

我在一个HTML文件中有JavaScript代码,从中调用服务器进行身份验证:

<html>
<script>
<head>
    var options = { authEndpoint: "api/pusher.json?socket_id=9900&channel_name=presence-channel" }
    var pusher = new Pusher('98384343434343434', options);
    pusher.connection.bind('connected', function() {
        console.log("connected");
        socketId = pusher.connection.socket_id;
        console.log("socketId" + socketId);
    });

    var channel = pusher.subscribe('presence-channel');
</script>
</head>
<body></body>
</html>

从pusher.authenticate返回的
authBody
应该为您提供响应客户端请求所需的一切。您只需要确保
sendDataResponse
authBody
作为JSON作为响应的主体发送回来

我已经更新了您提供的示例,以删除不需要的行:

@Path("/api/pusher")
public class PusherAction extends BusinessApiAction {
    @POST

    @Produces({ "application/Json", "application/xml" })
    public Response pusher(@Context ServletContext context, @Context HttpServletRequest req, @Context HttpServletResponse res, @FormParam("socket_id") String socketId, @FormParam("channel_name") String channelName) throws Exception {
        System.out.println("\n\n===channel==> " + channelName + "\t socket id-->" + socketId);

        Pusher pusher = new Pusher(APP_ID, APP_KEY, APP_SECRET);
        String userId = "5433d5da97d88628ec000300";
        Map<String, String> userInfo = new HashMap<>();
        userInfo.put("name", "Phil Leggetter");

        String authBody = pusher.authenticate(socketId, channelName, new PresenceUser(userId, userInfo));

        return sendDataResponse(authBody);
    }

}
@Path(“/api/pusher”)
公共类PusherAction扩展了BusinessApiaAction{
@职位
@产生({“application/Json”、“application/xml”})
公共响应推送程序(@Context-ServletContext、@Context-HttpServletRequest-req、@Context-httpservletres、@FormParam(“socket\u id”)字符串socketId、@FormParam(“channel\u name”)字符串channelName)引发异常{
System.out.println(“\n\n===通道==>”+channelName+“\t套接字id-->”+socketId);
推送器推送器=新推送器(应用程序ID、应用程序密钥、应用程序密钥);
字符串userId=“5433d5da97d88628ec000300”;
Map userInfo=newhashmap();
userInfo.put(“name”,“Phil Leggetter”);
字符串authBody=pusher.authenticate(socketId,channelName,newpresenceuser(userId,userInfo));
返回sendDataResponse(authBody);
}
}
pusher rest java库自述文件显示了不需要的附加功能:

感谢@leggetter的回复,我尝试使用var options={authEndpoint:“api/pusher.json”};但是我得到了错误参数[socketId]不应该为null。我遗漏了什么吗?应该是
socket\u id
,而不是
socketId
@Kamini你能更新这个问题,提供更多关于
pusher.json
处理代码的信息吗?e、 g.获取查询参数。@Kamini太棒了!你能把我的回答标记为答案吗?我只是想知道客户端对客户端的通信,现在每当我在服务器api/pusher Result=pusher.trigger(channelName,“client event”,authBody)中编写时,我就有2个html文件;并在client1.html中编写channel.bind('client-event',函数(data){alert(“来自服务器api的数据-->”+数据);});在这里,无论authbody发送什么数据,我都得到了警报,但我希望它通过客户端到客户端的通信来完成,我尝试在一个client2.html通道中使用触发器('client-event',{data:'hello client1'});但是没有在其他client1.html中获得警报,在那里我绑定了事件您已经共享了上面的应用程序机密。请确保在Pusher仪表板中重置应用程序机密,好吗?您可以从应用程序密钥->应用程序凭据部分执行此操作。
Pusher : Event sent : {"event":"pusher:subscribe","data":{"auth":"3055e2b132174078348c:980bf9a6d3a61d280d181785ccacd0e5e7999776085403f2d9bfe688842b8fe7","channel_data":"{\"user_info\":{\"name\":\"Phil Leggetter\"},\"user_id\":\"5433d5da97d88628ec000300\"}","channel":"presence-user2"}}

Pusher : Event recd : {"event":"pusher:error","data":{"code":null,"message":"Invalid signature: Expected HMAC SHA256 hex digest of 41797.10543542:presence-user2:{\"user_info\":{\"name\":\"Phil Leggetter\"},\"user_id\":\"5433d5da97d88628ec000300\"}, but got 980bf9a6d3a61d280d181785ccacd0e5e7999776085403f2d9bfe688842b8fe7"}}

Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Invalid signature: Expected HMAC SHA256 hex digest of 41797.10543542:presence-user2:{\"user_info\":{\"name\":\"Phil Leggetter\"},\"user_id\":\"5433d5da97d88628ec000300\"}, but got 980bf9a6d3a61d280d181785ccacd0e5e7999776085403f2d9bfe688842b8fe7"}}}
@Path("/api/pusher")
public class PusherAction extends BusinessApiAction {
    @POST

    @Produces({ "application/Json", "application/xml" })
    public Response pusher(@Context ServletContext context, @Context HttpServletRequest req, @Context HttpServletResponse res, @FormParam("socket_id") String socketId, @FormParam("channel_name") String channelName) throws Exception {
        System.out.println("\n\n===channel==> " + channelName + "\t socket id-->" + socketId);

        Pusher pusher = new Pusher(APP_ID, APP_KEY, APP_SECRET);
        String userId = "5433d5da97d88628ec000300";
        Map<String, String> userInfo = new HashMap<>();
        userInfo.put("name", "Phil Leggetter");

        String authBody = pusher.authenticate(socketId, channelName, new PresenceUser(userId, userInfo));

        return sendDataResponse(authBody);
    }

}