阿里云批量发送短信怎么写?

阿里云发送短信通知

短信模板: “尊敬的用户,您的户号是${houseno}。请关注xx进行缴费。”

这样写只能给每个手机号发送一样的短信模板,怎么样才能对每个手机号发送同一模板, houseno参数不一样呢?


 if (msgTemplate!=null&&msgTemplate.equals("户号信息")){
                ticket = Pattern.compile(regEx).matcher(strings.toString()).replaceAll("").trim();
                hhs=StringUtils.join(yhbm.toArray(), ",");
                System.out.println(strings);
                System.out.println(ticket);
                Client client = getClient();
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("houseno",yhbm);
                System.out.println(yhbm);
                
                SendSmsRequest sendSmsRequest = new SendSmsRequest()
                        .setPhoneNumbers(ticket)
                        .setTemplateCode("123456")
                        .setTemplateParam(jsonObject2.toString())
                        .setSignName("ASCEDSS");
                System.err.println(hashMaps);
                sendSmsResponse = client.sendSms(sendSmsRequest);
            }

发出来的短信是这样的

img

怎么样才能参数和手机号对应一一发送呢?

批量发送短信接口文档https://help.aliyun.com/document_detail/66041.html?spm=a2c4g.11186623.0.0.1cd15d7aemuOpb

短信发送接口文档https://help.aliyun.com/document_detail/55284.htm?spm=a2c4g.11186623.0.0.33a05d7aOxaJM7

更新
我改成了循环发送短信,但是现在报这个错,短信发不出去,debug没有问题

img

你的sdk下载的是否完整,还有按照他的操作是可以发送的,你的短信模板${houseno}他就是变量啊,你根据手机号确定户号,自己每次传那个户号就可以啊

我粗略看了一下,按你的想法来看:
同一个短信模板,手机号不同,且模板参数也不同,批量发送短信接口你肯定是用不了,
最简单的方法是只用单个短信发送接口,使用循环语句遍历调用即可