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. session与cookie的区别和用法

    一.session 1.保存在服务器的,每个人存一份2.可以存储任何类型数据3.有一个默认过期时间注意:在所有使用session的页面最顶端要开启session---session_start();存 ...

  2. paste 命令

    Linux paste命令用于合并文件的列. paste指令会把每个文件以列对列的方式,一列列地加以合并. 语法: paste [-s][-d <间隔字符>][--help][--vers ...

  3. Boto Config File

    Boto是AWS SDK for Python,可以通过pip安装,也可以下载源码直接安装.直接安装挺方便的. 安装后参照AWS给出的Sample Project,连接S3,遍历一下buckets,获 ...

  4. apktool逆向apk包

    在AndroidStudio创建so一节里创建了so,并且在java里面调用so的HelloWorld方法,编译Android Studio后生成包app-debug.apk. 在逆向apk时如果该a ...

  5. zabbix agent 3.4 安装指南

    从官方网站www.zabbix.com 下载zabbix agent安装包.目前最新版本是4.0 LTS release. 在需要监控的服务器上安装zabbix agent. 先解压安装包. 配置 c ...

  6. [zz]VC2005-应用程序正常初始化失败-0xc0150002

    最近几天被这个问题困惑了许久. 不禁感叹微软的东东真是越做越烂了,也终于明白了时隔12年大家仍然死守VC6的原因.. 用VC2005编译的程序,编译时没有任何错误,但是运行时就是提示“应用程序正常初始 ...

  7. 超经典sql练习题,在teradata上实现

    题目来源:https://blog.csdn.net/flycat296/article/details/63681089 teradata实现: drop table student; create ...

  8. 华为Eudemon 100E的密码恢复

    华为Eudemon 100E的密码恢复 转自http://blog.sina.com.cn/s/blog_53835f380100hdc3.html  为了让自己下次能记住 Eudemon 100E系 ...

  9. ZooKeeper 集群的安装部署

    0. 说明 ZooKeeper 安装在 s102.s103.s104上,这三个节点同时是 Hadoop 的 DataNode 1. ZooKeeper 本地模式安装配置 1.0 在 s101 上进行安 ...

  10. C# 颜色对照表

    参考资料 :https://www.cnblogs.com/msgarden/p/4949272.html Color.AliceBlue 240,248,255 Color.LightSalmon ...