1:创建一个项目用来调用第三方的类,右键Nuget添加第三方的引用类库 qcloudsms_csharp
/// <summary>
/// 第三方
/// </summary>
public class TenXunYunSMS
{
//appId
public int appId;
//appKey
public string appKey = "";
//短信模板ID
private int tmplateId = 379257;
//签名内容
private string smsSign = "7hhhcn";
/// <summary>
/// 验证码
/// </summary>
public int Code { get; set; }
/// <summary>
/// 发送验证码
/// </summary>
/// <param name="phone"></param>
/// <returns></returns>
public void SetSMS(string phone)
{
Random random = new Random();
int code = random.Next(100000, 999999);
try
{
SmsSingleSender ssender = new SmsSingleSender(appId, appKey);
var result = ssender.sendWithParam("86", phone,
tmplateId, new[] { code.ToString() }, smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
}
catch (JSONException ex)
{
}
catch (HTTPException ex)
{
}
catch (Exception ex)