- using System;
- using System.Net;
- using System.Drawing;
- using System.Text.RegularExpressions;
- using OnlineCard.Core;
- using CheckCodeLib;
- string cookieValue = CheckCodeHelper.SerializeCookie(cookie); //CheckCodeHelper为CheckCodeLib.dll中的方法目的是读取验证码的帮助类
- ViewState["CheckCodeCookieValue"] = cookieValue;
- //通过游戏区服取之相对应的ID值
- private int GetIdByZone(string GameZone)
- {
- int ZoneId=501;
- if(ViewState["orderStringId"] != null)
- {
- //IGameCardSaleMerchantOrder 名称空间using OnlineCard.Core;
- IGameCardSaleMerchantOrder gameSaleOrder = (IGameCardSaleMerchantOrder)MerchantOrderService.GetOrder(typeof(GameCardSaleMerchantOrder), ViewState["orderStringId"].ToString());
- if (gameSaleOrder != null)
- {
- //ZoneId=gameSaleOrder.Id;
- }
- }
- return ZoneId;
- }
- //根据游戏名称传替参数GameType
- string strGameName = txtGameName.Text.Trim();
- int GameType=-1;
- switch (strGameName)
- {
- case "仙境奇缘":
- GameType = 1;
- break;
- case "武林外传":
- GameType = 2;
- break;
- case "完美国际":
- GameType = 3;
- break;
- case "诛仙":
- GameType = 4;
- break;
- case "赤壁":
- GameType = 5;
- break;
- case "口袋西游":
- GameType = 6;
- break;
- default:
- break;
- }
- //获取验证码
- private void GetRandCode()
- {
- Bitmap checkCodeBitmap; //Bitmap 名称空间using System.Drawing;
- Cookie cookie; //Cookie 名称空间using System.Net;
- string strUrl = "http://pay.wanmei.com/e/servlet/getrandomimg";
- //CheckCodeHelper 名称空间using using CheckCodeLib;
- bool isGetCheckCode = CheckCodeHelper.GetCheckCodeBitmap(strUrl, out checkCodeBitmap, out cookie);
- if (isGetCheckCode)
- {
- string cookieValue = CheckCodeHelper.SerializeCookie(cookie);
- ViewState["CheckCodeCookieValue"] = cookieValue;
- //删除一天前ImgRandCode文件夹下自动生成的文件
- string vPath = Server.MapPath("~/ImgRandCode");
- DirectoryInfo dir = new DirectoryInfo(vPath);
- foreach (FileInfo fi in dir.GetFiles())
- {
- if (fi.CreationTime < DateTime.Today)
- fi.Delete();
- }
- CheckCodeAnalyzer ccAnalyzer = new CheckCodeAnalyzer(checkCodeBitmap); //CheckCodeAnalyzer 名称空间using CheckCodeLib;
- string checkCode = ccAnalyzer.Analyze();
- Guid id = Guid.NewGuid(); //Guid 名称空间using System;表示全局唯一标识符
- string strImg = @"ImgRandCode/" + id + ".bmp";
- string strImgUrl = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strImg);
- checkCodeBitmap.Save(strImgUrl);
- ImgRandCode.ImageUrl = "~/ImgRandCode/" + id + ".bmp";
- if (checkCode.Length == 0)
- {
- Tools.Alert("验证码分析失败,请手动输入!", this.Page);
- txtRandCode.Focus();
- return;
- }
- else
- {
- //Tools.Alert("验证码: " + checkCode, this.Page);
- txtRandCode.Text = checkCode;
- //return;
- }
- }
- else
- {
- Tools.Alert("获取验证码失败!", this.Page);
- return;
- }
- }
- // 将提交的字符串数据转换成字节数组
- string dataString = string.Format("gametype={0}&cardcode={1}&account={2}&reaccount={3}&zoneid_4={4}&randcode={5}",
- GameType, txtCardCode.Text.Trim(), txtAccount.Text.Trim(), txtAccount.Text.Trim(), GetIdByZone(txtZone.Text.Trim()), txtRandCode.Text.Trim());
- //已下代码将dataString获取的值通过post方法提交到http://pay.wanmei.com/e/trade/realCardUseActionStep1.do,目的是验证基本信息
- //PostRequestRobot为CheckCodeLib.dll中的方法目的是能够发送post请求的帮助类
- PostRequestRobot robot = new PostRequestRobot("http://pay.wanmei.com/e/trade/realCardUseActionStep1.do", dataString);
- string cookieValue = ViewState["CheckCodeCookieValue"].ToString();
- Cookie cookie = CheckCodeHelper.DeserializeCookie(cookieValue);
- robot.AddCookie(cookie);
- string htmlString = robot.GetResponse();
- Regex regex = new Regex("<span style=/"font-size:14px; color:#FF0000; font-weight:bold/">(.*?)</span><br />", RegexOptions.IgnoreCase | RegexOptions.Singleline);
- if (htmlString.IndexOf("验证码错误") > -1)
- {
- Response.Write("<script language='javascript'>alert('验证码错误现已重新获取');</script>");
- GetRandCode(); //获取验证码
- }
- else if (htmlString.IndexOf("您输入的账号不存在") > -1 || htmlString.IndexOf("请正确选择充值区域") > -1 )
- {
- Response.Write("<script language='javascript'>alert('" + regex.Match(htmlString).Groups[1].Value + "');</script>");
- }
- //基本信息正确,判断卡密
- else if (htmlString.IndexOf("") > -1)
- {
- string dataStringStep2 = string.Format("gametype={0}&password={1}",GameType, ViewState["cardPassword"].ToString());
- //验证卡密
- PostRequestRobot robotStep2 = new PostRequestRobot("http://pay.wanmei.com/e/trade/realCardUseActionStep2.do", dataStringStep2);
- string cookieValueStep2 = ViewState["CheckCodeCookieValue"].ToString();
- Cookie cookieStep2 = CheckCodeHelper.DeserializeCookie(cookieValueStep2);
- robotStep2.AddCookie(cookieStep2);
- string htmlStringStep2 = robotStep2.GetResponse();
- if (htmlStringStep2.IndexOf("卡号不存在或此卡已经使用过") > -1)
- {
- Response.Write("<script language='javascript'>alert('卡号不存在或此卡已经使用过,请核对您的卡号或改用其它充值方式!');</script>");
- }
- else if (htmlStringStep2.IndexOf("") > -1)
- {
- DepositSuccess(); //充值成功
- }
- }