- 新增小红书前端模块(启动服务、内容分析、爆款创作、发布记录、技能卡片、拟人设置、AI 助手) - 新增 xhs-agent-desktop 独立桌面 Agent,对接 OMS 任务调度 - 登录页重构,整合微信登录与 OMS JWT 认证 - 订单、渠道、用户中心等页面与 API 增强 Co-authored-by: Cursor <cursoragent@cursor.com>
94 lines
3.0 KiB
Markdown
94 lines
3.0 KiB
Markdown
# 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<string>();
|
||
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;
|
||
}
|
||
}
|
||
```
|