公共请求参数:
| 参数 | 类型 | 是否必填 | 最大长度 | 描述 | 示例值 |
|---|---|---|---|---|---|
| app_id | String | 是 | 32 | 酆泽提供给开发者的应用ID | FZ00000001 |
| method | String | 是 | 128 | 接口名称 | fzapi.crm.member_unbind_unionid |
| charset | String | 是 | 10 | 编码格式 | utf-8 |
| sign_type | String | 是 | 10 | 签名验证方式 | K11 |
| sign | String | 是 | 256 | 请求参数签名串 | 详见示例 |
| timestamp | String | 是 | 19 | 请求时间,格式 yyyy-MM-dd HH:mm:ss | 2018-06-07 12:01:50 |
| version | String | 是 | 10 | 版本 | 1.0.0 |
| content | Json | 是 | - | 请求参数集合,长度不限 | {"member_code":"0201000000012101","union_id":"xxxxxxxxxxxxx"} |
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 apiSecret { get; set; }
public content content { get; set; }
}
public class content
{
// IsConditionItem 是否必填 IsDatetime 是否日期时间 IsNum 是否数字
//会员卡号
[PropertyMappingAttribute(IsConditionItem = false, IsDatetime = false, IsNum = false)]
public string member_code { get; set; }
//union_id
[PropertyMappingAttribute(IsConditionItem = false, IsDatetime = false, IsNum = false)]
public string union_id { get; set; }
}
--请求例子
string json = "timestamp=2017-08-10 10:11:53&method=fzapi.crm.member_unbind_unionid&app_id=FZ200710011&charset=utf-8&sign_type=K11&content={\"member_code\":\"0599006008465101\",\"union_id\":\"o1L_Jwn1NdA2T3RgaaXNw4W5f3T8\",\"openid\":\"ojI8LjwcHMHL9KyrLAZwTv81twK4\",\"openid_type\":\"01\"}&version=1.0.0&sign=a502a2b312a663489fe5eefb5a3cc5b9";
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().Replace("=", "+").Replace("&", "").Replace("%3d", "=").Replace("%2f", "/");
}
MD5加密:
sign = md5(DictionarySort(JsonToDictionary(JsonConvert.SerializeObject(MemberModel)))).ToLower();
--注意
1,MemberModel的Sign参数不参与加密
2,MemberModel的content部分为json
eg:
{"timestamp":"2017-08-10 10:11:53","method":"fzapi.crm.member_unbind_unionid","app_id":"FZ200710011","charset":"utf-8","sign_type":"K11","content":"{\"member_code\":\"0599006008465101\",\"union_id\":\"o1L_Jwn1NdA2T3RgaaXNw4W5f3T8\",\"openid\":\"ojI8LjwcHMHL9KyrLAZwTv81twK4\",\"openid_type\":\"01\"}","version":"1.0.0","apiSecret":"7msj3cin"}
sign说明
JsonToDictionary :对JSON的数据进行字典化处理并且加上apiSecret 键值对 Sign参数不参与加密
DictionarySort:数据按键值对的KEY进行按acii 进行升序进行排序
md5/SHA256: MD5加密并且转为小写/SHA256(加密方式按具体需求决定)