淘宝API sign签名问题,高手请指点!多谢!

qwestw 2014-05-29 11:10:49
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//正确的sign
//http://gw.api.taobao.com/router/rest?sign=70950D9D8BEC7BF55BA572902733F261×tamp=2014-05-28+00%3A04%3A02&v=2.0&app_key=21792839&method=taobao.time.get&partner_id=top-apitools&format=json
Dictionary<string, string> param = new Dictionary<string, string>();

param["app_key"] = "21792839";
param["format"] = "json";
param["method"] = "taobao.time.get";
param["partner_id"] = "top-apitools";
param["timestamp"] = "2014-05-28 00:04:02";
param["v"] = "2.0";

string secret = "c22cd49550a5fac8a775893a34a0391c";
string x = getMD5String(param, secret);
textBox1.Text = x;
}
public static String getMD5String(Dictionary<string, string> param, String str)
{
String gets = getBeforeSign(param, str);
Console.WriteLine(gets);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash((new UTF8Encoding()).GetBytes(gets));
//result = md5.ComputeHash(result);
return byteArrayToHexString(result);
}

private static String byteArrayToHexString(byte[] b)
{
StringBuilder resultSb = new StringBuilder();
string stmp;
for (int i = 0; i < b.Length; i++)
{
int md = (b[i] & 0XFF);
stmp = "" + md.ToString("X"); ;
if (stmp.Length == 1)
resultSb.Append("0").Append(stmp);
else
resultSb.Append(stmp);
}
return resultSb.ToString().ToUpper();
}
private static String getBeforeSign(Dictionary<String, String> param, String orgin)
{
String indexs = orgin;
if (param == null)
return null;
foreach (KeyValuePair<String, String> var in param)
{
String name = (String)var.Key.ToString();
orgin += name;
orgin += param[name];
}

orgin = orgin + indexs;
return orgin;
}

}
}


2.运算结果:
848457EDB79276ACDC1B1E636CDC5757
3正确结果
sign=70950D9D8BEC7BF55BA572902733F261

请问到底是哪里不对?MD5算法问题,还是参数问题?
...全文
121 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Anymore 2014-05-30
  • 打赏
  • 举报
回复
md5:将secretcode同时拼接到参数字符串头、尾部进行md5加密后,再转化成大写 http://hi.baidu.com/mic1688/item/7b477c12470f300cb88a1a20

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