Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复华为推送(后端)无法使用的问题 #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
import com.huawei.push.message.Message;
import com.huawei.push.message.Notification;
import com.huawei.push.messaging.HuaweiApp;
import com.huawei.push.messaging.HuaweiCredential;
import com.huawei.push.messaging.HuaweiMessaging;
import com.huawei.push.messaging.HuaweiOption;
import com.huawei.push.model.Importance;
import com.huawei.push.model.Visibility;
import com.huawei.push.reponse.SendResponse;
import com.huawei.push.util.InitAppUtils;
import com.mixpush.sender.MixPushMessage;
import com.mixpush.sender.MixPushProvider;
import com.mixpush.sender.MixPushResult;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
Expand All @@ -29,10 +33,25 @@ public class HuaweiPushProvider extends MixPushProvider {
private final HuaweiMessaging huaweiMessaging;

public HuaweiPushProvider(String appId, String appSecret) {
HuaweiApp app = InitAppUtils.initializeApp(appId, appSecret);
HuaweiApp app = myInitializeApp(appId, appSecret);
this.huaweiMessaging = HuaweiMessaging.getInstance(app);
}

private static HuaweiApp myInitializeApp(String appId, String appSecret) {
HuaweiCredential credential = HuaweiCredential.builder().setAppId(appId).setAppSecret(appSecret).build();

HuaweiOption option = HuaweiOption.builder()
.setCredential(credential)
.setHttpClient(myCreateHttpClient())
.build();

return HuaweiApp.getInstance(option); // may use HuaweiApp.initializeApp?
}

private static CloseableHttpClient myCreateHttpClient() {
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
return HttpClients.custom().setConnectionManager(connManager).build();
}

@Override
protected MixPushResult sendMessageToSingle(MixPushMessage mixPushMessage, String regId) {
Expand Down