Beispiel #1
0
        /// <summary>
        /// 设置发送短信参数值
        /// </summary>
        /// <param name="msgInfoParam">Message info parameter.</param>
        private void SetRestRequestParams(SmsInfoParam smsInfoParam)
        {
            if (!requestSmsParams.ContainsKey("key"))
            {
                requestSmsParams.Add("key", smsInfoParam.Key);
            }
            else
            {
                requestSmsParams ["key"] = smsInfoParam.Key;
            }

            if (!requestSmsParams.ContainsKey("eaction"))
            {
                requestSmsParams.Add("eaction", smsInfoParam.Eaction);
            }
            else
            {
                requestSmsParams ["eaction"] = smsInfoParam.Eaction;
            }
            if (!requestSmsParams.ContainsKey("ePhoneNumber"))
            {
                requestSmsParams.Add("ePhoneNumber", smsInfoParam.EphoneNumber);
            }
            else
            {
                requestSmsParams ["ePhoneNumber"] = smsInfoParam.EphoneNumber;
            }
            if (!requestSmsParams.ContainsKey("ePassword"))
            {
                requestSmsParams.Add("ePassword", smsInfoParam.EpassWord);
            }
            else
            {
                requestSmsParams ["ePassword"] = smsInfoParam.EpassWord;
            }
            if (!requestSmsParams.ContainsKey("eNickName"))
            {
                requestSmsParams.Add("eNickName", smsInfoParam.EnickName);
            }
            else
            {
                requestSmsParams ["eNickName"] = smsInfoParam.EnickName;
            }
            if (!requestSmsParams.ContainsKey("md5"))
            {
                requestSmsParams.Add("md5", smsInfoParam.Md5);
            }
            else
            {
                requestSmsParams ["md5"] = smsInfoParam.Md5;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="phoneNum">Phone number.</param>
        private void SendSMS(string _phoneNumber)
        {
            ProgressDialogUtil.StartProgressDialog(this, "正在发送验证码...");

            //检测网络连接
            if (!EldYoungUtil.IsConnected(this))
            {
                Toast.MakeText(this, "网络连接超时,请检测网路", ToastLength.Short).Show();
                ProgressDialogUtil.StopProgressDialog();
                return;
            }

            var smsInfoParam = new SmsInfoParam()
            {
                PhoneNumber = phoneNum, NickName = nickName, PassWord = passWord
            };

            //使用restsharpApi方式

            SetRestRequestParams(smsInfoParam);

            var restSharpRequestHelp = new RestSharpRequestHelp(smsInfoParam.Url, requestSmsParams);

            restSharpRequestHelp.ExcuteAsync((response) => {
                if (response.ResponseStatus == ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    //获取并解析返回resultJson获取安全码结果值
                    var resultJson = response.Content;
                    var smsJson    = JsonConvert.DeserializeObject <SmsJson>(resultJson);
                    if (smsJson.statuscode == "1")
                    {
                        RunOnUiThread(() => {
                            securityCode = smsJson.data.ToString();

                            mc.Start();
                            tv_SendCodeStatusShow.Visibility = ViewStates.Visible;
                        });
                    }
                    else
                    {
                        RunOnUiThread(() =>
                        {
                            tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
                            Toast.MakeText(this, smsJson.message, ToastLength.Short).Show();
                        });
                    }
                }
                else if (response.ResponseStatus == ResponseStatus.TimedOut)
                {
                    RunOnUiThread(() =>
                    {
                        tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
                        Toast.MakeText(this, "网络连接超时", ToastLength.Short).Show();
                    });
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
                        Toast.MakeText(this, response.StatusDescription, ToastLength.Short).Show();
                    });
                }
                RunOnUiThread(() =>
                {
                    ProgressDialogUtil.StopProgressDialog();
                    return;
                });
            });
        }
Beispiel #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="phoneNum">Phone number.</param>
        private void SendSMS(string _phoneNumber)
        {
            ProgressDialogUtil.StartProgressDialog(this, "正在发送验证码...");

            //检测网络连接
            if (!EldYoungUtil.IsConnected(this))
            {
                Toast.MakeText(this, "网络连接超时,请检测网路", ToastLength.Short).Show();
                ProgressDialogUtil.StopProgressDialog();
                return;
            }

            var smsInfoParam = new SmsInfoParam()
            {
                PhoneNumber = phoneNumber, NickName = nickName, PassWord = passWord
            };

            //使用restsharpApi方式

            SetRestRequestParams(smsInfoParam);

            var restSharpRequestHelp = new RestSharpRequestHelp(smsInfoParam.Url, requestParams);

            restSharpRequestHelp.ExcuteAsync((resoponse) => {
                if (resoponse.ResponseStatus == ResponseStatus.Completed && resoponse.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    //获取并解析返回resultJson获取安全码结果值
                    var result  = resoponse.Content;
                    var smsJson = JsonConvert.DeserializeObject <SmsJson>(result);
                    if (smsJson.statuscode == "1")
                    {
                        RunOnUiThread(() => {
                            Intent intent = new Intent(this, typeof(RegisterResultActivity));
                            var bundle    = new Bundle();
                            bundle.PutString("phoneNum", phoneNumber);
                            bundle.PutString("nickName", nickName);
                            bundle.PutString("passWord", passWord);
                            bundle.PutString("securityCode", smsJson.data.ToString());
                            intent.PutExtras(bundle);
                            StartActivity(intent);
                        });
                    }
                    else
                    {
                        RunOnUiThread(() =>
                        {
                            Toast.MakeText(this, smsJson.message, ToastLength.Short).Show();
                        });
                    }
                }
                else if (resoponse.ResponseStatus == ResponseStatus.TimedOut)
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "网络连接超时", ToastLength.Short).Show();
                    });
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, resoponse.StatusDescription, ToastLength.Short).Show();
                    });
                }
                RunOnUiThread(() =>
                {
                    ProgressDialogUtil.StopProgressDialog();
                    return;
                });
            });
        }