微信小程序数据拼接_微信小程序用户数据解密算法Java版
生活随笔
收集整理的這篇文章主要介紹了
微信小程序数据拼接_微信小程序用户数据解密算法Java版
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
打開官方文檔,開心~ 騰訊爸爸竟然給提供了解密算法
然而我下載解壓后人傻了
可能鵝廠沒養Java程序猿吧
那就看這C++改造吧
public?class?AnthCodeVerify?{ private final static String cipherString = "AES/CBC/PKCS5Padding"; public static JSONObject decrypt(String encryptedData, String iv, String sessionKey) throws Exception { String jsonStr; try { BASE64Decoder base64Decoder = new BASE64Decoder();????????????byte[]?encryptedByte?=?base64Decoder.decodeBuffer(encryptedData); byte[] sessionKeyByte = base64Decoder.decodeBuffer(sessionKey); byte[] ivByte = base64Decoder.decodeBuffer(iv); SecretKeySpec skeySpec = new SecretKeySpec(sessionKeyByte, "AES"); Cipher cipher = Cipher.getInstance(cipherString); IvParameterSpec ivParameterSpec = new IvParameterSpec(ivByte); cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameterSpec); byte[] original = cipher.doFinal(encryptedByte); jsonStr = new String(original); } catch (Exception ex) { throw new Exception("Illegal Buffer"); } JSONObject jsonObject = new JSONObject(jsonStr); return jsonObject; }}解密后的數據格式如下:
{ "openId": "OPENID", "nickName": "NICKNAME", "gender": GENDER, "city": "CITY", "province": "PROVINCE", "country": "COUNTRY", "avatarUrl": "AVATARURL", "unionId": "UNIONID", "watermark": { "appid":"APPID", "timestamp":TIMESTAMP }}Q1: 為什么解密后的數據中沒有unionId?需要小程序管理員將小程序綁在微信開放平臺
總結
以上是生活随笔為你收集整理的微信小程序数据拼接_微信小程序用户数据解密算法Java版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bash ps1变量_在 Linux 中
- 下一篇: zemax迈克尔逊干涉仪_zemax非序