增加个推配置和公共方法
This commit is contained in:
parent
1df48ab98c
commit
740f11e95b
@ -1,6 +1,7 @@
|
||||
package com.suisung.mall.account.controller.mobile;
|
||||
|
||||
import com.suisung.mall.account.service.AccountSinglePushService;
|
||||
import com.suisung.mall.common.service.GeTuiPushService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -8,6 +9,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/account/singlePus")
|
||||
@Slf4j
|
||||
@ -15,6 +18,10 @@ public class SinglePushController {
|
||||
@Autowired
|
||||
private AccountSinglePushService accountSinglePushService;
|
||||
|
||||
|
||||
@Resource
|
||||
private GeTuiPushService geTuiPushService;
|
||||
|
||||
@RequestMapping("/getSingleToken")
|
||||
public String getToken() {
|
||||
return accountSinglePushService.getTokenString();
|
||||
@ -22,14 +29,14 @@ public class SinglePushController {
|
||||
|
||||
@RequestMapping("/delSingleToken")
|
||||
public String delSingleToken() {
|
||||
accountSinglePushService.delToken();
|
||||
return "success";
|
||||
// accountSinglePushService.delToken();
|
||||
return "success";
|
||||
}
|
||||
|
||||
@PostMapping("/pushTocid")
|
||||
public String pushTocid(@RequestParam String message,@RequestParam String userId) {
|
||||
public String pushTocid(@RequestParam String userId, @RequestParam String message) {
|
||||
log.info("pushTocid");
|
||||
accountSinglePushService.pushTocid(message,userId);
|
||||
accountSinglePushService.pushTocid(message, userId);
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
package com.suisung.mall.account.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.getui.push.v2.sdk.api.PushApi;
|
||||
import com.getui.push.v2.sdk.common.ApiResult;
|
||||
@ -9,11 +10,12 @@ import com.suisung.mall.account.service.AccountSinglePushService;
|
||||
import com.suisung.mall.account.service.UserDeviceBindService;
|
||||
import com.suisung.mall.common.modules.singlepush.UserDeviceBind;
|
||||
import com.suisung.mall.common.service.impl.SinglePushBaseServiceImpl;
|
||||
import com.suisung.mall.common.utils.ContextUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@lombok.extern.slf4j.Slf4j
|
||||
@ -24,38 +26,38 @@ public class AccountSinglePushServiceImpl extends SinglePushBaseServiceImpl impl
|
||||
|
||||
@Override
|
||||
public String getTokenString() {
|
||||
return super.getTokenDTO().getToken();
|
||||
return super.getTokenDTO().getToken();
|
||||
}
|
||||
|
||||
public void delToken(){
|
||||
public void delToken() {
|
||||
super.delToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushTocid(String message,String userId) {
|
||||
UserDeviceBind userDeviceBind= new UserDeviceBind();
|
||||
public void pushTocid(String message, String userId) {
|
||||
UserDeviceBind userDeviceBind = new UserDeviceBind();
|
||||
userDeviceBind.setUserId(userId);
|
||||
List<UserDeviceBind> list= userDeviceBindService.getActive(userDeviceBind);
|
||||
if(CollectionUtil.isEmpty(list)){
|
||||
List<UserDeviceBind> list = userDeviceBindService.getActive(userDeviceBind);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
log.error("登录时绑定设备不存在");
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
String cid=list.get(0).getCid();
|
||||
PushApi pushApi= this.getApiHelper().creatApi(PushApi.class);
|
||||
PushDTO<Audience> pushDTO=new PushDTO<>();
|
||||
Audience audience=new Audience();
|
||||
String cid = list.get(0).getCid();
|
||||
PushApi pushApi = this.getApiHelper().creatApi(PushApi.class);
|
||||
PushDTO<Audience> pushDTO = new PushDTO<>();
|
||||
Audience audience = new Audience();
|
||||
audience.addCid(cid);
|
||||
pushDTO.setAudience(audience);
|
||||
pushDTO.setRequestId(UUID.randomUUID().toString());
|
||||
PushMessage pushMessage=new PushMessage();
|
||||
PushMessage pushMessage = new PushMessage();
|
||||
pushMessage.setDuration(this.getDuration());
|
||||
pushMessage.setTransmission(message);
|
||||
pushDTO.setPushMessage(pushMessage);
|
||||
ApiResult<Map<String, Map<String, String>>> mapApiResult= pushApi.pushToSingleByCid(pushDTO,super.getTokenDTO());
|
||||
if(mapApiResult.getCode()==0){
|
||||
log.info("用户为{},cid为{}发送成功消息成功",list.get(0).getUserId(),list.get(0).getCid());
|
||||
ApiResult<Map<String, Map<String, String>>> mapApiResult = pushApi.pushToSingleByCid(pushDTO);//,super.getTokenDTO()
|
||||
if (mapApiResult.getCode() == 0) {
|
||||
log.info("用户为{},cid为{}发送成功消息成功", list.get(0).getUserId(), list.get(0).getCid());
|
||||
}
|
||||
log.info("mapApiResult的数据{}",mapApiResult);
|
||||
log.info("mapApiResult的数据{}", mapApiResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -281,13 +281,26 @@
|
||||
</dependency>
|
||||
<!-- 个推api-->
|
||||
<!-- https://mvnrepository.com/artifact/com.getui.push/restful-sdk -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.getui.push</groupId>-->
|
||||
<!-- <artifactId>restful-sdk</artifactId>-->
|
||||
<!-- <version>1.0.6.1</version>-->
|
||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/restful-sdk-1.0.6.1.jar</systemPath>-->
|
||||
<!-- <scope>system</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.getui.push</groupId>
|
||||
<artifactId>restful-sdk</artifactId>
|
||||
<version>1.0.6.1</version>
|
||||
<systemPath>${project.basedir}/src/main/resources/lib/restful-sdk-1.0.6.1.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
<version>1.0.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.getui.push</groupId>
|
||||
<artifactId>restful-sdk</artifactId>
|
||||
<version>1.0.6.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<!-- 指定仓库为阿里云与阿帕奇 -->
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.common.service;
|
||||
|
||||
import org.springframework.data.util.Pair;
|
||||
|
||||
public interface GeTuiPushService {
|
||||
|
||||
/**
|
||||
* 单个用户透传消息(支持H5、安卓、苹果系统)
|
||||
*
|
||||
* @param cid
|
||||
* @param transmission 透传消息 txt json 格式
|
||||
* @return
|
||||
*/
|
||||
Pair<Boolean, String> pushTransmissionToSingleByCid(String cid, String transmission);
|
||||
|
||||
/**
|
||||
* 单个用户推送消息(支持H5、安卓、苹果系统)
|
||||
* <p>
|
||||
* 通知消息内容参考:https://docs.getui.com/getui/server/rest_v2/common_args/?id=doc-title-6
|
||||
*
|
||||
* @param cid
|
||||
* @param title
|
||||
* @param content
|
||||
* @param clickType: 点击通知后续动作,
|
||||
* 目前支持以下后续动作,
|
||||
* intent:打开应用内特定页面(intent和want字段必须填写一个)
|
||||
* url:打开网页地址,
|
||||
* payload:自定义消息内容启动应用,
|
||||
* payload_custom:自定义消息内容不启动应用,
|
||||
* startapp:打开应用首页,
|
||||
* none:纯通知,无后续动作
|
||||
* @param clickContent
|
||||
* @return
|
||||
*/
|
||||
Pair<Boolean, String> pushMessageToSingleByCid(String cid, String title, String content, String clickType, String clickContent);
|
||||
}
|
||||
@ -1,12 +1,15 @@
|
||||
package com.suisung.mall.common.service;
|
||||
|
||||
import com.getui.push.v2.sdk.dto.res.TokenDTO;
|
||||
import com.suisung.mall.common.pojo.dto.SmsDto;
|
||||
|
||||
/**
|
||||
* 第三方服务
|
||||
*/
|
||||
public interface SinglePushBaseService {
|
||||
TokenDTO getTokenDTO();
|
||||
|
||||
void delToken();
|
||||
|
||||
|
||||
void pushToSingleByCid(String cid, String content);
|
||||
}
|
||||
|
||||
@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
||||
*/
|
||||
|
||||
package com.suisung.mall.common.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.getui.push.v2.sdk.ApiHelper;
|
||||
import com.getui.push.v2.sdk.GtApiConfiguration;
|
||||
import com.getui.push.v2.sdk.api.PushApi;
|
||||
import com.getui.push.v2.sdk.common.ApiResult;
|
||||
import com.getui.push.v2.sdk.dto.req.Audience;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushChannel;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.AndroidDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.Ups;
|
||||
import com.getui.push.v2.sdk.dto.req.message.harmony.HarmonyDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.Aps;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
|
||||
import com.suisung.mall.common.service.GeTuiPushService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class GeTuiPushServiceImpl implements GeTuiPushService {
|
||||
|
||||
@Value("${getui.push.appid}")
|
||||
private String appId;
|
||||
@Value("${getui.push.appkey}")
|
||||
private String appkey;
|
||||
@Value("${getui.push.mastersecret}")
|
||||
private String mastersecret;
|
||||
|
||||
@Value("${getui.push.domain}")
|
||||
private String getuiDomain;
|
||||
|
||||
|
||||
// 私有构造函数,防止外部实例化
|
||||
private PushApi creatPushApi() {
|
||||
// 初始化 PushApi 配置
|
||||
GtApiConfiguration config = new GtApiConfiguration();
|
||||
config.setAppId(appId);
|
||||
config.setAppKey(appkey);
|
||||
config.setMasterSecret(mastersecret);
|
||||
config.setDomain(getuiDomain);
|
||||
ApiHelper apiHelper = ApiHelper.build(config);
|
||||
// 创建 PushApi 实例
|
||||
return apiHelper.creatApi(PushApi.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单个用户透传消息(支持H5、安卓、苹果系统)
|
||||
*
|
||||
* @param cid
|
||||
* @param transmission
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Pair<Boolean, String> pushTransmissionToSingleByCid(String cid, String transmission) {
|
||||
PushDTO pushDTO = new PushDTO<Audience>();
|
||||
// 设置推送参数
|
||||
pushDTO.setRequestId(System.currentTimeMillis() + "");
|
||||
|
||||
/**** 设置个推通道参数 *****/
|
||||
PushMessage pushMessage = new PushMessage();
|
||||
pushMessage.setTransmission(transmission); // 设置透传消息
|
||||
pushDTO.setPushMessage(pushMessage);
|
||||
|
||||
/**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
|
||||
|
||||
/**** 设置厂商相关参数 ****/
|
||||
PushChannel pushChannel = new PushChannel();
|
||||
pushDTO.setPushChannel(pushChannel);
|
||||
/*配置安卓厂商参数*/
|
||||
AndroidDTO androidDTO = new AndroidDTO();
|
||||
pushChannel.setAndroid(androidDTO);
|
||||
Ups ups = new Ups();
|
||||
androidDTO.setUps(ups);
|
||||
ups.setTransmission(transmission); // 设置透传消息
|
||||
/*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
|
||||
|
||||
/*设置ios厂商参数*/
|
||||
IosDTO iosDTO = new IosDTO();
|
||||
pushChannel.setIos(iosDTO);
|
||||
Aps aps = new Aps();
|
||||
iosDTO.setAps(aps);
|
||||
aps.setContentAvailable(1);
|
||||
iosDTO.setPayload(transmission); // 设置透传消息
|
||||
/*设置ios厂商参数结束,更多参数请查看文档或对象源码*/
|
||||
|
||||
/*配置鸿蒙厂商参数*/
|
||||
HarmonyDTO harmonyDTO = new HarmonyDTO();
|
||||
pushChannel.setHarmony(harmonyDTO);
|
||||
harmonyDTO.setTransmission(transmission);
|
||||
/*配置鸿蒙厂商参数结束,更多参数请查看文档或对象源码*/
|
||||
|
||||
/*设置接收人信息*/
|
||||
Audience audience = new Audience();
|
||||
audience.addCid(cid);
|
||||
pushDTO.setAudience(audience);
|
||||
|
||||
// 进行cid单推
|
||||
ApiResult<JSONObject> apiResult = creatPushApi().pushToSingleByCid(pushDTO);
|
||||
if (!apiResult.isSuccess()) {
|
||||
log.error("个推推送失败:{}", apiResult);
|
||||
return Pair.of(false, "个推推送失败:" + apiResult.getMsg());
|
||||
}
|
||||
|
||||
return Pair.of(true, "推送成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个用户推送消息(支持H5、安卓、苹果系统)
|
||||
* <p>
|
||||
* 通知消息内容参考:https://docs.getui.com/getui/server/rest_v2/common_args/?id=doc-title-6
|
||||
*
|
||||
* @param cid
|
||||
* @param title
|
||||
* @param content
|
||||
* @param clickType: 点击通知后续动作,
|
||||
* 目前支持以下后续动作,
|
||||
* intent:打开应用内特定页面(intent和want字段必须填写一个)
|
||||
* url:打开网页地址,
|
||||
* payload:自定义消息内容启动应用,
|
||||
* payload_custom:自定义消息内容不启动应用,
|
||||
* startapp:打开应用首页,
|
||||
* none:纯通知,无后续动作
|
||||
* @param clickContent
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Pair<Boolean, String> pushMessageToSingleByCid(String cid, String title, String content, String clickType, String clickContent) {
|
||||
//根据cid进行单推
|
||||
PushDTO pushDTO = new PushDTO<Audience>();
|
||||
// 设置推送参数
|
||||
pushDTO.setRequestId(System.currentTimeMillis() + "");
|
||||
|
||||
|
||||
title = StrUtil.isBlank(title) ? "小发同城" : title;
|
||||
|
||||
/**** 设置个推通道参数 *****/
|
||||
PushMessage pushMessage = new PushMessage();
|
||||
pushDTO.setPushMessage(pushMessage);
|
||||
GTNotification notification = new GTNotification();
|
||||
pushMessage.setNotification(notification);
|
||||
notification.setTitle(title);
|
||||
notification.setBody(content);
|
||||
|
||||
notification.setClickType(clickType);
|
||||
switch (clickType) {
|
||||
case "url":
|
||||
notification.setUrl(clickContent);
|
||||
break;
|
||||
case "intent":
|
||||
notification.setIntent(clickContent);
|
||||
break;
|
||||
case "want":
|
||||
notification.setWant(clickContent);
|
||||
break;
|
||||
case "payload":
|
||||
case "payload_custom":
|
||||
notification.setPayload(clickContent);
|
||||
break;
|
||||
case "none":
|
||||
case "startapp":
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
|
||||
|
||||
/**** 设置厂商相关参数 ****/
|
||||
PushChannel pushChannel = new PushChannel();
|
||||
pushDTO.setPushChannel(pushChannel);
|
||||
/*配置安卓厂商参数*/
|
||||
AndroidDTO androidDTO = new AndroidDTO();
|
||||
pushChannel.setAndroid(androidDTO);
|
||||
Ups ups = new Ups();
|
||||
androidDTO.setUps(ups);
|
||||
ThirdNotification thirdNotification = new ThirdNotification();
|
||||
ups.setNotification(thirdNotification);
|
||||
thirdNotification.setTitle(title);
|
||||
thirdNotification.setBody(content);
|
||||
|
||||
thirdNotification.setClickType(clickType);
|
||||
switch (clickType) {
|
||||
case "url":
|
||||
thirdNotification.setUrl(clickContent);
|
||||
break;
|
||||
case "intent":
|
||||
thirdNotification.setIntent(clickContent);
|
||||
break;
|
||||
case "payload":
|
||||
case "payload_custom":
|
||||
thirdNotification.setPayload(clickContent);
|
||||
break;
|
||||
case "none":
|
||||
case "startapp":
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
|
||||
|
||||
/*设置ios厂商参数*/
|
||||
IosDTO iosDTO = new IosDTO();
|
||||
pushChannel.setIos(iosDTO);
|
||||
// 相同的collapseId会覆盖之前的消息
|
||||
iosDTO.setApnsCollapseId("xxx");
|
||||
Aps aps = new Aps();
|
||||
iosDTO.setAps(aps);
|
||||
Alert alert = new Alert();
|
||||
aps.setAlert(alert);
|
||||
alert.setTitle(title);
|
||||
alert.setBody(content);
|
||||
/*设置ios厂商参数结束,更多参数请查看文档或对象源码*/
|
||||
|
||||
|
||||
/*设置接收人信息*/
|
||||
Audience audience = new Audience();
|
||||
pushDTO.setAudience(audience);
|
||||
audience.addCid(cid);
|
||||
/*设置接收人信息结束*/
|
||||
/**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/
|
||||
|
||||
// 进行cid单推
|
||||
ApiResult<JSONObject> apiResult = creatPushApi().pushToSingleByCid(pushDTO);
|
||||
if (!apiResult.isSuccess()) {
|
||||
log.error("个推推送失败:{}", apiResult);
|
||||
return Pair.of(false, "个推推送失败:" + apiResult.getMsg());
|
||||
}
|
||||
|
||||
return Pair.of(true, "推送成功");
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,16 @@
|
||||
package com.suisung.mall.common.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.getui.push.v2.sdk.ApiHelper;
|
||||
import com.getui.push.v2.sdk.GtApiConfiguration;
|
||||
import com.getui.push.v2.sdk.api.AuthApi;
|
||||
import com.getui.push.v2.sdk.api.PushApi;
|
||||
import com.getui.push.v2.sdk.common.ApiResult;
|
||||
import com.getui.push.v2.sdk.dto.req.Audience;
|
||||
import com.getui.push.v2.sdk.dto.req.AuthDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
|
||||
import com.getui.push.v2.sdk.dto.res.TokenDTO;
|
||||
import com.suisung.mall.common.RedisKeyManage.RedisKey;
|
||||
import com.suisung.mall.common.service.SinglePushBaseService;
|
||||
@ -16,77 +20,118 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@lombok.extern.slf4j.Slf4j
|
||||
public class SinglePushBaseServiceImpl implements SinglePushBaseService {
|
||||
@Value("${single.push.mastersecret}")
|
||||
|
||||
@Value("${getui.push.appid}")
|
||||
private String appId;
|
||||
|
||||
@Value("${getui.push.appkey}")
|
||||
private String appkey;
|
||||
|
||||
@Value("${getui.push.mastersecret}")
|
||||
private String mastersecret;
|
||||
|
||||
@Value("${single.push.appkey}")
|
||||
private String appkey;
|
||||
@Value("${single.push.appId}")
|
||||
private String appId;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public TokenDTO getTokenDTO() {
|
||||
TokenDTO token=new TokenDTO();
|
||||
if(redisService.get(RedisKey.SINGLEPUSHTOKE)==null){
|
||||
TokenDTO token = new TokenDTO();
|
||||
if (redisService.get(RedisKey.SINGLEPUSHTOKE) == null) {
|
||||
return getTokenFromSingelPush();
|
||||
}else {
|
||||
Map map= (Map) redisService.get(RedisKey.SINGLEPUSHTOKE);
|
||||
} else {
|
||||
Map map = (Map) redisService.get(RedisKey.SINGLEPUSHTOKE);
|
||||
token.setToken(map.get("token").toString());
|
||||
token.setExpireTime((Long) map.get("expireTime"));
|
||||
}
|
||||
return token;
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delToken(){
|
||||
if(redisService.get(RedisKey.SINGLEPUSHTOKE)!=null){
|
||||
Map map= (Map) redisService.get(RedisKey.SINGLEPUSHTOKE);
|
||||
public void delToken() {
|
||||
if (redisService.get(RedisKey.SINGLEPUSHTOKE) != null) {
|
||||
Map map = (Map) redisService.get(RedisKey.SINGLEPUSHTOKE);
|
||||
AuthApi authApi = getApiHelper().creatApi(AuthApi.class);
|
||||
String token = (String) map.get("token");
|
||||
TokenDTO tokenDTO = new TokenDTO();
|
||||
tokenDTO.setToken(token);
|
||||
tokenDTO.setExpireTime((Long) map.get("expireTime"));
|
||||
log.info("token--{}",tokenDTO);
|
||||
authApi.close(token,tokenDTO);
|
||||
log.info("token--{}", tokenDTO);
|
||||
// authApi.close(token, tokenDTO);
|
||||
authApi.close(token);
|
||||
redisService.del(RedisKey.SINGLEPUSHTOKE);
|
||||
}
|
||||
}
|
||||
|
||||
public ApiHelper getApiHelper(){
|
||||
/**
|
||||
* @param cid
|
||||
* @param content
|
||||
*/
|
||||
@Override
|
||||
public void pushToSingleByCid(String cid, String content) {
|
||||
PushDTO<Audience> pushDTO = new PushDTO<>();
|
||||
// 设置推送参数
|
||||
pushDTO.setRequestId(System.currentTimeMillis() + "");
|
||||
/**** 设置个推通道参数 *****/
|
||||
PushMessage pushMessage = new PushMessage();
|
||||
pushDTO.setPushMessage(pushMessage);
|
||||
GTNotification notification = new GTNotification();
|
||||
pushMessage.setNotification(notification);
|
||||
notification.setTitle("小发同城");
|
||||
notification.setBody("小发同城欢迎你加入大家庭");
|
||||
notification.setClickType("url");
|
||||
notification.setUrl("https://www.getui.com");
|
||||
|
||||
/*设置接收人信息*/
|
||||
Audience audience = new Audience();
|
||||
pushDTO.setAudience(audience);
|
||||
audience.addCid("f9da7081a7951cff6d7f1d4e2d2f270b");
|
||||
|
||||
PushApi pushApi = getApiHelper().creatApi(PushApi.class);
|
||||
// 进行cid单推
|
||||
ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
|
||||
if (apiResult.isSuccess()) {
|
||||
// success
|
||||
System.out.println(apiResult.getData());
|
||||
} else {
|
||||
// failed
|
||||
System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
public ApiHelper getApiHelper() {
|
||||
GtApiConfiguration config = new GtApiConfiguration();
|
||||
config.setAppId(appId);
|
||||
config.setAppKey(appkey);
|
||||
config.setMasterSecret(mastersecret);
|
||||
config.setAppId(appId);
|
||||
config.setDomain("https://restapi.getui.com/v2/");
|
||||
return ApiHelper.build(config);
|
||||
}
|
||||
|
||||
public String getDuration(){
|
||||
public String getDuration() {
|
||||
long timestamp = System.currentTimeMillis(); // 当前时间的时间戳
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(timestamp);
|
||||
calendar.add(Calendar.MINUTE, 10); // 增加10分钟
|
||||
long newTimestamp = calendar.getTimeInMillis(); // 获取新的时间戳
|
||||
return timestamp+"-"+newTimestamp;
|
||||
return timestamp + "-" + newTimestamp;
|
||||
}
|
||||
|
||||
private TokenDTO getTokenFromSingelPush(){
|
||||
AuthApi authApi= getApiHelper().creatApi(AuthApi.class);
|
||||
AuthDTO authDTO= AuthDTO.build(appkey, mastersecret);
|
||||
ApiResult<TokenDTO> tokenDTOApiResult= authApi.auth(authDTO);
|
||||
TokenDTO token=null;
|
||||
if (tokenDTOApiResult!= null) {
|
||||
private TokenDTO getTokenFromSingelPush() {
|
||||
AuthApi authApi = getApiHelper().creatApi(AuthApi.class);
|
||||
AuthDTO authDTO = AuthDTO.build(appkey, mastersecret);
|
||||
ApiResult<TokenDTO> tokenDTOApiResult = authApi.auth(authDTO);
|
||||
TokenDTO token = null;
|
||||
if (tokenDTOApiResult != null) {
|
||||
token = tokenDTOApiResult.getData();
|
||||
Map map= BeanUtil.beanToMap(token);
|
||||
log.info("tokenDTO:{}",token);
|
||||
redisService.set(RedisKey.SINGLEPUSHTOKE, map,(token.getExpireTime()/1000)-60);
|
||||
Map map = BeanUtil.beanToMap(token);
|
||||
log.info("tokenDTO:{}", token);
|
||||
redisService.set(RedisKey.SINGLEPUSHTOKE, map, (token.getExpireTime() / 1000) - 60);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
@ -32,4 +32,11 @@ baidu:
|
||||
map:
|
||||
app_id: 116444176
|
||||
ak: qWKt2xbrqXsp2yK35YYXVBNZgrbiCG5v
|
||||
url: https://api.map.baidu.com/geoconv/v2/?
|
||||
url: https://api.map.baidu.com/geoconv/v2/?
|
||||
|
||||
getui: # 个推配置
|
||||
push:
|
||||
appid: KXgzOaKSzd5HG3p9IPaVa8
|
||||
appkey: neXXX9r1Tc7gMxN2PIcHA1
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
domain: https://restapi.getui.com/v2/
|
||||
@ -33,8 +33,9 @@ baidu:
|
||||
app_id: 116444176
|
||||
ak: qWKt2xbrqXsp2yK35YYXVBNZgrbiCG5v
|
||||
url: https://api.map.baidu.com/geoconv/v2/?
|
||||
single: # 个推配置
|
||||
getui: # 个推配置
|
||||
push:
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
appid: KXgzOaKSzd5HG3p9IPaVa8
|
||||
appkey: neXXX9r1Tc7gMxN2PIcHA1
|
||||
appId: KXgzOaKSzd5HG3p9IPaVa8
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
domain: https://restapi.getui.com/v2/
|
||||
|
||||
@ -33,8 +33,9 @@ baidu:
|
||||
app_id: 116444176
|
||||
ak: qWKt2xbrqXsp2yK35YYXVBNZgrbiCG5v
|
||||
url: https://api.map.baidu.com/geoconv/v2/?
|
||||
single: # 个推配置
|
||||
getui: # 个推配置
|
||||
push:
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
appid: KXgzOaKSzd5HG3p9IPaVa8
|
||||
appkey: neXXX9r1Tc7gMxN2PIcHA1
|
||||
appId: KXgzOaKSzd5HG3p9IPaVa8
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
domain: https://restapi.getui.com/v2/
|
||||
|
||||
@ -33,8 +33,9 @@ baidu:
|
||||
app_id: 116444176
|
||||
ak: qWKt2xbrqXsp2yK35YYXVBNZgrbiCG5v
|
||||
url: https://api.map.baidu.com/geoconv/v2/?
|
||||
single: # 个推配置
|
||||
getui: # 个推配置
|
||||
push:
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
appid: KXgzOaKSzd5HG3p9IPaVa8
|
||||
appkey: neXXX9r1Tc7gMxN2PIcHA1
|
||||
appId: KXgzOaKSzd5HG3p9IPaVa8
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
domain: https://restapi.getui.com/v2/
|
||||
@ -33,8 +33,10 @@ baidu:
|
||||
app_id: 116444176
|
||||
ak: qWKt2xbrqXsp2yK35YYXVBNZgrbiCG5v
|
||||
url: https://api.map.baidu.com/geoconv/v2/?
|
||||
single: # 个推配置
|
||||
|
||||
getui: # 个推配置
|
||||
push:
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
appid: KXgzOaKSzd5HG3p9IPaVa8
|
||||
appkey: neXXX9r1Tc7gMxN2PIcHA1
|
||||
appId: KXgzOaKSzd5HG3p9IPaVa8
|
||||
mastersecret: jYnpS1xYhh6GfyZQMlciJ
|
||||
domain: https://restapi.getui.com/v2/
|
||||
@ -10,6 +10,7 @@ package com.suisung.mall.shop.lakala.controller.mobile;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.suisung.mall.common.api.CommonResult;
|
||||
import com.suisung.mall.common.service.GeTuiPushService;
|
||||
import com.suisung.mall.common.service.impl.BaseControllerImpl;
|
||||
import com.suisung.mall.shop.lakala.service.LakalaApiService;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -32,11 +33,17 @@ public class LakalaController extends BaseControllerImpl {
|
||||
@Resource
|
||||
private LakalaApiService lakalaPayService;
|
||||
|
||||
@Resource
|
||||
private GeTuiPushService geTuiPushService;
|
||||
|
||||
@ApiOperation(value = "测试案例", notes = "测试案例")
|
||||
@RequestMapping(value = "/testcase", method = RequestMethod.POST)
|
||||
public Object testcase(@RequestBody JSONObject paramsJSON) {
|
||||
return lakalaPayService.applyLedgerMerEc(paramsJSON.getStr("mchMobile"));
|
||||
// return lakalaPayService.LedgerMerEcDownload(975790666910121984L);
|
||||
|
||||
// geTuiPushService.pushToSingleByCid("f9da7081a7951cff6d7f1d4e2d2f270b", "shop 发消息");
|
||||
// return "";
|
||||
}
|
||||
|
||||
@ApiOperation(value = "本地文件转base64", notes = "本地文件转base64")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user