阿里雲等服務商短信驗證碼服務要獲取的話必須網站通過備案,幸運的是發現了榛子雲短信平台 使用方法很簡單。
-
帳號註冊;
-
找到自己的AppId和AppSecret、以及模板id
3.pom中加入依賴
<dependency>
<groupId>com.zhenzikj</groupId>
<artifactId>zhenzisms</artifactId>
<version>2.0.2</version>
</dependency>
- 添加方法
private void ZhenziYunSmsSend(String mobile, String code){
ZhenziSmsClient client = new ZhenziSmsClient("https://sms_developer.zhenzikj.com", "your AppId here ", "your AppSecret here");
Map<String, Object> params = new HashMap<>();
params.put("number", mobile);
params.put("templateId", "xxx"); //
String[] templateParams = new String[1];
templateParams[0] = code;
params.put("templateParams", templateParams);
try {
String result = client.send(params);
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}