zoukankan      html  css  js  c++  java
  • 淘宝api 登录验证

    淘宝api登录验证代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;
    namespace TaobaoForm
    {
    public partial class Login : Form
    {
    public Login()
    {
    InitializeComponent();
    webBrowser1.Navigate(
    "http://open.taobao.com/isv/authorize.php? appkey=12053297");
    webBrowser2.Visible
    = false;
    }
    public string SessionKey;
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    string a= e.ToString();
    string htmltext= webBrowser1.DocumentText.ToString();

    String Authcode
    =GetAuthCode(htmltext);
    if (Authcode != null)
    {
    webBrowser2.Navigate(
    @"http://container.api.tbsandbox.com/container?authcode="+Authcode);
    webBrowser2.Visible
    = true;
    webBrowser1.Visible
    = false;
    }
    }
    public string GetAuthCode(string html)
    {
    string rxString = @"<input type=\""text\"" id=\""autoInput\"" value=""(.*)\"" ";

    MatchCollection mc
    = Regex.Matches(html, rxString);
    if (mc.Count != 0)
    {
    foreach (Match m in mc)
    {
    string a = m.Groups[1].Value.ToString();
    return a;
    }
    }
    else
    {
    return null;
    }
    return null;
    }
    public string GetTopSession(string html)
    {
    string rxString = @"top_session=(.*)(&amp);";
    MatchCollection mc
    = Regex.Matches(html, rxString);
    if (mc.Count != 0)
    {
    foreach (Match m in mc)
    {
    string a = m.Groups[1].Value.ToString();
    return a;
    }
    }
    return null;
    }

    private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    string htmltext2 = webBrowser2.DocumentText.ToString();
    Form1 form1
    = new Form1();
    SessionKey
    = GetTopSession(htmltext2);
    form1.SessionKey
    = GetTopSession(htmltext2);
    webBrowser2.Visible
    = false;
    SessionKeyClass.SessionKey
    = SessionKey;
    this.Close();
    }

    }
    }
    public string GetTopSession(string html)
            {
                string rxString = @"top_session=(.*)(&amp);";
                MatchCollection mc = Regex.Matches(html, rxString);
                if (mc.Count != 0)
                {
                    foreach (Match m in mc)
                    {
                        string a = m.Groups[1].Value.ToString();
                        return a;
                    }
                }
                return null;
            }
    

    以上代码是匹配淘宝api 中的 获取 网页中的 session值,

    以下为session值的页面

    代码
    <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\r\n<HTML><HEAD>\r\n<META content=\"text/html; charset=gb2312\" http-equiv=Content-Type></HEAD>\r\n<BODY><PRE>top_appkey=12053297&amp;top_parameters=aWZyYW1lPTAmdHM9MTI3MzQyNDY5MjcyOCZ2aWV3X21vZGU9ZnVsbCZ2aWV3X3dpZHRoPTAmdmlzaXRvcl9pZD0xNzU5NzgyNzQmdmlzaXRvcl9uaWNrPXNhbmRib3hfY181&amp;top_session=2827481fecfabd25be9a536f429a55701cc8a&amp;top_sign=hUqxHxqx5IIxoTsquwXjRw==</PRE></BODY></HTML>
  • 相关阅读:
    【转】PG数据库高级用法 之 12306 -- 链接
    javascript实现浏览器管理员工具鼠标获取Html元素 并生成 xpath
    java图片识别 [Tesseract-OCR]
    MongoDB从环境搭建到代码编程(Window 环境)
    webDriver + Firefox 浏览器 完美兼容
    SQLServer 将日期改造成标准日期格式(如: 2016/6 ->201606)
    Angularjs+bootstrap 实现横向滑屏
    js数组长度
    Angularjs 跨域post数据到springmvc
    Oracle 18c 数据库中scott用户不存在的解决方法
  • 原文地址:https://www.cnblogs.com/liushengchuan/p/1752294.html
Copyright © 2011-2022 走看看