userinfo
2013-11-09 15:07
225 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Security.Cryptography; using System.Net; using System.Web; using System.IO; using System.Text.RegularExpressions; using System.Configuration; namespace aliformerp { public struct acctk { public string uid; public string aliId; public string resource_owner; public string memberId; public string expires_in; public string refresh_token; public string access_token; } public class userinfo { public static acctk acctk2; public static string appKey = Properties.Settings.Default.appKey; public static string site = Properties.Settings.Default.site; public static string secretkey = Properties.Settings.Default.secretkey; public static string redirect_uri = Properties.Settings.Default.redirect_uri; public static string account = Properties.Settings.Default.account; public static string password = Properties.Settings.Default.password; public static string sign(Dictionary<string, string> paramDic, string appSecret) { byte[] signatureKey = Encoding.UTF8.GetBytes(appSecret); //第一步:拼装key+value List<string> list = new List<string>(); foreach (KeyValuePair<string, string> kv in paramDic) { list.Add(kv.Key + kv.Value); } //第二步:排序 list.Sort(); //第三步:拼装排序后的各个字符串 string tmp = ""; foreach (string kvstr in list) { tmp = tmp + kvstr; } //第四步:将拼装后的字符串和app密钥一起计算签名 //HMAC-SHA1 HMACSHA1 hmacsha1 = new HMACSHA1(signatureKey); hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(tmp)); byte[] hash = hmacsha1.Hash; //TO HEX return BitConverter.ToString(hash).Replace("-", string.Empty).ToUpper(); } public static string sign(string urlPath, Dictionary<string, string> paramDic) { byte[] signatureKey = Encoding.UTF8.GetBytes(secretkey);//此处用自己的签名密钥 List<string> list = new List<string>(); foreach (KeyValuePair<string, string> kv in paramDic) { list.Add(kv.Key + kv.Value); } list.Sort(); string tmp = urlPath; foreach (string kvstr in list) { tmp = tmp + kvstr; } //HMAC-SHA1 HMACSHA1 hmacsha1 = new HMACSHA1(signatureKey); hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(tmp)); /* hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(urlPath)); foreach (string kvstr in list) { hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(kvstr)); } */ byte[] hash = hmacsha1.Hash; //TO HEX return BitConverter.ToString(hash).Replace("-", string.Empty).ToUpper(); } public static string gethttpwithuri(string lingpaigeturl2) { string gethttpwithuriout = ""; HttpWebRequest http23 = WebRequest.Create(lingpaigeturl2) as HttpWebRequest; // http23.ServicePoint.Expect100Continue = false; //http23.Referer = lingpaigeturl; http23.Method = "GET"; http23.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; // http23.AllowAutoRedirect = true; // http23.Credentials = System.Net.CredentialCache.DefaultCredentials; http23.KeepAlive = true; http23.AllowAutoRedirect = true; // http23.ProtocolVersion = HttpVersion.Version10; // http23.CookieContainer = MyCookieContainer; //using (Stream request2 = http23.GetRequestStream()) //{ // try // { // // request2.Write(postData, 0, postData.Length); // } // catch // { // throw; // } // finally // { // request2.Close(); // } //} try { HttpWebResponse response12 = http23.GetResponse() as HttpWebResponse; StreamReader reader12 = new StreamReader(response12.GetResponseStream()); // richTextBox3.Text += "你获取的uri返回是:" + reader12.ReadToEnd().ToString(); gethttpwithuriout = reader12.ReadToEnd().ToString(); return gethttpwithuriout; } catch (System.Exception ex) { return ex.ToString(); } finally { /// return gethttpwithuriout; } } public static string uribuider(string apitpye, Dictionary<string, string> parm1, bool needaccess_token) { if (needaccess_token) { string oldori = "http://gw.open.1688.com/openapi/param2/1/cn.alibaba.open/" + apitpye + "/" + appKey + "?"; string signolduri = "param2/1/cn.alibaba.open/" + apitpye + "/" + appKey; // string signolduri2 = oldori + "param2/1/cn.alibaba.open/" + apitpye + "?"; parm1.Add("access_token", acctk2.access_token); string signwithuri = sign(signolduri, parm1); foreach (KeyValuePair<string, string> kv in parm1) { oldori += HttpUtility.HtmlEncode(kv.Key) + "=" + HttpUtility.HtmlEncode(kv.Value) + "&"; } oldori += "_aop_signature=" + signwithuri; return oldori; } else { string oldori = "http://gw.open.1688.com/openapi/param2/1/cn.alibaba.open/" + apitpye + "/" + appKey + "?"; string signolduri = "param2/1/cn.alibaba.open/" + apitpye + "/" + appKey; // string signolduri2 = oldori + "param2/1/cn.alibaba.open/" + apitpye + "?"; string signwithuri = sign(signolduri, parm1); foreach (KeyValuePair<string, string> kv in parm1) { oldori += HttpUtility.HtmlEncode(kv.Key) + "=" + HttpUtility.HtmlEncode(kv.Value) + "&"; } oldori += "_aop_signature=" + signwithuri; return oldori; } //return ""; } } }
相关文章推荐
- searchform
- 如何在VC++6.0中添加批量注释和取消批量注释的功能
- 【转载】js关闭当前页面(窗口)的几种方式总结
- 痛苦的经历--自信心什么的大大的削弱
- pugixml简单实用
- LNMP安装后自启动设置
- pugixml简单实用
- ubuntu LAMP 安装及配置
- 阿里巴巴开放平台使用测试app
- poj 2342
- C++读写文件
- spring MVC 与 MyBatis的整合实例
- MorningSale 使用帮助
- 开心菜鸟系列学习笔记--------初探Nodejs(了解篇)
- 深入理解Javascript中的循环优化
- Django 学习笔记(2)
- MorningSale 介绍
- Zend Studio 10 汉化——在线语言包安装步骤
- LINUX内核设计与实现之调试
- 贪心算法