微信服务号扫码登录

pull/26/head
3y 2 years ago
parent 46fc258f77
commit bf73a9cbd8

@ -33,5 +33,15 @@ public class AustinConstant {
public static final String SEND_ALL = "@all";
/**
* /
*/
public static final String DEFAULT_CREATOR = "Java3y";
public static final String DEFAULT_UPDATOR = "Java3y";
public static final String DEFAULT_TEAM = "Java3y公众号";
public static final String DEFAULT_AUDITOR = "Java3y";
}

@ -72,4 +72,14 @@ public class CommonConstant {
*/
public final static String CRON_FORMAT = "ss mm HH dd MM ? yyyy-yyyy";
/**
*
*/
public final static String ENV_DEV = "dev";
public final static String ENV_TEST = "test";
}

@ -28,7 +28,7 @@ public enum RespStatusEnum {
TEMPLATE_NOT_FOUND("A0002", "找不到模板或模板已被删除"),
TOO_MANY_RECEIVER("A0003", "传入的接收者大于100个"),
DO_NOT_NEED_LOGIN("A0004", "非测试环境,无须登录"),
NO_LOGIN("A0005", "还未登录"),
NO_LOGIN("A0005", "还未登录,请先登录"),
/**
*

@ -2,11 +2,7 @@ package com.java3y.austin.support.dao;
import com.java3y.austin.support.domain.ChannelAccount;
import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.support.domain.SmsRecord;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
@ -19,7 +15,17 @@ public interface ChannelAccountDao extends JpaRepository<ChannelAccount, Long> {
/**
* )
*
*
* @param deleted 0 1
* @param channelType
* @param creator
* @return
*/
List<ChannelAccount> findAllByIsDeletedEqualsAndCreatorEqualsAndSendChannelEquals(Integer deleted, String creator, Integer channelType);
/**
*
*
* @param deleted 0 1
* @param channelType
@ -27,6 +33,13 @@ public interface ChannelAccountDao extends JpaRepository<ChannelAccount, Long> {
*/
List<ChannelAccount> findAllByIsDeletedEqualsAndSendChannelEquals(Integer deleted, Integer channelType);
/**
*
*
* @param creator
* @return
*/
List<ChannelAccount> findAllByCreatorEquals(String creator);
/**
*

@ -48,6 +48,11 @@ public class ChannelAccount {
*/
private Integer isDeleted;
/**
*
*/
private String creator;
/**
* s
*/

@ -27,19 +27,7 @@ public class AccountUtils {
private ChannelAccountDao channelAccountDao;
/**
* local.properties
* (key:smsAccount)[{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDxxxxxxxx1WljQq","secretKey":"B4hwww39yxxxrrrrgxyi","smsSdkAppId":"1423123125","templateId":"1182097","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"caffff8234234231b5cd7","tpl_id":"523333332","supplierId":20,"supplierName":"云片"}}]
* (key:emailAccount)[{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423423@qq.com","pass":"23423432432423423","from":"234@qq.com","starttlsEnable":true,"auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"22222@163.com","pass":"23432423","from":"234324324234@163.com","starttlsEnable":false,"auth":true,"sslEnable":true}}]
* (key:enterpriseWechatAccount)[{"enterprise_wechat_10":{"corpId":"wwf87603333e00069c","corpSecret":"-IFWxS2222QxzPIorNV11144D915DM","agentId":10044442,"token":"rXROB3333Kf6i","aesKey":"MKZtoFxHIM44444M7ieag3r9ZPUsl"}}]
* (key:dingDingRobotAccount) [{"ding_ding_robot_10":{"secret":"SEC9222d4768aded74114faae92229de422222fedf","webhook":"https://oapi.dingtalk.com/robot/send?access_token=8d03b6442222203d87333367328b0c3003d164715d2c6c6e56"}}]
* (key:dingDingWorkNoticeAccount) [{"ding_ding_work_notice_10":{"appKey":"dingh6yyyyyyycrlbx","appSecret":"tQpvmkR863333yyyyyHP3QHyyyymy9Ao1yoL1oQX5NsdfsWHvWKbTu","agentId":"1523123123183622"}}]
* (key:officialAccount) [{"official_10":{"appId":"wxecb4693d2eef1ea7","secret":"624asdfsa1640d769ba20120821","templateId":"JHUk6eE9T5Ts7asdfsadfiKNDQsk-Q","url":"http://weixin.qq.com/download","miniProgramId":"xiaochengxuappid12345","path":"index?foo=bar"}}]
* (key:miniProgramAccount) [{"mini_program_10":{"appId":"wxecb4693d2eef1ea7","appSecret":"6240870f4d91701640d769ba20120821","templateId":"JHUk6eE9T5TasdfCrQsk-Q","grantType":"client_credential","miniProgramState":"trial","page":"index?foo=bar"}}]
* (key:alipayMiniProgramAccount) [{"alipay_mini_program_10":{"privateKey":"MIIEvQIBADANB......","alipayPublicKey":"MIIBIjANBg...","appId":"2014********7148","userTemplateId":"MDI4YzIxMDE2M2I5YTQzYjUxNWE4MjA4NmU1MTIyYmM=","page":"page/component/index"}}]
*/
public <T> T getAccountById(Integer sendAccountId, Class<T> clazz) {
try {
Optional<ChannelAccount> optionalChannelAccount = channelAccountDao.findById(Long.valueOf(sendAccountId));
if (optionalChannelAccount.isPresent()) {
@ -49,8 +37,6 @@ public class AccountUtils {
} catch (Exception e) {
log.error("AccountUtils#getAccount fail!", Throwables.getStackTraceAsString(e));
}
log.error("AccountUtils#getAccount not found!:{}", sendAccountId);
return null;
}

@ -2,17 +2,19 @@ package com.java3y.austin.web.controller;
import cn.hutool.core.util.StrUtil;
import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.common.vo.BasicResultVO;
import com.java3y.austin.support.domain.ChannelAccount;
import com.java3y.austin.web.service.ChannelAccountService;
import com.java3y.austin.web.vo.amis.CommonAmisVo;
import com.java3y.austin.web.utils.Convert4Amis;
import com.java3y.austin.web.utils.LoginUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -31,6 +33,8 @@ public class ChannelAccountController {
@Autowired
private ChannelAccountService channelAccountService;
@Autowired
private LoginUtils loginUtils;
/**
* Id
@ -39,6 +43,11 @@ public class ChannelAccountController {
@PostMapping("/save")
@ApiOperation("/保存数据")
public BasicResultVO saveOrUpdate(@RequestBody ChannelAccount channelAccount) {
if (loginUtils.needLogin() && StrUtil.isBlank(channelAccount.getCreator())) {
return BasicResultVO.fail(RespStatusEnum.NO_LOGIN);
}
channelAccount.setCreator(StrUtil.isBlank(channelAccount.getCreator()) ? AustinConstant.DEFAULT_CREATOR : channelAccount.getCreator());
return BasicResultVO.success(channelAccountService.save(channelAccount));
}
@ -47,15 +56,14 @@ public class ChannelAccountController {
*/
@GetMapping("/queryByChannelType")
@ApiOperation("/根据渠道标识查询相关的记录")
public BasicResultVO query(Integer channelType) {
List<CommonAmisVo> result = new ArrayList<>();
List<ChannelAccount> channelAccounts = channelAccountService.queryByChannelType(channelType);
for (ChannelAccount channelAccount : channelAccounts) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build();
result.add(commonAmisVo);
public BasicResultVO query(Integer channelType, String creator) {
if (loginUtils.needLogin() && StrUtil.isBlank(creator)) {
return BasicResultVO.fail(RespStatusEnum.NO_LOGIN);
}
return BasicResultVO.success(result);
creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator;
List<ChannelAccount> channelAccounts = channelAccountService.queryByChannelType(channelType, creator);
return BasicResultVO.success(Convert4Amis.getChannelAccountVo(channelAccounts));
}
/**
@ -63,8 +71,13 @@ public class ChannelAccountController {
*/
@GetMapping("/list")
@ApiOperation("/渠道账号列表信息")
public BasicResultVO list() {
return BasicResultVO.success(channelAccountService.list());
public BasicResultVO list(String creator) {
if (loginUtils.needLogin() && StrUtil.isBlank(creator)) {
return BasicResultVO.fail(RespStatusEnum.NO_LOGIN);
}
creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator;
return BasicResultVO.success(channelAccountService.list(creator));
}
/**

@ -16,6 +16,7 @@ import com.java3y.austin.service.api.service.SendService;
import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.web.service.MessageTemplateService;
import com.java3y.austin.web.utils.Convert4Amis;
import com.java3y.austin.web.utils.LoginUtils;
import com.java3y.austin.web.vo.MessageTemplateParam;
import com.java3y.austin.web.vo.MessageTemplateVo;
import com.java3y.austin.web.vo.amis.CommonAmisVo;
@ -56,6 +57,9 @@ public class MessageTemplateController {
@Autowired
private RecallService recallService;
@Autowired
private LoginUtils loginUtils;
@Value("${austin.business.upload.crowd.path}")
private String dataPath;
@ -66,6 +70,9 @@ public class MessageTemplateController {
@PostMapping("/save")
@ApiOperation("/保存数据")
public BasicResultVO saveOrUpdate(@RequestBody MessageTemplate messageTemplate) {
if (loginUtils.needLogin() && StrUtil.isBlank(messageTemplate.getCreator())) {
return BasicResultVO.fail(RespStatusEnum.NO_LOGIN);
}
MessageTemplate info = messageTemplateService.saveOrUpdate(messageTemplate);
return BasicResultVO.success(info);
}
@ -76,6 +83,9 @@ public class MessageTemplateController {
@GetMapping("/list")
@ApiOperation("/列表页")
public BasicResultVO queryList(@Validated MessageTemplateParam messageTemplateParam) {
if (loginUtils.needLogin() && StrUtil.isBlank(messageTemplateParam.getCreator())) {
return BasicResultVO.fail(RespStatusEnum.NO_LOGIN);
}
Page<MessageTemplate> messageTemplates = messageTemplateService.queryList(messageTemplateParam);
List<Map<String, Object>> result = Convert4Amis.flatListMap(messageTemplates.toList());
MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(messageTemplates.getTotalElements()).rows(result).build();
@ -202,8 +212,6 @@ public class MessageTemplateController {
localFile.mkdirs();
}
file.transferTo(localFile);
} catch (Exception e) {
log.error("MessageTemplateController#upload fail! e:{},params{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(file));
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR);

@ -12,6 +12,7 @@ import com.java3y.austin.common.vo.BasicResultVO;
import com.java3y.austin.support.utils.WxServiceUtils;
import com.java3y.austin.web.config.WeChatLoginConfig;
import com.java3y.austin.web.utils.Convert4Amis;
import com.java3y.austin.web.utils.LoginUtils;
import com.java3y.austin.web.vo.amis.CommonAmisVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -23,7 +24,6 @@ import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -49,7 +49,7 @@ public class OfficialAccountController {
private WxServiceUtils wxServiceUtils;
@Autowired
private ApplicationContext applicationContext;
private LoginUtils loginUtils;
@Autowired
private StringRedisTemplate redisTemplate;
@ -112,7 +112,7 @@ public class OfficialAccountController {
@ApiOperation("/接收微信的事件消息")
public String receiptMessage(HttpServletRequest request) {
try {
WeChatLoginConfig configService = applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class);
WeChatLoginConfig configService = loginUtils.getLoginConfig();
if (configService == null) {
return RespStatusEnum.DO_NOT_NEED_LOGIN.getMsg();
}
@ -163,7 +163,7 @@ public class OfficialAccountController {
@ApiOperation("/生成 服务号 二维码")
public BasicResultVO getQrCode() {
try {
WeChatLoginConfig configService = applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class);
WeChatLoginConfig configService = loginUtils.getLoginConfig();
if (configService == null) {
return BasicResultVO.fail(RespStatusEnum.DO_NOT_NEED_LOGIN);
}

@ -25,17 +25,18 @@ public interface ChannelAccountService {
*
*
* @param channelType
* @param creator
* @return
*/
List<ChannelAccount> queryByChannelType(Integer channelType);
List<ChannelAccount> queryByChannelType(Integer channelType,String creator);
/**
*
*
*
* @return
*/
List<ChannelAccount> list();
List<ChannelAccount> list(String creator);
/**
* (deleted=1)

@ -1,6 +1,8 @@
package com.java3y.austin.web.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.constant.CommonConstant;
import com.java3y.austin.support.dao.ChannelAccountDao;
import com.java3y.austin.support.domain.ChannelAccount;
@ -21,12 +23,14 @@ public class ChannelAccountServiceImpl implements ChannelAccountService {
private ChannelAccountDao channelAccountDao;
@Autowired
private WxServiceUtils wxServiceUtils;
@Override
public ChannelAccount save(ChannelAccount channelAccount) {
if (channelAccount.getId() == null) {
channelAccount.setCreated(Math.toIntExact(DateUtil.currentSeconds()));
channelAccount.setIsDeleted(CommonConstant.FALSE);
}
channelAccount.setCreator(StrUtil.isBlank(channelAccount.getCreator()) ? AustinConstant.DEFAULT_CREATOR : channelAccount.getCreator());
channelAccount.setUpdated(Math.toIntExact(DateUtil.currentSeconds()));
ChannelAccount result = channelAccountDao.save(channelAccount);
wxServiceUtils.fresh();
@ -34,13 +38,13 @@ public class ChannelAccountServiceImpl implements ChannelAccountService {
}
@Override
public List<ChannelAccount> queryByChannelType(Integer channelType) {
return channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, channelType);
public List<ChannelAccount> queryByChannelType(Integer channelType, String creator) {
return channelAccountDao.findAllByIsDeletedEqualsAndCreatorEqualsAndSendChannelEquals(CommonConstant.FALSE, creator, channelType);
}
@Override
public List<ChannelAccount> list() {
return channelAccountDao.findAll();
public List<ChannelAccount> list(String creator) {
return channelAccountDao.findAllByCreatorEquals(creator);
}
@Override

@ -23,10 +23,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
@ -52,6 +49,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
@Override
public Page<MessageTemplate> queryList(MessageTemplateParam param) {
PageRequest pageRequest = PageRequest.of(param.getPage() - 1, param.getPerPage());
String creator = StrUtil.isBlank(param.getCreator()) ? AustinConstant.DEFAULT_CREATOR : param.getCreator();
return messageTemplateDao.findAll((Specification<MessageTemplate>) (root, query, cb) -> {
List<Predicate> predicateList = new ArrayList<>();
// 加搜索条件
@ -59,6 +57,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
predicateList.add(cb.like(root.get("name").as(String.class), "%" + param.getKeywords() + "%"));
}
predicateList.add(cb.equal(root.get("isDeleted").as(Integer.class), CommonConstant.FALSE));
predicateList.add(cb.equal(root.get("creator").as(String.class), creator));
Predicate[] p = new Predicate[predicateList.size()];
// 查询
query.where(cb.and(predicateList.toArray(p)));
@ -91,7 +90,7 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
Iterable<MessageTemplate> messageTemplates = messageTemplateDao.findAllById(ids);
messageTemplates.forEach(messageTemplate -> messageTemplate.setIsDeleted(CommonConstant.TRUE));
for (MessageTemplate messageTemplate : messageTemplates) {
if (messageTemplate.getCronTaskId()!=null && messageTemplate.getCronTaskId() > 0) {
if (messageTemplate.getCronTaskId() != null && messageTemplate.getCronTaskId() > 0) {
cronTaskService.deleteCronTask(messageTemplate.getCronTaskId());
}
}
@ -149,14 +148,16 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
/**
*
* TODO
*
* @param messageTemplate
*/
private void initStatus(MessageTemplate messageTemplate) {
messageTemplate.setFlowId(StrUtil.EMPTY)
.setMsgStatus(MessageStatus.INIT.getCode()).setAuditStatus(AuditStatus.WAIT_AUDIT.getCode())
.setCreator("Java3y").setUpdator("Java3y").setTeam("公众号Java3y").setAuditor("3y")
.setCreator(StrUtil.isBlank(messageTemplate.getCreator()) ? AustinConstant.DEFAULT_CREATOR : messageTemplate.getCreator())
.setUpdator(StrUtil.isBlank(messageTemplate.getUpdator()) ? AustinConstant.DEFAULT_UPDATOR : messageTemplate.getUpdator())
.setTeam(StrUtil.isBlank(messageTemplate.getTeam()) ? AustinConstant.DEFAULT_TEAM : messageTemplate.getTeam())
.setAuditor(StrUtil.isBlank(messageTemplate.getAuditor()) ? AustinConstant.DEFAULT_AUDITOR : messageTemplate.getAuditor())
.setCreated(Math.toIntExact(DateUtil.currentSeconds()))
.setIsDeleted(CommonConstant.FALSE);

@ -6,6 +6,7 @@ import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.java3y.austin.support.domain.ChannelAccount;
import com.java3y.austin.web.vo.amis.CommonAmisVo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
@ -343,4 +344,20 @@ public class Convert4Amis {
return CommonAmisVo.builder().type("form").title("登录").mode("horizontal").body(Arrays.asList(image, service)).build();
}
/**
* amis
* <p>
*
*
* @return
*/
public static List<CommonAmisVo> getChannelAccountVo(List<ChannelAccount> channelAccounts) {
List<CommonAmisVo> result = new ArrayList<>();
for (ChannelAccount channelAccount : channelAccounts) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build();
result.add(commonAmisVo);
}
return result;
}
}

@ -0,0 +1,57 @@
package com.java3y.austin.web.utils;
import com.java3y.austin.common.constant.CommonConstant;
import com.java3y.austin.common.constant.OfficialAccountParamConstant;
import com.java3y.austin.web.config.WeChatLoginConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
/**
* @author 3y
* @date 2022/12/22
* Utils
*/
@Component
@Slf4j
public class LoginUtils {
@Autowired
private ApplicationContext applicationContext;
@Value("${spring.profiles.active}")
private String env;
/**
* 使
* WeChatLoginConfig
*
* @return
*/
public WeChatLoginConfig getLoginConfig() {
try {
return applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class);
} catch (Exception e) {
return null;
}
}
/**
* 使
*
*
* @return
*/
public boolean needLogin() {
try {
WeChatLoginConfig bean = applicationContext.getBean(OfficialAccountParamConstant.WE_CHAT_LOGIN_CONFIG, WeChatLoginConfig.class);
if (CommonConstant.ENV_TEST.equals(env) && bean != null) {
return true;
}
} catch (Exception e) {
}
return false;
}
}

@ -37,6 +37,11 @@ public class MessageTemplateParam {
*/
private Long id;
/**
*
*/
private String creator;
/**
* (使)
*/

@ -45,7 +45,7 @@ austin.grayLog.ip=austin.graylog
austin.business.upload.crowd.path=/Users/3y/temp
# TODO if [login use officialAccount] switch 【optional】, if austin.login.official.account.enable=true 【must】
austin.login.official.account.enable=false
austin.login.official.account.appId=wx22222b325
austin.login.official.account.secret=203233fa99
austin.login.official.account.enable=true
austin.login.official.account.appId=wx27f83ca10e06b325
austin.login.official.account.secret=203299484df873a18621d076db46fa99
austin.login.official.account.token=austin123

@ -68,6 +68,7 @@ CREATE TABLE `channel_account`
`name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '账号名称',
`send_channel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息发送渠道10.IM 20.Push 30.短信 40.Email 50.公众号 60.小程序 70.企业微信 80.钉钉机器人 90.钉钉工作通知 100.企业微信机器人 110.飞书机器人 110. 飞书应用消息 ',
`account_config` varchar(1024) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '账号配置',
`creator` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Java3y' COMMENT '拥有者',
`created` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`updated` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
`is_deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否删除0.不删除 1.删除',

Loading…
Cancel
Save