diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WxPayCredentials.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WxPayCredentials.java index f4bf181f..2711171e 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WxPayCredentials.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WxPayCredentials.java @@ -100,96 +100,5 @@ public class WxPayCredentials implements Credentials { + nonce + "\n" + body + "\n"; } - - - - public static void main(String[] args) { - try { - String nonceStr = "1659525492505"; - long timestamp = 1659525493; - String message = buildMessagettt(nonceStr, timestamp); - InputStream keyInputStream = loadConfigInputStream("C:\\ttttttt\\1036\\apiclient_key.pem"); - PrivateKey merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream); - Signer signer = new PrivateKeySigner("562723E501CBEACA6B6835666168EBEB777360A4", merchantPrivateKey); - Signer.SignatureResult signature = signer.sign(message.getBytes(StandardCharsets.UTF_8)); - String mchid = "1623869862"; - - String token = "mchid=\"" + mchid + "\"," - + "nonce_str=\"" + nonceStr + "\"," - + "timestamp=\"" + timestamp + "\"," - + "serial_no=\"" + signature.certificateSerialNumber + "\"," - + "signature=\"" + signature.sign + "\""; - - System.out.println(token); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (WxPayException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - - private static String buildMessagettt(String nonce, long timestamp) - throws IOException { - String body = "{\"appid\":\"wx649b3be73c1afe47\",\"batch_name\":\"百丽提现\",\"batch_remark\":\"提现编号:714465978943332352\",\"out_batch_no\":\"714465978943332352\",\"total_amount\":100,\"total_num\":1,\"transfer_detail_list\":[{\"openid\":\"opvcM5IEkl0U5pNiHcN49Ens40jU\",\"out_detail_no\":\"8c2145ceb1bf427ea147a88b42af9e9e\",\"transfer_amount\":100,\"transfer_remark\":\"百丽提现\"}]}"; - - return "POST" + "\n" - + "/v3/transfer/batches" + "\n" - + timestamp + "\n" - + nonce + "\n" - + body + "\n"; - } - - private static final String PROBLEM_MSG = "证书文件【%s】有问题,请核实!"; - private static final String NOT_FOUND_MSG = "证书文件【%s】不存在,请核实!"; - /** - * 从配置路径 加载配置 信息(支持 classpath、本地路径、网络url) - * @param configPath 配置路径 - * @return - * @throws WxPayException - */ - private static InputStream loadConfigInputStream(String configPath) throws WxPayException { - InputStream inputStream; - final String prefix = "classpath:"; - String fileHasProblemMsg = String.format(PROBLEM_MSG, configPath); - String fileNotFoundMsg = String.format(NOT_FOUND_MSG, configPath); - if (configPath.startsWith(prefix)) { - String path = RegExUtils.removeFirst(configPath, prefix); - if (!path.startsWith("/")) { - path = "/" + path; - } - try { - inputStream = ResourcesUtil.getResourceAsStream(path); - if (inputStream == null) { - throw new WxPayException(fileNotFoundMsg); - } - } catch (Exception e) { - throw new WxPayException(fileNotFoundMsg, e); - } - } else if (configPath.startsWith("http://") || configPath.startsWith("https://")) { - try { - inputStream = new URL(configPath).openStream(); - if (inputStream == null) { - throw new WxPayException(fileNotFoundMsg); - } - } catch (IOException e) { - throw new WxPayException(fileNotFoundMsg, e); - } - } else { - try { - File file = new File(configPath); - if (!file.exists()) { - throw new WxPayException(fileNotFoundMsg); - } - - inputStream = new FileInputStream(file); - } catch (IOException e) { - throw new WxPayException(fileHasProblemMsg, e); - } - } - return inputStream; - } }