Skip to content

Commit

Permalink
Update: README
Browse files Browse the repository at this point in the history
  • Loading branch information
xgd16 committed Jan 11, 2025
1 parent aa76464 commit 1b9676f
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,52 +101,6 @@ server:
[在线文档](https://apifox.com/apidoc/shared-335b66b6-90dd-42af-8a1b-f7d1a2c3f351)
[Open Api File](<./uniTranslate%20(统一翻译).openapi.json>)
## 接口身份验证 ts 示例
```typescript
import { MD5 } from "crypto-js";

/**
*
* @param key 平台设置的key
* @param params 请求参数
* @return 生成的身份验证码
*/
function AuthEncrypt(key: string, params: { [key: string]: any }): string {
return MD5(key + sortMapToStr(params)).toString();
}

const sortMapToStr = (map: { [key: string]: any }): string => {
let mapArr = new Array();
for (const key in map) {
const item = map[key];
if (Array.isArray(item)) {
mapArr.push(`${key}:${item.join(",")}`);
continue;
}
if (typeof item === "object") {
mapArr.push(`${key}:|${sortMapToStr(item)}|`);
continue;
}
mapArr.push(`${key}:${item}`);
}

return mapArr.sort().join("&");
};

const params: { [key: string]: any } = {
c: {
cc: 1,
cb: 2,
ca: 3,
cd: 4,
},
a: 1,
b: [4, 1, 2],
};

console.log(AuthEncrypt("123456", params));
```
请求示例
Expand Down

0 comments on commit 1b9676f

Please sign in to comment.