/// <summary> /// 设置发送短信参数值 /// </summary> /// <param name="msgInfoParam">Message info parameter.</param> private void SetRestRequestSendCodeParams(SendCodeParam sendcodeParam) { if (!requestsendcodeParams.ContainsKey ("key")) requestsendcodeParams.Add ("key", sendcodeParam.Key); else requestsendcodeParams ["key"] = sendcodeParam.Key; if (!requestsendcodeParams.ContainsKey ("eaction")) requestsendcodeParams.Add ("eaction", sendcodeParam.Eaction); else requestsendcodeParams ["eaction"] = sendcodeParam.Eaction; if (!requestsendcodeParams.ContainsKey ("ePhoneNumberOne")) requestsendcodeParams.Add ("ePhoneNumberOne", sendcodeParam.EphoneNumberOne); else requestsendcodeParams ["ePhoneNumberOne"] = sendcodeParam.EphoneNumberOne; if (!requestsendcodeParams.ContainsKey ("eType")) requestsendcodeParams.Add ("eType", sendcodeParam.Etype); else requestsendcodeParams ["eType"] = sendcodeParam.Etype; if (!requestsendcodeParams.ContainsKey ("md5")) requestsendcodeParams.Add ("md5", sendcodeParam.Md5); else requestsendcodeParams ["md5"] = sendcodeParam.Md5; }
/// <summary> /// 发送验证码 /// </summary> private void SendCode() { if (!ValidInput ()) { return; } ProgressDialogUtil.StartProgressDialog(this,"正在发送验证码..."); //检测网络连接 if(!EldYoungUtil.IsConnected(this)) { Toast.MakeText(this,"网络连接超时,请检测网络",ToastLength.Short).Show(); btn_Send.Enabled = true; ProgressDialogUtil.StopProgressDialog(); return; } var sendCodeParam = new SendCodeParam () { PhoneNumberOne = phoneNumber,Type = sendType }; //使用restsharpApi方式 SetRestRequestSendCodeParams (sendCodeParam); var restSharpRequestHelp = new RestSharpRequestHelp(sendCodeParam.Url,requestsendcodeParams); restSharpRequestHelp.ExcuteAsync ((RestSharp.IRestResponse response) => { if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK) { //获取并解析返回resultJson获取安全码结果值 var result = response.Content; var sendCodeJson = JsonConvert.DeserializeObject<SendCodeJson>(result); if(sendCodeJson.statuscode =="1") { RunOnUiThread(()=>{ securityCode = sendCodeJson.data.ToString(); ProgressDialogUtil.StopProgressDialog(); Toast.MakeText(this,"验证码发送成功",ToastLength.Short).Show(); tv_SendCodeStatusShow.Visibility = ViewStates.Visible; mc.Start(); }); } else { RunOnUiThread(()=> { Toast.MakeText(this,sendCodeJson.message,ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); btn_Send.Enabled = true; tv_SendCodeStatusShow.Visibility = ViewStates.Invisible; return; }); } } else if(response.ResponseStatus == RestSharp.ResponseStatus.TimedOut) { RunOnUiThread(()=> { Toast.MakeText(this,"网络连接超时",ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); btn_Send.Enabled = true; tv_SendCodeStatusShow.Visibility = ViewStates.Invisible; return; }); } else { RunOnUiThread(()=> { Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); btn_Send.Enabled = true; tv_SendCodeStatusShow.Visibility = ViewStates.Invisible; return; }); } }); }