Ali Yun Big Fish SMS using Demo

Source: Internet
Author: User

First, you need to go to the Aliyun platform to request SMS signatures and create SMS templates

public class Sendshortmsg {public static int sendmsg (String telphone,string personname,string project,string Group) {                Set timeout-Adjustable system.setproperty ("Sun.net.client.defaultConnectTimeout", "10000");
System.setproperty ("Sun.net.client.defaultReadTimeout", "10000"); Initialize ascclient required several parameters final string product = "DYSMSAPI";//SMS API Product name (SMS product name fixed, no need to modify) Final string domain = " Dysmsapi.aliyuncs.com "//SMS API Product domain name (interface address fixed, no need to modify)//replace your AK final String Accesskeyid =" ******** ";//Your Accesskeyid,
Refer to this document Step 2 final String Accesskeysecret = "Hu Jintao";//Your Accesskeysecret, reference this document step 2//Initialize ascclient, do not support multiple region at the moment
                Iclientprofile profile = Defaultprofile.getprofile ("Cn-hangzhou", Accesskeyid,accesskeysecret);
                try {defaultprofile.addendpoint ("Cn-hangzhou", "Cn-hangzhou", product, domain); catch (Clientexception e) {//TODO auto-generated catch block E.printstacktrace
                ();
        }        Iacsclient acsclient = new Defaultacsclient (profile);
                 Assembly Request Object Sendsmsrequest = new Sendsmsrequest ();
                 Use POST to submit Request.setmethod (Methodtype.post); Required: Mobile phone number to be sent. 
                 Support in a comma-separated form for batch calls, the volume limit of 1000 mobile phone numbers, batch calls relative to a single call timeliness slightly delayed, the type of validation code SMS recommended using a single call to the way Request.setphonenumbers (Telphone);
                 Required: SMS signature-can be found in the SMS console Request.setsignname ("SMS signature name");
                 Required: SMS templates-can be found in the SMS console Request.settemplatecode ("SMS Template Code"); Optional: Variables in the template replace the JSON string, such as the template content is "Dear ${name}, your authentication code is ${code}", the value here is//friendship tip: If you need a newline character in JSON, refer to the standard JSON protocol for line breaks, such as text The inclusion of the \ r \ n condition in the JSON needs to be represented as \\r\\n, otherwise it will cause JSON to resolve failure on the server (the following parameters are all declared in the SMS template and the double quotes need to be translated) Request.settemplateparam ("{\" personname\
                 ": \" "+personname+" \ ", \" project\ ": \" "+project+" \ ", \" Group\ ": \" "+group+" \ "}");
         Optional-Uplink SMS Extension code (no special needs of users please ignore this field)//request.setsmsupextendcode ("90997");        Optional: Outid to extend the field to the business side, and eventually bring the value back to the caller Request.setoutid ("Youroutid") in the SMS receipt message;
                Request failed here will throw clientexception exception sendsmsresponse sendsmsresponse = null;
                try {sendsmsresponse = acsclient.getacsresponse (request);
                catch (Serverexception e) {e.printstacktrace ();
                catch (Clientexception e) {e.printstacktrace ();
                } System.out.println (Sendsmsresponse.getcode () + "=====" +sendsmsresponse.getcode ()); if (Sendsmsresponse.getcode ()!= null && sendsmsresponse.getcode (). Equals ("OK")) {//Request successful Isv.tem
                    Plate_missing_parameters System.out.println ("========= request successful!");
                return 1;
                }else{return 2; }
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.