88import com .github .binarywang .wxpay .service .WxPayService ;
99import com .github .binarywang .wxpay .util .SignUtils ;
1010import lombok .RequiredArgsConstructor ;
11+ import lombok .SneakyThrows ;
1112import lombok .extern .slf4j .Slf4j ;
1213import me .chanjar .weixin .common .util .json .WxGsonBuilder ;
1314import org .apache .commons .lang3 .StringUtils ;
1415
1516import java .net .URLEncoder ;
17+ import java .nio .charset .StandardCharsets ;
1618
1719/**
1820 * @author chenliang
@@ -26,32 +28,40 @@ public class WxEntrustPapServiceImpl implements WxEntrustPapService {
2628
2729
2830 @ Override
31+ @ SneakyThrows
2932 public String mpSign (WxMpEntrustRequest wxMpEntrustRequest ) throws WxPayException {
3033 wxMpEntrustRequest .checkAndSign (payService .getConfig ());
3134 StringBuilder signStrTemp = new StringBuilder (payService .getPayBaseUrl () + "/papay/entrustweb" );
3235 signStrTemp .append ("?appid=" ).append (wxMpEntrustRequest .getAppid ());
3336 signStrTemp .append ("&contract_code=" ).append (wxMpEntrustRequest .getContractCode ());
34- signStrTemp .append ("&contract_display_account=" ).append (URLEncoder .encode (wxMpEntrustRequest .getContractDisplayAccount ()));
35- signStrTemp .append ("&mch_id=" ).append (wxMpEntrustRequest .getMchId ()).append ("¬ify_url=" ).append (URLEncoder .encode (wxMpEntrustRequest .getNotifyUrl ()));
37+ signStrTemp .append ("&contract_display_account=" )
38+ .append (URLEncoder .encode (wxMpEntrustRequest .getContractDisplayAccount (), StandardCharsets .UTF_8 .name ()));
39+ signStrTemp .append ("&mch_id=" ).append (wxMpEntrustRequest .getMchId ()).append ("¬ify_url=" )
40+ .append (URLEncoder .encode (wxMpEntrustRequest .getNotifyUrl (), StandardCharsets .UTF_8 .name ()));
3641 signStrTemp .append ("&plan_id=" ).append (wxMpEntrustRequest .getPlanId ());
37- signStrTemp .append ("&request_serial=" ).append (wxMpEntrustRequest .getRequestSerial ()).append ("×tamp=" ).append (wxMpEntrustRequest .getTimestamp ());
38- if (StringUtils .isNotEmpty (wxMpEntrustRequest .getReturnWeb ())) {
42+ signStrTemp .append ("&request_serial=" ).append (wxMpEntrustRequest .getRequestSerial ()).append ("×tamp=" )
43+ .append (wxMpEntrustRequest .getTimestamp ());
44+ // 根据微信支付文档,returnWeb字段只在值为1时需要添加到URL参数中,表示返回签约页面的referrer url
45+ if (wxMpEntrustRequest .getReturnWeb () != null && wxMpEntrustRequest .getReturnWeb () == 1 ) {
3946 signStrTemp .append ("&return_web=" ).append (wxMpEntrustRequest .getReturnWeb ());
4047 }
4148 if (StringUtils .isNotEmpty (wxMpEntrustRequest .getOuterId ())) {
42- signStrTemp .append ("&outerid=" ).append (URLEncoder .encode (wxMpEntrustRequest .getOuterId ()));
49+ signStrTemp .append ("&outerid=" ).append (URLEncoder .encode (wxMpEntrustRequest .getOuterId (), StandardCharsets . UTF_8 . name () ));
4350 }
44- signStrTemp .append ("&version=" ).append (wxMpEntrustRequest .getVersion ()).append ("&sign=" ).append (wxMpEntrustRequest .getSign ());
51+ signStrTemp .append ("&version=" ).append (wxMpEntrustRequest .getVersion ()).append ("&sign=" )
52+ .append (wxMpEntrustRequest .getSign ());
4553 return signStrTemp .toString ();
4654 }
4755
4856 @ Override
57+ @ SneakyThrows
4958 public String maSign (WxMaEntrustRequest wxMaEntrustRequest ) throws WxPayException {
5059 wxMaEntrustRequest .checkAndSign (payService .getConfig ());
51- wxMaEntrustRequest .setNotifyUrl (URLEncoder .encode (wxMaEntrustRequest .getNotifyUrl ()));
60+ wxMaEntrustRequest .setNotifyUrl (URLEncoder .encode (wxMaEntrustRequest .getNotifyUrl (), StandardCharsets . UTF_8 . name () ));
5261 return wxMaEntrustRequest .toString ();
5362 }
5463
64+ @ SneakyThrows
5565 @ Override
5666 public WxH5EntrustResult h5Sign (WxH5EntrustRequest wxH5EntrustRequest ) throws WxPayException {
5767 wxH5EntrustRequest .checkAndSign (payService .getConfig ());
@@ -70,11 +80,11 @@ public WxH5EntrustResult h5Sign(WxH5EntrustRequest wxH5EntrustRequest) throws Wx
7080 StringBuilder strBuilder = new StringBuilder (url );
7181 strBuilder .append ("?appid=" ).append (wxH5EntrustRequest .getAppid ());
7282 strBuilder .append ("&contract_code=" ).append (wxH5EntrustRequest .getContractCode ());
73- strBuilder .append ("&contract_display_account=" ).append (URLEncoder .encode (wxH5EntrustRequest .getContractDisplayAccount ()));
74- strBuilder .append ("&mch_id=" ).append (wxH5EntrustRequest .getMchId ()).append ("¬ify_url=" ).append (URLEncoder .encode (wxH5EntrustRequest .getNotifyUrl ()));
83+ strBuilder .append ("&contract_display_account=" ).append (URLEncoder .encode (wxH5EntrustRequest .getContractDisplayAccount (), StandardCharsets . UTF_8 . name () ));
84+ strBuilder .append ("&mch_id=" ).append (wxH5EntrustRequest .getMchId ()).append ("¬ify_url=" ).append (URLEncoder .encode (wxH5EntrustRequest .getNotifyUrl (), StandardCharsets . UTF_8 . name () ));
7585 strBuilder .append ("&plan_id=" ).append (wxH5EntrustRequest .getPlanId ());
7686 if (StringUtils .isNotEmpty (wxH5EntrustRequest .getOuterId ())) {
77- strBuilder .append ("&outerid=" ).append (URLEncoder .encode (wxH5EntrustRequest .getOuterId ()));
87+ strBuilder .append ("&outerid=" ).append (URLEncoder .encode (wxH5EntrustRequest .getOuterId (), StandardCharsets . UTF_8 . name () ));
7888 }
7989 if (StringUtils .isNotEmpty (wxH5EntrustRequest .getReturnAppid ())) {
8090 strBuilder .append ("&return_appid=" ).append (wxH5EntrustRequest .getReturnAppid ());
0 commit comments