Browse Source

短信发送

小么熊🐻 1 year ago
parent
commit
06d113c9bd

+ 103 - 0
jsjp-admin/src/main/java/com/miaxis/app/controller/userInfo/UserSmsController.java

@@ -0,0 +1,103 @@
+package com.miaxis.app.controller.userInfo;
+
+import com.miaxis.common.annotation.Log;
+import com.miaxis.common.constant.Constants;
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.domain.Response;
+import com.miaxis.common.enums.BusinessTypeEnum;
+import com.miaxis.common.utils.PrivateKeyUtil;
+import com.miaxis.sms.SendSms;
+import com.miaxis.sms.SendSmsSync;
+import com.miaxis.sms.domain.SmsInfo;
+import com.miaxis.sms.domain.SmsToUser;
+import com.miaxis.tms.dto.TmsCoachInfoIdDTO;
+import com.miaxis.userInfo.domain.UserVip;
+import com.miaxis.userInfo.service.IUserVipService;
+import com.miaxis.userInfo.vo.UserVipTFVO;
+import com.miaxis.userInfo.vo.UserVipVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.Signature;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.util.Base64;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 【会员信息】Controller
+ *
+ * @author miaxis
+ * @date 2022-06-02
+ */
+@RestController
+@RequestMapping("/userInfo/sms")
+@Api(tags = {"【app-学员短信通知】"})
+public class UserSmsController extends BaseController {
+
+    @Autowired
+    private SendSmsSync sendSmsSync;
+
+    @Autowired
+    private SendSms sendSms;
+
+    /**
+     * 发送短信至学员
+     *
+     * @return
+     */
+    @GetMapping(value = "/sendSms")
+    @ApiOperation("发送短信至学员")
+    public Response sendSms(SmsToUser smsToUser) throws Exception {
+
+        //参数处理
+//        String param = "{\"name\":\"" + smsToUser.getName() + "\",\"idcard\":\"" + smsToUser.getIdcard() + "\",\"password\":\"" + smsToUser.getPassword() + "\"}";
+//        SmsInfo smsInfo = new SmsInfo();
+//        smsInfo.setPhone(smsToUser.getPhone());
+//        smsInfo.setParam(param);
+//        smsInfo.setSignName("极速驾培");
+//        smsInfo.setTemplateCode("SMS_463607185");  //帐号密码模板
+//        sendSmsSync.sendSms(smsInfo);
+
+
+//        SmsInfo smsDown = new SmsInfo();
+//        smsDown.setPhone(smsToUser.getPhone());
+//        smsDown.setParam(null);
+//        smsDown.setSignName("极速驾培");
+//        smsDown.setTemplateCode("SMS_463677149");  //下载通知
+//        sendSmsSync.sendSms(smsDown);
+
+
+        String param = "{\"name\":\"" + smsToUser.getName() + "\",\"idcard\":\"" + smsToUser.getIdcard() + "\",\"password\":\"" + smsToUser.getPassword() + "\"}";
+        SmsInfo smsInfo = new SmsInfo();
+        smsInfo.setPhone(smsToUser.getPhone());
+        smsInfo.setParam(param);
+        smsInfo.setSignName("极速驾培");
+        smsInfo.setTemplateCode("SMS_463607185");  //帐号密码模板
+        sendSms.sendSms(smsInfo);
+
+
+        SmsInfo smsDown = new SmsInfo();
+        smsDown.setPhone(smsToUser.getPhone());
+        smsDown.setParam(null);
+        smsDown.setSignName("极速驾培");
+        smsDown.setTemplateCode("SMS_463677149");  //下载通知
+        sendSms.sendSms(smsDown);
+
+        return Response.success();
+    }
+
+
+
+
+
+
+
+}

+ 1 - 2
jsjp-admin/src/main/java/com/miaxis/system/controller/system/SysLoginController.java

@@ -17,7 +17,7 @@ import com.miaxis.feign.service.IWxService;
 import com.miaxis.framework.web.service.SysLoginService;
 import com.miaxis.framework.web.service.SysPermissionService;
 import com.miaxis.framework.web.service.TokenService;
-import com.miaxis.service.IAppleService;
+import com.miaxis.apple.IAppleService;
 import com.miaxis.system.dto.common.RouterDTO;
 import com.miaxis.system.dto.system.TokenDTO;
 import com.miaxis.system.dto.system.UserInfoDTO;
@@ -36,7 +36,6 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;

+ 5 - 0
jsjp-admin/src/main/resources/application-dev.yml

@@ -112,6 +112,11 @@ cos:
     preffix: test
     classId: 843437
 
+# 阿里云
+aliyun:
+    accessKeyId: LTAI5tFcVMdCUVz5FtM7JiD5
+    accessKeySecret: 3uHrfRlH6kQIhkwY3BHGCbtGPB8XLA
+
 
 # 微信支付
 #wxpay:

+ 5 - 0
jsjp-admin/src/main/resources/application-prod.yml

@@ -118,6 +118,11 @@ cos:
     preffix: t1
     classId: 843436
 
+# 阿里云
+aliyun:
+    accessKeyId: LTAI5tFcVMdCUVz5FtM7JiD5
+    accessKeySecret: 3uHrfRlH6kQIhkwY3BHGCbtGPB8XLA
+
 
 # 微信支付
 #wxpay:

+ 34 - 1
jsjp-admin/src/test/java/com/miaxis/test/Test03.java

@@ -20,10 +20,43 @@ public class Test03 {
        // test1();
 
         String token = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6Ijc1MzRjZGI3LTcyZGMtNGExZi1hYTc1LWFhYjlmYmYzMGI5YyJ9.iKl7-pr-mrkKNf-YRoSC86uRoZHCapTtM94PMvOz7mQAaSV32FsPqBdusA73p0jkn6HZMrZDcXTmKFmY-_9PAg";
-        test4();
+        test5();
 
     }
 
+    public static void test5() throws IOException {
+
+        String token = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6Ijg3ZTZkMjU3LTcyMjEtNGQ1ZS1iMTJlLWE3NzFmZWEyZmY4NiJ9.TEZUppM51gfRdAVa6k-nIOxuC18A7Zt2apJEaLie8bjlWAdELy0Oy9sv7yHCeYqwR2-g-KPt4S1U1-jxNS-dbA";
+        //String baseUrl = "https://jsjp-admin1.zzxcx.net/jsjp-admin/userInfo/sms/sendSms";
+        String baseUrl = "https://jsjp-admin1.zzxcx.net/jsjp-admin/userInfo/sms/sendSms";
+        String idcard = "350181198811231811";
+        String name = "陈宏杰";
+        String password = "123456";
+        String phone = "15060063160";
+
+        // Build the URL with query parameters
+        String urlWithParams = baseUrl + "?idcard=" + idcard + "&name=" + name + "&password=" + password + "&phone=" + phone;
+
+        URL url = new URL(urlWithParams);
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        conn.setDoOutput(true);
+        conn.setDoInput(true);
+        conn.setUseCaches(false);
+        conn.setRequestMethod("GET");
+        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+        conn.setRequestProperty("Authorization", token); // Don't forget to set your token
+        conn.connect();
+
+        // Get the response from the server
+        InputStream inputStream = conn.getInputStream();
+        String encoding = "utf-8";
+        String body = IOUtils.toString(inputStream, encoding);
+        System.out.println(body);
+
+        conn.disconnect();
+    }
+
+
     /**
      * 登录接口
      * @throws IOException

+ 63 - 0
jsjp-admin/src/test/java/com/miaxis/test/TestSms.java

@@ -0,0 +1,63 @@
+package com.miaxis.test;
+
+import com.miaxis.JsjpApplication;
+import com.miaxis.order.dto.QuerySchoolOrderListDTO;
+import com.miaxis.order.service.IOrderInfoService;
+import com.miaxis.order.vo.QuerySchoolOrderDetailedVo;
+import com.miaxis.sms.SendSms;
+import com.miaxis.sms.SendSmsSync;
+import com.miaxis.sms.domain.SmsInfo;
+import com.miaxis.sms.domain.SmsToUser;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+@SpringBootTest(classes = JsjpApplication.class)
+@RunWith(SpringRunner.class)
+public class TestSms {
+
+
+    @Autowired
+    private SendSmsSync sendSmsSync;
+
+    @Autowired
+    private SendSms sendSms;
+
+    @Test
+    public void test() throws Exception {
+
+        SmsToUser smsToUser = new SmsToUser();
+        smsToUser.setName("王小日");
+        smsToUser.setIdcard("350181198811231811");
+        smsToUser.setPhone("15060063160");
+        smsToUser.setPassword("123456");
+
+        //参数处理
+//        String param = "{\"name\":\"" + smsToUser.getName() + "\",\"idcard\":\"" + smsToUser.getIdcard() + "\",\"password\":\"" + smsToUser.getPassword() + "\"}";
+//        SmsInfo smsInfo = new SmsInfo();
+//        smsInfo.setPhone(smsToUser.getPhone());
+//        smsInfo.setParam(param);
+//        smsInfo.setSignName("极速驾培");
+//        smsInfo.setTemplateCode("SMS_463607185");  //帐号密码模板
+//        sendSmsSync.sendSms(smsInfo);
+
+
+        SmsInfo smsDown = new SmsInfo();
+        smsDown.setPhone(smsToUser.getPhone());
+        smsDown.setParam(null);
+        smsDown.setSignName("极速驾培");
+        smsDown.setTemplateCode("SMS_463677149");  //下载通知
+        sendSmsSync.sendSms(smsDown);
+
+
+
+
+    }
+
+
+
+}

+ 15 - 5
jsjp-common/pom.xml

@@ -235,11 +235,6 @@
             <version>1.9.4</version>
         </dependency>
 
-        <!--aliyunOSS OSS-->
-        <dependency>
-            <groupId>com.aliyun.oss</groupId>
-            <artifactId>aliyun-sdk-oss</artifactId>
-        </dependency>
 
         <dependency>
             <groupId>org.springframework.cloud</groupId>
@@ -262,6 +257,21 @@
             <version>0.2.2</version>
         </dependency>
 
+
+        <!--aliyunOSS 短信-->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>dysmsapi20170525</artifactId>
+            <version>2.0.24</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>alibabacloud-dysmsapi20170525</artifactId>
+            <version>2.0.24</version>
+        </dependency>
+
+
     </dependencies>
 
 </project>

+ 80 - 0
jsjp-common/src/main/java/com/miaxis/common/sms/SendSms.java

@@ -0,0 +1,80 @@
+package com.miaxis.common.sms;
+
+import com.aliyun.auth.credentials.Credential;
+import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
+import com.aliyun.core.http.HttpClient;
+import com.aliyun.core.http.HttpMethod;
+import com.aliyun.core.http.ProxyOptions;
+import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
+import com.aliyun.sdk.service.dysmsapi20170525.models.*;
+import com.aliyun.sdk.service.dysmsapi20170525.*;
+import com.google.gson.Gson;
+import darabonba.core.RequestConfiguration;
+import darabonba.core.client.ClientOverrideConfiguration;
+import darabonba.core.utils.CommonUtil;
+import darabonba.core.TeaPair;
+
+//import javax.net.ssl.KeyManager;
+//import javax.net.ssl.X509TrustManager;
+import java.net.InetSocketAddress;
+import java.time.Duration;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+
+
+public class SendSms {
+    public static void main(String[] args) throws Exception {
+
+
+
+        // Configure Credentials authentication information, including ak, secret, token
+        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
+                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
+                .accessKeyId("LTAI5tFcVMdCUVz5FtM7JiD5")
+                .accessKeySecret("3uHrfRlH6kQIhkwY3BHGCbtGPB8XLA")
+                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
+                .build());
+
+        // Configure the Client
+        AsyncClient client = AsyncClient.builder()
+                .region("cn-hangzhou") // Region ID
+                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
+                .credentialsProvider(provider)
+                //.serviceConfiguration(Configuration.create()) // Service-level configuration
+                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
+                .overrideConfiguration(
+                        ClientOverrideConfiguration.create()
+                                // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
+                                .setEndpointOverride("dysmsapi.aliyuncs.com")
+                        //.setConnectTimeout(Duration.ofSeconds(30))
+                )
+                .build();
+
+        // Parameter settings for API request
+        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
+                .phoneNumbers("15060063160")
+                .signName("极速驾培")
+                .templateCode("SMS_463607185")
+                .templateParam("{\"name\":\"周淑啊\",\"idcard\":\"350526198708052015\",\"password\":\"123456\"}")
+                // Request-level configuration rewrite, can set Http request parameters, etc.
+                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
+                .build();
+
+        // Asynchronously get the return value of the API request
+        CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
+        // Synchronously get the return value of the API request
+        SendSmsResponse resp = response.get();
+        System.out.println(new Gson().toJson(resp));
+        // Asynchronous processing of return values
+        /*response.thenAccept(resp -> {
+            System.out.println(new Gson().toJson(resp));
+        }).exceptionally(throwable -> { // Handling exceptions
+            System.out.println(throwable.getMessage());
+            return null;
+        });*/
+
+        // Finally, close the client
+        client.close();
+    }
+
+}

+ 90 - 0
jsjp-common/src/main/java/com/miaxis/common/sms/SendSmsSync.java

@@ -0,0 +1,90 @@
+package com.miaxis.common.sms;
+
+// This file is auto-generated, don't edit it. Thanks.
+
+import com.aliyun.tea.*;
+import org.springframework.beans.factory.annotation.Value;
+
+public class SendSmsSync {
+
+
+
+    @Value("${aliyun.accessKeyId}")
+    private static String accessKeyId;
+    @Value("${aliyun.accessKeySecret}")
+    private static String accessKeySecret;
+
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @param accessKeyId
+     * @param accessKeySecret
+     * @return Client
+     * @throws Exception
+     */
+    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+                // 必填,您的 AccessKey ID
+                .setAccessKeyId(accessKeyId)
+                // 必填,您的 AccessKey Secret
+                .setAccessKeySecret(accessKeySecret);
+        // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
+        config.endpoint = "dysmsapi.aliyuncs.com";
+        return new com.aliyun.dysmsapi20170525.Client(config);
+    }
+
+    public static void main(String[] args_) throws Exception {
+        java.util.List<String> args = java.util.Arrays.asList(args_);
+        // 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
+        // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
+        com.aliyun.dysmsapi20170525.Client client = SendSmsSync.createClient("", "");
+        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
+                .setPhoneNumbers("15060063160")
+                .setSignName("极速驾培")
+                .setTemplateCode("SMS_463607185")
+                .setTemplateParam("{\"name\":\"周淑萍\",\"idcard\":\"350526198708052015\",\"password\":\"123456\"}");
+        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+            client.sendSmsWithOptions(sendSmsRequest, runtime);
+        } catch (TeaException error) {
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+            error.printStackTrace();
+        } catch (Exception _error) {
+            TeaException error = new TeaException(_error.getMessage(), _error);
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+        }
+    }
+
+
+    public static boolean sendSms() throws Exception {
+
+        // 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
+        // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
+        com.aliyun.dysmsapi20170525.Client client = SendSmsSync.createClient(accessKeyId, accessKeySecret);
+        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
+                .setPhoneNumbers("15060063160")
+                .setSignName("极速驾培")
+                .setTemplateCode("SMS_463607185")
+                .setTemplateParam("{\"name\":\"周淑萍\",\"idcard\":\"350526198708052015\",\"password\":\"123456\"}");
+        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+            client.sendSmsWithOptions(sendSmsRequest, runtime);
+        } catch (TeaException error) {
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+            error.printStackTrace();
+        } catch (Exception _error) {
+            TeaException error = new TeaException(_error.getMessage(), _error);
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+        }
+
+        return false;
+    }
+
+}
+

+ 1 - 1
jsjp-service/src/main/java/com/miaxis/service/IAppleService.java → jsjp-service/src/main/java/com/miaxis/apple/IAppleService.java

@@ -1,4 +1,4 @@
-package com.miaxis.service;
+package com.miaxis.apple;
 
 import com.alibaba.fastjson.JSONObject;
 

+ 2 - 2
jsjp-service/src/main/java/com/miaxis/service/impl/AppleServiceImpl.java → jsjp-service/src/main/java/com/miaxis/apple/impl/AppleServiceImpl.java

@@ -1,10 +1,10 @@
-package com.miaxis.service.impl;
+package com.miaxis.apple.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.auth0.jwk.Jwk;
 import com.miaxis.common.exception.CustomException;
-import com.miaxis.service.IAppleService;
+import com.miaxis.apple.IAppleService;
 import io.jsonwebtoken.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.tomcat.util.codec.binary.Base64;

+ 84 - 0
jsjp-service/src/main/java/com/miaxis/sms/SendSms.java

@@ -0,0 +1,84 @@
+package com.miaxis.sms;
+
+import com.aliyun.auth.credentials.Credential;
+import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
+import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
+import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
+import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
+import com.google.gson.Gson;
+import com.miaxis.sms.domain.SmsInfo;
+import darabonba.core.client.ClientOverrideConfiguration;
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+//import javax.net.ssl.KeyManager;
+//import javax.net.ssl.X509TrustManager;
+
+@Component
+@Data
+public class SendSms {
+
+    @Value("${aliyun.accessKeyId}")
+    private String accessKeyId;
+    @Value("${aliyun.accessKeySecret}")
+    private String accessKeySecret;
+
+    public void sendSms(SmsInfo smsInfo) throws ExecutionException, InterruptedException {
+        // Configure Credentials authentication information, including ak, secret, token
+        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
+                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
+                .accessKeyId(accessKeyId)
+                .accessKeySecret(accessKeySecret)
+                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
+                .build());
+
+        // Configure the Client
+        AsyncClient client = AsyncClient.builder()
+                .region("cn-hangzhou") // Region ID
+                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
+                .credentialsProvider(provider)
+                //.serviceConfiguration(Configuration.create()) // Service-level configuration
+                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
+                .overrideConfiguration(
+                        ClientOverrideConfiguration.create()
+                                // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
+                                .setEndpointOverride("dysmsapi.aliyuncs.com")
+                        //.setConnectTimeout(Duration.ofSeconds(30))
+                )
+                .build();
+
+        // Parameter settings for API request
+        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
+                .phoneNumbers(smsInfo.getPhone())
+                .signName(smsInfo.getSignName())
+                .templateCode(smsInfo.getTemplateCode())
+                .templateParam(smsInfo.getParam())
+                // Request-level configuration rewrite, can set Http request parameters, etc.
+                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
+                .build();
+
+        // Asynchronously get the return value of the API request
+        CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
+        // Synchronously get the return value of the API request
+        SendSmsResponse resp = response.get();
+        System.out.println(new Gson().toJson(resp));
+        // Asynchronous processing of return values
+        /*response.thenAccept(resp -> {
+            System.out.println(new Gson().toJson(resp));
+        }).exceptionally(throwable -> { // Handling exceptions
+            System.out.println(throwable.getMessage());
+            return null;
+        });*/
+
+        // Finally, close the client
+        client.close();
+
+    }
+
+
+}

+ 77 - 0
jsjp-service/src/main/java/com/miaxis/sms/SendSmsSync.java

@@ -0,0 +1,77 @@
+package com.miaxis.sms;
+
+// This file is auto-generated, don't edit it. Thanks.
+
+import com.aliyun.tea.TeaException;
+import com.google.gson.Gson;
+import com.miaxis.sms.domain.SmsInfo;
+import com.miaxis.sms.domain.SmsToUser;
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+
+@Component
+@Data
+@ConfigurationProperties(prefix = "aliyun")
+public class SendSmsSync {
+
+    private String accessKeyId;
+    private String accessKeySecret;
+
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @param accessKeyId
+     * @param accessKeySecret
+     * @return Client
+     * @throws Exception
+     */
+    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+                // 必填,您的 AccessKey ID
+                .setAccessKeyId(accessKeyId)
+                // 必填,您的 AccessKey Secret
+                .setAccessKeySecret(accessKeySecret);
+        // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
+        config.endpoint = "dysmsapi.aliyuncs.com";
+        return new com.aliyun.dysmsapi20170525.Client(config);
+    }
+
+
+
+
+    public  boolean sendSms(SmsInfo smsInfo) throws Exception {
+        // 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
+        // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
+        //String oldParam = "{\"name\":\"周淑萍\",\"idcard\":\"350526198708052015\",\"password\":\"123456\"}";
+       // String param = "{\"name\":\"" + smsToUser.getName() + "\",\"idcard\":\"" + smsToUser.getIdcard() + "\",\"password\":\"" + smsToUser.getPassword() + "\"}";
+
+        com.aliyun.dysmsapi20170525.Client client = SendSmsSync.createClient(accessKeyId, accessKeySecret);
+        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
+                .setPhoneNumbers(smsInfo.getPhone())
+                .setSignName(smsInfo.getSignName())
+                .setTemplateCode(smsInfo.getTemplateCode())
+                .setTemplateParam(smsInfo.getParam());
+        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+            client.sendSmsWithOptions(sendSmsRequest, runtime);
+            return true;
+        } catch (TeaException error) {
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+            error.printStackTrace();
+            return false;
+        } catch (Exception _error) {
+            TeaException error = new TeaException(_error.getMessage(), _error);
+            // 如有需要,请打印 error
+            com.aliyun.teautil.Common.assertAsString(error.message);
+            return false;
+        }
+
+    }
+
+}
+

+ 33 - 0
jsjp-service/src/main/java/com/miaxis/sms/domain/SmsInfo.java

@@ -0,0 +1,33 @@
+package com.miaxis.sms.domain;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 用户对象 user_info
+ *
+ * @author miaxis
+ * @date 2021-01-11
+ */
+@Data
+public class SmsInfo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+
+    @ApiModelProperty(value = "手机号")
+    private String phone;
+
+    @ApiModelProperty(value = "参数")
+    private String param;
+
+    @ApiModelProperty(value = "模板编号")
+    private String templateCode;
+
+    @ApiModelProperty(value = "签名")
+    private String signName;
+
+
+}

+ 41 - 0
jsjp-service/src/main/java/com/miaxis/sms/domain/SmsToUser.java

@@ -0,0 +1,41 @@
+package com.miaxis.sms.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 用户对象 user_info
+ *
+ * @author miaxis
+ * @date 2021-01-11
+ */
+@Data
+public class SmsToUser implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+
+    @ApiModelProperty(value = "学员姓名")
+    private String name;
+
+    @ApiModelProperty(value = "学员身份证号码")
+    private String idcard;
+
+    @ApiModelProperty(value = "登录密码")
+    private String password;
+
+    @ApiModelProperty(value = "学员电话号码")
+    private String phone;
+
+
+
+}