You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
81 lines
2.9 KiB
using System;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Data;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Net.Security;
|
|
|
|
namespace FangYar.FYMQTT
|
|
{
|
|
public class RemindMessages
|
|
{
|
|
public static string ShortLetterUrl = System.Configuration.ConfigurationManager.AppSettings["ShortLetterUrl"].ToString();
|
|
|
|
/// <summary>
|
|
/// 单人发送短信
|
|
/// </summary>
|
|
/// <param name="phone">用户手机号</param>
|
|
/// <param name="templateCode">模版id</param>
|
|
/// <param name="param">这个模版中的参数,根据模版内容进行替换</param>
|
|
public string AloneVerificationCodePush(string phone, string templateCode, string param)
|
|
{
|
|
try
|
|
{
|
|
string param_s = "{\"templateCode\":\"" + templateCode + "\",\"phone\":[\"" + phone + "\"],\"param\":" + param + "}";
|
|
return InvokeWebApiPost(ShortLetterUrl, param_s);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 调用指定的url以post方式调用,默认超时时间为3000毫秒。
|
|
/// </summary>
|
|
/// <param name="url">待调用链接。</param>
|
|
/// <param name="param">参数列表,格式如 api=value1&arg1=value2</param>
|
|
/// <param name="timeout">超时时间(单位毫秒),默认值为3000。</param>
|
|
/// <returns>执行结果。</returns>
|
|
public static string InvokeWebApiPost(string url, string param, int timeout = 3000)
|
|
{
|
|
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
|
|
var resuleJson = string.Empty;
|
|
var req = (HttpWebRequest)WebRequest.Create(url);
|
|
req.Method = "POST";
|
|
req.ContentType = "application/json"; //Defalt
|
|
req.Accept = "accept";
|
|
|
|
using (var postStream = new StreamWriter(req.GetRequestStream()))
|
|
{
|
|
postStream.Write(param);
|
|
}
|
|
|
|
req.GetResponse();
|
|
return "";
|
|
|
|
//System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
|
|
//// 将参数字节化
|
|
//byte[] postData = Encoding.UTF8.GetBytes(param);
|
|
|
|
//var resuleJson = string.Empty;
|
|
//var req = (HttpWebRequest)WebRequest.Create(url);
|
|
//req.Method = "POST";
|
|
//req.ContentType = "application/json"; //Defalt
|
|
//req.Accept = "accept";
|
|
//req.ContentLength = postData.Length;
|
|
//using (var postStream = req.GetRequestStream())
|
|
//{
|
|
// //postStream.Write(param);
|
|
// //传输字节数据
|
|
// postStream.Write(postData, 0, postData.Length);
|
|
//}
|
|
//req.GetResponse();
|
|
//return "";
|
|
}
|
|
|
|
}
|
|
}
|
|
|