Browse Source

修复:商品描述过长导致支付失败的bug

main
科技小王子 2 weeks ago
parent
commit
591ed6a2fe
  1. 14
      src/test/java/com/gxwebsoft/shop/WechatPayDescriptionTest.java

14
src/test/java/com/gxwebsoft/shop/WechatPayDescriptionTest.java

@ -19,13 +19,13 @@ public class WechatPayDescriptionTest {
public void testTruncateToByteLimit() {
// 测试正常情况 - 字符串长度在限制内
String shortText = "正常商品描述";
String result1 = truncateToByteLimit(shortText, 127);
String result1 = WechatPayUtils.truncateToByteLimit(shortText, 127);
assertEquals(shortText, result1);
assertTrue(result1.getBytes(StandardCharsets.UTF_8).length <= 127);
// 测试超长中文字符串
String longText = "【湾区认证】【百千万工程帮扶产品 通过远方320项检测 湾区认证 丰江桥佛手瓜面】独特风味低脂轻食便捷速食非油炸 720g/袋";
String result2 = truncateToByteLimit(longText, 127);
String result2 = WechatPayUtils.truncateToByteLimit(longText, 127);
assertNotNull(result2);
assertTrue(result2.getBytes(StandardCharsets.UTF_8).length <= 127);
System.out.println("原始文本字节数: " + longText.getBytes(StandardCharsets.UTF_8).length);
@ -33,18 +33,18 @@ public class WechatPayDescriptionTest {
System.out.println("截断后字节数: " + result2.getBytes(StandardCharsets.UTF_8).length);
// 测试null和空字符串
assertNull(truncateToByteLimit(null, 127));
assertEquals("", truncateToByteLimit("", 127));
assertNull(WechatPayUtils.truncateToByteLimit(null, 127));
assertEquals("", WechatPayUtils.truncateToByteLimit("", 127));
// 测试英文字符串
String englishText = "This is a very long English description that might exceed the byte limit for WeChat Pay description field";
String result3 = truncateToByteLimit(englishText, 127);
String result3 = WechatPayUtils.truncateToByteLimit(englishText, 127);
assertNotNull(result3);
assertTrue(result3.getBytes(StandardCharsets.UTF_8).length <= 127);
// 测试混合字符串
String mixedText = "Product Name 产品名称 with special characters @#$%^&*()";
String result4 = truncateToByteLimit(mixedText, 50);
String result4 = WechatPayUtils.truncateToByteLimit(mixedText, 50);
assertNotNull(result4);
assertTrue(result4.getBytes(StandardCharsets.UTF_8).length <= 50);
}
@ -61,7 +61,7 @@ public class WechatPayDescriptionTest {
assertTrue(originalBytes > 127, "原始文本应该超过127字节");
// 测试截断
String truncated = truncateToByteLimit(errorText, 127);
String truncated = WechatPayUtils.processDescription(errorText);
int truncatedBytes = truncated.getBytes(StandardCharsets.UTF_8).length;
System.out.println("截断后文本: " + truncated);

Loading…
Cancel
Save