Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate the SMS verification code of Ronglian Cloud in springboot

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Many novices are not very clear about how springboot integrates Rong Lianyun's SMS verification code. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Recently, due to business requirements, the company arranged for me to use the SMS verification code function of Yong Lianyun to achieve login operation, because I did not read api carefully in the early stage, which led to a lot of unnecessary errors. And I didn't find the way to integrate Yong Lianyun with springboot on the Internet, and now I sort it out and share it with you. I only share the code here, not including account registration, if you use free registration, remember to add your test mobile phone number to the platform to accept text messages.

1. First, import the required maven dependency com.cloopen java-sms-sdk 1.0.1 com.google.code.gson gson 2.8.6 in the pom file of your project

two。 Find the development document on the home page of Yong Lianlian Cloud as shown below.

3. Then create a tool class to send text messages, and replace the ACCOUNT SID and the main account token AUTH TOKEN and APPID that you applied for in advance to the location of xxx. Import java.util.HashMap;import java.util.Random

Import com.cloopen.rest.sdk.CCPRestSmsSDK;import org.apache.commons.lang3.RandomStringUtils

/ * * author songjian * @ Date 2020-03-10 * / public class SDKTestSendTemplateSMS {/ * * send CAPTCHA tool * * @ param phone phone number * @ return CAPTCHA * / public static String sms (String phone) {HashMap result = null; CCPRestSmsSDK restAPI = new CCPRestSmsSDK () / / initialize the server address and port. The production environment is configured as app.cloopen.com, and the port is 8883. RestAPI.init ("app.cloopen.com", "8883"); / / initialize the main account name and the main account token. After logging in to the IM website, you can see the developer's main account ACCOUNT SID and the main account token AUTH TOKEN on the control home page. RestAPI.setAccount ("xxx", "xxx"); / / Please use the APPID of the created application in the administrative console. RestAPI.setAppId ("xxx"); String code = RandomStringUtils.randomNumeric (6); / / set the mobile number and verification code to be sent and the expiration time result = restAPI.sendTemplateSMS (phone, "1", new String [] {code, "10"}); if ("000000" .equals (result.get ("statusCode") {return code } else {/ / exception returns error code and error message String s = "error code =" + result.get ("statusCode") + "error message =" + result.get ("statusMsg"); return s;}

4. When testing, you can write a main method to test public static void main (String [] args) {String sms = sms ("1399999999999"); System.out.println (sms);}

And then the text message was sent successfully.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report