随着贷款,信用消费等兴起,如今越来越多公司需要客户的运营商报告
然后数据量非常大的运营商报告,即使客户自己也很难齐全地获取,这时候,就需要客户授权给我们,进行运营商数据的爬取
注意,运营商数据三网的爬取方式都是不同的,今天先以移动为例说明:
大体流程:客户授权 -> 分发程序 -> 开始爬取
如果有问题的朋友,或者想直接调用已开发好的接口,都可随时联系:手机/微信:15625101713
using Gecko;
using Gecko.Net;
using Gecko.Observers;
using Gecko.WebIDL;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FireFox
{
public partial class Form1 : Form
{
string phone = "";//
string app = "";
string tel = "";
string serviceP = ""; // 客户提供的服务密码
string company = "";
string region = "";
string action = "";
List<long> fileList = new List<long>();
HashSet<string> hs = new HashSet<string>();//存储最后数据
int globalCountDown = 0;//全局倒计时
GeckoWebBrowser geckoBrowser;
Dictionary<string, string> HttpDataDic = new Dictionary<string, string>();
remoteS.loanSoapClient a = new remoteS.loanSoapClient();
string[] monthList = new string[7];//中国移动月份参数
string[] typeList = new string[7];//中国移动拉取数据分类参数
//本地
//string FilePath = @"";
//服务器
string FilePath = @"";
public Form1(string phonePass, string appPass, string pwd)
{
phone = phonePass;
app = appPass;
serviceP = pwd;
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (phone != "" && app != "" && serviceP != "")
{
InitTypeAndMonth();
InitWebBrowser();
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += SetFristLoginAccountAndServierCode;
timer1.Interval = 5000;
timer1.Enabled = true;
}
else
{
this.Close();
}
}
/// <summary>
/// 初始化月份和数据分类参数的List
/// </summary>
void InitTypeAndMonth()
{
for (int i = 0; i < monthList.Length; i++)
{
monthList[i] = DateTime.Now.AddMonths(-i).ToString("yyyyMM");
typeList[i] = (i + 1).ToString().PadLeft(2, '0');
}
}
/// <summary>
/// 初始化浏览器
/// </summary>
private void InitWebBrowser()
{
string YYSWEB = "https://login.10086.cn/html/window/loginMini.html";
HttpWebRequest webReq2 = (System.Net.HttpWebRequest)WebRequest.Create("http://apis.juhe.cn/mobile/get?phone=" + tel + "&dtype=&key=您自己的key(可加微信:15625101713 获取 或直接调用接口)");
HttpWebResponse response2 = (HttpWebResponse)webReq2.GetResponse();
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.UTF8);
string ret2 = sr2.ReadToEnd();
JToken jo2 = (JToken)JsonConvert.DeserializeObject(ret2);
try
{
company = jo2["result"]["company"].ToString();
region = jo2["result"]["province"].ToString();
}
catch { }
switch (region)
{
case "广西": region = "广西壮族自治区"; break;
case "内蒙古": region = "内蒙古自治区"; break;
case "宁夏": region = "宁夏回族自治区"; break;
case "重庆": region = "重庆直辖市"; break;
case "北京": region = "北京直辖市"; break;
case "上海": region = "上海直辖市"; break;
default: region = region + "省"; break;
}
HttpWebRequest webReq = (System.Net.HttpWebRequest)WebRequest.Create(VPN代理商 (可加微信:15625101713 获取 或直接调用接口));
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string ret = sr.ReadToEnd();
JToken jo = (JToken)JsonConvert.DeserializeObject(ret);
try
{
#region 独立cookie的代码
var app_dir = Environment.CurrentDirectory;//程序目录
string cookiesName = DateTime.Now.ToString("yyyyMMddHHmmss") + phone + app;
string directory = Path.Combine(app_dir, "Cookies", cookiesName);//cookie目录
if (!System.IO.Directory.Exists(directory))
System.IO.Directory.CreateDirectory(directory);//检测目录是否存在
Gecko.Xpcom.ProfileDirectory = directory;//绑定cookie目录
FileStream fs1 = new FileStream(FilePath + "running" + phone + app + ".txt", System.IO.FileMode.Append, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine("deletePath:" + cookiesName);
sw1.WriteLine("------");
sw1.Close();
fs1.Close();
#endregion
Xpcom.Initialize(Path.Combine(app_dir, "FireFox"));//初始化 Xpcom
geckoBrowser = new GeckoWebBrowser() { Dock = DockStyle.Fill }; //创建浏览器实例
this.geckoBrowser.Name = "browser";
geckoBrowser.CreateControl();
panel1.Controls.Add(geckoBrowser);//把浏览器加入到选择夹控件内
GeckoPreferences.User["gfx.font_rendering.graphite.enabled"] = true;//设置偏好:字体
GeckoPreferences.User["privacy.donottrackheader.enabled"] = true;//设置浏览器不被追踪
GeckoPreferences.User["general.useragent.override"] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:59.0) Gecko/20100101 Firefox/59.0";
GeckoPreferences.User["intl.accept_languages"] = "zh-CN,zh;q=0.9,en;q=0.8";//不设置的话默认是英文区
#region 设置ip代理
var ip = jo["data"][0]["IP"].ToString();
var port = jo["data"][0]["Port"].ToString();
GeckoPreferences.User["network.proxy.http"] = ip;
GeckoPreferences.User["network.proxy.http_port"] = int.Parse(port);
GeckoPreferences.User["network.proxy.type"] = 1;
#endregion
geckoBrowser.Navigate(YYSWEB);
geckoBrowser.UseHttpActivityObserver = true;
geckoBrowser.ObserveHttpModifyRequest += Browser_ObserveHttpModifyRequest;
MyObserver MyObs = new MyObserver();
MyObs.TicketLoadedEvent += MyObs_TicketLoadedEvent;//如何处理捕捉到的response
MyObs.targetUrls = new List<string>() { "detailbillinfojsonp/" + tel, };//添加要拦截的url关键词
ObserverService.AddObserver(MyObs);//添加观察器
}
catch { }
}
#region 方法
/// <summary>
/// 拦截HTTP请求的类
/// </summary>
public class MyObserver : BaseHttpModifyRequestObserver
{
public delegate void TicketLoadedEventHandler(HttpChannel p_HttpChannel, object sender, System.EventArgs e);
/// <summary>
/// 处理事件委托
/// </summary>
public event TicketLoadedEventHandler TicketLoadedEvent;
/// <summary>
/// 需要拦截的网址,只要独一无二的关键词既可
/// </summary>
public List<string> targetUrls = new List<string>() { };
protected override void ObserveRequest(HttpChannel p_HttpChannel)
{
if (p_HttpChannel != null)
{
if (targetUrls.Any(s => p_HttpChannel.Uri.AbsoluteUri.Contains(s)))
{
TraceableChannel oTC = p_HttpChannel.CastToTraceableChannel();
StreamListenerTee oStream = new StreamListenerTee();
oStream.Completed += (sender, e) => TicketLoadedEvent(p_HttpChannel, sender, e);
oTC.SetNewListener(oStream);
}
}
}
}
public class NoPromptService : PromptService
{
public override void Alert(string dialogTitle, string text)
{
}
}
/// <summary>
/// 拦截请求
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Browser_ObserveHttpModifyRequest(object sender, GeckoObserveHttpModifyRequestEventArgs e)
{
}
/// <summary>
/// 拦截请求 现在用这个
/// </summary>
/// <param name="p_HttpChannel"></param>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MyObs_TicketLoadedEvent(Gecko.Net.HttpChannel p_HttpChannel, object sender, EventArgs e)
{
if (sender is StreamListenerTee)
{
if (getHttpRequestData)//登陆之后才可以爬
{
GetHttpRequestData(p_HttpChannel);
getHttpRequestData = false;
}
}
}
/// <summary>
/// 检测第一次登陆是否正确
/// </summary>
/// <returns></returns>
string LoginError()
{
string str = "";
try
{
if (geckoBrowser.Document.GetHtmlElementById("phone_error").Style.CssText.Contains("block"))
str += "[手机号]";
if (geckoBrowser.Document.GetHtmlElementById("phonepwd_error").Style.CssText.Contains("block"))
str += "[服务密码]";
if (geckoBrowser.Document.GetHtmlElementById("smsCode_error").Style.CssText.Contains("block"))
str += "[短信验证码]";
if (str != "")
{
return str + "有误,请关闭页面再重试";
}
else
{
return "未知错误,请关闭页面再重试";
}
}
catch
{
return "200";
}
}
/// <summary>
/// 为input设置值
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
bool SetValue(string id, string value)
{
try
{
GeckoHtmlElement ghe = geckoBrowser.Document.GetHtmlElementById(id);
ghe.Focus();
DomEventArgs ev = geckoBrowser.Document.CreateEvent("KeyEvents");//创建一个事件容器?
Event webEvent = new Event(geckoBrowser.Window.DomWindow, ev.DomEvent as nsISupports);//创建一个事件?
nsIDOMKeyEvent nsIEventVar = ((nsIDOMKeyEvent)ev.DomEvent); //创建一个键盘事件?
for (int i = 0; i < value.Length; i++)
{
Keys k1 = (Keys)value[i];
nsIEventVar.InitKeyEvent(new nsAString("keypress"), true, false, geckoBrowser.Window.DomWindow, false, false, false, false, (uint)k1, (uint)k1); //初始化键盘事件
ghe.GetEventTarget().DispatchEvent(ev); //触发
nsIEventVar.InitKeyEvent(new nsAString("keyup"), true, false, geckoBrowser.Window.DomWindow, false, false, false, false, (uint)k1, (uint)k1); //初始化键盘事件
ghe.GetEventTarget().DispatchEvent(ev); //触发
}
geckoBrowser.Document.Body.Click();
ghe.Blur();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 点击事件
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
bool ClickClick(string id)
{
try
{
geckoBrowser.Document.GetHtmlElementById(id).Click();
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 设置httpData 的 Dictionary
/// </summary>
/// <param name="dic"></param>
/// <param name="key"></param>
/// <param name="value"></param>
void AddDataToDictionary(Dictionary<string, string> dic, string key, string value)
{
if (dic.ContainsKey(key))
{
dic[key] = value;
}
else
{
dic.Add(key, value);
}
}
#endregion
string verifyCode1 = "";
string verifyCode2 = "";
string verifyPicture = "";
/// <summary>
/// 全局倒计时的timer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer_global_Tick(object sender, EventArgs e)
{
globalCountDown++;
if (globalCountDown > 360)
{
// MessageBox.Show("已经6分钟了");
this.Close();
}
}
void SetFristLoginAccountAndServierCode(object sender, EventArgs e)
{
if (SetValue("p_name", phone))
{
if (SetValue("p_pwd", serviceP))
{
if (ClickClick("getSMSpwd2"))
{
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 1000;
timer1.Tick += SetFristLoginVerifyCode;
timer1.Enabled = true;
timer_global.Enabled = true;
}
}
}
if (globalCountDown > 60)
{
MessageBox.Show("一分钟过了");
}
}
void SetFristLoginVerifyCode(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(FilePath + "running" + phone + app + ".txt", Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("smsCode"))
{
string[] cut = line.ToString().Split(':');
verifyCode1 = cut[1];
}
}
sr.Close();
if (verifyCode1 != "")//在数据库拿
{
if (SetValue("smsCode", verifyCode1))
{
if (ClickClick("submit_bt"))
{
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 2000;
timer1.Tick += CheckFirstLoginError;
timer1.Enabled = true;
}
}
}
}
void CheckFirstLoginError(object sender, EventArgs e)
{
string errorMessage = LoginError();
if (errorMessage == "200")
{
geckoBrowser.Navigate("https://shop.10086.cn/i/?f=billdetailqry");
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 2000;
timer1.Tick += GoToBill;
timer1.Enabled = true;
}
else
{
FileStream fs1 = new FileStream(FilePath + "running" + phone + app + ".txt", System.IO.FileMode.Append, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine("s1:" + errorMessage);
sw1.WriteLine("------");
sw1.Close();
fs1.Close();
this.Close();
}
}
int testIsLogin = 0;
void GoToBill(object sender, EventArgs e)
{
GeckoHtmlElement he_logout = null;
if (testIsLogin < 10)
{
try
{
he_logout = geckoBrowser.Document.GetHtmlElementById("logout");
}
catch { }
if (he_logout == null)
{
testIsLogin++;
}
}
else
{
this.Close();
}
GeckoHtmlElement he_loginStr = null;
try
{
he_loginStr = geckoBrowser.Document.GetHtmlElementById("loginStr");
if (he_loginStr != null)
{
GeckoElement temp = null;
try
{
temp = geckoBrowser.Document.GetElementsByClassName("ui-dialog")[0] as GeckoHtmlElement;
}
catch
{
}
if (temp == null && globalCountDown > 65)
{
ClickClick("month1");
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 2000;
timer1.Tick += GetSecondVerifyCode;
timer1.Enabled = true;
}
}
}
catch
{ }
}
GeckoElement verifyCode = null;
void GetSecondVerifyCode(object sender, EventArgs e)
{
ImageCreator imageCreator = new ImageCreator(geckoBrowser);
try
{
if (verifyCode == null)
{
verifyCode = geckoBrowser.DomDocument.GetElementById("imageVec");
verifyCode.SetAttribute("style", "position:fixed;top:0;left:0;");
}
else
{
pictureBox1.Width = verifyCode.ClientWidth;
pictureBox1.Height = verifyCode.ClientHeight;
byte[] b = imageCreator.CanvasGetPngImage((uint)0 + 16, (uint)0, (uint)verifyCode.ClientWidth, (uint)verifyCode.ClientHeight);
MemoryStream ms = new MemoryStream(b);
pictureBox1.Image = Image.FromStream(ms);
Image vicoImg = Image.FromStream(ms);
vicoImg.Save(FilePath + phone + ".jpg");
FileStream fs1 = new FileStream(FilePath + "running" + phone + app + ".txt", System.IO.FileMode.Append, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine("imageAdd:" + "yes");
sw1.WriteLine("------");
sw1.Close();
fs1.Close();
//databaseConnection dc = new databaseConnection();
//dc.uploadPic(pictureBox1, "update towerYYS set verifyCode = @imgname where phone = '" + phone + "' and app = '" + app + "' ");
PromptFactory.PromptServiceCreator = () => new NoPromptService();
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 2000;
timer1.Tick += ClickSecondSMSVerify;
timer1.Enabled = true;
}
}
catch
{ }
}
void ClickSecondSMSVerify(object sender, EventArgs e)
{
ClickClick("stc-send-sms");
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 1000;
timer1.Tick += SetSecondVerifyCode1;
timer1.Enabled = true;
}
void SetSecondVerifyCode1(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(FilePath + "running" + phone + app + ".txt", Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("smsSecondCode"))
{
string[] cut = line.ToString().Split(':');
verifyCode2 = cut[1];
}
if (line.Contains("imageCode"))
{
string[] cut = line.ToString().Split(':');
verifyPicture = cut[1];
}
}
sr.Close();
if (verifyCode2 != "" && verifyPicture != "")
{
if (SetValue("vec_imgcode", verifyPicture))
{
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 500;
timer1.Tick += SetSecondVerifyCode2;
timer1.Enabled = true;
}
}
}
void SetSecondVerifyCode2(object sender, EventArgs e)
{
if (verifyCode2 != "" && verifyPicture != "")
{
if (SetValue("vec_smspasswd", verifyCode2))
{
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 500;
timer1.Tick += SetSecondVerifyCode3;
timer1.Enabled = true;
}
}
}
void SetSecondVerifyCode3(object sender, EventArgs e)
{
if (SetValue("vec_servpasswd", serviceP))
{
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 500;
timer1.Tick += SetSecondVerifyCode4;
timer1.Enabled = true;
}
}
void SetSecondVerifyCode4(object sender, EventArgs e)
{
if (ClickClick("vecbtn"))
{
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 1000;
timer1.Tick += SecondLoadingError;
timer1.Enabled = true;
getHttpRequestData = true;
}
}
void SecondLoadingError(object sender, EventArgs e)
{
string errorMessage = "";
try
{
errorMessage = geckoBrowser.Document.GetHtmlElementById("detailerrmsg").GetAttribute("style");
if (errorMessage.Contains("block"))
{
///第二次登录出错
///
FileStream fs1 = new FileStream(FilePath + "running" + phone + app + ".txt", System.IO.FileMode.Append, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine("s1:" + "短信验证码或图片验证码错误,请关闭页面重试");
sw1.WriteLine("------");
sw1.Close();
fs1.Close();
}
}
catch
{ }
timer1.Enabled = false;
}
bool getHttpRequestData = false;
void GetHttpRequestData(Gecko.Net.HttpChannel p_HttpChannel)
{
string path = Path.Combine(Environment.CurrentDirectory, "TempText", DateTime.Now.ToString("yyyyMMddHHmmss") + phone + app + ".txt");
string oldurl = p_HttpChannel.OriginalUri.ToString();
string[] forcut = oldurl.Split('?');
string url = forcut[0];
string[] query = forcut[1].Split('&');
string tempUrl = "?callback=" + query[0].Split('=')[1] + "&curCuror=" + query[1].Split('=')[1] + "&step=" + query[2].Split('=')[1] + "&";
AddDataToDictionary(HttpDataDic, "Path", path);
AddDataToDictionary(HttpDataDic, "Url", url + tempUrl);
AddDataToDictionary(HttpDataDic, "Host", p_HttpChannel.GetRequestHeader("Host"));
AddDataToDictionary(HttpDataDic, "Accept", p_HttpChannel.GetRequestHeader("Accept"));
AddDataToDictionary(HttpDataDic, "Accept-Language", p_HttpChannel.GetRequestHeader("Accept-Language"));
AddDataToDictionary(HttpDataDic, "Accept-Encoding", p_HttpChannel.GetRequestHeader("Accept-Encoding"));
AddDataToDictionary(HttpDataDic, "Content-Type", p_HttpChannel.GetRequestHeader("Content-Type"));
AddDataToDictionary(HttpDataDic, "X-Requested-With", p_HttpChannel.GetRequestHeader("X-Requested-With"));
AddDataToDictionary(HttpDataDic, "Connection", p_HttpChannel.GetRequestHeader("Connection"));
AddDataToDictionary(HttpDataDic, "Referer", p_HttpChannel.GetRequestHeader("Referer"));
AddDataToDictionary(HttpDataDic, "Cookie", p_HttpChannel.GetRequestHeader("Cookie"));
timer1.Enabled = false;
timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 500;
timer1.Tick += papaTimer;
timer1.Enabled = true;
}
int m_index = 0;
int t_index = 0;
StringBuilder stringBuilder = new StringBuilder();
void papaTimer(object sender, EventArgs e)
{
try
{
long ts = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
string tempurl = "qryMonth=" + monthList[m_index] + "&billType=" + typeList[t_index] + "&" + "_=" + ts;
string url = HttpDataDic["Url"] + tempurl;
//创建请求
HttpWebRequest request = WebRequest.CreateHttp(url);
//request.Host = HttpDataDic["Host"];
request.Accept = HttpDataDic["Accept"];
request.Headers.Add("Accept-Language", HttpDataDic["Accept-Language"]);
request.Headers.Add("Accept-Encoding", HttpDataDic["Accept-Encoding"]);
request.ContentType = HttpDataDic["Content-Type"];
request.Headers.Add("X-Requested-With", HttpDataDic["X-Requested-With"]);
request.KeepAlive = true; //Connection属性
request.Referer = HttpDataDic["Referer"];
request.Headers.Add("Cookie", HttpDataDic["Cookie"]);
Task<WebResponse> res_async = request.GetResponseAsync();
while (!res_async.IsCompleted)
{
Thread.Sleep(500);
timer1.Enabled = false;
}
System.Net.HttpWebResponse response = res_async.Result as HttpWebResponse;
Stream stream = response.GetResponseStream();
if (response.ContentEncoding.ToLower().Contains("gzip"))
{
stream = new GZipStream(stream, CompressionMode.Decompress);
}
string responseData = "";
using (StreamReader sr = new StreamReader(stream))
{
responseData = sr.ReadToEnd();
}
string newData = responseData.Substring(responseData.IndexOf('(') + 1, responseData.LastIndexOf(')') - (responseData.IndexOf('(') + 1));
timer1.Enabled = true;
WriteDataToText(newData);
}
catch
{
if (timer1.Enabled == false)
{
timer1.Enabled = true;
}
}
}
void WriteDataToText(string newData)
{
if (!newData.Contains("\"retCode\":\"000000\""))
{
newData = "{}";
}
if (t_index < 4)//类型未拉到最后
{
if (m_index < 6)//月份未拉到最后
{
if (m_index == 0)
{
string temp = "";
switch (t_index)
{
case 0: temp += "\"package\":["; break;
case 1: temp += "\"call\":["; break;
case 2: temp += "\"sms \":["; break;
case 3: temp += "\"net\":["; break;
case 4: temp += "\"increment\":["; break;
//case 5: temp += "\"collection\":["; break;
//case 6: temp += "\"other\":["; break;
}
string insertStr = temp + newData + ",";
stringBuilder.Append(temp);
m_index++;
}
else
{
stringBuilder.Append(newData + ",");
m_index++;
}
}
else//月份到最后
{
stringBuilder.Append(newData + "],");
m_index++;
m_index = 0;
t_index++;
}
}
else
{
string path = HttpDataDic["Path"];
{
stringBuilder.Insert(0, "{");
stringBuilder.Replace(",", "}", stringBuilder.Length - 1, 1);
byte[] BA = System.Text.Encoding.Default.GetBytes(stringBuilder.ToString());
string connectionString = a.setConnectionString("");
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand com = new SqlCommand("insert into 。。。", conn);
com.Parameters.Add("json", SqlDbType.Image);
com.Parameters["json"].Value = BA;
com.ExecuteNonQuery();
conn.Close();
}
timer1.Enabled = false;
FileStream fs1 = new FileStream(FilePath + "running" + phone + app + ".txt", System.IO.FileMode.Append, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine("state:" + "succeed");
sw1.WriteLine("------");
sw1.Close();
fs1.Close();
a.notReadDB("update ... ", "");
}
this.Close();
}
}
private void modifyName(string oldName, string newName)
{
if (FilePath != "")
{
if (System.IO.File.Exists(FilePath + oldName))
{
FileInfo fi = new FileInfo(FilePath + oldName);
fi.MoveTo(FilePath + newName);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
verifyCode1 = textBox1.Text;
}
private void button2_Click(object sender, EventArgs e)
{
verifyCode2 = textBox2.Text;
}
private void button3_Click(object sender, EventArgs e)
{
verifyPicture = textBox3.Text;
}
private void timer1_Tick(object sender, EventArgs e)
{
}
Queue<string> qu = new Queue<string>();
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
modifyName("running" + phone + app + ".txt", "end" + phone + app + ".txt");
DirectoryInfo root = new DirectoryInfo(FilePath);
foreach (FileInfo f in root.GetFiles())
{
if (f.Name.Contains(phone) && f.Extension == ".jpg")
{
qu.Enqueue(f.Name);
}
}
for (int i = 0; i < qu.Count; i++)
{
System.IO.File.Delete(FilePath + qu.Dequeue());
}
}
}
}
查询结果
参考:https://blog.csdn.net/JamesData/article/details/103178888