微信小程序-订阅消息 接入,调试中。

master
3y 3 years ago
parent a72971bd5b
commit 6a9bce2955

@ -1,5 +1,9 @@
package com.java3y.austin.common.constant;
/**
* @author 3y
*/
public class CommonConstant {
public final static String PERIOD = ".";

@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author 3y
*/
@Data
@AllArgsConstructor
@NoArgsConstructor

@ -18,5 +18,16 @@ public class MiniProgramContentModel extends ContentModel {
/**
*
*/
Map<String, String> map;
Map<String, String> miniProgramParam;
/**
* Id
*/
private String templateId;
/**
*
*/
private String page;
}

@ -12,10 +12,12 @@ import lombok.ToString;
@ToString
@AllArgsConstructor
public enum MessageType {
NOTICE(10,"通知类消息","notice"),
MARKETING(20,"营销类消息","marketing"),
AUTH_CODE(30,"验证码消息","auth_code")
;
/**
*
*/

@ -1,38 +0,0 @@
package com.java3y.austin.handler.domain.wechat;
import lombok.Builder;
import lombok.Data;
import java.util.Map;
import java.util.Set;
/**
* @author sunql
* @date 20220506 15:56
*
*
*/
@Data
@Builder
public class WeChatMiniProgramParam {
/**
* Id
*/
private Long messageTemplateId;
/**
*
*/
private Integer sendAccount;
/**
* openid
*/
private Set<String> openIds;
/**
* { "key1": { "value": any }, "key2": { "value": any } }
*/
private Map<String, String> data;
}

@ -14,6 +14,7 @@ public interface FlowControlService {
*
* @param taskInfo
* @param flowControlParam
* @return
*/
Double flowControl(TaskInfo taskInfo, FlowControlParam flowControlParam);

@ -1,17 +1,15 @@
package com.java3y.austin.handler.flowcontrol.annotations;
import com.java3y.austin.handler.enums.RateLimitStrategy;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.stereotype.Service;
import java.lang.annotation.*;
/**
*
* Created by TOM
* On 2022/7/21 17:03
* @author TOM
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)

@ -10,9 +10,10 @@ import com.java3y.austin.handler.flowcontrol.annotations.LocalRateLimit;
/**
* Created by TOM
* On 2022/7/21 17:05
* @author TOM
*/
@LocalRateLimit(rateLimitStrategy = RateLimitStrategy.REQUEST_RATE_LIMIT)
public class RequestRateLimitService implements FlowControlService {
public class RequestRateLimitServiceImpl implements FlowControlService {
/**
*

@ -10,9 +10,10 @@ import com.java3y.austin.handler.flowcontrol.annotations.LocalRateLimit;
/**
* Created by TOM
* On 2022/7/21 17:14
* @author TOM
*/
@LocalRateLimit(rateLimitStrategy = RateLimitStrategy.SEND_USER_NUM_RATE_LIMIT)
public class SendUserNumRateLimitService implements FlowControlService {
public class SendUserNumRateLimitServiceImpl implements FlowControlService {
/**
*

@ -1,19 +1,25 @@
package com.java3y.austin.handler.handler.impl;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables;
import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.model.MiniProgramContentModel;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.domain.wechat.WeChatMiniProgramParam;
import com.java3y.austin.handler.handler.BaseHandler;
import com.java3y.austin.handler.handler.Handler;
import com.java3y.austin.handler.wechat.MiniProgramAccountService;
import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.support.utils.WxServiceUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author sunql
*
@ -21,9 +27,8 @@ import org.springframework.stereotype.Component;
@Component
@Slf4j
public class MiniProgramAccountHandler extends BaseHandler implements Handler {
@Autowired
private MiniProgramAccountService miniProgramAccountService;
private WxServiceUtils wxServiceUtils;
public MiniProgramAccountHandler() {
channelCode = ChannelType.MINI_PROGRAM.getCode();
@ -31,35 +36,47 @@ public class MiniProgramAccountHandler extends BaseHandler implements Handler {
@Override
public boolean handler(TaskInfo taskInfo) {
WeChatMiniProgramParam miniProgramParam = buildMiniProgramParam(taskInfo);
try {
miniProgramAccountService.send(miniProgramParam);
} catch (Exception e) {
log.error("MiniProgramAccountHandler#handler fail:{},params:{}",
Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo));
return false;
MiniProgramContentModel contentModel = (MiniProgramContentModel) taskInfo.getContentModel();
WxMaSubscribeService wxMaSubscribeService = wxServiceUtils.getMiniProgramServiceMap().get(taskInfo.getSendAccount().longValue());
List<WxMaSubscribeMessage> wxMaSubscribeMessages = assembleReq(taskInfo.getReceiver(), contentModel);
for (WxMaSubscribeMessage message : wxMaSubscribeMessages) {
try {
wxMaSubscribeService.sendSubscribeMsg(message);
} catch (Exception e) {
log.info("MiniProgramAccountHandler#handler fail! param:{},e:{}", JSON.toJSONString(taskInfo), Throwables.getStackTraceAsString(e));
}
}
return true;
}
/**
* taskInfo
*
* @param taskInfo
* @return
*
*/
private WeChatMiniProgramParam buildMiniProgramParam(TaskInfo taskInfo) {
// 小程序订阅消息可以关联到系统业务,通过接口查询。
WeChatMiniProgramParam miniProgramParam = WeChatMiniProgramParam.builder()
.openIds(taskInfo.getReceiver())
.messageTemplateId(taskInfo.getMessageTemplateId())
.sendAccount(taskInfo.getSendAccount())
.build();
private List<WxMaSubscribeMessage> assembleReq(Set<String> receiver, MiniProgramContentModel contentModel) {
List<WxMaSubscribeMessage> messageList = new ArrayList<>(receiver.size());
for (String openId : receiver) {
WxMaSubscribeMessage subscribeMessage = WxMaSubscribeMessage.builder()
.toUser(openId)
.data(getWxMaTemplateData(contentModel.getMiniProgramParam()))
.templateId(contentModel.getTemplateId())
.page(contentModel.getPage())
.build();
messageList.add(subscribeMessage);
}
return messageList;
}
MiniProgramContentModel contentModel = (MiniProgramContentModel) taskInfo.getContentModel();
miniProgramParam.setData(contentModel.getMap());
return miniProgramParam;
/**
*
*
* @returnp
*/
private List<WxMaSubscribeMessage.MsgData> getWxMaTemplateData(Map<String, String> data) {
List<WxMaSubscribeMessage.MsgData> templateDataList = new ArrayList<>(data.size());
data.forEach((k, v) -> templateDataList.add(new WxMaSubscribeMessage.MsgData(k, v)));
return templateDataList;
}
@Override
public void recall(MessageTemplate messageTemplate) {

@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@ -28,6 +29,9 @@ import java.util.Set;
@Slf4j
public class OfficialAccountHandler extends BaseHandler implements Handler {
@Autowired
private WxServiceUtils wxServiceUtils;
public OfficialAccountHandler() {
channelCode = ChannelType.OFFICIAL_ACCOUNT.getCode();
}
@ -36,7 +40,7 @@ public class OfficialAccountHandler extends BaseHandler implements Handler {
public boolean handler(TaskInfo taskInfo) {
try {
OfficialAccountsContentModel contentModel = (OfficialAccountsContentModel) taskInfo.getContentModel();
WxMpService wxMpService = WxServiceUtils.wxMpServiceMap.get(taskInfo.getSendAccount().longValue());
WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(taskInfo.getSendAccount().longValue());
List<WxMpTemplateMessage> messages = assembleReq(taskInfo.getReceiver(), contentModel);
for (WxMpTemplateMessage message : messages) {
try {

@ -41,6 +41,7 @@ public class SmsPullReceiptStarterImpl implements ReceiptMessageStater {
/**
*
*/
@Override
public void start() {
try {
List<ChannelAccount> channelAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.SMS.getCode());

@ -1,19 +0,0 @@
package com.java3y.austin.handler.wechat;
import com.java3y.austin.handler.domain.wechat.WeChatMiniProgramParam;
/**
* @author sunql
*/
public interface MiniProgramAccountService {
/**
*
*
* @param miniProgramParam
* @return
* @throws Exception
*/
void send(WeChatMiniProgramParam miniProgramParam) throws Exception;
}

@ -1,91 +0,0 @@
package com.java3y.austin.handler.wechat.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaSubscribeServiceImpl;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.java3y.austin.common.constant.SendAccountConstant;
import com.java3y.austin.common.dto.account.WeChatMiniProgramAccount;
import com.java3y.austin.handler.domain.wechat.WeChatMiniProgramParam;
import com.java3y.austin.handler.wechat.MiniProgramAccountService;
import com.java3y.austin.support.utils.AccountUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author sunql
* @date 20220506 16:41
*/
@Service
@Slf4j
public class MiniProgramAccountServiceImpl implements MiniProgramAccountService {
@Autowired
private AccountUtils accountUtils;
@Override
public void send(WeChatMiniProgramParam miniProgramParam) throws Exception {
WeChatMiniProgramAccount miniProgramAccount = accountUtils.getAccountById(miniProgramParam.getSendAccount(),
WeChatMiniProgramAccount.class);
WxMaSubscribeService wxMaSubscribeService = initService(miniProgramAccount);
List<WxMaSubscribeMessage> subscribeMessageList = assembleReq(miniProgramParam, miniProgramAccount);
for (WxMaSubscribeMessage subscribeMessage : subscribeMessageList) {
wxMaSubscribeService.sendSubscribeMsg(subscribeMessage);
}
}
/**
*
*/
private List<WxMaSubscribeMessage> assembleReq(WeChatMiniProgramParam miniProgramParam, WeChatMiniProgramAccount miniProgramAccount) {
Set<String> receiver = miniProgramParam.getOpenIds();
List<WxMaSubscribeMessage> messageList = new ArrayList<>(receiver.size());
// 构建微信小程序订阅消息
for (String openId : receiver) {
WxMaSubscribeMessage subscribeMessage = WxMaSubscribeMessage.builder()
.toUser(openId)
.data(getWxMTemplateData(miniProgramParam.getData()))
.miniprogramState(miniProgramAccount.getMiniProgramState())
.templateId(miniProgramAccount.getTemplateId())
.page(miniProgramAccount.getPage())
.build();
messageList.add(subscribeMessage);
}
return messageList;
}
/**
*
*
* @returnp
*/
private List<WxMaSubscribeMessage.MsgData> getWxMTemplateData(Map<String, String> data) {
List<WxMaSubscribeMessage.MsgData> templateDataList = new ArrayList<>(data.size());
data.forEach((k, v) -> templateDataList.add(new WxMaSubscribeMessage.MsgData(k, v)));
return templateDataList;
}
/**
*
*
* @return
*/
private WxMaSubscribeServiceImpl initService(WeChatMiniProgramAccount miniProgramAccount) {
WxMaService wxMaService = new WxMaServiceImpl();
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
wxMaConfig.setAppid(miniProgramAccount.getAppId());
wxMaConfig.setSecret(miniProgramAccount.getAppSecret());
wxMaService.setWxMaConfig(wxMaConfig);
return new WxMaSubscribeServiceImpl(wxMaService);
}
}

@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
/**
* @Autor xzcawl
* @author xzcawl
* @Date 2022/7/15 17:29
*/
@Slf4j

@ -1,12 +1,19 @@
package com.java3y.austin.support.utils;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaSubscribeServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.alibaba.fastjson.JSON;
import com.java3y.austin.common.constant.CommonConstant;
import com.java3y.austin.common.dto.account.WeChatMiniProgramAccount;
import com.java3y.austin.common.dto.account.WeChatOfficialAccount;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.support.dao.ChannelAccountDao;
import com.java3y.austin.support.domain.ChannelAccount;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
@ -26,21 +33,40 @@ import java.util.Map;
*/
@Component
@Slf4j
@Data
public class WxServiceUtils {
public static Map<Long, WxMpService> wxMpServiceMap = new HashMap<>();
public static Map<Long, WeChatOfficialAccount> accountHashMap = new HashMap<>();
private Map<Long, WxMpService> officialAccountServiceMap = new HashMap<>();
private Map<Long, WxMaSubscribeService> miniProgramServiceMap = new HashMap<>();
private Map<Long, WeChatOfficialAccount> officialAccountHashMap = new HashMap<>();
private Map<Long, WeChatMiniProgramAccount> miniProgramHashMap = new HashMap<>();
@Autowired
private ChannelAccountDao channelAccountDao;
@PostConstruct
public void init() {
initOfficialAccount();
initMiniProgram();
}
private void initMiniProgram() {
List<ChannelAccount> miniProgram = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.MINI_PROGRAM.getCode());
for (ChannelAccount channelAccount : miniProgram) {
WeChatMiniProgramAccount weChatMiniProgramAccount = JSON.parseObject(channelAccount.getAccountConfig(), WeChatMiniProgramAccount.class);
miniProgramServiceMap.put(channelAccount.getId(), initMiniProgramService(weChatMiniProgramAccount));
miniProgramHashMap.put(channelAccount.getId(), weChatMiniProgramAccount);
}
}
private void initOfficialAccount() {
List<ChannelAccount> officialAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.OFFICIAL_ACCOUNT.getCode());
for (ChannelAccount channelAccount : officialAccountList) {
WeChatOfficialAccount weChatOfficialAccount = JSON.parseObject(channelAccount.getAccountConfig(), WeChatOfficialAccount.class);
wxMpServiceMap.put(channelAccount.getId(), initService(weChatOfficialAccount));
accountHashMap.put(channelAccount.getId(), weChatOfficialAccount);
officialAccountServiceMap.put(channelAccount.getId(), initOfficialAccountService(weChatOfficialAccount));
officialAccountHashMap.put(channelAccount.getId(), weChatOfficialAccount);
}
}
@ -49,7 +75,7 @@ public class WxServiceUtils {
*
* @return
*/
public WxMpService initService(WeChatOfficialAccount officialAccount) {
public WxMpService initOfficialAccountService(WeChatOfficialAccount officialAccount) {
WxMpService wxMpService = new WxMpServiceImpl();
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
config.setAppId(officialAccount.getAppId());
@ -57,4 +83,18 @@ public class WxServiceUtils {
wxMpService.setWxMpConfigStorage(config);
return wxMpService;
}
/**
*
*
* @return
*/
private WxMaSubscribeServiceImpl initMiniProgramService(WeChatMiniProgramAccount miniProgramAccount) {
WxMaService wxMaService = new WxMaServiceImpl();
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
wxMaConfig.setAppid(miniProgramAccount.getAppId());
wxMaConfig.setSecret(miniProgramAccount.getAppSecret());
wxMaService.setWxMaConfig(wxMaConfig);
return new WxMaSubscribeServiceImpl(wxMaService);
}
}

@ -0,0 +1,79 @@
package com.java3y.austin.web.controller;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import com.google.common.base.Throwables;
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.utils.WxServiceUtils;
import com.java3y.austin.web.utils.Convert4Amis;
import com.java3y.austin.web.vo.amis.CommonAmisVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @author 3y
*/
@Slf4j
@RestController
@RequestMapping("/miniProgram")
@Api("微信服务号")
@CrossOrigin(origins = {AustinConstant.ORIGIN_VALUE}, allowCredentials = "true", allowedHeaders = "*", methods = {RequestMethod.PUT, RequestMethod.POST, RequestMethod.GET})
public class MiniProgramController {
@Autowired
private WxServiceUtils wxServiceUtils;
@GetMapping("/template/list")
@ApiOperation("/根据账号Id获取模板列表")
public BasicResultVO queryList(Long id) {
try {
List<CommonAmisVo> result = new ArrayList<>();
WxMaSubscribeService wxMaSubscribeService = wxServiceUtils.getMiniProgramServiceMap().get(id);
List<TemplateInfo> templateList = wxMaSubscribeService.getTemplateList();
for (TemplateInfo templateInfo : templateList) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(templateInfo.getTitle()).value(templateInfo.getPriTmplId()).build();
result.add(commonAmisVo);
}
return BasicResultVO.success(result);
} catch (Exception e) {
log.error("MiniProgramController#queryList fail:{}", Throwables.getStackTraceAsString(e));
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR);
}
}
/**
* IdID
*
* @return
*/
@PostMapping("/detailTemplate")
@ApiOperation("/根据账号Id和模板ID获取模板列表")
public BasicResultVO queryDetailList(Long id, String wxTemplateId) {
if (id == null || wxTemplateId == null) {
return BasicResultVO.success(RespStatusEnum.CLIENT_BAD_PARAMETERS);
}
try {
WxMaSubscribeService wxMaSubscribeService = wxServiceUtils.getMiniProgramServiceMap().get(id);
List<TemplateInfo> templateList = wxMaSubscribeService.getTemplateList();
CommonAmisVo wxMpTemplateParam = Convert4Amis.getWxMaTemplateParam(wxTemplateId, templateList);
return BasicResultVO.success(wxMpTemplateParam);
} catch (Exception e) {
log.error("MiniProgramController#queryDetailList fail:{}", Throwables.getStackTraceAsString(e));
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR);
}
}
}

@ -13,6 +13,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
@ -31,6 +32,8 @@ import java.util.List;
, allowCredentials = "true", allowedHeaders = "*", methods = {RequestMethod.PUT, RequestMethod.POST, RequestMethod.GET})
public class OfficialAccountController {
@Autowired
private WxServiceUtils wxServiceUtils;
/**
* @param id Id
@ -41,8 +44,8 @@ public class OfficialAccountController {
public BasicResultVO queryList(Long id) {
try {
List<CommonAmisVo> result = new ArrayList<>();
WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(id);
WxMpService wxMpService = WxServiceUtils.wxMpServiceMap.get(id);
List<WxMpTemplate> allPrivateTemplate = wxMpService.getTemplateMsgService().getAllPrivateTemplate();
for (WxMpTemplate wxMpTemplate : allPrivateTemplate) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(wxMpTemplate.getTitle()).value(wxMpTemplate.getTemplateId()).build();
@ -60,7 +63,6 @@ public class OfficialAccountController {
* IdID
*
* @return
* @
*/
@PostMapping("/detailTemplate")
@ApiOperation("/根据账号Id和模板ID获取模板列表")
@ -69,16 +71,15 @@ public class OfficialAccountController {
return BasicResultVO.success(RespStatusEnum.CLIENT_BAD_PARAMETERS);
}
try {
WxMpService wxMpService = WxServiceUtils.wxMpServiceMap.get(id);
WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(id);
List<WxMpTemplate> allPrivateTemplate = wxMpService.getTemplateMsgService().getAllPrivateTemplate();
CommonAmisVo wxMpTemplateParam = Convert4Amis.getWxMpTemplateParam(wxTemplateId, allPrivateTemplate);
return BasicResultVO.success(wxMpTemplateParam);
} catch (Exception e) {
log.error("OfficialAccountController#queryList fail:{}", Throwables.getStackTraceAsString(e));
log.error("OfficialAccountController#queryDetailList fail:{}", Throwables.getStackTraceAsString(e));
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR);
}
}
}

@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.java3y.austin.web.vo.amis.CommonAmisVo;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import java.lang.reflect.Field;
@ -24,12 +25,19 @@ import java.util.stream.Collectors;
*/
public class Convert4Amis {
// 标识忽略
public static final int ignoreTg = 0;
// 标识已读取到'$'字符
public static final int startTg = 1;
// 标识已读取到'{'字符
public static final int readTg = 2;
/**
*
*/
public static final int IGNORE_TG = 0;
/**
* '$'
*/
public static final int START_TG = 1;
/**
* '{'
*/
public static final int READ_TG = 2;
/**
* (json
* ()
@ -45,7 +53,7 @@ public class Convert4Amis {
/**
* (JSONObjectJSONArray)
*/
private static final List<String> PARSE_JSON_OBJ_TO_ARRAY = Arrays.asList("officialAccountParam");
private static final List<String> PARSE_JSON_OBJ_TO_ARRAY = Arrays.asList("officialAccountParam","miniProgramParam");
/**
* OA
@ -128,6 +136,7 @@ public class Convert4Amis {
/**
* amis
*
*
* @param wxTemplateId
* @param allPrivateTemplate
* @return
@ -209,31 +218,31 @@ public class Convert4Amis {
// 存储占位符 位置信息集合
List<String> placeholderList = new ArrayList<>();
// 当前标识
int modeTg = ignoreTg;
int modeTg = IGNORE_TG;
for (int m = 0; m < textChars.length; m++) {
char c = textChars[m];
textSofar.append(c);
switch (c) {
case '{': {
modeTg = startTg;
modeTg = START_TG;
sb.append(c);
}
break;
case '$': {
if (modeTg == startTg) {
if (modeTg == START_TG) {
sb.append(c);
modeTg = readTg;
modeTg = READ_TG;
} else {
if (modeTg == readTg) {
if (modeTg == READ_TG) {
sb = new StringBuilder();
modeTg = ignoreTg;
modeTg = IGNORE_TG;
}
}
}
break;
case '}': {
if (modeTg == readTg) {
modeTg = ignoreTg;
if (modeTg == READ_TG) {
modeTg = IGNORE_TG;
sb.append(c);
String str = sb.toString();
if (StrUtil.isNotEmpty(str)) {
@ -241,16 +250,17 @@ public class Convert4Amis {
textSofar = new StringBuilder();
}
sb = new StringBuilder();
} else if (modeTg == startTg) {
modeTg = ignoreTg;
} else if (modeTg == START_TG) {
modeTg = IGNORE_TG;
sb = new StringBuilder();
}
break;
}
default: {
if (modeTg == readTg) {
if (modeTg == READ_TG) {
sb.append(c);
} else if (modeTg == startTg) {
modeTg = ignoreTg;
} else if (modeTg == START_TG) {
modeTg = IGNORE_TG;
sb = new StringBuilder();
}
}
@ -260,4 +270,39 @@ public class Convert4Amis {
return result;
}
/**
* amis
*
*
* @param wxTemplateId
* @param templateList
* @return
*/
public static CommonAmisVo getWxMaTemplateParam(String wxTemplateId, List<TemplateInfo> templateList) {
CommonAmisVo officialAccountParam = null;
for (TemplateInfo templateInfo : templateList) {
if (wxTemplateId.equals(templateInfo.getPriTmplId())) {
String[] data = templateInfo.getContent().split(StrUtil.LF);
officialAccountParam = CommonAmisVo.builder()
.type("input-table")
.name("miniProgramParam")
.addable(true)
.editable(true)
.needConfirm(false)
.build();
List<CommonAmisVo.ColumnsDTO> columnsDTOS = new ArrayList<>();
for (String datum : data) {
String name = datum.substring(datum.indexOf("{{") + 2, datum.indexOf("."));
String label = datum.split(":")[0];
CommonAmisVo.ColumnsDTO columnsDTO = CommonAmisVo.ColumnsDTO.builder()
.name(name).type("input-text").required(true).quickEdit(true).label(label).build();
columnsDTOS.add(columnsDTO);
}
officialAccountParam.setColumns(columnsDTOS);
}
}
return officialAccountParam;
}
}

@ -11,6 +11,8 @@ import java.util.List;
/**
* amis
*
* @author 3y
*/
@Data
@Builder

Loading…
Cancel
Save