0

你能告诉我为什么标题中的错误会发生吗?

错误具体在下面的行中。

MessageResponse result = apiInstance.postMessage(appId, userId, messagePostBody);

下面我展示我的完整代码。

public class EnviaMensagemTeste {

private static final String JWT = "jwt";
private static final String BEARER = "Bearer";

private static ApiClient createClient(String apiKey) {
    ApiClient client = new ApiClient();
    ApiKeyAuth jwt = (ApiKeyAuth) client.getAuthentication(JWT);
    jwt.setApiKey(apiKey);
    jwt.setApiKeyPrefix(BEARER);

    // trust in all certificates
    TrustManager[] trustAllCerts = new TrustManager[] {
        new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            @Override
            public void checkClientTrusted(
                    java.security.cert.X509Certificate[] arg0, String arg1)
                    throws CertificateException {
                // TODO Auto-generated method stub

            }
            @Override
            public void checkServerTrusted(
                    java.security.cert.X509Certificate[] arg0, String arg1)
                    throws CertificateException {
                // TODO Auto-generated method stub

            }
        }
    };
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        client.getHttpClient().setSslSocketFactory(sc.getSocketFactory());

        HostnameVerifier allHostsValid = new HostnameVerifier() {
            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                // TODO Auto-generated method stub
                return true;
            }
        };
        client.getHttpClient().setHostnameVerifier(allHostsValid);
    } catch (NoSuchAlgorithmException e) {
    } catch (KeyManagementException e) {
    }

    return client;
}

public static void main(String args[]) {
    try {
        String jwt0 = Jwts.builder()
        .claim("scope", "app")
        .setHeaderParam(KEY_ID, <MY KEY>)
        .signWith(
            SignatureAlgorithm.HS256,
            <MY SECRET>.getBytes("UTF-8")).compact();

        ApiClient apiClient = createClient(jwt0);

        ConversationApi apiInstance = new ConversationApi(apiClient);
        String appId = "MY APP ID"; // String | Identifies the app.
        String userId = "MY USER ID"; // String | Identifies the user. Can be either the smoochId or the userId.
        MessagePost messagePostBody = new MessagePost(); 
        messagePostBody.setRole("appUser");
        messagePostBody.setType("text");
        messagePostBody.setText("hi");
        Destination destination = new Destination();
        destination.setIntegrationId("5735ddfb48011972d621dc09");
        destination.setIntegrationType("telegram");
        messagePostBody.setDestination(destination);
        try {
            MessageResponse result = apiInstance.postMessage(appId, userId, messagePostBody);
            System.out.println(result);
        } catch (Exception e) {
            System.out.println("Exception when calling ConversationApi#postMessage");
            e.printStackTrace();
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

4

0 回答 0