winform WebBroswer示例(联通号码查询)
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mshtml;
using System.Security.Cryptography;
using System.Web;
namespace LianTong
{
public partial class ltform : Form
{
//WebService引用
private ltifi.Service1SoapClient ifiobj = new LianTong.ltifi.Service1SoapClient();
//查询表对象
private ltifi.SelectUnicom sUnicom = new LianTong.ltifi.SelectUnicom();
//程序运行状态标识
//判断是否刷屏
private int islock = 0;
//记录上一个号码
private string oruoldnum = "";
//timer2运行状态
private bool timer2b = false;
//验证信息
private string str = "12345678";
//号码
private string orunum = "";
//用户姓名
private string username = "";
//信息编号:
private string oruId = "";
//余额
private string remain = "";
//编号记录
private string oruoldId = "";
public ltform()
{
InitializeComponent();
}
private void toolStripLabel1_Click(object sender, EventArgs e)
{
webpage.Url = new Uri("http://192.168.3.60:8080/java_redirect.php");
}
private void toolStripLabel2_Click(object sender, EventArgs e)
{
if (cbbtime.Text == "")
{
MessageBox.Show("请选择间隔时间,推荐5000毫秒");
return;
}
if (toolStripLabel2.Text == "开始查询")
{
toolStripLabel2.Text = "停止查询";
timer1.Interval = Convert.ToInt32(cbbtime.Text.ToString().Trim());
timer1.Enabled = true;
}
else
{
toolStripLabel2.Text = "开始查询";
timer1.Enabled = false;
timer2b = false;
timer2.Enabled = false;
}
}
private void webpage_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webpage.ReadyState < WebBrowserReadyState.Complete)
return;
}
private void webpage_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
try
{
HtmlDocument doc = webpage.Document.Window.Frames["right_page"].Document.Window.Frames["cash_pay_query"].Document;
IHTMLWindow2 win = (IHTMLWindow2)doc.Window.DomWindow;
string s = "function confirm(str) {";
s += "return false;";
s += "}";
win.execScript(s, "javascript");
string s1 = "function alert(str) {return '';}";
win.execScript(s1, "javascript");
}
catch (Exception)
{
throw;
}
try
{
HtmlDocument doc = webpage.Document.Window.Frames["right_page"].Document.Window.Frames["cash_pay_result"].Document;
IHTMLWindow2 win = (IHTMLWindow2)doc.Window.DomWindow;
string s = "function confirm(str) {";
s += "return false;";
s += "}";
win.execScript(s, "javascript");
string s1 = "function alert(str) {return '';}";
win.execScript(s1, "javascript");
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 开始抓取数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
string strorder = "";
try
{
strorder = ifiobj.selectOneSelectStratMobile(Encrypt(), "1");
}
catch (Exception)
{
throw;
}
if (str == "")
{
return;
}
string[] strunicom = strorder.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
//订单编号
oruId = strunicom[0].ToString().Trim();
//订单号码
orunum = strunicom[1].ToString().Trim();
//订单金额
if (oruId != "0" && orunum != "0")
{
toolStripLabel5.Text = orunum + ":正在查询";
if (submit())
{
}
else
{
toolStripLabel5.Text = orunum + ":查询失败";
databind(oruId, orunum, "查询失败", "0", "查询失败", 9);
}
}
}
private bool submit()
{
try
{
HtmlDocument doc = webpage.Document.Window.Frames["right_page"].Document.Window.Frames["cash_pay_query"].Document;
HtmlElement serverid = doc.All["txt_serverid"];
HtmlElement sreach = doc.All["cmd_query"];
if (serverid == null || sreach == null)
{
return false;
}
serverid.SetAttribute("value", orunum);
timer1.Enabled = false;
islock = 0;
sreach.InvokeMember("click");
//System.Threading.Thread.Sleep(2000);
timer2b = true;
timer2.Enabled = true;
timer2.Interval = 1000;
}
catch (Exception)
{
throw;
}
return true;
}
/// <summary>
/// 读取页面信息判断是否成功
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer2_Tick(object sender, EventArgs e)
{
if (islock < 5)
{
HtmlDocument doc1 = webpage.Document.Window.Frames["right_page"].Document.Window.Frames["cash_pay_query"].Document;
HtmlElement reset = doc1.All["cmd_reset"];
try
{
string frm_result = webpage.Document.Window.Frames["right_page"].Document.Window.Frames["cash_pay_result"].Document.All[0].InnerText;
string[] strorder = frm_result.Split(new string[] { "话费余额", "用户信息" }, StringSplitOptions.RemoveEmptyEntries);
if (strorder.Length > 1)
{
string[] userinfo = strorder[1].ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] useri = strorder[0].ToString().Split(new string[] { "代理商账户", "帐户信息" }, StringSplitOptions.RemoveEmptyEntries);
string[] usern = useri[1].ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
//对读取出的内容进行截取
username = usern[0].ToString();
remain = userinfo[userinfo.Length - 1];
oruoldnum = orunum;
toolStripLabel5.Text = orunum + ":查询成功";
databind(oruId, orunum, username, remain, "查询成功", 8);
oruoldId = oruId;
reset.InvokeMember("click");
timer2b = false;
timer1.Enabled = true;
timer2.Enabled = false;
islock++;
return;
}
islock++;
}
catch (Exception)
{
return;
}
}
else
{
HtmlDocument doc1 = webpage.Document.Window.Frames["right_page"].Document.Window.Frames["cash_pay_query"].Document;
HtmlElement reset = doc1.All["cmd_reset"];
timer2b = false;
toolStripLabel5.Text = orunum + ":查询失败";
databind(oruId, orunum, "查询失败", "0", "查询失败", 9);
reset.InvokeMember("click");
timer1.Enabled = true;
timer2.Enabled = false;
islock++;
}
}
private void ltform_Load(object sender, EventArgs e)
{
cbbtime.Text = "6000";
lvorder.Columns.Add("编号", 40);
lvorder.Columns.Add("号码", 80);
lvorder.Columns.Add("用户姓名", 80);
lvorder.Columns.Add("用户余额", 80);
lvorder.Columns.Add("状态", 120);
lvorder.GridLines = true; //显示表格线
lvorder.View = View.Details;//显示表格细节
lvorder.HeaderStyle = ColumnHeaderStyle.Clickable;//对表头进行设置
lvorder.FullRowSelect = true;//是否可以选择行
this.Text = "联通号码查询";
toolStripLabel5.Text = orunum + "联通号码查询";
}
/// <summary>
/// 联通充值数据信息状态更新
/// </summary>
/// <param name="ormd"> 信息编号</param>
/// <param name="ormn">号码</param>
/// <param name="ormoney">金额</param>
/// <param name="state">状态</param>
/// <param name="n">状态标识</param>
private void databind(string ormd, string ormn, string name, string money, string state, int n)
{
bool id = false;
sUnicom.scuId = Convert.ToInt32(ormd.Trim());
sUnicom.scuName = name;
sUnicom.scuExecTime = DateTime.Now;
sUnicom.scuState = n;
sUnicom.scuRemainAmount = Convert.ToDecimal(money.ToString());
try
{
id = ifiobj.updateOneSelectUnicom(Encrypt(), sUnicom);
if (!id)
id = ifiobj.updateOneSelectUnicom(Encrypt(), sUnicom);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
ListViewItem[] listViewItem = new ListViewItem[1];
listViewItem[0] = new ListViewItem(new string[] { ormd, ormn, name, money + "元", state });
lvorder.Items.AddRange(listViewItem);
}
/// <summary>
/// 加密数据
/// </summary>
/// <returns></returns>
public static string Encrypt()
{
string Text = "asuygp834p8934g8ye893rehfvasu78698734r";
string sKey = "as4564656uygp834p893";
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
return ret.ToString();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
timer2b = false;
webpage.Url = new Uri("http://192.168.3.60:8080/java_redirect.php");
}
}
}
转载于:https://www.cnblogs.com/gjs85/archive/2010/01/24/1655422.html
winform WebBroswer示例(联通号码查询)相关推荐
- 中国联通物联卡ICCID号码查询原理
近年来,中国联通物联卡因为种种原因爆红于通信市场,越来越多人开始加入中国联通物联卡办理大军,在推动物联网市场发展的同时也利用中国联通物联卡来实现自身产业的变革.随着中国联通物联卡使用人数增多,各种物联 ...
- 「SAP技术」SAP WM 如何根据TR号码查询TO号码?
「SAP技术」SAP WM 如何根据TR号码查询TO号码? 今日下午,收到K项目的仓库部门用户的提问,如何通过TR号码查找TO单号码.笔者想到了LT22 & LT23等TO查询的报表里,是可以 ...
- memcachedb 加 memcached engine无法提高 示例检索的查询速度
memcachedb 加 memcached engine无法提高 示例检索的查询速度,原因参加下文中红字所是 http://blog.s135.com/post/357/#entrymore 鉴于国 ...
- 智能实验室-身份证号码查询(IDio) 1.4.0.140
身份证号码查询(IDio)是用以根据身份证号码查找所属的省市区.出生年月日.性别等信息的工具. 特点: 1.准确及时:包括最新的行政区域信息: 2.地图定位:一键显示地区地图信息: 3.完全免费:我们 ...
- Winform开发框架之通用高级查询模块--SNF快速开发平台3.3-Spring.Net.Framework
最近项目确实忙,但也是一直忙于有关项目和框架技术的事情,也一直致力于改善我的WInform开发框架.使得自己及客户使用起来更加方便,更加友好,更加高效. 在很多程序模块中都很常见,也是给客户扩展查询的 ...
- 根据身份证号和社会保险号码查询不出您的医保信息 请核实后重新填写
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 今天打算 ...
- 携号转网查询(联通空号查询)
携号转网查询(联通空号查询) 1) 请求地址 http://www.591mf.top/home/query_is_null?phone=13113345586 2) 调用方式:HTTP post 3 ...
- 安卓开发之使用第三方的聚合数据API,QQ测吉凶案、身份证号码查询。
在安卓开发中,肯定需要很多API接口, 比如天气获.快递实时信息.身份证号码查询和基本的短信验证码. API(Application Programming Interface,应用程序编程接口)是一 ...
- Android 身份证号码查询、手机号码查询、天气查询
1.基本信息 身份证号码查询: http://apistore.baidu.com/apiworks/servicedetail/113.html 手机号码: http://apistore.baid ...
最新文章
- 使用OpenCV进行图像全景拼接
- android图片的处理方法,android 处理图片到固定像素解决办法
- slidingmenu 中view使用练习
- 自己动手写一个Struts2
- python内置函数——sorted、filter、map、format
- Java面试题系列之Java基础类库(一)
- Java 系列之spring学习--spring搭建(一)
- 等保2.0标准下,测评中重点关注的内容
- ASP.NET MVC Html.BeginForm用法1
- 介绍一款国际性的本体社群聊天软件Discord
- 安卓kotlin教程
- renderTo和applyTo的区别
- 塞班系统是如何没落的
- 倪光南回应方舟CPU失败论,企业失败不等于技术失败
- setuptools-scm was unable to detect version for‘…/…/某git包‘
- 东华考研复试21-30oj
- Docker部署rabbitmq遇到的两个问题
- 微信公众号配置网页授权域名报错:无法访问xxx指向的web服务器或虚拟主机的目录
- 怎样制作u盘系统安装盘图文教程
- GICv3软件overview手册之GICv3基本功能(1)
热门文章
- 用canvas画飞机大战(一步步详解附带源代码,源码和素材上传到csdn,可以免费下载)
- 计算机从哪找隐藏视频文件,什么是隐藏文件,如何查看隐藏文件?
- brpc访问MySQL_brpc一些笔记 -- 从http看协议实现
- 计算机软考能申请正高职称吗,拿到软考证书后如何申请评职称
- 黑客比程序员高在哪里?程序员厉害还是黑客厉害?
- PyTorch torch.Tensor.contiguous() 用法与理解
- .NET 是信息技术应用创新产业重要参与者
- Haproxy部署网站LB集群
- 解决 Unresolved variable $ 的两种方法
- windows 开机自启动设置 注册表修改