1414
1515import java .math .BigDecimal ;
1616
17+ import static com .github .binarywang .wxpay .constant .WxPayConstants .SignType .ALL_SIGN_TYPES ;
18+
1719/**
1820 * <pre>
1921 * Created by Binary Wang on 2016-10-24.
@@ -189,8 +191,9 @@ public String toXML() {
189191 * </pre>
190192 *
191193 * @param config 支付配置对象,用于读取相应系统配置信息
194+ * @param isIgnoreSignType 签名时,是否忽略signType
192195 */
193- public void checkAndSign (WxPayConfig config ) throws WxPayException {
196+ public void checkAndSign (WxPayConfig config , boolean isIgnoreSignType ) throws WxPayException {
194197 this .checkFields ();
195198
196199 if (StringUtils .isBlank (getAppid ())) {
@@ -209,11 +212,24 @@ public void checkAndSign(WxPayConfig config) throws WxPayException {
209212 this .setSubMchId (config .getSubMchId ());
210213 }
211214
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+
212226 if (StringUtils .isBlank (getNonceStr ())) {
213227 this .setNonceStr (String .valueOf (System .currentTimeMillis ()));
214228 }
229+
215230 //设置签名字段的值
216- this .setSign (SignUtils .createSign (this , config .getMchKey (), this .signType ));
231+ this .setSign (SignUtils .createSign (this , this .getSignType (), config .getMchKey (),
232+ isIgnoreSignType ));
217233 }
218234
219235}
0 commit comments