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>
  • 相关阅读:
    Python代写使用矩阵分解法找到类似的音乐
    (转)语义分析透镜洞察婚庆微博用户行为数据
    (转)虎扑论坛基因探秘:社群用户行为数据洞察
    bzoj 4922: [Lydsy1706月赛]Karp-de-Chant Number 贪心+dp
    bzoj 1110: [POI2007]砝码Odw 贪心
    bzoj 3721: PA2014 Final Bazarek 贪心
    bzoj 2563: 阿狸和桃子的游戏 贪心
    bzoj 3999: [TJOI2015]旅游 LCT
    bzoj 4240: 有趣的家庭菜园 树状数组+贪心
    CF369E Valera and Queries kdtree
  • 原文地址:https://www.cnblogs.com/liushengchuan/p/1752294.html
Copyright © 2011-2022 走看看