- 微信虚拟支付调用auth.checkSessionKey接口报错87009?
rawData:::::{"nickName":"Ekko","gender":0,"language":"zh_CN","city":"","province":"","country":"","avatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKt1cFB8TUnb1np2HKbJRQhkfl5pW8AEHF8mI8p23PzL6BQcwGeVDd80QmibVOhtvxVibKEVSMVAQUw/132"} signature::::::b979ab4b002ce87d98e0888b88fa55eb4dc50c71 》》》》》微信返回的 Signature加密后的值:b979ab4b002ce87d98e0888b88fa55eb4dc50c71 》》》》》按照微信接口文档加密得到的 验证Session-key ----apiUrl:https://api.weixin.qq.com/wxa/checksession?access_token=74_Qg4aPchVi-mQmaDub78_HLRP3RPStbQVIiS8d1x29pAlCX9tj6Gc_7xo86PEiC6x_-xAwv-jcHhsmDtP3PVFHSS_3QIIrWDekcPogX1eN693yxim38l9a_1RNvcTVCfACAZBI&signature=b979ab4b002ce87d98e0888b88fa55eb4dc50c71&openid=ohhBa5TqLyYV-Aap9OECmBWij5L0&sig_method=hmac_sha256 检查sessionkey时效__Response: {"errcode":87009,"errmsg":"invalid signature rid: 6552e3da-6397437b-3f0d4f01"} 我的参数加密后和微信的signature一致,但是提示signature无效 //验证sesssionkey String sessiontimeliness = WeChatPayUtils.sessiontimeliness(rawData, sessionkey, openid); /** * 检查sessionkey是否有效 * * @date 2023/10/30 16:38 */ public static String sessiontimeliness(String date ,String sessionkey ,String openids) { String errcode =null; // 替换以下值为实际的 ACCESS_TOKEN、SIGNATURE、OPENID 和 SIG_METHOD String access_token = getcredential(); System.out.println("access_token : " + access_token); String signature = getUserSignature(date,sessionkey); String openid = openids; String sig_method = "hmac_sha256";//;getUsersig_method(date,sessionkey) // 构建请求URL getUsersig_method(date,sessionkey) String apiUrl = "https://api.weixin.qq.com/wxa/checksession" + "?access_token=" + access_token + "&signature=" + signature + "&openid=" + openid + "&sig_method=" + sig_method; System.out.println("验证Session-key ----apiUrl:"+apiUrl); try { URL url = new URL(apiUrl); // 打开连接 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // 设置请求方法为GET connection.setRequestMethod("GET"); // 获取响应 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder response = new StringBuilder(); while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); // 输出响应结果 System.out.println("检查sessionkey时效__Response:\n" + response.toString()); JSONObject jsonObject = JSON.parseObject(response.toString()); errcode = jsonObject.getString("errcode"); // 关闭连接 connection.disconnect(); } catch (Exception e) { throw new RuntimeException(e); } /** * 获取signature * * @date 2023/10/30 16:38 * <p> * <p> * String datas, String secretKey */ public static String getUserSignature(String datas, String secretKey) { String sha1 = null; String input = datas + secretKey; System.out.println("拼接后的串:=======*************" + input); try { // 创建SHA-1消息摘要对象 MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); // 将字符串转换为字节数组 byte[] data = input.getBytes(); // 计算哈希值 byte[] sha1Hash = messageDigest.digest(data); // 将哈希值转换为十六进制字符串 StringBuilder hexString = new StringBuilder(); for (byte b : sha1Hash) { String hex = Integer.toHexString(0xff & b); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } sha1 = hexString.toString(); System.out.println("Signature加密后的值:" + sha1); } catch (NoSuchAlgorithmException e) { System.err.println("SHA-1 algorithm is not available."); } return sha1; } 有大神知道解决方法吗,都说是sessionkey过期了,但是,在登录时直接验证也会报这个错误,按照文档拼接rawdata和session通过加密与微信返回的sintrue也是一至的,求大神解答!!!
2023-11-14 - 微信虚拟支付调用auth.checkSessionKey接口报错87009
rawData:::::{"nickName":"Ekko","gender":0,"language":"zh_CN","city":"","province":"","country":"","avatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKt1cFB8TUnb1np2HKbJRQhkfl5pW8AEHF8mI8p23PzL6BQcwGeVDd80QmibVOhtvxVibKEVSMVAQUw/132"} signature::::::b979ab4b002ce87d98e0888b88fa55eb4dc50c71 》》》》》微信返回的 Signature加密后的值:b979ab4b002ce87d98e0888b88fa55eb4dc50c71 》》》》》按照微信接口文档加密得到的 验证Session-key ----apiUrl:https://api.weixin.qq.com/wxa/checksession?access_token=74_Qg4aPchVi-mQmaDub78_HLRP3RPStbQVIiS8d1x29pAlCX9tj6Gc_7xo86PEiC6x_-xAwv-jcHhsmDtP3PVFHSS_3QIIrWDekcPogX1eN693yxim38l9a_1RNvcTVCfACAZBI&signature=b979ab4b002ce87d98e0888b88fa55eb4dc50c71&openid=ohhBa5TqLyYV-Aap9OECmBWij5L0&sig_method=hmac_sha256 检查sessionkey时效__Response: {"errcode":87009,"errmsg":"invalid signature rid: 6552e3da-6397437b-3f0d4f01"} 我的参数加密后和微信的signature一致,但是提示signature无效 //验证sesssionkey String sessiontimeliness = WeChatPayUtils.sessiontimeliness(rawData, sessionkey, openid); /** * 检查sessionkey是否有效 * * @date 2023/10/30 16:38 */ public static String sessiontimeliness(String date ,String sessionkey ,String openids) { String errcode =null; // 替换以下值为实际的 ACCESS_TOKEN、SIGNATURE、OPENID 和 SIG_METHOD String access_token = getcredential(); System.out.println("access_token : " + access_token); String signature = getUserSignature(date,sessionkey); String openid = openids; String sig_method = "hmac_sha256";//;getUsersig_method(date,sessionkey) // 构建请求URL getUsersig_method(date,sessionkey) String apiUrl = "https://api.weixin.qq.com/wxa/checksession" + "?access_token=" + access_token + "&signature=" + signature + "&openid=" + openid + "&sig_method=" + sig_method; System.out.println("验证Session-key ----apiUrl:"+apiUrl); try { URL url = new URL(apiUrl); // 打开连接 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // 设置请求方法为GET connection.setRequestMethod("GET"); // 获取响应 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder response = new StringBuilder(); while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); // 输出响应结果 System.out.println("检查sessionkey时效__Response:\n" + response.toString()); JSONObject jsonObject = JSON.parseObject(response.toString()); errcode = jsonObject.getString("errcode"); // 关闭连接 connection.disconnect(); } catch (Exception e) { throw new RuntimeException(e); } /** * 获取signature * * @date 2023/10/30 16:38 * <p> * <p> * String datas, String secretKey */ public static String getUserSignature(String datas, String secretKey) { String sha1 = null; String input = datas + secretKey; System.out.println("拼接后的串:=======*************" + input); try { // 创建SHA-1消息摘要对象 MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); // 将字符串转换为字节数组 byte[] data = input.getBytes(); // 计算哈希值 byte[] sha1Hash = messageDigest.digest(data); // 将哈希值转换为十六进制字符串 StringBuilder hexString = new StringBuilder(); for (byte b : sha1Hash) { String hex = Integer.toHexString(0xff & b); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } sha1 = hexString.toString(); System.out.println("Signature加密后的值:" + sha1); } catch (NoSuchAlgorithmException e) { System.err.println("SHA-1 algorithm is not available."); } return sha1; } 有大神知道解决方法吗,都说是sessionkey过期了,但是,在登录时直接验证也会报这个错误,按照文档拼接rawdata和session通过加密与微信返回的sintrue也是一至的,求大神解答!!!
2023-11-14 - "errcode":87009,"errmsg":"invalid signature rid: ?
Response Code: 200 Response: {"session_key":"s5e9\/1DeB8UyOO0YsMxZEQ==","openid":"ohhBa5SnVFeO1dTS1PTQyYlp3KE4"} openid:ohhBa5SnVFeO1dTS1PTQyYlp3KE4 colde: 0f1YuPGa17sRlG0L41Ja16FwYk1YuPGg session_key: s5e9/1DeB8UyOO0YsMxZEQ== rawData: {"nickName":"小杨同学","gender":0,"language":"zh_CN","city":"","province":"","country":"","avatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTL5fzC8pBD28oSTDNicFh333dKMQKgLxHfoWc0FNqZibu3K0qsJbPxKlQAicYSzibkw5VAh21Az69ibcXQ/132"} signature :f8cf8ad973e4109a4a50bcf139a3af938206d998 Response_access_token: 74_8VFarlnhberhVIw087kw6csqHd_Ohh55_S6dV6_yG-sJN3zoH2oXI0r_tYZRMB8K7xGAF4vS_9Vc0sjyTb8k-M4ig-HHIUFQxt-Kz52_DAhoBqK1P56C9_KW3LkAEVhAAADHY access_token : 74_8VFarlnhberhVIw087kw6csqHd_Ohh55_S6dV6_yG-sJN3zoH2oXI0r_tYZRMB8K7xGAF4vS_9Vc0sjyTb8k-M4ig-HHIUFQxt-Kz52_DAhoBqK1P56C9_KW3LkAEVhAAADHY 自己加密的与微信返回的sigtrue一致,还是返回errcode":87009,"errmsg":"invalid signature rid,求大神解答 /** * 检查sessionkey是否有效 * * @date 2023/10/30 16:38 */ public static String sessiontimeliness(String date ,String sessionkey ,String openids) { String errcode =null; // 替换以下值为实际的 ACCESS_TOKEN、SIGNATURE、OPENID 和 SIG_METHOD String access_token = getcredential(); System.out.println("access_token : " + access_token); String signature = getUserSignature(date,sessionkey); String openid = openids; String sig_method = "hmac_sha256";//;getUsersig_method(date,sessionkey) // 构建请求URL getUsersig_method(date,sessionkey) String apiUrl = "https://api.weixin.qq.com/wxa/checksession" + "?access_token=" + access_token + "&signature=" + signature + "&openid=" + openid + "&sig_method=" + sig_method; System.out.println("验证Session-key ----apiUrl:"+apiUrl); try { URL url = new URL(apiUrl); // 打开连接 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // 设置请求方法为GET connection.setRequestMethod("GET"); // 获取响应 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder response = new StringBuilder(); while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); // 输出响应结果 System.out.println("检查sessionkey时效__Response:\n" + response.toString()); JSONObject jsonObject = JSON.parseObject(response.toString()); errcode = jsonObject.getString("errcode"); // 关闭连接 connection.disconnect(); } catch (Exception e) { throw new RuntimeException(e); } return errcode; } /** * 获取signature * * @date 2023/10/30 16:38 * <p> * <p> * String datas, String secretKey */staticStringStringStringStringnullString"拼接后的串:=======*************"try// 创建SHA-1消息摘要对象"SHA-1"// 将字符串转换为字节数组// 计算哈希值// 将哈希值转换为十六进制字符串newforString0xffif1'0'"Signature加密后的值:"catch"SHA-1 algorithm is not available."return sha1; }
2023-11-06