如何解决短信网关api问题? [英] How do I solve sms gateway api problem ?
问题描述
我想在成功发送短信时在日志表中插入日志。
string uid = xxxx;
string password = xxxx跨度>;
string SenderId = xxxx跨度>;
string message = 确认订单号 + OrderNo + 。此订单确认已发送给您参考订单号: + PoRefNo + 。;
string phoneNos = CustomerContact;
HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create( http://xxxx.com /Xxxsms/xxxsms.aspx?user = + uid + & password = +密码+ & msisdn = + phoneNos + & sid = + SenderId + & msg = + message + & fl = 0& gwid = 2 跨度>);
HttpWebResponse myResp =(HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
if (responseString!= 失败的#Invalid Mobile Numbers)
{
B2B_Order_Master_SAP_BAL objOrderBAL = new B2B_Order_Master_SAP_BAL();
DataSet dsMessage = objOrderBAL.uspB2BCustomerPortal_InsertOrderSMSLog(hfCustomerId.Value.ToString(),CustomerContact,OrderNo,message, 客户服务, UploadOrder_CustCare);
}
我的尝试:
我正在检查string responseString = respStreamReader.ReadToEnd();中的值。
if(responseString!=Failed #Invalid Mobile Numbers )
{
//插入日志
}
现在问题是我只知道这一个输出:无效的移动号码失败是在向api发送无效号码时生成的。
我想知道其他什么回复将由api根据sms失败给出。
第一件事:他们的API是否共享这些字符串?他们的API必须登记来自服务器的错误值。
其次,我会用不同的方式写它,就像这样,
if (!responseString.Contains( 失败)){
// 成功
} else {
// 错误处理
var errorMessage = responseString.Split(' #')[ 1 ];
// 获取无效的手机号码
// 将其保存到数据库,显示给用户或其他任何内容。
}
我仍然建议阅读他们的API指南和文档,以了解更多错误以及如何返回错误。
只是我自己的意见,我相信使用错误代码是指导客户有关错误而不是发送字符串的更好方法。
I want to INSERT a log in a Log table when a sms is sent successfully.
string uid = "xxxx";
string password = "xxxx";
string SenderId = "xxxx";
string message = "Confirm Order No " + OrderNo + ". This Order Confirmation has been sent to you for your Ref. Order No: " + PoRefNo + ".";
string phoneNos = CustomerContact;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://xxxx.com/Xxxsms/xxxsms.aspx?user=" + uid + "&password=" + password + "&msisdn=" + phoneNos + "&sid=" + SenderId + "&msg=" + message + "&fl=0&gwid=2");
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
if (responseString != "Failed#Invalid Mobile Numbers")
{
B2B_Order_Master_SAP_BAL objOrderBAL = new B2B_Order_Master_SAP_BAL();
DataSet dsMessage = objOrderBAL.uspB2BCustomerPortal_InsertOrderSMSLog(hfCustomerId.Value.ToString(), CustomerContact, OrderNo, message, "Customer Care", "UploadOrder_CustCare");
}
What I have tried:
I am checking the value in "string responseString = respStreamReader.ReadToEnd(); "
if (responseString != "Failed#Invalid Mobile Numbers")
{
//Insert Log
}
Now the problem is i only know this one output:"Failed#Invalid Mobile Numbers" which is generated when invalid number is sent to api.
I want to know what other responses will be given by the api in terms of sms failure.
First thing: Didn't their API share those strings? Their API must enlist the values of the errors that come from servers.
Secondly, I would write it a bit differently, like this,
if (!responseString.Contains("Failed")) { // Success } else { // Error handling var errorMessage = responseString.Split('#')[1]; // Get the Invalid Mobile Number part // Save it to the database, show it to the user or whatever. }
I would still recommend reading their API guides and documentation to learn more errors and how they are returned.
Just my own opinion, I believe using error codes is a better way to guide the clients about the errors instead of sending the strings.
这篇关于如何解决短信网关api问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!