| | |
| | | import darabonba.core.client.ClientOverrideConfiguration; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | //import javax.net.ssl.KeyManager; |
| | | //import javax.net.ssl.X509TrustManager; |
| | | import java.util.concurrent.CompletableFuture; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class AliPushUtil { |
| | | |
| | | @Value("${ali.push.accessKeyId}") |
| | |
| | | private Long appKey; |
| | | @Value("${ali.push.iosAppKey}") |
| | | private Long iosAppKey; |
| | | @Value("${ali.push.channelId}") |
| | | private String channelId; |
| | | @Value("${ali.push.iosChannelId}") |
| | | private String iosChannelId; |
| | | /** |
| | | * 消息类型 MESSAGE 消息 NOTICE 通知 |
| | | */ |
| | |
| | | |
| | | |
| | | /** |
| | | * |
| | | * 消息推送方法 |
| | | * @param account 运维手机号 |
| | | * @param title 标题 |
| | | * @param body 消息内容 |
| | | * @throws Exception |
| | | */ |
| | | public String pushMessage(Integer deviceType,String account, String title, String body) throws Exception { |
| | | public String pushMessage(Integer deviceType,String account, String title, String body){ |
| | | |
| | | try { |
| | | StaticCredentialProvider credentialProvider = StaticCredentialProvider.create( |
| | | Credential.builder() |
| | | .accessKeyId(accessKeyId) |
| | |
| | | appKeys = iosAppKey; |
| | | } |
| | | |
| | | String channelIds = channelId; |
| | | if(deviceType == 2){ |
| | | channelIds = iosChannelId; |
| | | } |
| | | |
| | | PushRequest pushRequest = PushRequest.builder() |
| | | .appKey(appKeys) |
| | | .pushType(PUSH_TYPE) |
| | |
| | | .targetValue(account) |
| | | .title(title) |
| | | .body(body) |
| | | .androidNotificationChannel(channelIds) |
| | | .build(); |
| | | CompletableFuture<PushResponse> response = client.push(pushRequest); |
| | | PushResponse resp = response.get(); |
| | |
| | | return null; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("运维APP-消息推送失败-异常"); |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |