java-短信服务开发-发送验证码

One. ready

Signatures and templates are created by themselves. Below is the path.

Create an AccessKey

With the above, you can develop it.

Second: development

2.1 Click to learn quickly - View API Demo

This should be the case after opening - then open the API documentation

Of course, you must download the Java SDK instructions according to the above figure .

I posted it for convenience

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>3.7.0</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-ecs</artifactId>
    <version>4.11.0</version>
</dependency>

This is Maven.

Jar package address: https://developer.aliyun.com/tools/sdk?spm=a2c1g.8271268.10000.92.772fdf25IHfsiT

The SDK is also available.

2.2 Fill in some of the fills. According to the documentation above the documentation.

Get the code on the right and copy it to your development tool. This is the code I changed.

一定记得更改AccessKey ID 和 Access Key Secret

在这里:贴上下面的内容之后就点击运行就行了。

//        DefaultProfile profile = DefaultProfile.getProfile("default", "AccessKey ID", "	Access Key Secret");
//        IAcsClient client = new DefaultAcsClient(profile);
//
//        CommonRequest request = new CommonRequest();
//        //request.setProtocol(ProtocolType.HTTPS);
//        request.setMethod(MethodType.POST);
//        request.setDomain("dysmsapi.aliyuncs.com");
//        request.setVersion("2017-05-25");
//        request.setAction("SendSms");
//        request.putQueryParameter("PhoneNumbers", "15717350550");
//        request.putQueryParameter("SignName", "容易购");
//        request.putQueryParameter("TemplateCode", "SMS_162195761");
//        request.putQueryParameter("TemplateParam", "{\"code\":\"1111\"}");
//        try {
//            CommonResponse response = client.getCommonResponse(request);
//            System.out.println(response.getData());
//        } catch (ServerException e) {
//            logger.error("服务端出错",e);
//        } catch (ClientException e) {
//            logger.error("客户端出错",e);
//        }

这是运行结果:

//{"Message":"OK","RequestId":"9C9C2A34-A3BD-4175-8133-FF631C586392","BizId":"172202954430355358^0","Code":"OK"}

当然你得保证你的账户有钱,5分钱一次短信。

发布了37 篇原创文章 · 获赞 4 · 访问量 6834

猜你喜欢

转载自blog.csdn.net/m0_37918421/article/details/89041829
今日推荐