Просмотр исходного кода

[微信支付body超长处理][修复]

release_toaliyun_real
Stormeye.Wu 7 лет назад
Родитель
Сommit
8239ef4a06
2 измененных файлов: 39 добавлений и 1 удалений
  1. +10
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java
  2. +29
    -0
      mallinkService/src/main/java/com/iformall/utils/Utility.java

+ 10
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java Просмотреть файл

@@ -14,6 +14,7 @@ import com.iformall.service.WxCUserService;
import com.iformall.service.WxOrderService;
import com.iformall.service.WxPayOrderService;
import com.iformall.utils.RedisLock;
import com.iformall.utils.Utility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -231,7 +232,15 @@ public class WxOrderServiceImpl implements WxOrderService {

// body
// tenant_id + merchant_id + title + subtitle
String bodyStr = coupon.getTitle() + "-" + coupon.getSubTitle();
String bodyStr = "";
try {
bodyStr = Utility.substring(wxMerchant.getName(), Math.min(64, wxMerchant.getName().getBytes().length), "utf-8") +
Utility.substring(coupon.getTitle(), Math.min(62, coupon.getTitle().getBytes().length), "utf-8");
} catch (Exception e) {
logger.error("body:" + e.getMessage());
bodyStr = wxMerchant.getName() + "-" + EnumCouponType.getEnum(coupon.getType());
}


WxOrder record = new WxOrder();
record.setId(orderNumber);


+ 29
- 0
mallinkService/src/main/java/com/iformall/utils/Utility.java Просмотреть файл

@@ -572,4 +572,33 @@ public final class Utility {
}
return false;
}

/**
* @param text
* 目标字符串
* @param length
* 截取长度
* @param encode
* 采用的编码方式
* @return
* @throws UnsupportedEncodingException
*/

public static String substring(String text, int length, String encode)
throws UnsupportedEncodingException {
if (text == null) {
return null;
}
StringBuilder sb = new StringBuilder();
int currentLength = 0;
for (char c : text.toCharArray()) {
currentLength += String.valueOf(c).getBytes(encode).length;
if (currentLength <= length) {
sb.append(c);
} else {
break;
}
}
return sb.toString();
}
}

Загрузка…
Отмена
Сохранить