TC官方合作论坛

 找回密码
 立即注册
查看: 1212|回复: 1

[源码分享] 内网学习TC C#转TC求大神看下

[复制链接]
发表于 2014-5-26 18:23:49 | 显示全部楼层 |阅读模式

马上加入TC

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
内网用TC做个小插件,实现自动打**  现在实现不了功能   原功能源码是用C#写的  现在想改成TC  求大神 指教

using System;
using System.Collecti**.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Configuration;
using System.Windows.Forms;
using System.Threading;
using System.Globalization;
using DocManagerServer.Tools;


namespace DocManagerServer.Net
{
    public delegate void sendWebData(string msg);

    class Electric
    {
        public static event sendWebData **endWebData;
        public static bool isHtmlLoadDown;

        public static void LogIn()
        {
           
        }

        public static int CheckPayment(string account)
        {
            HttpHeader header = new HttpHeader();
            header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; " +
                ".NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; .NET4.0C; .NET4.0E)";
            header.maxTry = int.MaxValue;
            header.accept = "*/*";

            // 得到会话id
            CookieContainer cookieContainer = new CookieContainer();
            string url = "http  ://epm.zj.sgcc.com.cn/web/";
            cookieContainer = HttpConnect.GetCooKie(url, header);

            // 登入请求
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string username = config.AppSettings.Settings["登入帐号"].Value;
            string password = config.AppSettings.Settings["登入密码"].Value;
           

            url = "http  ://epm.zj.sgcc.com.cn/web/pf/authentication/logon.do;" + HttpConnect.HttpHeadStr;
            string postData = "kind=1&clientIPAddr=&clientMacAddr=&clientMachineName=&username=" + username + "&password=" + password;
            LogManager.WriteLog("Post登入请求url: " + url);

            HttpHeader postHeader = new HttpHeader();
            postHeader.contentType = "application/x-www-form-urlencoded";
            postHeader.method = "POST";
            postHeader.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; " +
                ".NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; .NET4.0C; .NET4.0E)";
            string html = HttpConnect.GetHtml(url, postData, cookieContainer, postHeader);

            if (html == "")
            {
                LogManager.WriteLog("登入系统失败");
                return 2;
            }
            else
            {
                LogManager.WriteLog("登入系统返回的: " + html);
            }

            LogManager.WriteLog("开始设置cookie");
            Cookie myCookie = new Cookie("logonUsername", username, "/", "epm.zj.sgcc.com.cn");
            cookieContainer.Add(myCookie);


            // 点击客户号开始查询
            url = "http  ://epm.zj.sgcc.com.cn/web/cus/cusmanage/c**umerView.do?action=init&c**No=" + account + "&U=1377048849156";
            html = HttpConnect.GetHtml(url, cookieContainer, header, "");
            //LogManager.WriteLog("点击客户号查询返回:" + html);

            int pos = html.IndexOf("用户认证错误");
            if (pos != -1)
            {
                LogManager.WriteLog("用户认证错误,请重新登入");
                return 2;
            }

            pos = html.IndexOf("orgNo=");
            if (pos == -1)
            {
                return 2;
            }
            string orgNo = html.Substring(pos + 6, 20);
            pos = orgNo.IndexOf("\"");
            orgNo = orgNo.Substring(0, pos);
            LogManager.WriteLog("机构号:" + orgNo);
            if (orgNo == "")
            {
                LogManager.WriteLog("网络连接错误");
                return 2;
            }

            LogManager.WriteLog("开始查询缴费情况");
            // 输入客户号查询
            url = "http  ://epm.zj.sgcc.com.cn/web/ca/pay/settleRcvblQuery.do?action=init&c**No=" + account + "&orgNo=" + orgNo + "&cap=15";
            string referUrl = "http  ://epm.zj.sgcc.com.cn/web/ca/pay/c**Query.do?action=initC**&c**No=" + account + "&orgNo=" + orgNo;


            html = HttpConnect.GetHtml(url, cookieContainer, header, referUrl);

            LogManager.WriteLog("欠费查询返回:" + html);

            if (html == "")
            {
                LogManager.WriteLog("网络连接失败");
                return 2;
            }

            pos = html.IndexOf("<td noWrap>欠费</td>");
            if (pos == -1)
            {
                LogManager.WriteLog("无欠费");
                return 0;
            }
            else
            {
                LogManager.WriteLog("欠费");
                return 1;
            }
        }


