请教淘宝API sign签名问题,望高人指点!谢谢!

 


   对淘宝API sign签名老计算不对

代码如下:

 

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;
        }

    }
}


运行结果:

848457EDB79276ACDC1B1E636CDC5757

 

正确结果:

70950D9D8BEC7BF55BA572902733F261

请问是什么问题?

  • 1
    点赞
  • 13
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

评论 13 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

qwestw

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值