8
8
import com .github .binarywang .wxpay .service .WxPayService ;
9
9
import com .github .binarywang .wxpay .util .SignUtils ;
10
10
import lombok .RequiredArgsConstructor ;
11
+ import lombok .SneakyThrows ;
11
12
import lombok .extern .slf4j .Slf4j ;
12
13
import me .chanjar .weixin .common .util .json .WxGsonBuilder ;
13
14
import org .apache .commons .lang3 .StringUtils ;
14
15
15
16
import java .net .URLEncoder ;
17
+ import java .nio .charset .StandardCharsets ;
16
18
17
19
/**
18
20
* @author chenliang
@@ -26,32 +28,40 @@ public class WxEntrustPapServiceImpl implements WxEntrustPapService {
26
28
27
29
28
30
@ Override
31
+ @ SneakyThrows
29
32
public String mpSign (WxMpEntrustRequest wxMpEntrustRequest ) throws WxPayException {
30
33
wxMpEntrustRequest .checkAndSign (payService .getConfig ());
31
34
StringBuilder signStrTemp = new StringBuilder (payService .getPayBaseUrl () + "/papay/entrustweb" );
32
35
signStrTemp .append ("?appid=" ).append (wxMpEntrustRequest .getAppid ());
33
36
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 ()));
36
41
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 ) {
39
46
signStrTemp .append ("&return_web=" ).append (wxMpEntrustRequest .getReturnWeb ());
40
47
}
41
48
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 () ));
43
50
}
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 ());
45
53
return signStrTemp .toString ();
46
54
}
47
55
48
56
@ Override
57
+ @ SneakyThrows
49
58
public String maSign (WxMaEntrustRequest wxMaEntrustRequest ) throws WxPayException {
50
59
wxMaEntrustRequest .checkAndSign (payService .getConfig ());
51
- wxMaEntrustRequest .setNotifyUrl (URLEncoder .encode (wxMaEntrustRequest .getNotifyUrl ()));
60
+ wxMaEntrustRequest .setNotifyUrl (URLEncoder .encode (wxMaEntrustRequest .getNotifyUrl (), StandardCharsets . UTF_8 . name () ));
52
61
return wxMaEntrustRequest .toString ();
53
62
}
54
63
64
+ @ SneakyThrows
55
65
@ Override
56
66
public WxH5EntrustResult h5Sign (WxH5EntrustRequest wxH5EntrustRequest ) throws WxPayException {
57
67
wxH5EntrustRequest .checkAndSign (payService .getConfig ());
@@ -70,11 +80,11 @@ public WxH5EntrustResult h5Sign(WxH5EntrustRequest wxH5EntrustRequest) throws Wx
70
80
StringBuilder strBuilder = new StringBuilder (url );
71
81
strBuilder .append ("?appid=" ).append (wxH5EntrustRequest .getAppid ());
72
82
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 () ));
75
85
strBuilder .append ("&plan_id=" ).append (wxH5EntrustRequest .getPlanId ());
76
86
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 () ));
78
88
}
79
89
if (StringUtils .isNotEmpty (wxH5EntrustRequest .getReturnAppid ())) {
80
90
strBuilder .append ("&return_appid=" ).append (wxH5EntrustRequest .getReturnAppid ());
0 commit comments