Java字符串转map集合,List集合转转数组
使用json转map原因是因为,我们发送短信是多渠道的,阿里和腾讯云的发送短信变量不一样,通过自己封装的统一code,和模板变量进行发送短信;所以模板变量就需要统一,这样就要想怎么在发送腾讯云短信的时候怎么能使用阿里的模板变量,因为起初没有做多渠道的时候,我们单一使用阿里云,发送短信;所以就有了下面变量取值,用到json转map获取值传给腾讯云
【阿里云短信模板变量规范参考】
https://help.aliyun.com/document_detail/108253.html
【腾讯云短信模板变量规范参考】
https://cloud.tencent.com/document/product/382/39023
https://cloud.tencent.com/document/product/382/39031
【腾讯发送短信】—参数只传变量数字
https://cloud.tencent.com/document/product/382/55981
1.按顺序遍历的map集合
String variable="{\"变量1\":\"值1\",\"变量2\":\"值2\",\"变量3\":\"值3\"}";
Map paraMap = JSON.parseObject(variable, LinkedHashMap.class, Feature.OrderedField);
List<Object> listVariable=new ArrayList<>();
for (Object value:paraMap.values()){
listVariable.add(value);
//你们可以在这里打印看结果,我这里是取得map集合value值发到list集合里
}
//list集合转数组
String[] templateParamSet1 = listVariable.stream().toArray(String[]::new);
发送短信业务编码【些许配置这里面你们可能用不到,我也没放到上面,如果报红的话可以更改】
@SneakyThrows
@Override
public CommonResult sendRenevTemplateMore(String clientId, long phone, String templateCode, String variable) {
boolean isPhone = Util.isPhoneLegal(phone);
if (!isPhone) {
return CommonResult.result(ResultCode.SMS_MOBILE_NUMBER_ILLEGAL_ERR);
}
ChannelApp channel = verifyChannel(clientId);
if (channel == null) {
return CommonResult.result(ResultCode.CHANNEL_NULL_ERR);
}
SendSmsResponse sendSmsResponse = null;
//查缓存
Object smsTemplateCash = redisService.get(templateCode);
List<SmsTemplateSupplierDto> smsTemplateSuppliers=new ArrayList<SmsTemplateSupplierDto>();
if(smsTemplateCash==null){
//发送短信模板------根据统一code查询审核通过的分支平台渠道code,如果有多个平台渠道code,默认走其中一个就可以
QueryWrapper<SmsTemplateSupplier> wrapperSupplier = new QueryWrapper<SmsTemplateSupplier>();
//wrapperSupplier.eq("t