using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Web;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
namespace Test1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void button1_Click(object sender, RoutedEventArgs e)
{
var mainUrl =
@"http://api.wap.guoguo-app.com/h5/mtop.cnwireless.cnlogisticdetailservice.wapquerylogisticpackagebymailno/1.0/";
var cookieUrl =
@"http://api.wap.guoguo-app.com/h5/mtop.cnwireless.cncainiaoappservice.getlogisticscompanylist/1.0/?v=1.0&api=mtop.cnwireless.CNCainiaoAppService.getLogisticsCompanyList&appKey=12574478&t=1496741493353&callback=mtopjsonp1&type=jsonp&sign=b0f7376271effd90e311f998ad3a3efb&data=%7B%22version%22%3A0%2C%22cptype%22%3A%22all%22%7D"; var mailNo = "826060403";//运单号码
//准备参数
var tikets = (DateTime.Now - Convert.ToDateTime("1970-01-01 00:00:00")).Ticks.ToString();
var cookie = GetCookie(cookieUrl);//先请求一次获得cookie,可以先缓存下来。
MessageBox.Show(cookie);
var key = new Regex(@"(?:^|;\s*)_m_h5_tk\=([^;]+)(?:;\s*|$)").Match(cookie).Value.Split('=')[1]
.Split('_')[0];
var sign = GetMD5Hash(key + "&" + tikets + "&12574478" + "&{\"mailNo\":\"" + mailNo + "\"}")
.ToLower(); //获得参数列表
var urlParas = string.Format(
"?v=1.0&api=mtop.cnwireless.CNLogisticDetailService.wapqueryLogisticPackageByMailNo&appKey=12574478&t={0}&callback=mtopjsonp&type=jsonp&sign={1}",
tikets, sign);
urlParas += "&data={\"mailNo\":\"" + mailNo + "\"}"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mainUrl + urlParas);
request.Method = "GET";
request.Headers.Add("Cookie", cookie);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
Console.WriteLine(content);
MessageBox.Show(content);
} //md5加密
public static string GetMD5Hash(String input)
{ // Use input string to calculate MD5 hash
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes); // Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
// To force the hex string to lower-case letters instead of
// upper-case, use he following line instead:
// sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
// return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(input, "md5"); } //获得cookie
public static string GetCookie(string url, int Timeout = 5000, bool isNeedProxy = true)
{
try
{ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.AllowAutoRedirect = false;
request.ContentType = "application/x-www-form-urlencoded;charset=gbk";
request.CookieContainer = new CookieContainer();
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"; HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
return response.Headers.Get("Set-Cookie");
}
catch (Exception ex)
{ return null;
}
} }
}

  

c# 淘宝运单查询的更多相关文章

  1. 淘宝SKU组合查询算法实现

    淘宝SKU组合查询算法实现 2015-11-14 16:18 1140人阅读 评论(0) 收藏 举报  分类: JavaScript(14)    目录(?)[+]   前端有多少事情可以做,能做到多 ...

  2. 两个月淘宝刷单,连续死N次血泪史 (转)

    两个月淘宝刷单,连续死N次血泪史 派代网 2014/10/13 刷单 分享到:3 [思路网注] 看来是靠刷流量刷销量是行不通了,点击率与展现无法匹配,这是致命的!!那么,贵就贵点,直通车来吧!!再删宝 ...

  3. 用Python完成毫秒级抢单,助你秒杀淘宝大单

    目录: 引言 环境 需求分析&前期准备 淘宝购物流程回顾 秒杀的实现 代码梳理 总结 0 引言 年中购物618大狂欢开始了,各大电商又开始了大力度的折扣促销,我们的小胖又给大家谋了一波福利,淘 ...

  4. Python 教你识别淘宝刷单,买到称心如意的商品

    发际线堪忧的小 Q,为了守住头发最后的尊严,深入分析了几十款防脱洗发水的评价,最后综合选了一款他认为最完美的防脱洗发水. 一星期后,他没察觉到任何变化. 一个月后,他用卷尺量了量,发际线竟然后退了 0 ...

  5. python 利用淘宝IP库 查询IP归属地

    #coding:utf-8 from django.test import TestCase import json import urllib ip = "114.114.114.114& ...

  6. 淘宝IP地址查询

    官方网址:http://ip.taobao.com/index.php 相关文章: http://www.cnblogs.com/zetee/p/3482085.html http://www.cnb ...

  7. 使用python调用淘宝的ip地址库查询接口结合zabbix判断dnspod域名解析是否正确

    #encoding:utf-8 import socket import requests import json ''' 使用python结合zabbix判断dnspod域名解析是否正确 服务器分国 ...

  8. 淘宝API总结

    1. 淘宝客API https://open.alimama.com/?spm=a219t.11816995.1998910419.d8546b700.2a8f75a5C0NajI#!/documen ...

  9. NPM和Yarn添加淘宝镜像

    NPM设置淘宝镜像 1.查询当前配置的镜像 npm get registry > https://registry.npmjs.org/ 设置成淘宝镜像 npm config set regis ...

随机推荐

  1. 大数据【八】Flume部署

    如果说大数据中分布式收集日志用的是什么,你完全可以回答Flume!(面试小心问到哦) 首先说一个复制本服务器文件到目标服务器上,需要目标服务器的ip和密码: 命令: scp  filename   i ...

  2. [Android] 图片裁剪总结——自定义裁剪工具

    上次弄完调用系统裁剪之后,我又试着做一个自定义的裁剪工具. 原文地址请保留http://www.cnblogs.com/rossoneri/p/3988405.html 老习惯,文章开始前还是先把我参 ...

  3. servlet和jsp页面过滤器Filter的作用及配置

    刚刚有个朋友问我,Servlet的过滤器有什么作用? 现在发个帖子说明一下,            过滤器是一个对象,可以传输请求或修改响应.它可以在请求到达Servlet/JSP之前对其进行预处理, ...

  4. ubuntu下编译qt5

    编译步骤参考: http://doc.qt.io/qt-5/linux.html 我们使用源代码和编译目录分离的编译方式, 这样避免编译主机系统和目标系统间的独立. 参考: Qt Configure ...

  5. SQL Server 的 RowGuid/RowGuidCol 是什么意思?

    SQL Server 中设计表时,有个属性叫 RowGuid(用 SQL 时,关键词是 RowGuidCol),这个是什么意思呢?这个是全局唯一标识符,与“标识”不同,标识是只在本表中唯一,全局唯一标 ...

  6. Bitlocker驱动器加密使用

      前言 Bitlocker驱动器加密可以将磁盘加密,确保数据的安全.如果被加密保护的磁盘是Windows Server 2012操作系统磁盘,即使他被拿到另外一台计算机启动,除非已解锁,否则无法启动 ...

  7. 【转】Java学习---Java中volatile关键字实现原理

    [原文]https://www.toutiao.com/i6592879392400081412/ 前言 我们知道volatile关键字的作用是保证变量在多线程之间的可见性,它是java.util.c ...

  8. 【转】Java学习---Java核心数据结构(List,Map,Set)使用技巧与优化

    [原文]https://www.toutiao.com/i6594587397101453827/ Java核心数据结构(List,Map,Set)使用技巧与优化 JDK提供了一组主要的数据结构实现, ...

  9. October 13th 2017 Week 41st Friday

    The shortest distance between two people is a smile. 人与人之间最短的距离是微笑. I find a smiling face can bring ...

  10. PyQt5--InputDiaglog

    # -*- coding:utf-8 -*- ''' Created on Sep 14, 2018 @author: SaShuangYiBing Comment: ''' import sys f ...