Esempio n. 1
0
        public SmsProxy(SmsPortTypeClient smsPortTypeClient, string sessionId)
        {
            _client =
                smsPortTypeClient;

            _sessionId = sessionId;
        }
Esempio n. 2
0
        public static SmsProvider[] QueryProvider(string server, string userName, string password)
        {
            SmsProvider[] providers;

            var binding =
                new BasicHttpsBinding {
                AllowCookies = true
            };

            var vimEndpoint =
                new EndpointAddress(string.Format("https://{0}/sdk/vimService", server));

            var smsEndpoint =
                new EndpointAddress(string.Format("https://{0}/sms/sdk", server));

            ServicePointManager.ServerCertificateValidationCallback += (sender, x509Certificate, chain, errors) => true;

            using (var client = new VimPortTypeClient(binding, vimEndpoint))
            {
                client.Open();

                var vimProxy = new VimProxy(client);

                string sessionId;

                var content =
                    vimProxy.RetrieveServiceContent();

                var credential =
                    new NetworkCredential {
                    UserName = userName, Password = password
                };

                vimProxy.Login(content.sessionManager, credential, null, out sessionId);

                using (var smsClient = new SmsPortTypeClient(binding, smsEndpoint))
                {
                    smsClient.Open();

                    var smsProxy = new SmsProxy(smsClient, sessionId);

                    var storageManager =
                        smsProxy.QueryStorageManager();

                    var providerRefs =
                        smsProxy.QueryProvider(storageManager);

                    providers =
                        providerRefs.Select(smsProxy.QueryProviderInfo).Select(GetProvider).ToArray();

                    smsClient.Close();
                }

                vimProxy.Logout(content.sessionManager);

                client.Close();
            }

            return(providers);
        }
Esempio n. 3
0
        private static string UPwd      = string.Empty; //"密码";

        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="telephone">手机号码</param>
        /// <param name="msg">内容</param>
        /// <returns></returns>

        /*
         *  Sms请求参数说明:
         *  类别	   参数名称	类型	    说明
         *  输入	   In0	    string	企业编号
         *  输入	   In1	    string	用户名称
         *  输入	   In2	    string	用户密码ww
         *  输入	   In3	    string	短信内容, 最大402个字或字符,短信发送必须按照短信模板,否则就会报模板不符,短信模板说明见3.1.1。
         *  输入	   In4	    string	手机号码(多个号码用”,”分隔),最多1000个号码
         *  输入	   In5	    string	流水号,20位数字,每个请求流水号要求唯一(规则自定义,建议时间格式精确到毫秒)必填参数,与回执接口中的流水号一一对应,不传后面回执接口无法查询数据。
         *  输入	   In6	    string	预约发送时间,格式:yyyyMMddHHmmss,如‘20090901010101’, 立即发送请填空(预约时间要写当前时间5分钟之后的时间,若预约时间少于5分钟,则为立即发送。)
         *  输入	   In7	    string	提交时检测方式
         *                          1 --- 提交号码中有效的号码仍正常发出短信,无效的号码在返回参数faillist中列出
         *                          不为1 或该参数不存在 --- 提交号码中只要有无效的号码,那么所有的号码都不发出短信,所有的号码在返回参数faillist中列出
         *  输入	   In8	    string	保留(空值)
         *  输入	   In9	    string	接入号扩展号(默认不填,扩展号为数字,扩展位数由当前所配的接入号长度决定,整个接入号最长20位)
         *  输入	   In10	    string	保留(空值)
         */
        public async Task <string> Send(string telephone, string msg)
        {
            try
            {
                SmsPortTypeClient SmsSurport = SmsSurport = new SmsPortTypeClient(new BasicHttpBinding(), new EndpointAddress(E_SMS_URL));
                var response = await SmsSurport.SmsAsync(Crop_NO, UName, UPwd, msg, telephone.Trim(), DateTime.Now.ToString("yyyyMMddHHmmssfff") + "000", "", "1", "", "", "");

                //LoggHelper.GetInstance().LogInfo("", "");
                return(response.@out);


                //SqlDataHelper_IH.WriteLlFile("[创业短信] Mobiles[" + telephone.Trim() + "]发送成功!流水号是:" + sResult + "\r", "_SMSoc");
            }
            catch (Exception ex)
            {
                // SqlDataHelper_IH.WriteLoclFile("[创业短信] Mobiles[" + telephone.Trim() + "]发送失败!ERROR:" + ex.Message + "\r", "_SMS");
                throw ex;
            }
        }
