Sinch java错误

时间:2017-12-18 16:35:27

标签: sinch

我正在使用来自java的sinch,我最近对该帐户进行了信用,现在当我尝试发送消息时,我收到了成功消息,但是短信没有发送。在链接https://messagingapi.sinch.com/v1/sms/162393899之后我得到了这个

  

{“errorCode”:40107,“message”:“无效的授权密钥:   维维****** @ gmail.com”, “参考”: “BA:维维****** @ gmail.com_GtIfKPDMJEKL4VJWR0kkJQ”}

代码

try {
            String phoneNumber = "+40732******";
            String appKey = "*****";
            String appSecret = "****";
            String message = "Test";
            URL url = new URL("https://messagingapi.sinch.com/v1/sms/" + phoneNumber);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            String userCredentials = "application\\" + appKey + ":" + appSecret;
            byte[] encoded = Base64.encodeBase64(userCredentials.getBytes());
            String basicAuth = "Basic " + new String(encoded);
            connection.setRequestProperty("Authorization", basicAuth);
            String postData = "{\"Message\":\"" + message + "\"}";
            OutputStream os = connection.getOutputStream();
            os.write(postData.getBytes());
            StringBuilder response = new StringBuilder();
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ( (line = br.readLine()) != null)
                response.append(line);
            br.close();
            os.close();
            System.out.println(response.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

0 个答案:

没有答案