# itfx PrefixScript 示例库 > 仅为模式参考;生成脚本时**以用户描述的文档规则为准**,不要生搬硬套。 - 参数名 **`obj`**,无 `using`,类型全限定名 --- ## 模式 1:HMAC + urlPath + 排序 keyvalue → Query 适用:开放平台 `signatureWithParamsAndUrlPath` 一类(如阿里国际站 notifyBizEvent)。 ```csharp string secret = obj.GetAccountFieldValueOrNull("appSecret"); string appKey = obj.GetAccountFieldValueOrNull("appKey"); string urlPath = "param2/1/vendor.namespace/api.name/" + appKey; string dto = null; for (int i = 0; i < obj.QueryFieldList.Count; i++) { if (obj.QueryFieldList[i].Name == "bizPayload") { dto = obj.QueryFieldList[i].Value; break; } } if (string.IsNullOrEmpty(dto) || dto == "$FromMappingBody") { dto = Newtonsoft.Json.JsonConvert.SerializeObject(obj.OriginalInterfaceMappedInput); } var parts = new System.Collections.Generic.List(); parts.Add("bizPayload" + dto); parts.Sort(System.StringComparer.Ordinal); var sb = new System.Text.StringBuilder(); sb.Append(urlPath); for (int i = 0; i < parts.Count; i++) sb.Append(parts[i]); using (var hmac = new System.Security.Cryptography.HMACSHA1(System.Text.Encoding.UTF8.GetBytes(secret))) { byte[] hash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(sb.ToString())); string sign = System.BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); for (int i = 0; i < obj.QueryFieldList.Count; i++) { if (obj.QueryFieldList[i].Name == "_aop_signature") { obj.QueryFieldList[i].Value = sign; break; } } } ``` --- ## 模式 2:MD5(secret + params + secret) → Header ```csharp string secret = obj.GetAccountFieldValueOrNull("apiSecret") ?? ""; string body = Newtonsoft.Json.JsonConvert.SerializeObject(obj.OriginalInterfaceMappedInput); string signStr = secret + "body" + body + secret; var md5 = System.Security.Cryptography.MD5.Create(); byte[] hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signStr)); string sign = System.BitConverter.ToString(hash).Replace("-", "").ToUpperInvariant(); for (int i = 0; i < obj.HeaderFieldList.Count; i++) { if (obj.HeaderFieldList[i].Name == "sign") { obj.HeaderFieldList[i].Value = sign; break; } } ``` --- ## 模式 3:HMAC-SHA256 + JSON Body 字段 ```csharp string secret = obj.GetAccountFieldValueOrNull("appSecret") ?? ""; string payload = Newtonsoft.Json.JsonConvert.SerializeObject(obj.OriginalInterfaceMappedInput); using (var hmac = new System.Security.Cryptography.HMACSHA256(System.Text.Encoding.UTF8.GetBytes(secret))) { byte[] hash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(payload)); string sign = System.Convert.ToBase64String(hash); obj.OriginalInterfaceMappedInput["signature"] = sign; } ``` --- ## 模式 4:Form 表单字段签名 ```csharp string sign = "..."; // 按文档计算 for (int i = 0; i < obj.FormFieldList.Count; i++) { if (obj.FormFieldList[i].Name == "sign") { obj.FormFieldList[i].Value = sign; break; } } ```