Recent projects need to use text messaging interfaces, chose Ali contrasting with the short message interface
The following is the Development Notes:
In the docking interface class:
/ ** * Constant class * / Private static Constant Constant; // Name: Cloud Communications SMS API product, developers do not need to replace static Final String Product = "Dysmsapi" ; // product domain, developers do not need to replace static Final String Domain = "dysmsapi.aliyuncs.com" ; // here you need to replace the developer's own AK (access Ali cloud console seeking) static Final String accessKeyId = constant.accessKeyId; static Final String accessKeySecret = constant.accessKeySecret;
AK relevant here need to console themselves Ali query
Method call:
/ ** * SMS Interface * @author ZK * @ DATE: 2019 Nian 5 30 afternoon 3:59:15 * @param Phone * @param Status 1: Registration * @return * / @ RequestMapping ( "/ getSms" ) @ResponseBody public String getSms (Phone String, String Status) { // can be self-adjusted timeout System.setProperty ( "sun.net.client.defaultConnectTimeout", "10000" ); System.setProperty ( "sun.net.client. defaultReadTimeout "," 10000 " ); // initialize acsClient, does not support the region of IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); try { DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); } catch (ClientException e1) { e1.printStackTrace(); } IAcsClient acsClient = new DefaultAcsClient(profile); //随机生成六位验证码 int code = (int)((Math.random()*9+1)*100000); Sendsms sendsmsselect = new Sendsms(); sendsmsselect.setIsdel("0" ); sendsmsselect.setStatus (Status); sendsmsselect.setPhone (Phone); List <SendSMS> List = sendsmsService.selectAll (sendsmsselect); IF ! (List = null ) { IF (list.size ()> 0 ) { SendSMS SendSMS1 = List.get (0 ); sendsms1.setIsdel ( ". 1"); // time before deleting the record number sendsmsService.updateByPrimaryKey (SendSMS1); } } / ** * number of codes stored in the database * / sendsmsselect.setCode (code+ "" ); Sendsmsselect.setCreatetime ( new new a Date ()); sendsmsService.insert (sendsmsselect); // Assembly requested object - particularly described Console - part document SendSmsRequest = Request new new SendSmsRequest (); // Required: phone number to be sent request.setPhoneNumbers (phone); // required: SMS signature - can be found in the SMS console, your content in signature management in the request.setSignName (constant.SignName); // required: SMS templates - SMS can be found in the console, you manage templates in the template number request.setTemplateCode (constant.TemplateCode); // optional: template variable substitution JSON string, such as the template reads "Dear $ {name}, your ", the verification code value here code} {$ request.setTemplateParam (" {\ "code \": \ "" + + code "\"}"); // optional - up message spreading code (no special needs of users ignore this field) // request.setSmsUpExtendCode ( "90997"); // Optional: outId is provided to the business side extension field in the final message receipt messages this value back to the caller request.setOutId ( "yourOutId" ); // hint here may throw exceptions, noted that the catch sendSmsResponse sendSmsResponse = null ; the try { sendSmsResponse = acsClient.getAcsResponse (Request); } the catch (a ServerException E) { e.printStackTrace (); } the catch (ClientException E) { e.printStackTrace (); } // Get transmission state String cod = sendSmsResponse.getCode(); // System.out.println(cod); return cod; }
This is done to verify the use of all relevant codes generated and stored database operations, may be partially replaced by their needs