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); }
private void BT_ZFB_REG_TB_SMS_ENTERVCODE_Click(object sender, EventArgs e) { string res = ""; bool isRevicedSmsCode = false; LogManager.WriteLog("msgAutoResetEvent 阻塞"); msgAutoResetEvent.Reset(); new Thread(() => { for (int i = 0; i < 5; i++) { Thread.Sleep(3000); res = SmsApi.GetMessage("2", TB_ZFB_REG_TB_ShouJi.Text); //您于2014年05月11日申请了手机验证,校验码是295768。如非本人操作,请拨0571-88158198【淘宝网】 if (!string.IsNullOrEmpty(res) && res.Contains("校验码是")) { isRevicedSmsCode = true; msgAutoResetEvent.Set(); LogManager.WriteLog("msgAutoResetEvent 释放"); break; } } if (!isRevicedSmsCode) { msgAutoResetEvent.Set(); LogManager.WriteLog("msgAutoResetEvent 释放.没有收到信息"); } }).Start(); LogManager.WriteLog("msgAutoResetEvent 等待"); msgAutoResetEvent.WaitOne(); LogManager.WriteLog("msgAutoResetEvent 继续"); TB_SMS_MSG.Text = res; if (isRevicedSmsCode) { int index1 = res.IndexOf("是") + 1; string num = res.Substring(index1, 6); LBS_sms.Text = num; TB_SMS_vcode.Text = num; string js2run = " document.getElementById('J_PhoneCheckCode').value='{0}';".With(TB_SMS_vcode.Text) + "document.getElementsByClassName('btn-s')[0].click();"; CefFrameHelper.ExcuteJs(_mfForm.MainCefFrame, js2run); } else { TB_SMS_MSG.Text = "没有收到验证码,耐心等等"; } }
public string GetMessage(SmsServer smstype, string phone) { return(SmsApi.GetMessage(ConvertServerId2(smstype), phone));// GetPhone(ConvertServerId2(smstype)) }