整合短信验证码
依赖
配置
sms:
ipyy:
url: xx
account: xx
password: xx
smsSign: xx
enable: false
prefix:
客户端SSLClient
package com.cyz.swagger3.config.sms;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class SSLClient {
public static CloseableHttpClient createSSLClientDefault() {
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(
null, new TrustStrategy() {
工具类
package com.cyz.swagger3.config.sms;
import com.alibaba.fastjson.JSONObject;
import com.cyz.swagger3.common.AjaxResult;
import com.cyz.swagger3.common.md5.MD5;
import com.cyz.swagger3.config.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;
import static com.cyz.swagger3.common.AjaxResult.error;
import static com.cyz.swagger3.common.AjaxResult.success;
@Component
@Slf4j
public class SMSUtils {
@Value("${sms.ipyy.prefix}")
private String ipyyPrefix;
@Value("${sms.ipyy.url}")
private String ipyyUrl;
@Value("${sms.ipyy.account}")
private String ipyyAccount;
@Value("${sms.ipyy.password}")
private String ipyyPassword;
@Value("${sms.ipyy.smsSign}")
private String ipyySmsSign;
@Value("${sms.ipyy.enable}")
private boolean ipyyEnable;
@Value("${swagger3.captcha.key}")
private String captchaKey;
@Autowired
private RedisCache redisCache;
private static CloseableHttpClient httpclient;
private static final String SYMBOLS = "0123456789";