
https://{{url}}?appKey={{app_key}}&appSecret={{app_secret}}&phones={{mobile}}&content=【{{sign}}】{{content}}https://xxxyun.com/sendsms?appKey=aaaaa&appSecret=bbbb&phones=13888888888&content=【某云】您的验证码是:666666
| 参数名 | 说明 |
|---|---|
| url | 请求地址 |
| app_key | 客户在供应商注册的唯一key码 |
| app_secret | 客户在供应商注册的唯一secret码 |
| mobile | 接收短信的用户手机号 |
| sign | 短信内容的产品名称 |
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
* 短信发送工具类
*
* http接口请求依赖 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 = "【签名】";
private static final String APP_KEY = "app_key";
private static final String APP_SECRET = "app_secret";
/**
* 测试请求
* @param args
*/
public static void main(String[] args) {
String mobile = "18566770000";
String code = "666666";
String body = sendSmsCode(mobile, code);
System.out.println(body);
}
/**
* 发送短信验证码
* @param mobile 接收手机号
* @param code 验证码
*/
public static String sendSmsCode(String mobile, String code) {
StringBuffer content = new StringBuffer().append("验证码:" ).append(code).append(",如非本人操作请忽略。");
return sendSms(mobile, content.toString());
}
/**
* 发送短信信息
* @param mobile 接收手机号
* @param content 短信内容
*/
public static String sendSms(String mobile, String content) {
// 拼接请求参数
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);
// 封装请求参数
Request request = new Request.Builder().url(url.toString()).get().build();
OkHttpClient client = new OkHttpClient();
try {
// 发起请求
Response response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
using 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 = "【签名】";
private static String APP_KEY = "app_key";
private static String APP_SECRET = "APP_SECRET";
static void Main(string[] args)
{
string mobile = "手机号";
string code = "内容";
string body = sendSmsCode(mobile, code);
Console.WriteLine(body);
}
/**
* 发送短信验证码
* @param mobile 接收手机号
* @param code 验证码
*/
public static String sendSmsCode(String mobile, String code)
{
StringBuilder content = new StringBuilder().Append("验证码:").Append(code).Append(",如非本人操作请忽略。");
return sendSms(mobile, content.ToString());
// StringBuilder
}
/**
* 发送短信信息
* @param mobile 接收手机号
* @param content 短信内容
*/
public static string sendSms(String mobile, String content)
{
string msg = string.Empty;
// 拼接请求参数
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);
// 封装请求参数
try
{
// 发起请求
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;
}
}
}
{"errorCode":"000000","errorMsg":"提交成功"}
000000
提交成功

blog.guijianpan.com
上一篇:大数据运营之数据治理
下一篇:大数据服务之数据管理