14
14
15
15
import java .math .BigDecimal ;
16
16
17
+ import static com .github .binarywang .wxpay .constant .WxPayConstants .SignType .ALL_SIGN_TYPES ;
18
+
17
19
/**
18
20
* <pre>
19
21
* Created by Binary Wang on 2016-10-24.
@@ -189,8 +191,9 @@ public String toXML() {
189
191
* </pre>
190
192
*
191
193
* @param config 支付配置对象,用于读取相应系统配置信息
194
+ * @param isIgnoreSignType 签名时,是否忽略signType
192
195
*/
193
- public void checkAndSign (WxPayConfig config ) throws WxPayException {
196
+ public void checkAndSign (WxPayConfig config , boolean isIgnoreSignType ) throws WxPayException {
194
197
this .checkFields ();
195
198
196
199
if (StringUtils .isBlank (getAppid ())) {
@@ -209,11 +212,24 @@ public void checkAndSign(WxPayConfig config) throws WxPayException {
209
212
this .setSubMchId (config .getSubMchId ());
210
213
}
211
214
215
+ if (StringUtils .isBlank (getSignType ())) {
216
+ if (config .getSignType () != null && !ALL_SIGN_TYPES .contains (config .getSignType ())) {
217
+ throw new WxPayException ("非法的signType配置:" + config .getSignType () + ",请检查配置!" );
218
+ }
219
+ this .setSignType (StringUtils .trimToNull (config .getSignType ()));
220
+ } else {
221
+ if (!ALL_SIGN_TYPES .contains (this .getSignType ())) {
222
+ throw new WxPayException ("非法的sign_type参数:" + this .getSignType ());
223
+ }
224
+ }
225
+
212
226
if (StringUtils .isBlank (getNonceStr ())) {
213
227
this .setNonceStr (String .valueOf (System .currentTimeMillis ()));
214
228
}
229
+
215
230
//设置签名字段的值
216
- this .setSign (SignUtils .createSign (this , config .getMchKey (), this .signType ));
231
+ this .setSign (SignUtils .createSign (this , this .getSignType (), config .getMchKey (),
232
+ isIgnoreSignType ));
217
233
}
218
234
219
235
}
0 commit comments