feat(mobile-h5): add RSA login body builder with jsencrypt

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-10 15:57:35 +08:00
1 parent 2bc7f353f0
commit 8efa992e21
3 files changed
+37 -2

No files matched your search

+8 -1
View File
@@ -8,7 +8,8 @@
"name": "mobile-h5",
"version": "1.0.0",
"dependencies": {
"@vant/weapp": "^1.11.7"
"@vant/weapp": "^1.11.7",
"jsencrypt": "^3.5.4"
}
},
"node_modules/@vant/weapp": {
@@ -16,6 +17,12 @@
"resolved": "https://registry.npmmirror.com/@vant/weapp/-/weapp-1.11.7.tgz",
"integrity": "sha512-Rwn9BBnb4kHSV4XmvBicwtd42J+amEUfnFDcXJsGNPNX4a9c/DoT6YLsm4X1wB2+sQbdiQsbFBLAvGRBxCkD8g==",
"license": "MIT"
},
"node_modules/jsencrypt": {
"version": "3.5.4",
"resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.5.4.tgz",
"integrity": "sha512-kNjfYEMNASxrDGsmcSQh/rUTmcoRfSUkxnAz+MMywM8jtGu+fFEZ3nJjHM58zscVnwR0fYmG9sGkTDjqUdpiwA==",
"license": "MIT"
}
}
}
+2 -1
View File
@@ -4,6 +4,7 @@
"private": true,
"description": "zkxw mobile uni-app (HBuilderX) + Vant Weapp",
"dependencies": {
"@vant/weapp": "^1.11.7"
"@vant/weapp": "^1.11.7",
"jsencrypt": "^3.5.4"
}
}
+27
View File
@@ -0,0 +1,27 @@
import JSEncrypt from 'jsencrypt'
import { get } from './request.js'
/**
* 对齐 web-admin `buildWebEncryptedLoginBody`:
* 拉公钥后加密 { username, password, ts }。
* @returns {Promise<{ encryptedLogin: string }>}
*/
export async function buildEncryptedLoginBody(username, password) {
const data = await get('/web/auth/login-rsa-public-key')
const publicKeyPem = data && data.publicKeyPem
if (!publicKeyPem) {
throw new Error('获取登录公钥失败')
}
const crypt = new JSEncrypt()
crypt.setPublicKey(publicKeyPem)
const payload = JSON.stringify({
username,
password,
ts: Date.now()
})
const encryptedLogin = crypt.encrypt(payload)
if (!encryptedLogin) {
throw new Error('登录加密失败,请重试')
}
return { encryptedLogin }
}