Esempio n. 1
0
        public int Balance()
        {
            if (_inited)
            {
                var url = _smsurl + "GetNum&account=" + _account + "&password="******"ns", namespaceURI);
                        var code = Convert.ToInt32(dom.SelectSingleNode("//ns:code", nsmgr).InnerText);
                        var msg = dom.SelectSingleNode("//ns:msg", nsmgr).InnerText;
                        var num = Convert.ToInt32(dom.SelectSingleNode("//ns:num", nsmgr).InnerText);
                        if (code == 2)
                        {
                            balance = num;
                        }
                        else
                        {
                            taskThrow = new SmsInterfaceException(code, msg);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Warn("调用查看短信平台余额接口出现错误", ex);
                        taskThrow = new SmsInterfaceException(-1, ex.Message);
                    }

                    if (taskThrow != null) throw taskThrow;
                    else return balance;
                }
            }

            return 1;
        }
Esempio n. 2
0
        public void Send(string mobile, string content)
        {
            if (_inited)
            {
                Exception taskThrow = null;
                using (HttpClient client = new HttpClient())
                {
                    var url = _smsurl + "?uid=" + _account + "&pwd=" + _password + "&mobile=" + mobile + "&encode=utf8&content=" + HttpUtility.UrlEncode(content, Encoding.UTF8);

                    try
                    {
                        var rep = client.GetAsync(url).Result;
                        var result = rep.Content.ReadAsStringAsync().Result;

                        if (result != "100")
                        {
                            var msg = "C123发送短信失败,状态码" + result;
                            taskThrow = new SmsInterfaceException(int.Parse(result), "C123发送短信失败,状态码" + result);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("发送短信验证码时出现异常", ex);
                        taskThrow = ex;
                    }

                    if (taskThrow != null) throw taskThrow;
                }
            }
        }
Esempio n. 3
0
        public void Send(string mobile, string content)
        {
            if (_inited)
            {
                Exception taskThrow = null;
                using (HttpClient client = new HttpClient())
                {
                    var url = _smsurl + "Submit&account=" + _account + "&password="******"&mobile=" + mobile + "&content=" + content;

                    try
                    {
                        var rep = client.GetAsync(url).Result;
                        var xmlmsg = rep.Content.ReadAsStringAsync().Result;
                        XmlDocument dom = new XmlDocument();
                        dom.LoadXml(xmlmsg);
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(dom.NameTable);
                        nsmgr.AddNamespace("ns", namespaceURI);
                        var code = Convert.ToInt32(dom.SelectSingleNode("//ns:code", nsmgr).InnerText);
                        var msg = dom.SelectSingleNode("//ns:msg", nsmgr).InnerText;
                        var smsid = dom.SelectSingleNode("//ns:smsid", nsmgr).InnerText;

                        if (code != 2) taskThrow = new SmsInterfaceException(code, msg);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("发送短信验证码时出现异常", ex);
                        taskThrow = ex;
                    }

                    if (taskThrow != null) throw taskThrow;
                }
            }
        }