12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package com.kmall.api.util;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * @author huangyaqin
- * @version 1.0
- * 2018-10-16 11:27
- */
- public class SendMsgUtil {
- /**
- * 发送短信消息
- * 方法说明
- * @Discription:扩展说明
- * @param phones
- * @param content
- * @return
- * @return String
- */
- @SuppressWarnings("deprecation")
- public static String sendMsg(String phones,String content) {
- try {
- content = java.net.URLEncoder.encode(content,"utf-8");
- System.out.println(content);
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- String sendMsgapiKey = "d6d33c8e7ad847cc3f3d7e9f75d0abb1";
- //短信接口URL提交地址
- String url = "https://api.dingdongcloud.com/v1/sms/sendyzm";
- Map<String, String> params = new HashMap<String, String>();
- params.put("name", "13530612313");
- params.put("pwd", "nm81875o");
- // params.put("dxlbid", "短信类别编号");
- // params.put("extno", "扩展编号");
- params.put("apikey", sendMsgapiKey);
- //手机号码,多个号码使用英文逗号进行分割
- params.put("mobile", phones);
- //将短信内容进行URLEncoder编码
- params.put("content", URLEncoder.encode(content));
- params.put("sendTs", "");
- return HttpRequestUtil.postRequest(url, params);
- }
- /**
- * 随机生成6位随机验证码
- * 方法说明
- * @Discription:扩展说明
- * @return
- * @return String
- */
- public static String createRandomVcode(){
- //验证码
- String vcode = "";
- for (int i = 0; i < 6; i++) {
- vcode = vcode + (int)(Math.random() * 9);
- }
- return vcode;
- }
- /**
- * 测试
- * 方法说明
- * @Discription:扩展说明
- * @param args
- * @return void
- */
- public static void main(String[] args) {
- // System.out.println(SendMsgUtil.createRandomVcode());
- // System.out.println("&ecb=12".substring(1));
- System.out.println(sendMsg("18201150549", "【签名】尊敬的用户,您的验证码为" + SendMsgUtil.createRandomVcode() + ",请在10分钟内输入。请勿告诉其他人!"));
- }
- }
|