public static bool GetSmsOfPhone(string phone, ref string Vcode, string serverid) { string res = ""; bool isRevicedSmsCode = false; //释放一次 LogManager.WriteLog("msgAutoResetEvent 释放"); msgAutoResetEvent.Set(); LogManager.WriteLog("msgAutoResetEvent 阻塞"); msgAutoResetEvent.Reset(); new Thread(() => { int ReTryTelCount = int.Parse(ConfigHelper.GetValue("ReTrySingleTelReviceCount")); int ReTryTelCountInterTime = int.Parse(ConfigHelper.GetValue("ReTrySingleTelReviceInterTime")); for (int i = 0; i < ReTryTelCount; i++) { Thread.Sleep(ReTryTelCountInterTime * 1000); res = SmsApi.GetMessage(serverid, phone); //您于2014年05月11日申请了手机验证,校验码是295768。如非本人操作,请拨0571-88158198【淘宝网】 if (!string.IsNullOrEmpty(res) && res.Contains("校验码是")) { isRevicedSmsCode = true; msgAutoResetEvent.Set(); LogManager.WriteLog("msgAutoResetEvent 释放 取到验证码"); break; } else { LogManager.WriteLog("没有取到验证码 等待时间5秒钟 剩余等待次数{0} " .With(ReTryTelCount - i)); } } if (!isRevicedSmsCode) { LogManager.WriteLog("msgAutoResetEvent 释放.释放手机{0}".With(phone)); SmsApi.ReleasePhone(phone, serverid); msgAutoResetEvent.Set(); } }).Start(); LogManager.WriteLog("msgAutoResetEvent 等待"); msgAutoResetEvent.WaitOne(); LogManager.WriteLog("msgAutoResetEvent 继续 "); //SmsApi.ReleasePhone(sender.ToString(), "2"); if (!string.IsNullOrEmpty(res) && res.Contains("校验码是")) { // TB_TB_sms_res.Text = res; int index1 = res.IndexOf("是") + 1; Vcode = res.Substring(index1, 6); } return(isRevicedSmsCode); }
//淘宝V2 更换手机号码 //1.登录手机 //2.获取可用手机() // 2.1 获取手机 //3.获取可用短信 public void BT_TB_ChangeTel_Click(object sender, EventArgs e) { //1.登录手机 SmsConfigHelper.GetConfigOfSms(); if (!SmsApi.logined) { LBS_sms.Text = "登录失败"; return; } string phone = ""; Application.DoEvents(); lock (changeTel) { bool getPhoneOK = false; bool isVcodeOk = false; new Thread(() => { Thread.Sleep(2000); // bool isTelOK = false; for (int i = 0; i < 7; i++) { //2.1 检测是否当前已经通过手机验证 if (MainForm.state == BusinessStatus.regitster_confirm) { LogManager.WriteLog("当前不是获取手机号码{0}的页面了.".With(phone)); MainForm.state = BusinessStatus.new_email_reg_two; _mfForm.MainCefFrame.Browser.GoBack(); getPhoneOK = true; break; } //2.2 获取手机 phone = EnterPhone(); //2.3 检测手机是否可用 LogManager.WriteLog("check valueOfStyle"); string valueOfStyle = ""; bool is_valueOfStyle_ok = false; for (int j = 0; j < 3; j++) { valueOfStyle = CefFrameHelper.GetUrlListByHapId(MainCefFrame, "J_PhoneFormTip", "div", "style").FirstOrDefault(); LogManager.WriteLog("valueOfStyle:" + valueOfStyle); is_valueOfStyle_ok = valueOfStyle != null && valueOfStyle.Contains("hidden"); if (is_valueOfStyle_ok) { break; } else { Application.DoEvents(); Thread.Sleep(2000); } } if (valueOfStyle != null && valueOfStyle.Contains("hidden")) { //可用 LogManager.WriteLog("手机号码 {0} 可用.".With(phone)); isVcodeOk = UseThisPhoneNum(phone); if (isVcodeOk) { break; } else { //未获取到验证码的处理 TB_SMS_MSG.Text = "没有收到验证码,返回重新接收"; LogManager.WriteLog(TB_SMS_MSG.Text); // new Thread(() => { //页面上点击 返回修改手机号码 string js2run = "document.getElementById('J_RewritePhone').click()';"; CefFrameHelper.ExcuteJs(_mfForm.MainCefFrame, js2run); } } else { LogManager.WriteLog("手机号码 {1} 不可用.重新获取,{0}".With(5 - i, phone)); //释放单个手机 SmsApi.ReleasePhone(phone, "2"); } } if (!getPhoneOK || !isVcodeOk) { _mfForm.ShowStatus("获取手机失败,重新获取,或者自己去网站获取。"); } }).Start(); } // BT_ZFB_REG_TB_SMS_ENTERVCODE_Click(sender, e); }
public void ReleasePhone(string phone, SmsServer smstype) { SmsApi.ReleasePhone(phone, ConvertServerId2(smstype)); }