【发布时间】:2016-04-26 20:52:07
【问题描述】:
如何使用 c# 通过 GSM 调制解调器发送 USSD 请求。
我希望能够执行任何代码,并且响应应该以对象或字符串的形式返回,我可以将其用于正则表达式
【问题讨论】:
-
回答这个问题需要更多信息... C# 不包括对此的本机支持。你在使用任何库吗?
-
我正在使用 GSM 通信库
如何使用 c# 通过 GSM 调制解调器发送 USSD 请求。
我希望能够执行任何代码,并且响应应该以对象或字符串的形式返回,我可以将其用于正则表达式
【问题讨论】:
这是我在 GSM COMm 库中使用的摘录
public string SendUssdRequest(string request)
{
log.DebugFormat("Sending USSD Request {0}", request);
string result = "";
try
{
IProtocol protocol = comm.GetProtocol();
string gottenString = protocol.ExecAndReceiveMultiple("AT+CUSD=1," + request + ",15");
result = gottenString;
int i = 0;
if (!gottenString.Contains("\r\n+CUSD: 2"))
{
bool receiving = false;
do
{
receiving = protocol.Receive(out gottenString);
result += gottenString;
++i;
} while (receiving);
}
result = result.Replace("\r\n", "");
result = result.Replace("+CUSD: 2,", "");
result = result.Replace(",15", "");
log.DebugFormat("{1} - USSD Response is: {0}", result,SenderNumber);
return result;
}
catch(Exception ex)
{
log.Error(ex);
}
finally
{
comm.ReleaseProtocol();
}
return "";
}
【讨论】: