引包
<!--七牛云-->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>7.2.28</version>
</dependency>
这是maven示例,jar包可以自己去maven仓库下载,搜【qiniu-java-sdk】
maven仓库
示例代码
import java.util.HashMap;
import java.util.Map;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
public class QiNiuSmsUtil {
// 设置需要操作的账号的AK和SK
public static String ACCESS_KEY = "";
public static String SECRET_KEY = "";
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("code", "123456");
sendQiNiuSms("", "", map);
}
/**
* 发七牛云短信
* @param signId 短信签名
* @param phoneNumber 手机号
* @param map 参数对象
*/
public static void sendQiNiuSms(String signId,String phoneNumber,Map<String, String> map){
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
// 实例化一个SmsManager对象
SmsManager smsManager = new SmsManager(auth);
try {
Response resp = smsManager.sendMessage(signId, new String[] {phoneNumber}, map);
System.out.println(resp.bodyString());
} catch (QiniuException e) {
System.out.println(e);
}
}
}
七牛云参数
有帮助请点个赞,谢谢!