gpt4 book ai didi

java - Smooch.io postmessage api 在 header 参数中传递 jwt

转载 作者:行者123 更新时间:2023-12-02 13:20:51 26 4
gpt4 key购买 nike

如何使用我不想在smooch java代码中更改的java代码在 header 邮政中传递jwt承载 token

我尝试更改对话 api 的 postMessageCall,效果很好

但我不想更改 smooch 代码

    ConversationApi conversationApi = new ConversationApi();

Action action = new Action();
action.setType(TypeEnum.REPLY);

action.setText("reply");


ArrayList<Action> actionList = new ArrayList<Action>();
actionList.add(action);

MessageItem item1 = new MessageItem();
item1.setActions(actionList);
item1.setTitle("yes");

ArrayList<MessageItem> messageItems = new ArrayList<>();
messageItems.add(item1);

MessagePost messagePost = new MessagePost();
messagePost.setText("amit thak gya hai ");
messagePost.setType(io.smooch.client.model.MessagePost.TypeEnum.TEXT);
messagePost.setRole("appMaker");
messagePost.setItems(null);
messagePost.setActions(null);

ApiClient apiClient = new ApiClient();
Map<String, String> setJWTToken = setJWTToken(apiClient);
// String userId = userId;
try {
// conversationApi.setApiClient(setJWTToken);
PostMessagesResponse postMessage = conversationApi.postMessage(userId, messagePost);
System.out.println("Response : " + postMessage);
} catch (ApiException exception) {
// TODO: prateek. Write exception handling code
System.out.println("Exception : " + exception);
}
}

private static Map<String, String> setJWTToken(ApiClient apiClient) {
Map<String, String> localVarHeaderParams = new HashMap<String, String>();

final String bearer = "Bearer some token value";
final String[] localVarAccepts = {bearer};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
localVarHeaderParams.put("Authorization", bearer);
return localVarHeaderParams;
}

}

最佳答案

之前的流程是“我的类”->“conversationAPI”->“apiClient”现在我通过在我的类中设置 header 参数跳过了中间层流程是我的类 -> apiClient

关于java - Smooch.io postmessage api 在 header 参数中传递 jwt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com