com.alipay.api.AlipayConstants Java Examples
The following examples show how to use
com.alipay.api.AlipayConstants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlConverter.java From pay with Apache License 2.0 | 6 votes |
/** * 获取签名 * * @param body * @return */ private String getSign(String body) { String signNodeName = "<" + AlipayConstants.SIGN + ">"; String signEndNodeName = "</" + AlipayConstants.SIGN + ">"; int indexOfSignNode = body.indexOf(signNodeName); int indexOfSignEndNode = body.indexOf(signEndNodeName); if (indexOfSignNode < 0 || indexOfSignEndNode < 0) { return null; } // 签名 return body.substring(indexOfSignNode + signNodeName.length(), indexOfSignEndNode); }
Example #2
Source File: AlipayLogger.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
/** * 业务/系统错误日志 */ public static void logBizDebug(String rsp) { if (!needEnableLogger) { return; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE)); StringBuilder sb = new StringBuilder(); sb.append(df.format(new Date())); sb.append("^_^"); sb.append(rsp); if (blog.isDebugEnabled()) { blog.debug(sb.toString()); } }
Example #3
Source File: RSAEncryptor.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
protected String doSign(String content, String charset, String privateKey) throws Exception { PrivateKey priKey = getPrivateKeyFromPKCS8(AlipayConstants.SIGN_TYPE_RSA, new ByteArrayInputStream(privateKey.getBytes())); Signature signature = Signature.getInstance(getSignAlgorithm()); signature.initSign(priKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } byte[] signed = signature.sign(); return new String(Base64.encodeBase64(signed)); }
Example #4
Source File: AlipayLogger.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
/** * 业务/系统错误日志 */ public static void logBizError(String rsp, Map<String, Long> costTimeMap) { if (!needEnableLogger) { return; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE)); StringBuilder sb = new StringBuilder(); sb.append(df.format(new Date())); sb.append("^_^"); sb.append(rsp); sb.append("^_^"); sb.append(costTimeMap.get("prepareCostTime")); sb.append("ms,"); sb.append(costTimeMap.get("requestCostTime")); sb.append("ms,"); sb.append(costTimeMap.get("postCostTime")); sb.append("ms"); blog.error(sb.toString()); }
Example #5
Source File: AlipaySignature.java From pay with Apache License 2.0 | 6 votes |
public static boolean rsaCheckContent(String content, String sign, String publicKey, String charset) throws AlipayApiException { try { PublicKey pubKey = getPublicKeyFromX509("RSA", new ByteArrayInputStream(publicKey.getBytes())); java.security.Signature signature = java.security.Signature .getInstance(AlipayConstants.SIGN_ALGORITHMS); signature.initVerify(pubKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } return signature.verify(Base64.decodeBase64(sign.getBytes())); } catch (Exception e) { throw new AlipayApiException( "RSAcontent = " + content + ",sign=" + sign + ",charset = " + charset, e); } }
Example #6
Source File: PayBizContent.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
@Override public String toString() { JsonObject json = new JsonObject(); json.put("out_trade_no", this.outTradeNo); json.put("total_amount", CommonUtils.getStringFromIntFen(Integer.parseInt(this.totalAmount))); json.put("subject", this.subject); json.put("product_code", "QUICK_WAP_PAY"); if (null != this.passbackParams) { try { json.put("passback_params", URLEncoder.encode(this.passbackParams, AlipayConstants.CHARSET_UTF8)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return json.toString(); }
Example #7
Source File: AliPayApi.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
/** * 该方法实现了支付宝手机网页的支付功能; * 方法将调用支付宝支付页面需要用到的数据拼接和设置好,然后,写到响应中,前台会自动弹出支付宝支付页面; * 其中,支付金额要求大于0.01,并且小于100000000,需要调用者自己检查该值再传进来,否则页面会报获取不到订单信息错误; * * @param aliAccountInfo 保存了支付宝账户的信息,包括appId、用户私钥、支付宝公钥和回调地址等,具体参考AliAccountInfo类的属性说明 * @param payBizContent 保存了订单信息,包括本地订单号、金额等,具体参考BizContent类的属性说明 * Create by quandong */ public static void wapPay(AliAccountInfo aliAccountInfo, PayBizContent payBizContent, HttpServerResponse httpResponse) throws IOException { AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 从客户端工厂中获取AlipayClient AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest(); // 创建API对应的request String form = ""; alipayRequest.setReturnUrl(aliAccountInfo.getReturnUrl()); // 设置回跳地址 alipayRequest.setNotifyUrl(aliAccountInfo.getNotifyUrl()); // 设置通知地址 alipayRequest.setBizContent(payBizContent.toString()); // 填充业务参数 try { form = alipayClient.pageExecute(alipayRequest).getBody(); // 调用SDK生成表单 } catch (AlipayApiException e) { e.printStackTrace(); } httpResponse.putHeader("Content-Type", "text/html;charset=" + AlipayConstants.CHARSET_UTF8); // 设置文本类型及编码 httpResponse.end(form); // 直接将完整的表单html输出到页面 }
Example #8
Source File: AlipaySignature.java From pay with Apache License 2.0 | 6 votes |
public static boolean rsa256CheckContent(String content, String sign, String publicKey, String charset) throws AlipayApiException { try { PublicKey pubKey = getPublicKeyFromX509("RSA", new ByteArrayInputStream(publicKey.getBytes())); java.security.Signature signature = java.security.Signature .getInstance(AlipayConstants.SIGN_SHA256RSA_ALGORITHMS); signature.initVerify(pubKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } return signature.verify(Base64.decodeBase64(sign.getBytes())); } catch (Exception e) { throw new AlipayApiException( "RSAcontent = " + content + ",sign=" + sign + ",charset = " + charset, e); } }
Example #9
Source File: JsonConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * * @param request * @param body * @return */ private String getSignSourceData(AlipayRequest<?> request, String body) { // 加签源串起点 String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); // 成功或者新版接口 if (indexOfRootNode > 0) { return parseSignSourceData(body, rootNode, indexOfRootNode); // 老版本失败接口 } else if (indexOfErrorRoot > 0) { return parseSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #10
Source File: JsonConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * 获取JSON响应加签内容串 * * @param request * @param body * @return */ private ResponseParseItem getJSONSignSourceData(AlipayRequest<?> request, String body) { String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); if (indexOfRootNode > 0) { return parseJSONSignSourceData(body, rootNode, indexOfRootNode); } else if (indexOfErrorRoot > 0) { return parseJSONSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #11
Source File: AlipaySignature.java From pay with Apache License 2.0 | 6 votes |
public static String rsaSign(String content, String privateKey, String charset) throws AlipayApiException { try { PrivateKey priKey = getPrivateKeyFromPKCS8(AlipayConstants.SIGN_TYPE_RSA, new ByteArrayInputStream(privateKey.getBytes())); java.security.Signature signature = java.security.Signature .getInstance(AlipayConstants.SIGN_ALGORITHMS); signature.initSign(priKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } byte[] signed = signature.sign(); return new String(Base64.encodeBase64(signed)); } catch (InvalidKeySpecException ie) { throw new AlipayApiException("RSA私钥格式不正确,请检查是否正确配置了PKCS8格式的私钥", ie); } catch (Exception e) { throw new AlipayApiException("RSAcontent = " + content + "; charset = " + charset, e); } }
Example #12
Source File: XmlConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * * @param request * @param body * @return */ private String getSignSourceData(AlipayRequest<?> request, String body) { // XML不同的节点 String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); // 成功或者新版接口 if (indexOfRootNode > 0) { return parseSignSourceData(body, rootNode, indexOfRootNode); // 老版本接口 } else if (indexOfErrorRoot > 0) { return parseSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #13
Source File: XmlConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * 获取签名 * * @param body * @return */ private String getSign(String body) { String signNodeName = "<" + AlipayConstants.SIGN + ">"; String signEndNodeName = "</" + AlipayConstants.SIGN + ">"; int indexOfSignNode = body.indexOf(signNodeName); int indexOfSignEndNode = body.indexOf(signEndNodeName); if (indexOfSignNode < 0 || indexOfSignEndNode < 0) { return null; } // 签名 return body.substring(indexOfSignNode + signNodeName.length(), indexOfSignEndNode); }
Example #14
Source File: XmlConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * * @param request * @param body * @return */ private ResponseParseItem getXMLSignSourceData(AlipayRequest<?> request, String body) { // XML涓������������� String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); if (indexOfRootNode > 0) { return parseXMLSignSourceData(body, rootNode, indexOfRootNode); } else if (indexOfErrorRoot > 0) { return parseXMLSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #15
Source File: JsonConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * 获取签名源串内容 * * * @param body * @param rootNode * @param indexOfRootNode * @return */ private String parseSignSourceData(String body, String rootNode, int indexOfRootNode) { // 第一个字母+长度+引号和分号 int signDataStartIndex = indexOfRootNode + rootNode.length() + 2; int indexOfSign = body.indexOf("\"" + AlipayConstants.SIGN + "\""); if (indexOfSign < 0) { return null; } // 签名前-逗号 int signDataEndIndex = indexOfSign - 1; return body.substring(signDataStartIndex, signDataEndIndex); }
Example #16
Source File: XmlConverter.java From pay with Apache License 2.0 | 6 votes |
/** * * @param request * @param body * @return */ private String getSignSourceData(AlipayRequest<?> request, String body) { // XML不同的节点 String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); // 成功或者新版接口 if (indexOfRootNode > 0) { return parseSignSourceData(body, rootNode, indexOfRootNode); // 老版本接口 } else if (indexOfErrorRoot > 0) { return parseSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #17
Source File: XmlConverter.java From pay with Apache License 2.0 | 6 votes |
/** * 签名源串 * * @param body * @param rootNode * @param indexOfRootNode * @return */ private String parseSignSourceData(String body, String rootNode, int indexOfRootNode) { // 第一个字母+长度+> int signDataStartIndex = indexOfRootNode + rootNode.length() + 1; int indexOfSign = body.indexOf("<" + AlipayConstants.SIGN); if (indexOfSign < 0) { return null; } // 签名前减去 int signDataEndIndex = indexOfSign; return body.substring(signDataStartIndex, signDataEndIndex); }
Example #18
Source File: JsonConverter.java From pay with Apache License 2.0 | 6 votes |
/** * 获取JSON响应加签内容串 * * @param request * @param body * @return */ private ResponseParseItem getJSONSignSourceData(AlipayRequest<?> request, String body) { String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); if (indexOfRootNode > 0) { return parseJSONSignSourceData(body, rootNode, indexOfRootNode); } else if (indexOfErrorRoot > 0) { return parseJSONSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #19
Source File: JsonConverter.java From pay with Apache License 2.0 | 6 votes |
/** * 获取签名源串内容 * * * @param body * @param rootNode * @param indexOfRootNode * @return */ private String parseSignSourceData(String body, String rootNode, int indexOfRootNode) { // 第一个字母+长度+引号和分号 int signDataStartIndex = indexOfRootNode + rootNode.length() + 2; int indexOfSign = body.indexOf("\"" + AlipayConstants.SIGN + "\""); if (indexOfSign < 0) { return null; } // 签名前-逗号 int signDataEndIndex = indexOfSign - 1; return body.substring(signDataStartIndex, signDataEndIndex); }
Example #20
Source File: JsonConverter.java From pay with Apache License 2.0 | 6 votes |
/** * * @param request * @param body * @return */ private String getSignSourceData(AlipayRequest<?> request, String body) { // 加签源串起点 String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); // 成功或者新版接口 if (indexOfRootNode > 0) { return parseSignSourceData(body, rootNode, indexOfRootNode); // 老版本失败接口 } else if (indexOfErrorRoot > 0) { return parseSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #21
Source File: AlipayLogger.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * 业务/系统错误日志 */ public static void logBizDebug(String rsp) { if (!needEnableLogger) { return; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE)); StringBuilder sb = new StringBuilder(); sb.append(df.format(new Date())); sb.append("^_^"); sb.append(rsp); if (blog.isDebugEnabled()) { blog.debug(sb.toString()); } }
Example #22
Source File: AlipaySignature.java From alipay-sdk with Apache License 2.0 | 6 votes |
public static boolean rsaCheckContent(String content, String sign, String publicKey, String charset) throws AlipayApiException { try { PublicKey pubKey = getPublicKeyFromX509("RSA", new ByteArrayInputStream(publicKey.getBytes())); java.security.Signature signature = java.security.Signature .getInstance(AlipayConstants.SIGN_ALGORITHMS); signature.initVerify(pubKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } return signature.verify(Base64.decodeBase64(sign.getBytes())); } catch (Exception e) { throw new AlipayApiException( "RSAcontent = " + content + ",sign=" + sign + ",charset = " + charset, e); } }
Example #23
Source File: AlipaySignature.java From alipay-sdk with Apache License 2.0 | 6 votes |
public static boolean rsa256CheckContent(String content, String sign, String publicKey, String charset) throws AlipayApiException { try { PublicKey pubKey = getPublicKeyFromX509("RSA", new ByteArrayInputStream(publicKey.getBytes())); java.security.Signature signature = java.security.Signature .getInstance(AlipayConstants.SIGN_SHA256RSA_ALGORITHMS); signature.initVerify(pubKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } return signature.verify(Base64.decodeBase64(sign.getBytes())); } catch (Exception e) { throw new AlipayApiException( "RSAcontent = " + content + ",sign=" + sign + ",charset = " + charset, e); } }
Example #24
Source File: XmlConverter.java From pay with Apache License 2.0 | 6 votes |
/** * * @param request * @param body * @return */ private ResponseParseItem getXMLSignSourceData(AlipayRequest<?> request, String body) { // XML涓������������� String rootNode = request.getApiMethodName().replace('.', '_') + AlipayConstants.RESPONSE_SUFFIX; String errorRootNode = AlipayConstants.ERROR_RESPONSE; int indexOfRootNode = body.indexOf(rootNode); int indexOfErrorRoot = body.indexOf(errorRootNode); if (indexOfRootNode > 0) { return parseXMLSignSourceData(body, rootNode, indexOfRootNode); } else if (indexOfErrorRoot > 0) { return parseXMLSignSourceData(body, errorRootNode, indexOfErrorRoot); } else { return null; } }
Example #25
Source File: AlipaySignature.java From pay with Apache License 2.0 | 6 votes |
public static String rsa256Sign(String content, String privateKey, String charset) throws AlipayApiException { try { PrivateKey priKey = getPrivateKeyFromPKCS8(AlipayConstants.SIGN_TYPE_RSA, new ByteArrayInputStream(privateKey.getBytes())); java.security.Signature signature = java.security.Signature .getInstance(AlipayConstants.SIGN_SHA256RSA_ALGORITHMS); signature.initSign(priKey); if (StringUtils.isEmpty(charset)) { signature.update(content.getBytes()); } else { signature.update(content.getBytes(charset)); } byte[] signed = signature.sign(); return new String(Base64.encodeBase64(signed)); } catch (Exception e) { throw new AlipayApiException("RSAcontent = " + content + "; charset = " + charset, e); } }
Example #26
Source File: XmlConverter.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * 签名源串 * * @param body * @param rootNode * @param indexOfRootNode * @return */ private String parseSignSourceData(String body, String rootNode, int indexOfRootNode) { // 第一个字母+长度+> int signDataStartIndex = indexOfRootNode + rootNode.length() + 1; int indexOfSign = body.indexOf("<" + AlipayConstants.SIGN); if (indexOfSign < 0) { return null; } // 签名前减去 int signDataEndIndex = indexOfSign; return body.substring(signDataStartIndex, signDataEndIndex); }
Example #27
Source File: AlipayLogger.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
/** * 业务/系统错误日志 */ public static void logBizError(String rsp) { if (!needEnableLogger) { return; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE)); StringBuilder sb = new StringBuilder(); sb.append(df.format(new Date())); sb.append("^_^"); sb.append(rsp); blog.error(sb.toString()); }
Example #28
Source File: AlipayLogger.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * 发生特别错误时记录完整错误现场 */ public static void logErrorScene(Map<String, Object> rt, AlipayResponse tRsp, String appSecret) { if (!needEnableLogger) { return; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE)); StringBuilder sb = new StringBuilder(); sb.append("ErrorScene"); sb.append("^_^"); sb.append(tRsp.getErrorCode()); sb.append("^_^"); sb.append(tRsp.getSubCode()); sb.append("^_^"); sb.append(ip); sb.append("^_^"); sb.append(osName); sb.append("^_^"); sb.append(df.format(new Date())); sb.append("^_^"); sb.append("ProtocalMustParams:"); appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb); sb.append("^_^"); sb.append("ProtocalOptParams:"); appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb); sb.append("^_^"); sb.append("ApplicationParams:"); appendLog((AlipayHashMap) rt.get("textParams"), sb); sb.append("^_^"); sb.append("Body:"); sb.append((String) rt.get("rsp")); blog.error(sb.toString()); }
Example #29
Source File: AlipayLogger.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * 通讯错误日志 */ private static void _logCommError(Exception e, HttpURLConnection conn, String url, String appKey, String method, Map<String, String> params) { DateFormat df = new SimpleDateFormat(AlipayConstants.DATE_TIME_FORMAT); df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE)); String sdkName = AlipayConstants.SDK_VERSION; String urlStr = null; String rspCode = ""; if (conn != null) { try { urlStr = conn.getURL().toString(); rspCode = "HTTP_ERROR_" + conn.getResponseCode(); } catch (IOException ioe) { } } else { urlStr = url; rspCode = ""; } StringBuilder sb = new StringBuilder(); sb.append(df.format(new Date()));// 时间 sb.append("^_^"); sb.append(method);// API sb.append("^_^"); sb.append(appKey);// APP sb.append("^_^"); sb.append(getIp());// IP地址 sb.append("^_^"); sb.append(osName);// 操作系统 sb.append("^_^"); sb.append(sdkName);// SDK名字,这是例子,请换成其他名字 sb.append("^_^"); sb.append(urlStr);// 请求URL sb.append("^_^"); sb.append(rspCode); sb.append("^_^"); sb.append((e.getMessage() + "").replaceAll("\r\n", " ")); clog.error(sb.toString()); }
Example #30
Source File: AlipaySignature.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * 公钥加密 * * @param content 待加密内容 * @param publicKey 公钥 * @param charset 字符集,如UTF-8, GBK, GB2312 * @return 密文内容 * @throws AlipayApiException */ public static String rsaEncrypt(String content, String publicKey, String charset) throws AlipayApiException { try { PublicKey pubKey = getPublicKeyFromX509(AlipayConstants.SIGN_TYPE_RSA, new ByteArrayInputStream(publicKey.getBytes())); Cipher cipher = Cipher.getInstance(AlipayConstants.SIGN_TYPE_RSA); cipher.init(Cipher.ENCRYPT_MODE, pubKey); byte[] data = StringUtils.isEmpty(charset) ? content.getBytes() : content.getBytes(charset); int inputLen = data.length; ByteArrayOutputStream out = new ByteArrayOutputStream(); int offSet = 0; byte[] cache; int i = 0; // 对数据分段加密 while (inputLen - offSet > 0) { if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); } else { cache = cipher.doFinal(data, offSet, inputLen - offSet); } out.write(cache, 0, cache.length); i++; offSet = i * MAX_ENCRYPT_BLOCK; } byte[] encryptedData = Base64.encodeBase64(out.toByteArray()); out.close(); return StringUtils.isEmpty(charset) ? new String(encryptedData) : new String(encryptedData, charset); } catch (Exception e) { throw new AlipayApiException("EncryptContent = " + content + ",charset = " + charset, e); } }