相對阿里雲來說, 使用七牛雲中短信業務發送短信還是比較划算點的, 雖然他們是一家. 他們價錢差不多, 七牛雲每星期會送200條系統短信, 100條推廣短信.
再寫發送短信驗證碼代碼前, 要去七牛雲配置相關的簽名, 模板, 購買資源包
七牛雲申請簽名

七牛雲申請短信模板

pom.xml導入jar 請看我這篇 上傳文件到七牛雲 的博客
代碼
//發送短信驗證碼
public static HashMap<String, String> sendSms(String phone) {
HashMap<String, String> resultMap = new HashMap<>();
String[] phones = {phone};
//ACCESS_KEY 公鑰, SECRET_KEY 私鑰
Auth auth = Auth.create(QiNiuContent.ACCESS_KEY, QiNiuContent.SECRET_KEY);
// 實例化一個SmsManager對象
SmsManager smsManager = new SmsManager(auth);
String code = HBYAppUtils.code();
try {
Map<String, String> map = new HashMap<String, String>();
map.put("code", code);
// TEMPLATED 七牛雲短信模板ID
Response resp = smsManager.sendMessage(QiNiuContent.TEMPLATED, phones, map);
resultMap.put("code", code);
resultMap.put("status", "1");
} catch (QiniuException e) {
e.printStackTrace();
resultMap.put("status", "0");
resultMap.put("code", "0");
}
return resultMap;
}
