/// <summary> /// Sets the rest request parameters. /// </summary> /// <param name="registerInfoParam">Register info parameter.</param> private void SetRestRequestParams(RegisterInfoParam registerInfoParam) { if (!requestParams.ContainsKey ("key")) requestParams.Add ("key", registerInfoParam.Key); else requestParams ["key"] = registerInfoParam.Key; if (!requestParams.ContainsKey ("eaction")) requestParams.Add ("eaction", registerInfoParam.Eaction); else requestParams ["eaction"] = registerInfoParam.Eaction; if (!requestParams.ContainsKey ("ePhoneNumber")) requestParams.Add ("ePhoneNumber", registerInfoParam.EphoneNumber); else requestParams ["ePhoneNumber"] = registerInfoParam.EphoneNumber; if (!requestParams.ContainsKey ("ePassword")) requestParams.Add ("ePassword", registerInfoParam.EpassWord); else requestParams ["ePassword"] = registerInfoParam.EpassWord; if (!requestParams.ContainsKey ("eNickName")) requestParams.Add ("eNickName", registerInfoParam.EnickName); else requestParams ["eNickName"] = registerInfoParam.EnickName; if (!requestParams.ContainsKey ("md5")) requestParams.Add ("md5", registerInfoParam.Md5); else requestParams ["md5"] = registerInfoParam.Md5; }
/// <summary> /// Reister this instance. /// </summary> private void Reister() { ProgressDialogUtil.StartProgressDialog(this,"正在注册..."); //检测网络连接 if(!EldYoungUtil.IsConnected(this)) { Toast.MakeText(this,"网络连接超时,请检测网路",ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); return; } //todo:调用restapi注册,将用户名、密码信息写 var registerInfoParam = new RegisterInfoParam () { PhoneNumber = phoneNum,NickName = nickName,PassWord = passWord }; //初始化参数 SetRestRequestParams (registerInfoParam); var restSharpRequestHelp = new RestSharpRequestHelp(registerInfoParam.Url,requestParams); restSharpRequestHelp.ExcuteAsync ((response) => { if(response.ResponseStatus == ResponseStatus.Completed) { //获取并解析返回resultJson获取Guid结果值 if(response.StatusCode == System.Net.HttpStatusCode.OK) { var resultJson = response.Content; var registerJson = JsonConvert.DeserializeObject<RegisterJson>(resultJson); if(registerJson.statuscode=="1") { Global.MyInfo = registerJson.data.Table[0]; var Uid = Global.MyInfo.UId; var guidAsAlias = Uid.Replace("-","_"); //注册用户成功,写极光推送别名,进入主界面 _jpushUtil.SetAlias(guidAsAlias); sp_userinfo.Edit().PutString(Global.login_UserName,nickName).Commit(); sp_userinfo.Edit().PutString(Global.login_Password,passWord).Commit(); sp_userinfo.Edit().PutBoolean(Global.login_Password_Check,true).Commit(); RunOnUiThread(()=> { //跳转到功能主界面 var intent = new Intent(this,typeof(MainFragActivity)); intent.SetFlags(ActivityFlags.ClearTask|ActivityFlags.NewTask); StartActivity(intent); this.Finish(); ProgressDialogUtil.StopProgressDialog(); Toast.MakeText(this,"注册成功",ToastLength.Short).Show(); OverridePendingTransition(Android.Resource.Animation.SlideInLeft,Android.Resource.Animation.SlideOutRight); }); } else { //注册失败 RunOnUiThread(()=> { Toast.MakeText(this,registerJson.message,ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); return; }); } } } else if(response.ResponseStatus == ResponseStatus.TimedOut) { RunOnUiThread(()=> { Toast.MakeText(this,"网络连接超时",ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); return; }); } else { RunOnUiThread(()=> { Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show(); ProgressDialogUtil.StopProgressDialog(); return; }); } }); }