工具类util
package com.cbb.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import org.springframework.stereotype.Component;
/**
* 登录验证码网站 http://yun.loktong.com/ 先注册一个账号,获得账号密码 需要在文本短信签名模板管理提交认证 获得token与模板Id
*
@author 陈斌斌
* @Date 2022年5月11日 14点23分
*
*/
@Component
public class Verification {
/**
* 发送验证码的接口地址
*/
private static final String URL = "http://www.lokapi.cn/smsUTF8.aspx";
/**
* 开通服务的账号
*/
private static final String USERNAME = "xxxxxxxxxxxx";
/**
* 登录密码
*/
private static final String PASSWORD = "xxxxxxxxxxxx";
/**
* 在文字短信 -产品总览- 验证码TOCKEN
*/
private static final String TOCKEN = "xxxxxxxx";
/**
* 模板管理-模板Id
*/
private static final String ACCOUNTSID = "xxxxxxxx";
/**
* 获得当前毫秒数
*/
private static final long TIMESTAMP = System.currentTimeMillis();
/**
* 传一个你要发送验证码的手机号
*
* @param phone
* @return
* @throws ParseException
*/
public Map<String, String> verificationCode(String phone) throws ParseException {
String beforSign = "action=sendtemplate&username=" + USERNAME + "&password=" + getMD5String(PASSWORD)
+ "&token=" + TOCKEN + "×tamp=" + TIMESTAMP;
String postData = "action=sendtemplate&username=" + USERNAME + "&password=" + getMD5String(PASSWORD) + "&token="
+ TOCKEN + "&templateid=" + ACCOUNTSID + "¶m=" + phone + "|" + randomCode()
+ "&rece=json×tamp=" + TIMESTAMP + "&sign=" + getMD5String(beforSign);
Map<String, String> map = new HashMap<String, String>();
try {
sendPost(URL, postData);
map.put("code", "200");
map.put("randomCode",String.valueOf(randomCode()));
map.put("message", "发送成功");
return map;
} catch (Exception e) {
map.put(