...
注意:不管是微信环境下的openid、unionid,还是其他的用户身份标识(audienceUserInfo下的用户识别字段),每个用户每次最多可传入5组身份标识。比如,可以从openid、unionid、会员号、手机号、身份证号、车牌号和社保账号等信息中选择5个,将openid、unionid放到wechatUserInfo下传入,另外再选择3个身份放到audienceUserInfo下传入。
代码块 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const userInfo = { // 传入用户信息,包括昵称、头像、性别、省、市及其他自定义的用户信息 wechatUserInfo: { nickname: "", headimgurl: "", sex: 0, city: "", province: "", country: "", // 必传字段,值为自建应用id,表明数据来源于某自建应用 platform: app_id, customFields: [ { // 这里只是示例 fieldValue: ["手机号码值","项目编码值"], fieldId: 123 } ] // 用户自定义字段,对象数组的形式,fieldValue为字符串数组类型,可传入多条数据,fieldId为工作台【用户】-【字段管理】中的 字段id(非 字段名称) }, audienceUserInfo: { // 传入用户身份标识,使用key value形式传入,key为识别字段的类型(对应工作台-【用户】-【用户身份管理】中的用户身份id),value为对应值,如果需使用微信openid和unionid作为用户身份标识,也许按照此格式在此处传递 // 如身份证,可传入"idCardNo":"xxxxxxxxxxxxxxx", 此处仅为举例,具体字段类型请根据接入方自身的用户身份识别标识传入 // 如openid,可传入"openid": "xxxxxxxx", 此处仅为举例,具体字段类型请根据接入方自身的用户身份识别标识传入 // 如third_userid,可传入"third_userid": "1234567890", 此处仅为举例,具体字段类型请根据接入方自身的用户身份识别标识传入 // 身份类型标识,全局唯一用户ID标识建议用 third_userid 。自定义身份字段名需要优先在 兔展 用户-身份字段管理中新增配置后才能正常使用 key: value, }, }; |
...
代码块 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
vue下的前端加密 安装依赖:npm install crypto-js 代码示例: /** * AES加密 * @param {string} secretKey 用于加密的key * @param {string} content 待加密明文字符串 * @returns {string} 加密后的密文 */ export function setTzEncrypt (content) { const secretKey = 'DpOGgKkq7-AFkKpUu5LsluM7acc' const key = crypto.SHA1(crypto.SHA1(secretKey)).toString().substring(0, 32) const newKey = crypto.enc.Hex.parse(key) const newContent = crypto.enc.Utf8.parse(content) const encrypted = crypto.AES.encrypt(newContent, newKey, { mode: crypto.mode.ECB, padding: crypto.pad.Pkcs7 }) return encrypted.ciphertext.toString().toUpperCase() } |
Java版AES(ECB)加密demo:
以下为Java版本的AES加密demo。
代码块 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// 加密方法实现如下(加密的key:自建应用的授权密钥secretkey) /** * AES加密 (默认加密模式: AES/ECB/PKCS5Padding) * * @param secretKey: 用于加密的key * @param content: 待加密明文字符串 * @return 加密后密文 */ public static String encrypt(String secretKey, String content) throws Exception { // 1.构造密钥生成器,指定为AES算法,不区分大小写 KeyGenerator keygen = KeyGenerator.getInstance("AES"); // 2.根据encodeRules规则初始化密钥生成器,生成一个128位的随机源,根据传入的字节数组 SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); secureRandom.setSeed(secretKey.getBytes(StandardCharsets.UTF_8)); keygen.init(128, secureRandom); // 3.产生原始对称密钥 SecretKey originalKey = keygen.generateKey(); // 4.获得原始对称密钥的字节数组 byte[] raw = originalKey.getEncoded(); // 5.根据字节数组生成AES密钥 SecretKey key = new SecretKeySpec(raw, "AES"); // 6.根据指定算法AES生成密码器 Cipher cipher = Cipher.getInstance("AES"); // 7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密(Decrypt_mode)操作,第二个参数为使用的KEY cipher.init(Cipher.ENCRYPT_MODE, key); // 8.获取加密内容的字节数组(这里要设置为utf-8)不然内容中如果有中文和英文混合中文就会解密为乱码 byte[] byteContent = content.getBytes(StandardCharsets.UTF_8); // 9.根据密码器的初始化方式--加密:将数据加密 byte[] byteAES = cipher.doFinal(byteContent); // 10.将加密后的数据转换为字符串并返回 return parseByte2HexStr(byteAES); } /** * 将二进制转换为16进制 * * @param buf 待转换二进制数组 * @return 16进制字符串 */ private static String parseByte2HexStr(byte[] buf) { StringBuilder sb = new StringBuilder(); for (byte b : buf) { String hex = Integer.toHexString(b & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } sb.append(hex.toUpperCase()); } return sb.toString(); } |
...