In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
First, the purpose of this paper is that most platforms have a need to access and send SMS verification code and notify SMS. Although the interfaces of most platforms on the market are just a very common HTTP-GET request, there are still friends who need to learn and use them. The original intention of this article is to provide learning convenience and to facilitate beginners to learn simple http interface implementation. As the API parameters of the major SMS channel service providers are basically the same, this Demo can appropriately reduce the development cost of the SMS channel interface for developers and provide reference. If you have friends who do not want to copy the source code from the article, you need to download it directly, and the source code has been uploaded to GitHub. GitHub Portal: https://github.com/yzchen0o0/demo-sms 2. Send SMS API request parameter template https://{{url}}?appKey={{app_key}}&appSecret={{app_secret}}&phones={{mobile}}&content= [{{sign}}] {{content}} example https://xxxyun.com/sendsms?appKey=aaaaa&appSecret=bbbb&phones=13888888888&content= [a cloud] your verification code is: 666666. Parameter description parameter name description url request address app_key customer unique keycode app _ secret customer registered with supplier unique secret code mobile user receiving SMS message mobile number sign product name of SMS content 4, implementation of each development language 1, Javaimport okhttp3.OkHttpClient Import okhttp3.Request;import okhttp3.Response;/** * SMS sending tool class *
* http API request depends on okhttp-3.14.2.jar, okio-1.17.2.jar *
* / public class SmsUtil {private static final String HOST = "https://api.zhuanxinyun.com/api/v2/sendSms.json"; private static final String SIGN =" [signature] "; private static final String APP_KEY =" app_key "; private static final String APP_SECRET =" app_secret "; / * * Test request * @ param args * / public static void main (String [] args) {String mobile =" 18566770000 " String code = "666666"; String body = sendSmsCode (mobile, code); System.out.println (body) } / * send SMS verification code * @ param mobile to receive mobile phone number * @ param code verification code * / public static String sendSmsCode (String mobile, String code) {StringBuffer content = new StringBuffer () .append ("verification code:") .append (code) .append ("ignore if you do not do it yourself.") ; return sendSms (mobile, content.toString ()) } / * send SMS message * @ param mobile receive mobile number * @ param content SMS content * / public static String sendSms (String mobile String content) {/ / stitching request parameter StringBuffer url = new StringBuffer (). Append (HOST) .append ("? appKey=") .append (APP_KEY) .append ("& appSecret=") .append (APP_SECRET) .append ("& phones=") .append (mobile) .append ("& content=") .append (SIGN) .append (content) / / Encapsulation request parameter Request request = new Request.Builder () .url (url.toString ()) .get () .build (); OkHttpClient client = new OkHttpClient (); try {/ / initiate request Response response = client.newCall (request) .execute (); return response.body () .string () } catch (Exception e) {e.printStackTrace ();} return null;}} 2, php3, .Netusing System;using System.IO;using System.Net;using System.Text;namespace SmsCode {class Program {private static String HOST = "https://api.zhuanxinyun.com/api/v2/sendSms.json"; private static String SIGN =" [signature] " Private static String APP_KEY = "app_key"; private static String APP_SECRET = "APP_SECRET"; static void Main (string [] args) {string mobile = "Mobile number"; string code = "content"; string body = sendSmsCode (mobile, code); Console.WriteLine (body) } / * send SMS verification code * @ param mobile to receive mobile phone number * @ param code verification code * / public static String sendSmsCode (String mobile, String code) {StringBuilder content = new StringBuilder () .Append ("verification code:") .append (code) .append ("ignore if you do not do it yourself.") ; return sendSms (mobile, content.ToString ()); / / StringBuilder} / * * send SMS message * @ param mobile receive mobile number * @ param content SMS content * / public static string sendSms (String mobile, String content) {string msg = string.Empty / / stitching request parameter StringBuilder url = new StringBuilder (). Append (HOST) .append ("? appKey=") .append (APP_KEY) .append ("& appSecret=") .append (APP_SECRET) .append ("& phones=") .append (mobile) .append ("& content=") .append (SIGN) .append (content) / / Encapsulation request parameter try {/ / initiate request msg= Request_GET (url.ToString (), "UTF-8");} catch (Exception ex) {msg=ex.Message;} return msg } public static string Request_GET (string urlString, string encoding) {HttpWebRequest httpWebRequest = null; HttpWebResponse httpWebResponse = null; Stream stream = null; StreamReader streamReader = null; string result = string.Empty; try {httpWebRequest = (WebRequest.Create (urlString) as HttpWebRequest) HttpWebRequest.Method = "GET"; / / httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Maxthon 2.0)"; httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse (); stream = httpWebResponse.GetResponseStream (); streamReader = new StreamReader (stream, Encoding.GetEncoding (encoding)) Result = streamReader.ReadToEnd ();} catch (SystemException ex) {result = "err:" + ex.Message;} finally {if (httpWebRequest! = null) {httpWebRequest.Abort () } if (httpWebResponse! = null) {httpWebResponse.Close ();} if (stream! = null) {stream.Close () } if (streamReader! = null) {streamReader.Close ();}} return result;}} V. Return value {"errorCode": "000000", "errorMsg": "submitted successfully"} 000000 successful technical exchange
My Blog
Blog.guijianpan.com
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.