ASP.NET MVC 2FA中的备用SMSService

问题描述

美好的一天,

我正尝试在不使用Microsoft提供的Twilio或ASPSMS的情况下,为ASP.NET MVC两因素身份验证实现替代SMSService,因为它们在我的居住国家/地区收费很高。

我有一个用于其他警报的SMS服务,但我想为Identity 2FA实施它。下面是我正在编写的代码,但未发送SMS。

我错过了什么吗?

public class SmsService : IIdentityMessageService
{
    public void sendsms(string phone,string actualmessage)
    {
        
        string smsUsername = ConfigurationManager.AppSettings["SMSUsername"];
        string smsPassword = ConfigurationManager.AppSettings["SMSPassword"];

        string smsUrl = "https://portal.nigeriabulksms.com/api/?username=" + smsUsername + "&password=" + smsPassword + "&message=" + actualmessage + "&sender=AGENTKUNLE&verbose=true&mobiles=" + phone + "";
        SendSMSAPI.SendSms(smsUrl);
    }
    public Task SendAsync(IdentityMessage message)
    {

        sendsms(message.Destination,message.Body);
        // Plug in your sms service here to send a text message.
        return Task.Fromresult(0);
    }
}

SendSMSAPI.sendsms()中引用的代码如下:

 public static string SendSms(string apiUrl)
    {
        var targetUri = new Uri(apiUrl);
        var webRequest = (HttpWebRequest)WebRequest.Create(targetUri);
        webRequest.Method = WebRequestMethods.Http.Get;
        try
        {
            string webResponse;
            using (var getresponse = (HttpWebResponse)webRequest.GetResponse())
            {
                var stream = getresponse.GetResponseStream();
                if (stream != null)
                    using (var reader = new StreamReader(stream))
                    {
                        webResponse = reader.ReadToEnd();
                        reader.Close();
                    }
                else
                    webResponse = null;
                getresponse.Close();
            }
            if (!string.IsNullOrEmpty(webResponse?.Trim()))
                return webResponse.Trim();
        }
        catch (WebException ex)
        {
            Console.WriteLine(ex.Message,"Error in Saving");

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message,"Error in Saving");
        }
        finally
        {
            webRequest.Abort();
        }
        return null;
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)