|  |  |  | 
|---|
|  |  |  | import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponseBody; | 
|---|
|  |  |  | import darabonba.core.client.ClientOverrideConfiguration; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.Random; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.CompletableFuture; | 
|---|
|  |  |  | import java.util.regex.Matcher; | 
|---|
|  |  |  | import java.util.regex.Pattern; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public class SmsUtils { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static AsyncClient getClient() { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 阿里云市场API | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private static boolean aliyun_1(String phone, String code) { | 
|---|
|  |  |  | ArrayList<Map<String, Object>> list = new ArrayList<>(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | HashMap<String, Object> headers = new HashMap<>(); | 
|---|
|  |  |  | HashMap<String, Object> param = new HashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String APPCODE = "15ce5d8be5e348c7b680dfd7cfb8307e"; | 
|---|
|  |  |  | headers.put("Authorization", "APPCODE " + APPCODE); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | param.put("templateId", "MEA92C3A45"); | 
|---|
|  |  |  | param.put("receive", phone); | 
|---|
|  |  |  | param.put("tag", code); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri("https://smkjdxtzjk.market.alicloudapi.com") | 
|---|
|  |  |  | .setPath("/standard/sms/send") | 
|---|
|  |  |  | .setHeaders(headers) | 
|---|
|  |  |  | .setParams(param) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | if (Integer.parseInt(jsonObject.get("code").toString()) == 200) { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 阿里云市场API  分配了新的规划申请单任务!请注意查收! | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private static boolean aliyun_2(String phone, String code) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | HashMap<String, Object> headers = new HashMap<>(); | 
|---|
|  |  |  | HashMap<String, Object> param = new HashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String APPCODE = "15ce5d8be5e348c7b680dfd7cfb8307e"; | 
|---|
|  |  |  | headers.put("Authorization", "APPCODE " + APPCODE); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | param.put("templateId", "M6F3C81FE3"); | 
|---|
|  |  |  | param.put("receive", phone); | 
|---|
|  |  |  | param.put("tag", code); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri("https://smkjdxtzjk.market.alicloudapi.com") | 
|---|
|  |  |  | .setPath("/standard/sms/send") | 
|---|
|  |  |  | .setHeaders(headers) | 
|---|
|  |  |  | .setParams(param) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | if (Integer.parseInt(jsonObject.get("code").toString()) == 200) { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static AsyncClient getClient() { | 
|---|
|  |  |  | StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() | 
|---|
|  |  |  | .accessKeyId("LTAI4GBCtqGZAn5XDEREh1Pp") | 
|---|
|  |  |  | .accessKeySecret("SQQkh2kps3wxfbNXUg5nLZgWS2CMjm") | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发送短信验证码 | 
|---|
|  |  |  | * 发送短信验证码-阿里云原生 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static boolean sendSmsCode(String phone, String code) { | 
|---|
|  |  |  | private static boolean aliyun_origin(String phone, String code) { | 
|---|
|  |  |  | AsyncClient client = getClient(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | HashMap<String, Object> templateParam = new HashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发送短信验证码-阿里云原生 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static boolean sendSmsCode(String phone, String code) { | 
|---|
|  |  |  | return aliyun_1(phone, code); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发送短信-阿里云原生 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static boolean sendSmsCodeText(String phone, String code) { | 
|---|
|  |  |  | return aliyun_2(phone, code); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取随机数 | 
|---|
|  |  |  | * @param length 随机数长度 | 
|---|
|  |  |  | */ | 
|---|