| Line 1... |
Line 1... |
| 1 |
package com.smartdukaan.cron.scheduled;
|
1 |
package com.smartdukaan.cron.scheduled;
|
| 2 |
|
2 |
|
| - |
|
3 |
import com.google.auth.oauth2.GoogleCredentials;
|
| 3 |
import com.google.common.collect.Lists;
|
4 |
import com.google.common.collect.Lists;
|
| 4 |
import com.google.gson.Gson;
|
5 |
import com.google.gson.Gson;
|
| 5 |
import com.razorpay.Payment;
|
6 |
import com.razorpay.Payment;
|
| 6 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationNewService;
|
7 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationNewService;
|
| 7 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
|
8 |
import com.smartdukaan.cron.itelImeiActivation.ItelImeiActivationService;
|
| Line 484... |
Line 485... |
| 484 |
private FofoSolr fofoSolr;
|
485 |
private FofoSolr fofoSolr;
|
| 485 |
|
486 |
|
| 486 |
|
487 |
|
| 487 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
488 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 488 |
|
489 |
|
| 489 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
490 |
private String FCM_URL = "https://fcm.googleapis.com/v1/projects/api-project-309385327230/messages:send";
|
| 490 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
491 |
private String FCM_SCOPED = "https://www.googleapis.com/auth/cloud-platform";
|
| 491 |
|
492 |
|
| 492 |
@Autowired
|
493 |
@Autowired
|
| 493 |
private TagListingRepository tagListingRepository;
|
494 |
private TagListingRepository tagListingRepository;
|
| 494 |
@Autowired
|
495 |
@Autowired
|
| 495 |
private RunOnceTasks runOnceTasks;
|
496 |
private RunOnceTasks runOnceTasks;
|
| Line 1059... |
Line 1060... |
| 1059 |
|
1060 |
|
| 1060 |
@Autowired
|
1061 |
@Autowired
|
| 1061 |
WarehouseProviderRepository warehouseProviderRepository;
|
1062 |
WarehouseProviderRepository warehouseProviderRepository;
|
| 1062 |
public void test() throws Exception {
|
1063 |
public void test() throws Exception {
|
| 1063 |
//runOnceTasks.migratePurchaseFix();
|
1064 |
//runOnceTasks.migratePurchaseFix();
|
| 1064 |
sdCreditService.fundWallet(175139079);
|
1065 |
//sdCreditService.fundWallet(175139079);
|
| 1065 |
//runOnceTasks.migratePurchase();
|
1066 |
//runOnceTasks.migratePurchase();
|
| 1066 |
//this.persistRbmTodayTargets();
|
1067 |
//this.persistRbmTodayTargets();
|
| 1067 |
//this.persistRbmTodayAchievements();
|
1068 |
//this.persistRbmTodayAchievements();
|
| 1068 |
//Should return 22792
|
1069 |
//Should return 22792
|
| 1069 |
|
1070 |
|
| Line 2580... |
Line 2581... |
| 2580 |
}
|
2581 |
}
|
| 2581 |
|
2582 |
|
| 2582 |
public void sendNotification() throws Exception {
|
2583 |
public void sendNotification() throws Exception {
|
| 2583 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllPendingNotifications();
|
2584 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllPendingNotifications();
|
| 2584 |
if (!pushNotifications.isEmpty()) {
|
2585 |
if (!pushNotifications.isEmpty()) {
|
| - |
|
2586 |
FileInputStream serviceAccount = new FileInputStream(getClass().getClassLoader().getResource("service-account.json").getPath());
|
| - |
|
2587 |
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(serviceAccount).createScoped(FCM_SCOPED);
|
| - |
|
2588 |
googleCredentials.refreshIfExpired();
|
| - |
|
2589 |
String accessToken = googleCredentials.getAccessToken().getTokenValue();
|
| - |
|
2590 |
|
| 2585 |
for (PushNotifications pushNotification : pushNotifications) {
|
2591 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 2586 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
2592 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 2587 |
NotificationCampaign notificationCampaign = notificationCampaignRepository.selectById(pushNotification.getNotificationCampaignid());
|
2593 |
NotificationCampaign notificationCampaign = notificationCampaignRepository.selectById(pushNotification.getNotificationCampaignid());
|
| 2588 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(), SimpleCampaignParams.class);
|
2594 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(), SimpleCampaignParams.class);
|
| 2589 |
Campaign campaign = new SimpleCampaign(scp);
|
2595 |
Campaign campaign = new SimpleCampaign(scp);
|
| 2590 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
2596 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| - |
|
2597 |
|
| 2591 |
JSONObject json = new JSONObject();
|
2598 |
JSONObject message = new JSONObject();
|
| 2592 |
json.put("to", device.getFcmId());
|
2599 |
message.put("token", device.getFcmId());
|
| - |
|
2600 |
|
| 2593 |
JSONObject jsonObj = new JSONObject();
|
2601 |
JSONObject notification = new JSONObject();
|
| 2594 |
jsonObj.put("message", campaign.getMessage());
|
2602 |
notification.put("title", campaign.getTitle());
|
| 2595 |
jsonObj.put("title", campaign.getTitle());
|
2603 |
notification.put("body", campaign.getMessage());
|
| - |
|
2604 |
message.put("notification", notification);
|
| - |
|
2605 |
|
| - |
|
2606 |
JSONObject data = new JSONObject();
|
| 2596 |
jsonObj.put("type", campaign.getType());
|
2607 |
data.put("type", campaign.getType());
|
| 2597 |
jsonObj.put("url", result_url);
|
2608 |
data.put("url", result_url);
|
| 2598 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
2609 |
data.put("time_to_live", campaign.getExpireTimestamp());
|
| 2599 |
jsonObj.put("image", campaign.getImageUrl());
|
2610 |
data.put("image", campaign.getImageUrl());
|
| 2600 |
jsonObj.put("largeIcon", "large_icon");
|
2611 |
data.put("largeIcon", "large_icon");
|
| 2601 |
jsonObj.put("smallIcon", "small_icon");
|
2612 |
data.put("smallIcon", "small_icon");
|
| 2602 |
jsonObj.put("vibrate", 1);
|
2613 |
data.put("vibrate", 1);
|
| 2603 |
jsonObj.put("pid", pushNotification.getId());
|
2614 |
data.put("pid", pushNotification.getId());
|
| 2604 |
jsonObj.put("sound", 1);
|
2615 |
data.put("sound", 1);
|
| 2605 |
jsonObj.put("priority", "high");
|
2616 |
data.put("priority", "high");
|
| 2606 |
json.put("data", jsonObj);
|
2617 |
message.put("data", data);
|
| - |
|
2618 |
|
| - |
|
2619 |
JSONObject payload = new JSONObject();
|
| - |
|
2620 |
payload.put("message", message);
|
| - |
|
2621 |
|
| 2607 |
try {
|
2622 |
try {
|
| 2608 |
CloseableHttpClient client = HttpClients.createDefault();
|
2623 |
CloseableHttpClient client = HttpClients.createDefault();
|
| 2609 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
2624 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 2610 |
|
2625 |
|
| 2611 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
2626 |
httpPost.setHeader("Authorization", "Bearer " + accessToken);
|
| 2612 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
2627 |
httpPost.setHeader("Content-Type", "application/json");
|
| - |
|
2628 |
|
| 2613 |
StringEntity entity = new StringEntity(json.toString());
|
2629 |
StringEntity entity = new StringEntity(payload.toString());
|
| 2614 |
httpPost.setEntity(entity);
|
2630 |
httpPost.setEntity(entity);
|
| 2615 |
CloseableHttpResponse response = client.execute(httpPost);
|
2631 |
CloseableHttpResponse response = client.execute(httpPost);
|
| 2616 |
|
- |
|
| - |
|
2632 |
LOGGER.info("google FCM status code: {}",response.getStatusLine().getStatusCode());
|
| 2617 |
if (response.getStatusLine().getStatusCode() == 200) {
|
2633 |
if (response.getStatusLine().getStatusCode() == 200) {
|
| 2618 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
2634 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
| 2619 |
} else {
|
2635 |
} else {
|
| 2620 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
2636 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 2621 |
LOGGER.info("message" + "not sent");
|
2637 |
LOGGER.info("message" + "not sent");
|