最近在老家出差,老家电网改革,使用了智能电表,把老式电表全部换了还给了一个客户号,
终于也可以在支付宝什么的交电费了,但我们那里支付宝还不能查询剩余多少钱,这让人很恼火,
于是就来国家电网http://www.95598.cn/person/index.shtml 查询了一下,发现需要客户号、查询密码、验证码,客户号我知道,查询密码是不知道的,随便输入,提示错误,
于是打95598问了下客服,得知了默认密码是6个8,查询了一下,出来消息了,但想每次都上电脑上查,貌似有点不方便,就想自己做一个模拟提交的,
模拟提交就要解决验证码识别的问题,看看也不复杂,就捣鼓了一会,然后分析提交的信息及url,
然后看到一个http://www.95598.cn/95598/per/shortCut/getShortCutAccount 这个地址,只传了2个参数,一个客户号,还有一个不知道是什么,
就直接测试了下这个url,post提交了两个参数,然后居然信息直接出来了,
还是josn格式。。。客户名称、电表地址、电表号,余额、违约金、欠费信息,还有部分类型的客户居然还带近期的电费记录,
到这我就想问特么你之前验证的查询密码和验证码了 干什么用的? 只是个慌子吗?我书都的少,你别骗我,這么大一个国家电网,居然这个查询密码是个渣?
好吧 代码我也上上来吧,但没什么技术含量了
////// 获取电费 /// /// 客户号 /// public static void GetPowerRate (T consNo) { HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.95598.cn/95598/per/shortCut/getShortCutAccount"); httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; httpWebRequest.Method = "POST"; var data = System.Text.Encoding.UTF8.GetBytes(string.Format("consNo={0}&orgNo=43101", consNo)); using (Stream stream = httpWebRequest.GetRequestStream()) { stream.Write(data, 0, data.Length); stream.Close(); } data = null; Result result = new Result(); try { HttpWebResponse webResponse = httpWebRequest.GetResponse() as HttpWebResponse; using (System.IO.StreamReader stream = new StreamReader(webResponse.GetResponseStream())) { result = Newtonsoft.Json.JsonConvert.DeserializeObject (stream.ReadToEnd()); } httpWebRequest = null; webResponse.Close(); webResponse = null; } catch { } result.billInfo.consNo = consNo.ToString(); Write(result); }
返回json 示例:
"{\"statusCode\":200,\"orgNo\":\"43101\",\"billInfo\":{\"errorCode\":null,\"count\":\"21\",\"errorMessage\":null,\"orgNo\":\"xxx52\",\"consNo\":\"1xxx4\",\"consName\":\"唐xx\",\"elecAddr\":\"岳麓-长沙市岳麓区望岳路xxx\",\"consSortCode\":\"城网低压居民\",\"rtnCode\":null,\"rtnMsg\":null,\"acctOrgNo\":null,\"purchaseType\":\"普通缴费\",\"balLists\":[ {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000360600225\",\"rcvblAmt\":\"27.64\",\"owePenalty\":\"0\",\"rcvedAmt\":\"27.64\",\"oweAmt\":\"0\",\"rcvblYm\":\"201412\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000384456503\",\"rcvblAmt\":\"27.64\",\"owePenalty\":\"0\",\"rcvedAmt\":\"27.64\",\"oweAmt\":\"0\",\"rcvblYm\":\"201501\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000417908221\",\"rcvblAmt\":\"1.76\",\"owePenalty\":\"0\",\"rcvedAmt\":\"1.76\",\"oweAmt\":\"0\",\"rcvblYm\":\"201503\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000458719783\",\"rcvblAmt\":\"32.93\",\"owePenalty\":\"0\",\"rcvedAmt\":\"32.93\",\"oweAmt\":\"0\",\"rcvblYm\":\"201505\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000475907830\",\"rcvblAmt\":\"33.52\",\"owePenalty\":\"0\",\"rcvedAmt\":\"33.52\",\"oweAmt\":\"0\",\"rcvblYm\":\"201506\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000494109461\",\"rcvblAmt\":\"114.13\",\"owePenalty\":\"0\",\"rcvedAmt\":\"114.13\",\"oweAmt\":\"0\",\"rcvblYm\":\"201507\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000517111477\",\"rcvblAmt\":\"84.67\",\"owePenalty\":\"0\",\"rcvedAmt\":\"5.87\",\"oweAmt\":\"78.8\",\"rcvblYm\":\"201508\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000400353270\",\"rcvblAmt\":\"11.76\",\"owePenalty\":\"0\",\"rcvedAmt\":\"11.76\",\"oweAmt\":\"0\",\"rcvblYm\":\"201502\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2015000435879133\",\"rcvblAmt\":\"8.23\",\"owePenalty\":\"0\",\"rcvedAmt\":\"8.23\",\"oweAmt\":\"0\",\"rcvblYm\":\"201504\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2013000201613636\",\"rcvblAmt\":\"148.59\",\"owePenalty\":\"0\",\"rcvedAmt\":\"148.59\",\"oweAmt\":\"0\",\"rcvblYm\":\"201312\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000206170080\",\"rcvblAmt\":\"288.76\",\"owePenalty\":\"0\",\"rcvedAmt\":\"288.76\",\"oweAmt\":\"0\",\"rcvblYm\":\"201401\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000213433834\",\"rcvblAmt\":\"178.57\",\"owePenalty\":\"0\",\"rcvedAmt\":\"178.57\",\"oweAmt\":\"0\",\"rcvblYm\":\"201402\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000220409307\",\"rcvblAmt\":\"0.59\",\"owePenalty\":\"0\",\"rcvedAmt\":\"0.59\",\"oweAmt\":\"0\",\"rcvblYm\":\"201403\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000224346917\",\"rcvblAmt\":\"9.41\",\"owePenalty\":\"0\",\"rcvedAmt\":\"9.41\",\"oweAmt\":\"0\",\"rcvblYm\":\"201404\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000235525969\",\"rcvblAmt\":\"22.34\",\"owePenalty\":\"0\",\"rcvedAmt\":\"22.34\",\"oweAmt\":\"0\",\"rcvblYm\":\"201405\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000250824152\",\"rcvblAmt\":\"24.7\",\"owePenalty\":\"0\",\"rcvedAmt\":\"24.7\",\"oweAmt\":\"0\",\"rcvblYm\":\"201406\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000265451425\",\"rcvblAmt\":\"32.34\",\"owePenalty\":\"0\",\"rcvedAmt\":\"32.34\",\"oweAmt\":\"0\",\"rcvblYm\":\"201407\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000287619069\",\"rcvblAmt\":\"100.55\",\"owePenalty\":\"0\",\"rcvedAmt\":\"100.55\",\"oweAmt\":\"0\",\"rcvblYm\":\"201408\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000302284130\",\"rcvblAmt\":\"97.02\",\"owePenalty\":\"0\",\"rcvedAmt\":\"97.02\",\"oweAmt\":\"0\",\"rcvblYm\":\"201409\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000329656994\",\"rcvblAmt\":\"34.1\",\"owePenalty\":\"0\",\"rcvedAmt\":\"34.1\",\"oweAmt\":\"0\",\"rcvblYm\":\"201410\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}, {\"statusCode\":\"非锁定\",\"rcvblAmtId\":\"2014000342784003\",\"rcvblAmt\":\"23.52\",\"owePenalty\":\"0\",\"rcvedAmt\":\"23.52\",\"oweAmt\":\"0\",\"rcvblYm\":\"201411\",\"rcvedPenalty\":null,\"billType\":\"正常电费\",\"addBal\":null}], \"acctBal\":\"0\",\"chargeBal\":null,\"freezeBal\":null,\"oweAmtSum\":\"78.8\",\"owePenaltySum\":\"0\",\"purchaseInfos\":null,\"levDisBeginYm\":null,\"levDisEndYm\":null,\"levDisAmt\":null,\"isLevDisFlag\":null,\"limitReason\":null},\"date\":\"2015-08-18\"}"////
示例中部分信息被我用xx代替了,
字段说明:
consN(客户号)、consName(客户姓名)、elecAddr(电表地址)、consSortCode类型、 acctBal(账户余额)、oweAmtSum(账户欠费)、
statusCode 固定为200 不管客户号有没有都是200 然后就是billInfo消息中如果consNo(客户号)为null则表示没有客户,
农村的返回稍微有点一样,但关键信息都有,今天不捣鼓了,洗洗睡了