rely:
<!--腾讯短信依赖--> <dependency> <groupId>com.github.qcloudsms</groupId> <artifactId>qcloudsms</artifactId> <version>1.0.6</version> </dependency>
Code:
public class SMSUtil { Private static Final int AppID = XXXXX ; Private static Final String AppKey = "xxxxxx" ; public static String Send (String phoneNumbers) { int YZM = Random (); String NUM = Integer.toString (YZM); SmsSingleSenderResult Result = null ; the try { String smsSign = "" + + YZM "as your login code, please fill in the two minutes I as a non-operating, please ignore this message";.. // NOTE: here's signature "Tencent cloud "just an example, the real need to apply for signature in the message console, in addition to the signature parameters used are` `signature content, rather than` signature ID Ssender = SmsSingleSender new new SmsSingleSender (AppID, AppKey); Result = ssender.send (0, "86", phoneNumbers, smsSign, "", "" ); IF (result.result == 0 ) { // sent successfully verified return code return NUM; } } the catch (HTTPException E) { // System.out.println ( "the HTTP error response code"); return result.toString (); } the catch (JSONException E) { // System.out.println ( "json parse error"); return result.toString (); }the catch (IOException E) { // System.out.println ( "IO Error Network"); return result.toString (); } the catch (com.github.qcloudsms.httpclient.HTTPException E) { e.printStackTrace (); } return result.toString (); } / * generate six codes * / Private static int Random () { the Random R & lt = new new the Random (); the StringBuffer SB = new new the StringBuffer (); int [] = C new new int [. 6 ] ; for (int i = 0; i < 6; i++) { c[i] = r.nextInt(9) + 1; sb.append(c[i]); } return Integer.parseInt(sb.toString()); } public static void main(String[] args) { String send = SMSUtil.send("这里给手机号码"); System.out.println(send); } }