Esempio n. 4
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(SmsPortTypeClient.GetEndpointAddress(EndpointConfiguration.SmsHttpPort));
 }
Esempio n. 5
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(SmsPortTypeClient.GetBindingForEndpoint(EndpointConfiguration.SmsHttpPort));
 }
Esempio n. 6
0
 public SmsPortTypeClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(SmsPortTypeClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Esempio n. 7
0
 public SmsPortTypeClient(EndpointConfiguration endpointConfiguration) :
     base(SmsPortTypeClient.GetBindingForEndpoint(endpointConfiguration), SmsPortTypeClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Esempio n. 8
0
 public SmsPortTypeClient() :
     base(SmsPortTypeClient.GetDefaultBinding(), SmsPortTypeClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.SmsHttpPort.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Esempio n. 9
0
 private ShortMessageHelper(SmsPortTypeClient smsClient)
 {
     this.client = smsClient;
 }
Esempio n. 10
0
        public static SmsProvider RegisterProvider(
            ProviderElement providerConfiguration,
            X509Certificate2 vasaCertificate,
            String vCenter,
            String vCenterUserName,
            String vCenterPassword)
        {
            SmsProvider provider;

            var smsData = new VasaProviderSpec
            {
                name        = providerConfiguration.Name,
                url         = String.Format("{0}", providerConfiguration.VasaVersionXmlUri),
                username    = providerConfiguration.Credentials.Login,
                password    = providerConfiguration.Credentials.Password,
                certificate = Convert.ToBase64String(vasaCertificate.RawData)
            };

            var binding = new BasicHttpsBinding {
                AllowCookies = true
            };
            var vimEndpoint = new EndpointAddress(string.Format("https://{0}/sdk/vimService", vCenter));
            var smsEndpoint = new EndpointAddress(string.Format("https://{0}/sms/sdk", vCenter));

            ServicePointManager.ServerCertificateValidationCallback += (sender, x509Certificate, chain, errors) => true;

            using (var client = new VimPortTypeClient(binding, vimEndpoint))
            {
                client.Open();

                var vimProxy = new VimProxy(client);

                string sessionId;

                var content = vimProxy.RetrieveServiceContent();

                var vCenterCredential = new NetworkCredential
                {
                    UserName = vCenterUserName, Password = vCenterPassword
                };
                vimProxy.Login(content.sessionManager, vCenterCredential, null, out sessionId);

                using (var smsClient = new SmsPortTypeClient(binding, smsEndpoint))
                {
                    smsClient.Open();

                    var smsProxy       = new SmsProxy(smsClient, sessionId);
                    var storageManager = smsProxy.QueryStorageManager();
                    var taskRef        = smsProxy.RegisterProvider(storageManager, smsData);

                    var timeout = TimeSpan.FromMinutes(10);
                    if (!smsProxy.WaitSmsTask(taskRef, timeout))
                    {
                        try
                        {
                            var vimTaskRef = new DataCore.Vim.ManagedObjectReference {
                                type = taskRef.type, Value = taskRef.Value
                            };
                            client.CancelTask(vimTaskRef);
                        }
                        catch (Exception ex)
                        {
                            _traceSource.TraceEvent(TraceEventType.Warning, 0,
                                                    Resources.ErrorCancelingVasaProviderRegistration,
                                                    taskRef.Value, ex.ToString());
                        }

                        var msg = String.Format(
                            Resources.VasaProviderRegistrationTimeoutError,
                            taskRef.Value, timeout);

                        _traceSource.TraceEvent(TraceEventType.Error, 0, msg);
                        throw new TimeoutException(msg);
                    }

                    var task = smsProxy.QuerySmsTaskInfo(taskRef);

                    if (task.state.Equals("error", StringComparison.OrdinalIgnoreCase))
                    {
                        var error = task.error;

                        var msg = String.Format(
                            Resources.ErrorOnVasaProviderRegistration,
                            error.fault.GetType().Name, error.localizedMessage);

                        _traceSource.TraceEvent(TraceEventType.Error, 0, msg);
                        throw new Exception(msg);
                    }

                    var result =
                        smsProxy.QuerySmsTaskResult(taskRef);

                    var providerInfo =
                        smsProxy.QueryProviderInfo((Sms.ManagedObjectReference)result);

                    provider = GetProvider(providerInfo);

                    smsClient.Close();
                }
                vimProxy.Logout(content.sessionManager);
                client.Close();
            }

            return(provider);
        }