        // 打印缴费清单
        public static int PrintList(string account)
        {
            HttpHeader header = new HttpHeader();
            header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727;" +
                " .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; .NET4.0C; .NET4.0E)";
            header.maxTry = int.MaxValue;
            header.accept = "*/*";

            
            // 登入请求
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string username = config.AppSettings.Settings["登入帐号"].Value;
            string password = config.AppSettings.Settings["登入密码"].Value;
            string company = config.AppSettings.Settings["公司名称"].Value;

            // 得到会话id
            CookieContainer cookieContainer = new CookieContainer();
            string url = "http  ://epm.zj.sgcc.com.cn/web/";
            cookieContainer = HttpConnect.GetCooKie(url, header);

            // 提交登入请求
            url = "http  ://epm.zj.sgcc.com.cn/web/pf/authentication/logon.do;" + HttpConnect.HttpHeadStr;
            string postData = "kind=1&clientIPAddr=&clientMacAddr=&clientMachineName=&username=" +
                username + "&password=" + password;
            LogManager.WriteLog("Post登入请求url: " + url);

            HttpHeader postHeader = new HttpHeader();
            postHeader.contentType = "application/x-www-form-urlencoded";
            postHeader.method = "POST";
            postHeader.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; " +
                ".NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; .NET4.0C; .NET4.0E)";

            string html = HttpConnect.GetHtml(url, postData, cookieContainer, postHeader);
            if (html == "")
            {
                LogManager.WriteLog("登入系统失败");
                return 2;
            }
            else
            {
                LogManager.WriteLog("登入系统返回的: " + html);
            }

            LogManager.WriteLog("开始设置cookie");
            Cookie myCookie = new Cookie("logonUsername", username, "/", "epm.zj.sgcc.com.cn");
            cookieContainer.Add(myCookie);

            // 查询出此户号的机构号
            url = "http  ://epm.zj.sgcc.com.cn/web/cus/cusmanage/c**umerView.do?action=init&c**No=" + account + "&U=1377048849156";
            html = HttpConnect.GetHtml(url, cookieContainer, header, "");
            //LogManager.WriteLog("点击客户号查询返回:" + html);

            int pos = html.IndexOf("用户认证错误");
            if (pos != -1)
            {
                LogManager.WriteLog("用户认证错误,请重新登入");
                return 2;
            }

            pos = html.IndexOf("orgNo=");
            if (pos == -1)
            {
                return 2;
            }
            string orgNo = html.Substring(pos + 6, 20);
            pos = orgNo.IndexOf("\"");
            orgNo = orgNo.Substring(0, pos);
            LogManager.WriteLog("机构号:" + orgNo);

            if (orgNo == "")
            {
                LogManager.WriteLog("网络连接错误");
                return 2;
            }

            //查询是否有打印清单

            string orgName = company.Trim();
            string date = DateTime.Now.ToString("yyyyMM");
            //string date = "201308";  //测试用

            url = "http  ://epm.zj.sgcc.com.cn/web/ca/pay/zjDyhInv.do";
            postData = "oper=" + username + "&infoOrgNo=" + orgNo + "&infoOrgName=" + orgName + "&amtYm=" + date +
                "&fxbz=YFX&mrSectNoBegin=&mrSectNoEnd=&c**No=" + account + "&isBatch=no&yhlx=all&fplx=alldyh&action=search";

            html = HttpConnect.GetHtml(url, postData, cookieContainer, postHeader);
            LogManager.WriteLog("查询打印清单返回: " + html);

            string search = "<input type=\"checkbox\" class=\"grid-checkbox\" name=\"hhbox\" value=\"";
            LogManager.WriteLog("打印清单搜索字符串:" + search);

            while (true)
            {
                pos = html.IndexOf(search);
                if (pos == -1)
                {
                    LogManager.WriteLog("没有找到打印清单");
                    return 0;
                }
                else
                {
                    html = html.Substring(pos + search.Length);
                    LogManager.WriteLog("打印截取返回: " + html);

                    pos = html.IndexOf(",");
                    string appNo = html.Substring(0, pos);
                    string hh = html.Substring(pos + 1, 10); // 不可靠算法

                    LogManager.WriteLog("appNO:" + appNo);
                    LogManager.WriteLog("hh:" + hh);

                    string fmtDate = "ddd?MMM?dd?HH:mm:ss?'UTC'zz'00'?yyyy";
                    CultureInfo ciDate = CultureInfo.CreateSpecificCulture("en-US");
                    //将C#时间转换成JS时间字符串????

                    string nowDateTime = DateTime.Now.ToString(fmtDate, ciDate);

                    // 打印清单请求
                    url = "http  ://epm.zj.sgcc.com.cn/web/pub/basis/report/print.do?action=print&appModel=zjfpQdPrintInv&rptType=zjfpPrintInvHhRpt&appNo=" +
                        appNo + "&hh=" + hh + "&orgNo=" + orgNo + "&dfny=" + date + "&fplx=alldyh&yhlx=all&isfx=YFX&czy=" + username +
                        "&isBatch=no&U=" + nowDateTime;

                    string printHtml = HttpConnect.GetHtml(url, cookieContainer, header, "");
                    LogManager.WriteLog("打印返回: " + printHtml);

                    pos = printHtml.IndexOf("<!--import taglibs -->");
                    isHtmlLoadDown = false;
                    string sbu = printHtml.Substring(pos + 24);
                    **endWebData(sbu);

                    for (int i = 0; i < 100; i++)
                    {
                        if (isHtmlLoadDown == true)
                        {
                            LogManager.WriteLog("html加载完成了");
                            break;
                        }
                        LogManager.WriteLog("等待html加载完成");
                        Thread.Sleep(100);
                    }
                }
            }
           // **endWebData("<html><body><input type=\"button\" name=\"action.print\" value=\"打印\" onclick=\"\" class=\"button\" /></body></html>");
        }
    }
}


现在用根据教程 用常规库 写不了
求大神指点 。。。。 因为不能发地址所以 所有 HTTP 后面 加了2个空格
留个邮箱地址    ljc1207@qq.com
回复

使用道具 举报

发表于 2014-5-26 19:51:16 | 显示全部楼层
如果是急需,直接用c#的不就好了,如果只是为学习,建议还是从基本的入手。。哪一点不懂问哪点,这样直接发代码。。估计很少人会去看。再说,也不一定能懂c#
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条

关闭

小黑屋|TC官方合作论坛 (苏ICP备18045623号)

GMT+8, 2024-6-12 21:47 , Processed in 0.034666 second(s), 22 queries .

Powered by 海安简单软件服务部

© 2008-2019 版权所有 保留所有权利

快速回复 返回顶部 返回列表