C# 实现对接电信交费易自动缴费
- 他有这样一个JS PassGuardCtrl.js 部分代码
1 defaults:{2 obj:null,3 random:null,//随机因子数4 hidPwdName:'password',//隐藏密码框名字,用来保存加密后的密码值5 outInputClass:'',//要把密码输入框写到的位置6 params:{//附加属性,可选7 pgePath: "./ocx/",//控件文件目录8 pgeId: "_ocx_password",//控件ID9 pgeEdittype: 0,//控件类型,0星号,1明文10 pgeEreg1: "[\\s\\S]*",//输入过程中字符类型限制11 pgeEreg2: "[\\s\\S]{6,50}", //输入完毕后字符类型判断条件12 pgeMaxlength: 50,//允许最大输入长度13 pgeTabindex: 2,//tab键顺序14 pgeClass: "ocx_style",//控件css样式15 pgeInstallClass: "ocx_style",//针对安装或升级16 pgeOnkeydown:"FormSubmit()",//回车键响应函数17 tabCallback:"_ocx_password2"18 }这段 js 就是对密码控件初始化.后台我在后面会把它改成 C#的_setRandom:function(){if(null==this.settings.random){alert("error:random is empty");return false;}this.object.pwdSetSk(this.settings.random);return true;} }pwdSetSk: function(s) {if (this.checkInstall()) {try {var control = document.getElementById(this.settings.pgeId);if (this.osBrowser==1 || this.osBrowser==3 || this.osBrowser==6 || this.osBrowser==8) {control.input1=s;} else if (this.osBrowser==2 || this.osBrowser==4 || this.osBrowser==5) {control.input(1,s);}} catch (err) {}}这个js文件是设置安全控件的 随机因子 操作的是 安全控件的 input1pwdResult: function() {var code = '';if (!this.checkInstall()) {code = '';}else{try {var control = document.getElementById(this.settings.pgeId);if (this.osBrowser==1 || this.osBrowser==3) {code = control.output1;} else if (this.osBrowser==2 || this.osBrowser==4 || this.osBrowser==5) {code = control.output(7);}else if (this.osBrowser==6 || this.osBrowser==8) {code = control.get_output1();}} catch (err) {code = '';}}//alert(code);return code;},这个文件是我们的主角,就是当我们在安全控件中输入内容后,自动的将我们的密码加密.但是加出的密码并不是提交的那个密文,还要进行一次 BASE64加密function setPwdVal(clazz){var _$=jQuery;_$("input."+clazz).each(function(i,n){var _objId = _$(n).attr("objId");var _code = null;var control = _$("#"+_objId)[0];_code=window["PassGuardCtrl"+control.id.split("-")[0].toLocaleLowerCase()].pwdResult();//_code = Base64.encoder(_code);_code=BASE64.encoder(_code);_$(n).val(_code);});}在这这个方法中可以看到,使用了一次 BASE64加密,经过上面这几个步骤后.可以将我们的密码加密成和提交时候的一样,VS中添加安全控件, 大家可能都用过,基本的是 首先在工具栏右键->选择项->COM组件->选择对应的组件,OK了但是很不幸 当你把控件拖入到界面上的时候,你的VS就崩了,我用vs2005,vs2008 vs2010 vs2013 都崩没找到好的办法,只能自己手动来创建,这个估计要点功点了.我估计这是控件的安全性引起VS崩溃的吧,以前做支机支付辅助也一样VS也会崩,发现这个控件其实是同一个,只是只不同的名称,(应该是 电信和移动的项目外包到同一家公司了,呵呵)现在把密码和加密码方式的核心代码段贴上,public static String GetPayPass(AxPassGuardCtrlLib.AxPassGuard paypwd, String random) {paypwd.input1 = random;paypwd.edittype = 0;paypwd.maxlength = 50;paypwd.input2 = "[\\s\\S]*";//输入过程中字符类型限制paypwd.input13 = "[\\s\\S]{6,50}";String strPwd = paypwd.output1;paypwd.ClearSeCtrl();return EncodeBase64(strPwd);}这个random 随机因子大你登陆的那个页上可以找到注意哦,这个并不是不变的,每次好像都是不一样的当你刷新页面的时候,所有我们要登陆首页先请求下登陆面把这个随机因子获取出来下面是我的登陆部分方法.internal void Login() {String Result = "";net.Url = "https://b.bestpay.com.cn/bppf/login.do?method=login";net.Method = NetHelper.RequestMethod.GET;net.IsStream = false;Result = net.SendRequest();if (Result.StartsWith("-1")) { LastError = "无法连接服务器"; return; }String random = Utils.GetValue(Result, "pwdSetSk\\(\"", "\"");Utils.SetPassword(PassGuard, LoginPass);net.Url = "https://b.bestpay.com.cn/bppf/vimage.do?0." + Utils.GetUnixTime();net.Referer = "https://b.bestpay.com.cn/bppf/login.do?method=login";net.IsStream = true;net.Method = NetHelper.RequestMethod.GET;net.SendRequest();if (net.IOStream == null) { LastError = "获取验证码失败"; return; }Bitmap bmp = new Bitmap(net.IOStream);String chkCode = Captcha.GetCheckString(bmp);//检测验证码net.Url = "https://b.bestpay.com.cn/bppf/verifyCode";net.PostData = "verifyCode=" + chkCode;net.IsStream = false;net.Method = NetHelper.RequestMethod.POST;Result = net.SendRequest();if (Result.StartsWith("-1") || Result != "true") { LastError = "无法连接服务器"; return; }String LoginPwd = Utils.GetPayPass(PassGuard, random);net.Url = "https://b.bestpay.com.cn/bppf/login.do";net.PostData = "signature=&certSN=&toURL=&TOURL_MENUID=&sysLoginType=BPPF&username=" + MerchantId + "&password=" + LoginPwd + "&method=login&verifyCode=" + chkCode;net.Method = NetHelper.RequestMethod.POST;net.Encode = "gbk";net.IsStream = false;Result = net.SendRequest();LastError = Result;if (Result.Contains("商户ID:" + MerchantId)) {IsLogin = true;dAmt0 = Convert.ToDecimal(Utils.GetValue(Result, "账户余额:<span class=\"property-amount\">", "</span>"));dAmt1 = Convert.ToDecimal(Utils.GetValue(Result, "可用余额:<span class=\"property-amount\">", "</span>"));dAmt2 = Convert.ToDecimal(Utils.GetValue(Result, "酬金余额:<span class=\"property-amount\">", "</span>"));dAmt3 = Convert.ToDecimal(Utils.GetValue(Result, "冻结金额:<span class=\"property-amount\">", "</span>"));}}手机充值下单方法internal Boolean MobilePay(Order order, ref String msg) {Boolean isSuccess = false;for (int i = 0; i < 3; i++) {String Result = "";net.Url = "https://b.bestpay.com.cn/bppf/ipos/mobilerecharge.do?method=process";net.Method = NetHelper.RequestMethod.POST;net.PostData = "mobile=" + order.Account + "&otherMoney=" + order.Price + "&moneyText=";net.IsStream = false;Result = net.SendRequest();if (Result.StartsWith("-1")) { continue; }if (!Result.Contains("请您核对好运营商信息、充值号码和金额,避免充错")) { continue; }String random = Utils.GetValue(Result, "pwdSetSk\\(\"", "\"");String token = Utils.GetValue(Result, "\"org.apache\\.struts\\.taglib\\.html\\.TOKEN\"", "type");token = Utils.GetValue(Result, "value=\"", "\"").Trim();String phone = Utils.GetValue(Result, "name=\"phone\" value=\"", "\"").Trim();String money = Utils.GetValue(Result, "name=\"money\" value=\"", "\"").Trim();String txnAmount = Utils.GetValue(Result, "name=\"txnAmount\" value=\"", "\"").Trim();String poundage = Utils.GetValue(Result, "name=\"poundage\" value=\"", "\"").Trim();Utils.SetPassword(PassGuard, PayPass);if (order.Account != phone) {msg = "充值帐号袚篡改"; return false;}if (order.Price != money) {msg = "充值金额袚篡改"; return false;}String PayPwd = Utils.GetPayPass(PassGuard, random);net.Url = "https://b.bestpay.com.cn/bppf/ipos/mobilerecharge.do?method=checkPayPwd&payPwd=" + PayPwd;net.Method = NetHelper.RequestMethod.POST;net.PostData = "";net.IsStream = false;Result = net.SendRequest();Log.Write(Result, "debut.txt");net.Url = "https://b.bestpay.com.cn/bppf/ipos/mobilerecharge.do?method=confirm";net.Method = NetHelper.RequestMethod.POST;net.PostData = String.Format("org.apache.struts.taglib.html.TOKEN={0}&phone={1}&money={2}&txnAmount={3}£age={4}&receivePhone={5}&payPwd={6}", token, phone, money, txnAmount, poundage, phone, PayPwd);Log.Write(net.PostData,"debug.txt");net.IsStream = false;Result = net.SendRequest();if(Result.Contains("充值成功")){msg = "缴费下单成功";return true;}msg = Utils.GetValue(Result, "充值失败原因:</span><span class=\"title\" style=\"color: red;\">", "</span>");Log.Write(Result, "debut.txt");}return isSuccess;}
C# 实现对接电信交费易自动缴费的更多相关文章
- C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码)
原文:C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码) 自动填密码大家可能都不莫生,最有名的应该是 按键精灵 只要是一个可以输入的地方都可以能过按键精灵来完成输入.我今 ...
- freeswitch对接电信线路VOLTE视频通话
在public.xml上设置视频编码: <action application="export" data="nolocal:absolute_codec_stri ...
- 那些年,我们开发的接口之:QQ登录(OAuth2.0)
那些年,我们开发的接口之:QQ登录(OAuth2.0) 吴剑 2013-06-14 原创文章,转载必须注明出处:http://www.cnblogs.com/wu-jian 前言 开发这些年,做过很多 ...
- Immutable Object模式
多线程共享变量的情况下,为了保证数据一致性,往往需要对这些变量的访问进行加锁.而锁本身又会带来一些问题和开销.Immutable Object模式使得我们可以在不使用锁的情况下,既保证共享变量访问的线 ...
- QQ登录(OAuth2.0)
QQ登录(OAuth2.0) 那些年,我们开发的接口之:QQ登录(OAuth2.0) 吴剑 2013-06-14 原创文章,转载必须注明出处:http://www.cnblogs.com/wujian ...
- 盘点和反思在微信的阴影下艰难求生的移动端IM应用
本文原作者:李越,由银杏财经原创发布,本次内容改动. 1.前言 上线一周完成1.5亿元融资,上线10天总激活用户数超400万,8月29日单日新增用户超100万,这是子弹短信交出的最新成绩单(详见< ...
- Java多线程编程模式实战指南(二):Immutable Object模式
多线程共享变量的情况下,为了保证数据一致性,往往需要对这些变量的访问进行加锁.而锁本身又会带来一些问题和开销.Immutable Object模式使得我们可以在不使用锁的情况下,既保证共享变量访问的线 ...
- .NET RSA解密、签名、验签
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Sec ...
- 浅谈WebService的调用<转>
0.前言 前段时间,公司和电信有个合作,产品对接电信的某个平台,使用了WebService接口的调用,实现了业务受理以及单点登录.终于使用到了WebService,楼主还是比较兴奋的,目前功能已经上线 ...
随机推荐
- Android journey3 @点击事件的4种写法
对于android布局中的控件,如Button等会有相应的点击事件去响应它所需要的功能,今天我们就以电话拨号器的代码说明下几种点击事件: package com.itheima.phone; impo ...
- 搭建Asp.Net MVC4
启动vs2012,开始创建一个新的web应用程序.使用菜单:“文件”>“新建项目” 请在左侧选择 Visual C#,然后选择ASP.NET MVC 4 Web 应用程序.命名您的工程为&quo ...
- 导入 github 步骤
https://github.com/dotnet/corefx 如果出现未能找到解决方案的情况,则找项目文件打开,如:
- MoveManager管理类
MoveManager:移动管理类 struct MoveOpt { int cur_seq; ObjecInfo* obj; }; std::map<ObjID, MoveOpt> m_ ...
- app被Rejected 的各种原因翻译
1. Terms and conditions(法律与条款) 1.1 As a developer of applications for the App Store you are bound by ...
- Finite State Machine
Contents [hide] 1 Description 2 Components 3 C# - FSMSystem.cs 4 Example Description This is a Dete ...
- CentOS安装视频播放器SMPlayer
首先下载rpmforg,下载对应的版本,就是对应CentOS版本,还有32位与64位也要对应上.地址如下: http://wiki.centos.org/AdditionalResources/Rep ...
- POJ2513Colored Sticks
http://poj.org/problem?id=2513 题意 : 一些木棒,两端都涂上颜色,求是否能将木棒首尾相接,连成一条直线,要求不同木棒相接的一边必须是相同颜色的. 思路 : 这个题的话就 ...
- ElasticSearch Java api 详解_V1.0
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
- LintCode 字符串比较
比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是大写字母: 给出 A = "ABCD" B = "AABC", 返回 false ...