{"id":15199948,"url":"https://github.com/imHansiy/EdgeWecomCrypto","last_synced_at":"2025-10-28T14:30:53.932Z","repository":{"id":234721442,"uuid":"789421156","full_name":"imHansiy/EdgeWecomCrypto","owner":"imHansiy","description":"EdgeWeComCrypto是专门针对企业微信在边缘计算领域重新编写的库，主要实现了消息加密、解密和域验证。利用Web标准API，它可以在CloudFlare Workers、Vercel、Deno、BUN等平台上无缝运行，确保微信消息的安全传输和验证。","archived":false,"fork":false,"pushed_at":"2024-04-21T08:41:17.000Z","size":335,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-10T05:25:19.344Z","etag":null,"topics":["cloudflare-workers","crypto","edge","vercel","wecom","wecomcrypto"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imHansiy.png","metadata":{"files":{"readme":"README.en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-20T13:57:40.000Z","updated_at":"2025-02-10T02:20:45.000Z","dependencies_parsed_at":"2024-04-20T15:03:46.969Z","dependency_job_id":"2580f8f1-91a7-425b-88f8-dbaf6ec42238","html_url":"https://github.com/imHansiy/EdgeWecomCrypto","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.1428571428571429,"last_synced_commit":"ee33833861123e184a8d4381c9edf9404a92e3a5"},"previous_names":["1802024110/edgewecomcrypto","imhansiy/edgewecomcrypto"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imHansiy%2FEdgeWecomCrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imHansiy%2FEdgeWecomCrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imHansiy%2FEdgeWecomCrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imHansiy%2FEdgeWecomCrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imHansiy","download_url":"https://codeload.github.com/imHansiy/EdgeWecomCrypto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238662706,"owners_count":19509652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","crypto","edge","vercel","wecom","wecomcrypto"],"created_at":"2024-09-28T02:22:09.051Z","updated_at":"2025-10-28T14:30:47.564Z","avatar_url":"https://github.com/imHansiy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Languages\n\n[中文](./README.md)|[English](./README.en.md)\n\n# Introduction\n\nEdgeWeComCrypto is a library specifically rewritten for enterprise WeChat in the field of edge computing, mainly\nimplementing message encryption, decryption, and domain verification. Using Web standard APIs, it seamlessly runs on\nplatforms such as CloudFlare Workers, Vercel, Deno, BUN, etc., ensuring the secure transmission and validation of WeChat\nmessages.\n\n# Usage\n\n## NPM\n\n1. Install via npm\n\n```npm\nnpm i edgewecomcrypto\n```\n\n2. Example\n\n```js\nimport {decrypt} from \"edgewecomcrypto\";\n\nconst encryptMsg = \"CH0HBGa+pgJEdeHMFNghyqbf1TJSg+W7vVx/6HThtdfrK3CLYGhEcUC/2Ayfecgck+/MxeRNOb0ZgtBzIBZso4+2LZU11zLQyDx++txixg7tYDrnE/aicQo65AdR6vMcBFb47xUK8vjC8EbQElQhzlVcb9QOlTLYIw6eAksyAJ85WL2XPha0Q5MgiowUSD98movbhdwGc3SV580qhQWtNZsVAp2ghi2EcNPxk36a8itTtlZsPHXcdy1mR4HhYlSrZVhlnz4mkfzVu9zo0wVu1zQ9JT2iKMaeDSya6C7ffZWwY1CXBeWnTpf4urs7GvFyMM6n8vVHCTHRFXGpHfvxccWvz0YgR75xjTpUzk6nOID1s761/efsymuPNLkZ5XCw453pErAloXiMMJ3SED+UMA==\"\nconst encodingAESKey = \"FMox2C8OsO0yfD8jzz6fRElAb6r6hm9BRJfUqxjnCUe\"\nconst {message} = decrypt(encodingAESKey, encryptMsg);\nconsole.log(message);\n```\n\n## CDN\n\n1. Import\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/1802024110/EdgeWecomCrypto/dist/index.min.js\"\u003e\u003c/script\u003e\n```\n\n2. Example\n\n```js\nconst encryptMsg = \"CH0HBGa+pgJEdeHMFNghyqbf1TJSg+W7vVx/6HThtdfrK3CLYGhEcUC/2Ayfecgck+/MxeRNOb0ZgtBzIBZso4+2LZU11zLQyDx++txixg7tYDrnE/aicQo65AdR6vMcBFb47xUK8vjC8EbQElQhzlVcb9QOlTLYIw6eAksyAJ85WL2XPha0Q5MgiowUSD98movbhdwGc3SV580qhQWtNZsVAp2ghi2EcNPxk36a8itTtlZsPHXcdy1mR4HhYlSrZVhlnz4mkfzVu9zo0wVu1zQ9JT2iKMaeDSya6C7ffZWwY1CXBeWnTpf4urs7GvFyMM6n8vVHCTHRFXGpHfvxccWvz0YgR75xjTpUzk6nOID1s761/efsymuPNLkZ5XCw453pErAloXiMMJ3SED+UMA==\"\nconst encodingAESKey = \"FMox2C8OsO0yfD8jzz6fRElAb6r6hm9BRJfUqxjnCUe\"\nconst {message} = WecomCrypto.decrypt(encodingAESKey, encryptMsg);\nconsole.log(message);\n```\n\n# Functions\n\n## Get Signature (`getSignature`)\n\nGet the signature.\n\n* `token`: Token\n* `timestamp`: Timestamp\n* `nonce`: Nonce\n* `echostr`: Encrypted data\n\nReturns a `Promise` containing the signature string.\n\n---\n\n## Decrypt (`decrypt`)\n\nDecrypt.\n\n* `encodingAESKey`: EncodingAESKey\n* `encryptTxt`: Ciphertext\n\nReturns an object containing the decrypted information:\n\n* `id`: Decrypted ID\n* `message`: Decrypted message\n* `random`: Decrypted random number\n\n---\n\n### Example\n\n```js\nimport {decrypt} from \"edgewecomcrypto\";\n\nconst encodingAESKey = \"FMox2C8OsO0yfD8jzz6fRElAb6r6hm9BRJfUqxjnCUe\"\nconst encryptTxt = \"bwhkOMneUrrkav5ZhvH24Jqz56GHpzwNxJCQRbTuoGneBOQZxRlckJYtbWX+HJBIDywmH9EvSxqjqBnVyTTB1+OVp9X+oGgYk0uA6/5AOGzTrK65kKjjoGwf6CYktHWTF2nh2qpRKw+ah/6XjxXnIpQ1wUsmjVmFety57eh97l+j9U/AG14zOsBciNTsAR5ei4yMcQZxF+FQF2qAxWKCQTBPrfhp4eccuwHR5/huRk8mH4zTy875B6B1kneR8sE75Rmwx1FRO0rFdMWBq0ti6hnSTXK35aAg0+VWEpZc2BK9zd4MiX0c89l9m4E7MCmbj3xPAYn9nos16pgxfVnv9+WbA1aM9xXEo0p8XXOktq+3kr4gULTAO7ik51TArHNk4q6mG5YsR5PkIoCztOZu8w==\"\nconst {message} = decrypt(encodingAESKey, encryptTxt);\nconsole.log(message);\n```\n\n## Encrypt (`encrypt`)\n\n\u003e This function is untested (because there is no domain available for testing), and there is probably a problem if it\n\u003e cannot run normally. If it doesn't work properly, please refer to\n\u003e the [official documentation](https://developer.work.weixin.qq.com/document/path/91144#%E5%8A%A0%E5%AF%86%E5%87%BD%E6%95%B0)\n\u003e and modify it yourself. Welcome to submit a PR with modified code.\n\nEncrypts the given message using the AES encryption algorithm.\n\n* `encodingAESKey`: AES key used for encryption, Base64 encoded.\n* `message`: Message to be encrypted.\n* `corpid`: Corporate ID.\n* `random` (optional): Random number, default is 16 bytes.\n\nReturns the encrypted message, Base64 encoded.\n\n### Example\n\n```js\nimport {encrypt} from \"edgewecomcrypto\";\n\nconst encodingAESKey = \"FMox2C8OsO0yfD8jzz6fRElAb6r6hm9BRJfUqxjnCUe\"\nconst message = `\n\u003cxml\u003e\n\u003cToUserName\u003e\u003c![CDATA[toUser]]\u003e\u003c/ToUserName\u003e\n\u003cFromUserName\u003e\u003c![CDATA[fromUser]]\u003e\u003c/FromUserName\u003e\n\u003cCreateTime\u003e1357290913\u003c/CreateTime\u003e\n\u003cMsgType\u003e\u003c![CDATA[voice]]\u003e\u003c/MsgType\u003e\n\u003cVoice\u003e\n    \u003cMediaId\u003e\u003c![CDATA[media_id]]\u003e\u003c/MediaId\u003e\n\u003c/Voice\u003e\n\u003c/xml\u003e\n`\nconst corpid = \"wwb230a336235c4ea\"\nconst encryptMsg = encrypt(encodingAESKey, message, corpid);\nconsole.log(encryptMsg);\n```\n\n---\n\n## Get JS-SDK Signature (`getJsApiSignature`)\n\nGet the JS-SDK signature, which is the `MsgSignature` parameter in the passive reply message.\n\n* `jsapi_ticket`: JS-SDK ticket\n* `url`: The URL of the current webpage, including the trailing `/`, but not including the `#` and beyond. Needs to be\n  configured as a **trusted domain** in the enterprise WeChat backend.\n* `nonceStr` (optional): Random string, with a length of less than 32 characters.\n* `timestamp` (optional): Current timestamp (in seconds).\n\nReturns a `Promise` containing the signature string.\n\n---\n\n## Get Access Token (`getAccessToken`)\n\nGet the access token of the account.\n\n* `corpid`: Corporate ID\n* `corpsecret`: Application's credential secret\n\nReturns a `Promise` containing the access token string. Valid for 7200 seconds.\n\n---\n\n## Get JSAPI Ticket (`getJsapiTicket`)\n\nGet the jsapi\\_ticket of the account.\n\n* `access_token`: Account's access token\n\nReturns a `Promise` containing the jsapi\\_ticket string. Within one hour, an enterprise can get a maximum of 400 times,\nand a single application cannot exceed 100 times.\n\n# Reference Documents\n\n* [Enterprise WeChat Development Documentation](https://work.weixin.qq.com/api/doc/90000/90135/90231)\n* [Enterprise WeChat Online Debugging Tool](https://developer.work.weixin.qq.com/resource/devtool)\n\n# License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FimHansiy%2FEdgeWecomCrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FimHansiy%2FEdgeWecomCrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FimHansiy%2FEdgeWecomCrypto/lists"}