收藏
回答

如何获取微信用户的手机号?

此段代码原先可以获取到微信用户的手机号,现在解密后的信息中没有手机号码了,是什么原因
byte[] encrypData = Base64Utils.decodeFromString(encryptedData);
byte[] ivData = Base64Utils.decodeFromString(iv);
byte[] sessionKey = Base64Utils.decodeFromString(key);

AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivData);
String resultString = null;
try {
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    SecretKeySpec keySpec = new SecretKeySpec(sessionKey, "AES");

    // 设置为解密模式
    cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
    resultString = new String(cipher.doFinal(encrypData), "UTF-8");
} catch (Exception e) {
    e.printStackTrace();
}
JSONObject object = JSONObject.parseObject(resultString);
//获取用户登录的手机号码
return object.getString("purePhoneNumber");
回答关注问题邀请回答
收藏

1 个回答

  • 小庄梦蝶
    小庄梦蝶
    2021-06-04
    public Object getPhoneNumber(String session_key, String encryptedData, String iv) throws UnsupportedEncodingException{
        String session_key1=session_key.replace(" ","+");
        String encryptedData1=encryptedData.replace(" ","+");
        String iv1=iv.replace(" ","+");
        byte[] encrypData =Base64.getDecoder().decode(encryptedData1);
    
        byte[] ivData =Base64.getDecoder().decode(iv1);
    
        byte[] keyByte=Base64.getDecoder().decode(session_key1);
        
        AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivData);
        String resultString = null;
        try {
            int base = 16;
            if (keyByte.length % base != 0) {
                int groups = keyByte.length / base + (keyByte.length % base != 0 ? 1 : 0);
                byte[] temp = new byte[groups * base];
                Arrays.fill(temp, (byte) 0);
                System.arraycopy(keyByte, 0, temp, 0, keyByte.length);
                keyByte = temp;
            }
            Security.addProvider(new BouncyCastleProvider());
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");
            cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
            resultString = new String(cipher.doFinal(encrypData), "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject object = JSONObject.parseObject(resultString);
        return object.getString("purePhoneNumber");
    }
    //这都运行不了那把小程序砸了
    


    2021-06-04
    有用
    回复
登录 后发表内容
问题标签