zoukankan      html  css  js  c++  java
  • 微信红包签名算法 C#代码实现

    string stringA = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA";
    
                string stringSignTemp = stringA + "&key=192006250b4c09247ec02edce69f6a2d";
    
                string sign = MD5Helper.GetMD5Hash(stringSignTemp).ToUpper();
     public class MD5Helper
        {
            public static string GetMD5Hash(string value)
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] hashByte = md5.ComputeHash(Encoding.Default.GetBytes(value));
                StringBuilder sb = new StringBuilder();
                foreach (byte b in hashByte)
                {
                    sb.Append(b.ToString("x").PadLeft(2, '0'));
                }
                return sb.ToString();
            }
        }

    假设传送的参数如下:

    appid: wxd930ea5d5a258f4f

    mch_id: 10000100

    device_info: 1000

    body: test

    nonce_str: ibuaiVcKdpRxkhJA

    第一步:对参数按照key=value的格式,并按照参数名ASCII字典序排序如下:

    stringA="appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA";

    第二步:拼接API密钥:

    stringSignTemp="stringA&key=192006250b4c09247ec02edce69f6a2d"

    sign=MD5(stringSignTemp).toUpperCase()="9A0A8659F005D6984697E2CA0A9CF3B7"

    最终得到最终发送的数据:

    <xml>

    <appid>wxd930ea5d5a258f4f</appid>

    <mch_id>10000100</mch_id>

    <device_info>1000<device_info>

    <body>test</body>

    <nonce_str>ibuaiVcKdpRxkhJA</nonce_str>

    <sign>9A0A8659F005D6984697E2CA0A9CF3B7</sign>

    <xml>

    https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=4_3

  • 相关阅读:
    poj--2031--Building a Space Station(prime)
    nyoj--364--田忌赛马(贪心)
    nyoj--496--巡回赛(拓扑排序)
    nyoj--1100--WAJUEJI which home strong!(bfs)
    hdoj--5625--Clarke and chemistry(枚举)
    poj--1753--Flip Game(dfs好题)
    poj--1101--The Game(bfs)
    冒泡排序
    php常见错误
    php乱码
  • 原文地址:https://www.cnblogs.com/weiweictgu/p/4898231.html
Copyright © 2011-2022 走看看