消息通知

This commit is contained in:
lzh
2023-03-16 23:49:04 +08:00
parent cfffca82fa
commit 9afc113da3
9 changed files with 299 additions and 25 deletions

View File

@@ -204,12 +204,12 @@
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>com.getui.push</groupId>
<artifactId>restful-sdk</artifactId>
<version>1.0.0.11</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.getui.push</groupId>-->
<!-- <artifactId>restful-sdk</artifactId>-->
<!-- <version>1.0.0.11</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
</dependencies>
<build>

View File

@@ -1,6 +1,7 @@
package com.zscat.mallplus.single;
import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.annotation.IgnoreAuth;
@@ -25,6 +26,7 @@ import com.zscat.mallplus.ums.service.IAdminSysNoticeService;
import com.zscat.mallplus.ums.service.IUmsMemberLocationService;
import com.zscat.mallplus.ums.service.IUmsMemberService;
import com.zscat.mallplus.ums.service.RedisService;
import com.zscat.mallplus.unipush.PushCidsService;
import com.zscat.mallplus.util.JsonUtils;
import com.zscat.mallplus.util.OssAliyunUtil;
import com.zscat.mallplus.utils.CommonResult;
@@ -98,10 +100,14 @@ public class SingelHomeController {
@Resource
private MallplusProperties mallplusProperties;
@Resource
private PushCidsService pushCidsService;
@RequestMapping(value = "/sysInfo", method = RequestMethod.GET)
public Object sysInfo() {
return new CommonResult().success(mallplusProperties);
}
@IgnoreAuth
@ApiOperation("首页内容页信息展示")
@SysLog(MODULE = "home", REMARK = "首页内容页信息展示")
@@ -348,7 +354,8 @@ public class SingelHomeController {
@ApiOperation(value = "手机号 密码登录")
@PostMapping(value = "/login")
public Object login(@RequestParam("phone") String phone,
@RequestParam("password") String password) {
@RequestParam("password") String password,
@RequestParam(required = false) String cid) {
if (phone == null || "".equals(phone)) {
return new CommonResult().validateFailed("用户名或密码错误");
}
@@ -361,6 +368,9 @@ public class SingelHomeController {
log.info("用户名或密码错误");
return new CommonResult().failed("用户名或密码错误");
}
if (StringUtils.isNotBlank(cid) && StringUtils.isNotBlank(phone)) {
ThreadUtil.execute(() -> pushCidsService.bindPhone(cid, phone));
}
return new CommonResult().success(token);
} catch (AuthenticationException e) {
log.info("用户名或密码错误");
@@ -376,7 +386,8 @@ public class SingelHomeController {
@ApiOperation(value = "手机和验证码登录")
@PostMapping(value = "/loginByCode")
public Object loginByCode(@RequestParam String phone,
@RequestParam String authCode) {
@RequestParam String authCode,
@RequestParam(required = false) String cid) {
if (phone == null || "".equals(phone)) {
return new CommonResult().validateFailed("用户名或密码错误");
}
@@ -388,6 +399,9 @@ public class SingelHomeController {
if (token.get("token") == null) {
return new CommonResult().validateFailed("用户名或密码错误");
}
if (StringUtils.isNotBlank(cid) && StringUtils.isNotBlank(phone)) {
ThreadUtil.execute(() -> pushCidsService.bindPhone(cid, phone));
}
return new CommonResult().success(token);
} catch (AuthenticationException e) {
return new CommonResult().validateFailed("用户名或密码错误");
@@ -448,19 +462,19 @@ public class SingelHomeController {
@IgnoreAuth
@ApiOperation("获取验证码")
@PostMapping(value = "/sms/codes")
public Object sendSmsCode(@RequestParam("phone") String phone,@RequestParam(value = "type")String type) {
public Object sendSmsCode(@RequestParam("phone") String phone, @RequestParam(value = "type") String type) {
try {
if (!PhoneUtil.checkPhone(phone)) {
throw new IllegalArgumentException("手机号格式不正确");
}
if(StringUtils.isBlank(type)){
if (StringUtils.isBlank(type)) {
return new CommonResult().failed("参数错误type");
}
//缓存识别码
String redisKey = "";
if(SmsEnum.SendEnum.LOGIN.getCode().equals(type)){
if (SmsEnum.SendEnum.LOGIN.getCode().equals(type)) {
redisKey = REDIS_KEY_PREFIX_LOGIN_CODE;
}else if(SmsEnum.SendEnum.FORGET.getCode().equals(type)){
} else if (SmsEnum.SendEnum.FORGET.getCode().equals(type)) {
redisKey = REDIS_KEY_PREFIX_FORGET_CODE;
}
Date date = new Date();
@@ -473,7 +487,7 @@ public class SingelHomeController {
return new CommonResult().failed("请等待一分钟后再次重试!");
}
}
SmsCode smsCode = memberService.generateCode(phone,type,date);
SmsCode smsCode = memberService.generateCode(phone, type, date);
return new CommonResult().success(smsCode);
} catch (Exception e) {
@@ -606,4 +620,15 @@ public class SingelHomeController {
SecurityContextHolder.getContext().setAuthentication(null);
return new CommonResult().success(null);
}
@IgnoreAuth
@ApiOperation("提供unipush的ClientID")
@PostMapping(value = "/pushCid")
public Object pushCid(@RequestParam String cid) {
if (StringUtils.isNotBlank(cid)) {
ThreadUtil.execute(() -> pushCidsService.pushCid(cid));
}
return new CommonResult().success();
}
}

View File

@@ -0,0 +1,94 @@
/*********************************************************
*********************************************************
******************** *******************
************* ************
******* _oo0oo_ *******
*** o8888888o ***
* 88" . "88 *
* (| -_- |) *
* 0\ = /0 *
* ___/`---'\___ *
* .' \\| |// '. *
* / \\||| : |||// \ *
* / _||||| -:- |||||- \ *
* | | \\\ - /// | | *
* | \_| ''\---/'' |_/ | *
* \ .-\__ '-' ___/-. / *
* ___'. .' /--.--\ `. .'___ *
* ."" '< `.___\_<|>_/___.' >' "". *
* | | : `- \`.;`\ _ /`;.`/ - ` : | | *
* \ \ `_. \_ __\ /__ _/ .-` / / *
* =====`-.____`.___ \_____/___.-`___.-'===== *
* `=---=' *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
*********__佛祖保佑__永无BUG__验收通过__钞票多多__*********
*********************************************************/
package com.zscat.mallplus.unipush;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zscat.mallplus.unipush.entity.PushCids;
import com.zscat.mallplus.unipush.mapper.PushCidsMapper;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* Project: mallplus <br/>
* File: IPushCidsService.java <br/>
* Class: com.zscat.mallplus.unipush.service.IPushCidsService <br/>
* Description: <描述类的功能>. <br/>
* Copyright: Copyright (c) 2011 <br/>
* Company: https://gitee.com/liuzp315 <br/>
* Makedate: 2023/3/16 22:18 <br/>
*
* @author liupopo
* @version 1.0
* @since 1.0
*/
@Service
public class PushCidsService extends ServiceImpl<PushCidsMapper, PushCids> {
public void pushCid(String cid) {
List<PushCids> list = listByCid(cid);
if (list == null || list.isEmpty()) {
baseMapper.insert(new PushCids(cid));
}
}
public List<PushCids> listByCid(String cid) {
QueryWrapper<PushCids> qw = new QueryWrapper<>();
qw.eq("getuiCid", cid);
return baseMapper.selectList(qw);
}
public void bindPhone(String cid, String phone) {
List<PushCids> list = listByCid(cid);
if (list != null && list.size() == 1) { // 只有一条cid数据判断是否和手机号相同
PushCids pc = list.get(0);
if (!phone.equals(pc.getUserPhone())) { // 手机号不同或为空,更新手机号
UpdateWrapper<PushCids> uw = new UpdateWrapper<>();
uw.set("userPhone", phone);
uw.eq("getuiCid", cid);
baseMapper.update(null, uw);
}
return;
}
if (list == null || list.isEmpty()) { // 如果没有cid直接插入
baseMapper.insert(new PushCids(cid, phone));
return;
}
// cid不为空且多于1条全部删除只保留一条
deleteByCid(cid);
baseMapper.insert(new PushCids(cid, phone));
}
private void deleteByCid(String cid) {
UpdateWrapper<PushCids> uw = new UpdateWrapper<>();
uw.eq("getuiCid", cid);
baseMapper.delete(uw);
}
}

View File

@@ -1,110 +0,0 @@
package com.zscat.mallplus.unipush;
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 org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class UniPushService {
public void test() {
// 设置httpClient最大连接数当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
System.setProperty("http.maxConnections", "200");
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
//填写应用配置
apiConfiguration.setAppId("UBUIDJ8NQm50rGJsB6LYx1");
apiConfiguration.setAppKey("RS3UZfeS509hcNEkmfS6R");
apiConfiguration.setMasterSecret("6fjUinwRfDA3BcEnDQvTl5");
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
apiConfiguration.setDomain("https://restapi.getui.com/v2/");
// 实例化ApiHelper对象用于创建接口对象
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
// 创建对象建议复用。目前有PushApi、StatisticApi、UserApi
PushApi pushApi = apiHelper.creatApi(PushApi.class);
//根据cid进行单推
PushDTO<Audience> pushDTO = new PushDTO<Audience>();
// 设置推送参数
pushDTO.setRequestId(System.currentTimeMillis() + "");
/**** 设置个推通道参数 *****/
PushMessage pushMessage = new PushMessage();
pushDTO.setPushMessage(pushMessage);
GTNotification notification = new GTNotification();
pushMessage.setNotification(notification);
notification.setTitle("测试TitleXXX");
notification.setBody("测试BodyXXXXXX");
String payload = "{\"title\":\"liutitle\",\"body\":\"liubody\",\"name\":\"hao\",\"userid\":101,\"msgtitle\":\"haha\"}";
notification.setPayload(payload);
notification.setClickType("payload");
// notification.setClickType("url");
// notification.setUrl("https://www.getui.com");
/**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
// /**** 设置厂商相关参数 ****/
// 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("厂商body");
// thirdNotification.setClickType("url");
// thirdNotification.setUrl("https://www.getui.com");
// // 两条消息的notify_id相同新的消息会覆盖老的消息取值范围0-2147483647
// // thirdNotification.setNotifyId("11177");
// /*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
// /*设置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("ios title");
// alert.setBody("ios body");
// /*设置ios厂商参数结束更多参数请查看文档或对象源码*/
/*设置接收人信息*/
Audience audience = new Audience();
pushDTO.setAudience(audience);
audience.addCid("89e286aee78d38faf748a690e603b1a3");
/*设置接收人信息结束*/
/**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/
// 进行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 static void main(String[] args) {
new UniPushService().test();
}
}

View File

@@ -135,10 +135,3 @@ wxsubpay.partnerKey=xxxx
wxsubpay.certPath=xxxx
wxsubpay.domain=xxxx
unipush.baseurl=https://restapi.getui.com/v2/UBUIDJ8NQm50rGJsB6LYx1
unipush.appid=UBUIDJ8NQm50rGJsB6LYx1
unipush.appkey=RS3UZfeS509hcNEkmfS6R
unipush.appsecret=6QuFcPWFga8DQzSa03ruR7
unipush.mastersecret=6fjUinwRfDA3BcEnDQvTl5
unipush.apppackage=org.jbase.yxt.yyd.pyw