小程序获取手机号bug,偶尔出现让人抓狂!!!
发布于 5 年前 作者 tding 1381 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

有时候点击获取手机号按钮一次不管用,需要多次点击才可以!!!!!!!

1、偶尔点击无响应

点击获取手机号按钮

<button style=“display: inline-block;border-radius: 50px;background: #ebc64b;padding: 15px 25px;box-shadow: 4px 7px 7px rgba(164, 144, 85, .3);” open-type=“getPhoneNumber” bindgetphonenumber=“getPhoneNumber”>解锁我的测试报告</button>

没有调用相关方法

getPhoneNumber: function (e) {

wx.login({

success: function ® {

console.log(e.detail.errMsg);

console.log(e.detail.iv);

console.log(e.detail.encryptedData);

console.log(r.code);

2、有时点击了,也响应了,但是没有传上来参数encryptedData和iv

2019-04-13 11:46:09

[INFO]-[Thread: http-bio-443-exec-15]-[com.jmwyw.action.WxUserInfoController.getPhoneNumber()]: 

 ----------------- encryptedData

undefined

2019-04-13 11:46:09

[INFO]-[Thread: http-bio-443-exec-15]-[com.jmwyw.action.WxUserInfoController.getPhoneNumber()]: 

 ----------------- session_key

aug6AQmtUWAPKuL16+QR/Q==

2019-04-13 11:46:09

[INFO]-[Thread: http-bio-443-exec-15]-[com.jmwyw.action.WxUserInfoController.getPhoneNumber()]: 

 ----------------- iv

undefined

3、有时候数据传上来了,但是,解密出错

有两组数据,第一次点击获取失败,紧接着再次点击调用成功

result = AesCbcUtil.decrypt("p3QhMucG/aQijjxCRcK4eIXHQINJGW15uBxG3DdmvRRDchxLIrnc63fs06Q4i98RqiPyJH0jlepTUrh/LhzLEARXkLrTT8Q0H8HQC3LpwusYYfiWXcQMayGOoiAUiPqCU6Y+pdrwuPSCJktLU8d/A0xneqnWWqrNPmjqgtoyP5YOtLbuYIeTJ8VTMF5AkWnA5NkT9AHSDMMIM47nCWoxTw==",

"QI0UESfcf7Hmm8Za8MaO+g==", "OPxEk42/SpgdXpau8CZ3og==");

System.out.print("\r\n ----------------- decrypt result \r\n"+result);

result = AesCbcUtil.decrypt("V4svsc89WcGrClnTgQdVYsWJqG4m48Fus1BkyAF5YtlIM93E86Y6QiF1wSSW35Iizi2ewMzvG5al3qlCrExjynHZRyRmqb0ajsf9HvFQqkPBxOA0hixBnUo4jPfyiNluemL9ch7J0aeswB8KS/EgnLmXE+Rt17Iev22p0i9uXCk2gM3/Krbc8DQ4/fF4rhhLP5+4/kLjr2xdLRqmvdUmzQ==",

"QI0UESfcf7Hmm8Za8MaO+g==", "swCamFyUjAPosQTZMQWzCA==");

System.out.print("\r\n ----------------- decrypt result \r\n"+result);

    

    public static String decrypt(String data, String key, String iv) throws Exception {

//      initialize();


byte[] encrypData = Base64.decodeBase64(data);

byte[] ivData = Base64.decodeBase64(iv);

byte[] sessionKey = Base64.decodeBase64(key);

String str = "";

try {

// str = decrypt(sessionKey, ivData, encrypData);

AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivData);

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

SecretKeySpec keySpec = new SecretKeySpec(sessionKey, "AES");

cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

// 解析解密后的字符串

str= new String(cipher.doFinal(encrypData), "UTF-8");

第一组数据调用失败

2019-04-15 09:48:38

[ERROR]-[Thread: main]-[com.jmwyw.action.utils.AesCbcUtil.decrypt()]: javax.crypto.BadPaddingException: Given final block not properly padded

2019-04-15 09:48:38

[INFO]-[Thread: main]-[com.jmwyw.action.utils.AesCbcUtil.decrypt()]: 

小程序返回手机号解密出错!!!!!

data:

p3QhMucG/aQijjxCRcK4eIXHQINJGW15uBxG3DdmvRRDchxLIrnc63fs06Q4i98RqiPyJH0jlepTUrh/LhzLEARXkLrTT8Q0H8HQC3LpwusYYfiWXcQMayGOoiAUiPqCU6Y+pdrwuPSCJktLU8d/A0xneqnWWqrNPmjqgtoyP5YOtLbuYIeTJ8VTMF5AkWnA5NkT9AHSDMMIM47nCWoxTw==

key:QI0UESfcf7Hmm8Za8MaO+g==

iv:OPxEk42/SpgdXpau8CZ3og==

第二组数据调用成功,如期返回数据

{“phoneNumber”:“13706896229”,“purePhoneNumber”:“13706896229”,“countryCode”:“86”,“watermark”:{“timestamp”:1555122913,“appid”:“wx4902ff5a6ed1fe4a”}}

  • 预期表现
  • 复现路径

不确定出现,无法准确复现

  • 提供一个最简复现 Demo
2 回复

同样遇到了,怎么解决呢,很急

小程序获取手机号bug,不定期出现让人抓狂!!!!

点击获取手机号按钮

1、有时候没有响应

2、有时候传上来的数据为空

3、有时候传过来的密码不对

回到顶部