公共请求参数:

参数 类型 是否必填 最大长度 描述 示例值
app_id String 32 酆泽提供给开发者的应用ID DRC8000401
method String 128 接口名称 fzapi.crm.EnqMemberInfo
charset String 10 编码格式 utf-8
sign_type String 10 签名验证方式 MD5
sign String 256 请求参数签名串 详见示例
timestamp String 19 请求时间,格式 yyyy-MM-dd HH:mm:ss 2018-06-07 12:01:50
version String 10 版本 1.0.0
format String 10 格式 json
content Json - 请求参数集合,长度不限 {"member_code":"80004020018778"}
public class MemberModel
{

    public string timestamp { get; set; }

    public string method { get; set; }

    public string app_id { get; set; }

    public string charset { get; set; }

    public string sign_type { get; set; }

    public string sign { get; set; }

    public string version { get; set; }

    public string format { get; set; }

    public string apiSecret { get; set; }

    public content content { get; set; }

}
public class content
{
     public string member_code{ get; set; }
}
        --请求例子
          string json = "timestamp=2018-08-10 10:20:44&method=fzapi.crm.EnqMemberInfo&app_id=DRC8000401&apiSecret=fz7msj3cin&charset=utf-8&sign_type=md5&version=1.0.0&format=json&sign=0e4a8a99d13b4127c8bf6131b4abec51&content={"member_code":"80004020018778"}";


            byte[] data = encoding.GetBytes(json);

            // Prepare web request
            HttpWebRequest myRequest =
                (HttpWebRequest)WebRequest.Create("http://localhost:32052/fzapi.ashx");

            myRequest.Method = "POST";
            //  myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentType = "application/json";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();
            // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string strresponse = reader.ReadToEnd();
            --JSON转字典
          public static Dictionary<string, object> JsonToDictionary(string jsonData)
        {

            //实例化JavaScriptSerializer类的新实例
            JavaScriptSerializer jss = new JavaScriptSerializer();
            try
            {
                //将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象
                return jss.Deserialize<Dictionary<string, object>>(jsonData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
           --字典排序
            public static string DictionarySort(Dictionary<string, object> dic)
        {
            StringBuilder sb = new StringBuilder();
            if (dic.Count > 0)
            {
                List<KeyValuePair<string, object>> lst = new List<KeyValuePair<string, object>>(dic);
                lst.Sort(delegate(KeyValuePair<string, object> s1, KeyValuePair<string, object> s2)
                {
                    return s1.Key.CompareTo(s2.Key);
                });
                dic.Clear();

                for (int i = 0; i < lst.Count; i++)
                {
                    sb.Append((i == 0 ? "" : "&") + lst[i].Key + "=" + lst[i].Value);
                }


            }
            return sb.ToString();
        }
 MD5加密:

sign = md5(DictionarySort(JsonToDictionary(JsonConvert.SerializeObject(MemberModel)))).ToLower();
MD5加密前:apiSecret=fz7msj3cin&app_id=DRC8000401&charset=utf-8&content={"member_code":"80004020018778"}&format=json&method=fzapi.crm.EnqMemberInfo&sign_type=md5&timestamp=2018-08-10 10:20:44&version=1.0.0

 --注意
 1,MemberModel的Sign参数不参与加密
 2,MemberModel的content部分为json
 eg:
 {"timestamp":"2018-08-10 10:20:44","method":"fzapi.crm.EnqMemberInfo","app_id":"DRC8000401","charset":"utf-8","sign_type":"md5","content":"{\"member_code\":\"80004020018778\"}","version":"1.0.0","apiSecret":"fz7msj3cin","format":"json"}

sign说明

JsonToDictionary :对JSON的数据进行字典化处理并且加上apiSecret 键值对 Sign参数不参与加密

DictionarySort:数据按键值对的KEY进行按acii 进行升序进行排序

md5/SHA256: MD5加密并且转为小写/SHA256(加密方式按具体需求决定)

results matching ""

    No results matching ""