签名算法

签名算法

签名规则:

    第一步:将⾮空输入参数按照参数名(key)进行升序排序(排序规则:ASCII码从小到⼤排序-字典序排序。例如:
           排序前   api_method,api_version,app_key,access_token,timestamp,nonce_str,api_data                      排序后      access_token,api_data,api_method,api_version,app_key,nonce_str,timestamp
       第二步:按照url键值对的形式(key=value&key=value)拼接参数名与参数值。形成字符串。

示例:access_token=xxx&api_data=xxx&api_method=xxx&api_version=xxx&app_key=xxx&nonce_str=xxx&timestamp=xxx

第三步: 在字符串末尾,拼接加入”app_secret“的值(不含app_secret的键) 示例:access_token=xxx&api_data=xxx&api_method=xxx&api_version=xxx&app_key=xxx&nonce_str=xxx×tamp=xxxapp_secret的值
第四步: 对字符串进行Md5运算(运算方式:32位小写),得到签名参数“signature"的值 示例:string signature= Md5(拼接后的字符串)


签名示例:

  1.    1.假设现在有如下输入参数
    {
             "api_method":"u-city-list",
             "api_version":"1.0",
             "app_key":"wxd930ea5d5a258f4f",
             "access_token":"xxxx",
             "nonce_str":"ibuaiVcKdpRxkhJA",
    "timestamp":"1559096649", "signature":"xxxx", "api_data":{

    "city_id":1002,
    "order_vehicle_id":402,
    "vehicle_std":["双排座"],
    "spec_req":[2,5],
    "city_info_revision":296,
    "order_time":1568895707,
    "addr_info":[{
    "name":"维也纳国际酒店(深圳北站店)",
    "addr":"深圳市⻰华区致远中路2号",
    "city_id":1002,
    "city_name":"深圳",
    "district_name":"宝安区",
    "house_number":"20层2003号房",
    "contacts_name":"刘⽣",
    "contacts_phone_no":"136999969966",
    "lat_lon":{
    "lon":114.02309914676592,
    "lat":22.609618527821251
    }
    },
    {
    "name":"⻓城开发⾼层公寓",
    "addr":"皇岗路5000号",
    "city_id":1002,
    "city_name":"深圳",
    "district_name":"福⽥区",
    "house_number":"",
    "contacts_name":"",
    "contacts_phone_no":"",
    "lat_lon":{
    "lon":114.06548381551384,
    "lat":22.569156830453188
    }
    }]
    }

    }

      2.先对输入参数中非空值参数 按照(ascii字典序)进行升序排序,排序结果如下

  2. {
        "access_token":"xxxx",
        "api_data":{
            "city_id":1002,
            "order_vehicle_id":402,
            "vehicle_std":["双排座"],
            "spec_req":[2,5],
            "city_info_revision":296,
            "order_time":1568895707,
            "addr_info":[{
                    "name":"维也纳国际酒店(深圳北站店)",
                    "addr":"深圳市⻰华区致远中路2号",
                    "city_id":1002,
                    "city_name":"深圳",
                    "district_name":"宝安区",
                    "house_number":"20层2003号房",
                    "contacts_name":"刘⽣",
                    "contacts_phone_no":"136999969966",
                    "lat_lon":{
                        "lon":114.02309914676592,
                        "lat":22.609618527821251
                    }
                },
                {
                    "name":"⻓城开发⾼层公寓",
                    "addr":"皇岗路5000号",
                    "city_id":1002,
                    "city_name":"深圳",
                    "district_name":"福⽥区",
                    "house_number":"",
                    "contacts_name":"",
                    "contacts_phone_no":"",
                    "lat_lon":{
                        "lon":114.06548381551384,
                        "lat":22.569156830453188
                    }
                }
            ]
        },     "api_method":"u-city-list",     "api_version":"1.0",
        "app_key":"wxd930ea5d5a258f4f",
        "nonce_str":"ibuaiVcKdpRxkhJA",
        "timestamp":"1559096649"
    }


  3. 3.按照key=value&key=value的格式形成键值对,并使用&符号拼接各个键值对,示例如下:  

  4. "access_token=xxxxx&
     api_data={
    

    "city_id":1002,
    "order_vehicle_id":402,
    "vehicle_std":["双排座"],
    "spec_req":[2,5],
    "city_info_revision":296,
    "order_time":1568895707,
    "addr_info":[{
    "name":"维也纳国际酒店(深圳北站店)",
    "addr":"深圳市⻰华区致远中路2号",
    "city_id":1002,
    "city_name":"深圳",
    "district_name":"宝安区",
    "house_number":"20层2003号房",
    "contacts_name":"刘⽣",
    "contacts_phone_no":"136999969966",
    "lat_lon":{
    "lon":114.02309914676592,
    "lat":22.609618527821251
    }
    },
    {
    "name":"⻓城开发⾼层公寓",
    "addr":"皇岗路5000号",
    "city_id":1002,
    "city_name":"深圳",
    "district_name":"福⽥区",
    "house_number":"",
    "contacts_name":"",
    "contacts_phone_no":"",
    "lat_lon":{
    "lon":114.06548381551384,
    "lat":22.569156830453188
    }
    }
    ]

    }& api_method=xxx& api_version=xxx& app_key=xxx& nonce_str=xxx& timestamp=xxx "

     4.尾部加入app_secret的值,假设app_secret=192006250b4c09247ec02edce69f6a2d,示例如下:     

    "access_token=xxxxx&
    api_data={
    "city_id":1002,
    "order_vehicle_id":402,
    "vehicle_std":["双排座"],
    "spec_req":[2,5],
    "city_info_revision":296,
    "order_time":1568895707,
    "addr_info":[{
    "name":"维也纳国际酒店(深圳北站店)",
    "addr":"深圳市⻰华区致远中路2号",
    "city_id":1002,
    "city_name":"深圳",
    "district_name":"宝安区",
    "house_number":"20层2003号房",
    "contacts_name":"刘⽣",
    "contacts_phone_no":"136999969966",
    "lat_lon":{
    "lon":114.02309914676592,
    "lat":22.609618527821251
    }
    },
    {
    "name":"⻓城开发⾼层公寓",
    "addr":"皇岗路5000号",
    "city_id":1002,
    "city_name":"深圳",
    "district_name":"福⽥区",
    "house_number":"",
    "contacts_name":"",
    "contacts_phone_no":"",
    "lat_lon":{
    "lon":114.06548381551384,
    "lat":22.569156830453188
    }
    }
    ]

    }&
    api_method=xxx&
    api_version=xxx&
    app_key=xxx&
    nonce_str=xxx&
    timestamp=xxx
    app_secret的值

    "
  5. 5. 对最终形成的字符串进行md5运算(32位小写),示例如下,运算结果就是签名值signature  

  6. String signature=Md5(str);