如何使用 Java 通过 Proxy 发送华为推送通知

How to send Huawei push notification through Proxy using Java

如何通过代理服务器

为使用Java的华为设备发送推送通知
    HttpPost httpPost = new HttpPost(this.HcmPushUrl);
    StringEntity entity = new StringEntity(JSON.toJSONString(map), "UTF-8");
    httpPost.setHeader("Authorization", "Bearer " + accessToken);
    httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
    httpPost.setEntity(entity);
    CloseableHttpResponse response = httpClient.execute(httpPost);
    String rpsContent = EntityUtils.toString(response.getEntity());

类似于APNS调用的ProxyManager.setProxy(proxyAddress, proxyPort)

请参考以下代码:

HuaweiCredential credential = HuaweiCredential.builder()
.setAppId(appId)
.setAppSecret(appSecret)
.setHttpClient()//set your own http client with proxy here
.build();

// Create HuaweiOption
HuaweiOption option = HuaweiOption.builder()
.setCredential(credential)
.setHttpClient()//set your own http client with proxy here
.build();

HMS Pushkit Java 服务器演示开启 Github