foxinmy/weixin4j

刷卡支付无法进行下去

Closed this issue · 5 comments

刷卡支付类型是TradeType.MICROPAY,定义如下

public enum TradeType {
    /**
     * JS支付
     */
    JSAPI(true),
    /**
     * 刷卡支付:不需要设置TradeType参数
     */
    MICROPAY(false),
    /**
     * 扫码支付
     */
    NATIVE(true),
    /**
     * APP支付
     */
    APP(true),
    /**
     * WAP支付
     */
    WAP(true);

    boolean isPayRequestParameter;

    private TradeType(boolean isPayRequestParameter) {
        this.isPayRequestParameter = isPayRequestParameter;
    }

    /**
     * 是否作为支付请求参数
     * 
     * @return
     */
    public boolean isPayRequestParameter() {
        return isPayRequestParameter;
    }
}

可见设置为false,那如果调用isPayRequestParameter一定返回的是false

然后通过weiXinPayProxy.createMicroPayRequest来创建订单,这个方法会一层层调用到

public MchPayRequest createMicroPayRequest(String authCode, String body,
            String outTradeNo, double totalFee, String createIp, String attach)
            throws WeixinException {
        return payApi.createMicroPayRequest(authCode, body, outTradeNo,
                totalFee, createIp, attach);
    }

|
|

    public MchPayRequest createMicroPayRequest(String authCode, String body,
            String outTradeNo, double totalFee, String createIp, String attach)
            throws WeixinException {
        MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
                totalFee, null, createIp, TradeType.MICROPAY, null, authCode,
                null, attach);
        return createPayRequest(payPackage);
    }

注意这里是MchPayPackage对象,以及参数TradeType.MICROPAY,调用构造函数

    public MchPayPackage(String body, String outTradeNo, double totalFee,
            String notifyUrl, String createIp, TradeType tradeType,
            String openId, String authCode, String productId, String attach) {
        this(body, null, outTradeNo, totalFee, notifyUrl, createIp, tradeType,
                openId, authCode, productId, attach, null, null, null, null,
                null);
    }

    public MchPayPackage(String body, String detial, String outTradeNo,
            double totalFee, String notifyUrl, String createIp,
            TradeType tradeType, String openId, String authCode,
            String productId, String attach, Date timeStart, Date timeExpire,
            String goodsTag, String limitPay, String subOpenId) {
        super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
                timeStart, timeExpire, goodsTag);

               // 注意这个判断,如果为false就不设置这个值
        if (tradeType.isPayRequestParameter()) {
            this.tradeType = tradeType.name();
        }
        this.openId = openId;
        this.authCode = authCode;
        this.productId = productId;
        this.limitPay = limitPay;
        this.subOpenId = subOpenId;
    }

下面接着调用

    public MchPayRequest createPayRequest(MchPayPackage payPackage)
            throws WeixinException {

               // 第一句就判断了是否为空,上面构造函数已经把为false的TradeType.MICROPAY排除了
        if (StringUtil.isBlank(payPackage.getTradeType())) {
            throw new WeixinException("tradeType not be empty");
        }
        String tradeType = payPackage.getTradeType().toUpperCase();
        if (TradeType.MICROPAY.name().equals(tradeType)) {
            super.declareMerchant(payPackage);
            payPackage.setSign(weixinSignature.sign(payPackage));
            String para = XmlStream.toXML(payPackage);
            WeixinResponse response = weixinExecutor.post(
                    getRequestUri("micropay_uri"), para);
            MICROPayRequest microPayRequest = response
                    .getAsObject(new TypeReference<MICROPayRequest>() {
                    });
            microPayRequest.setPaymentAccount(weixinAccount);
            return microPayRequest;
        }
        PrePay prePay = createPrePay(payPackage);
        if (TradeType.APP.name().equals(tradeType)) {
            return new APPPayRequest(prePay.getPrepayId(), weixinAccount);
        } else if (TradeType.JSAPI.name().equals(tradeType)) {
            return new JSAPIPayRequest(prePay.getPrepayId(), weixinAccount);
        } else if (TradeType.NATIVE.name().equals(tradeType)) {
            return new NATIVEPayRequest(prePay.getPrepayId(),
                    prePay.getCodeUrl(), weixinAccount);
        } else if (TradeType.WAP.name().equals(tradeType)) {
            return new WAPPayRequest(prePay.getPrepayId(), weixinAccount);
        } else {
            throw new WeixinException("unknown tradeType:" + tradeType);
        }
    }

结果:com.foxinmy.weixin4j.exception.WeixinException: -1 >> tradeType not be empty >> 系统繁忙,请稍后再试

        啊,我太大意了,确实是个bug,这几天不太方便改,预计要下周三才有时间修改。抱歉发自网易邮箱大师
        在2016年08月26日 21:52,KIWI 写道:刷卡支付类型是TradeType.MICROPAY,定义如下

public enum TradeType {
/**
* JS支付
/
JSAPI(true),
/
*
* 刷卡支付:不需要设置TradeType参数
/
MICROPAY(false),
/
*
* 扫码支付
/
NATIVE(true),
/
*
* APP支付
/
APP(true),
/
*
* WAP支付
*/
WAP(true);

boolean isPayRequestParameter;

private TradeType(boolean isPayRequestParameter) {
    this.isPayRequestParameter = isPayRequestParameter;
}

/**
 * 是否作为支付请求参数
 * 
 * @return
 */
public boolean isPayRequestParameter() {
    return isPayRequestParameter;
}

}

可见设置为false,那如果调用isPayRequestParameter一定返回的是false

然后通过weiXinPayProxy.createMicroPayRequest来创建订单,这个方法会一层层调用到

public MchPayRequest createMicroPayRequest(String authCode, String body,
String outTradeNo, double totalFee, String createIp, String attach)
throws WeixinException {
return payApi.createMicroPayRequest(authCode, body, outTradeNo,
totalFee, createIp, attach);
}

public MchPayRequest createMicroPayRequest(String authCode, String body,
        String outTradeNo, double totalFee, String createIp, String attach)
        throws WeixinException {
    MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
            totalFee, null, createIp, TradeType.MICROPAY, null, authCode,
            null, attach);
    return createPayRequest(payPackage);
}

注意这里是MchPayPackage对象,以及参数TradeType.MICROPAY,调用构造函数

public MchPayPackage(String body, String outTradeNo, double totalFee,
        String notifyUrl, String createIp, TradeType tradeType,
        String openId, String authCode, String productId, String attach) {
    this(body, null, outTradeNo, totalFee, notifyUrl, createIp, tradeType,
            openId, authCode, productId, attach, null, null, null, null,
            null);
}

public MchPayPackage(String body, String detial, String outTradeNo,
        double totalFee, String notifyUrl, String createIp,
        TradeType tradeType, String openId, String authCode,
        String productId, String attach, Date timeStart, Date timeExpire,
        String goodsTag, String limitPay, String subOpenId) {
    super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
            timeStart, timeExpire, goodsTag);

           // 注意这个判断,如果为false就不设置这个值
    if (tradeType.isPayRequestParameter()) {
        this.tradeType = tradeType.name();
    }
    this.openId = openId;
    this.authCode = authCode;
    this.productId = productId;
    this.limitPay = limitPay;
    this.subOpenId = subOpenId;
}

下面接着调用

public MchPayRequest createPayRequest(MchPayPackage payPackage)
        throws WeixinException {

           // 第一句就判断了是否为空,上面构造函数已经把为false的TradeType.MICROPAY排除了
    if (StringUtil.isBlank(payPackage.getTradeType())) {
        throw new WeixinException("tradeType not be empty");
    }
    String tradeType = payPackage.getTradeType().toUpperCase();
    if (TradeType.MICROPAY.name().equals(tradeType)) {
        super.declareMerchant(payPackage);
        payPackage.setSign(weixinSignature.sign(payPackage));
        String para = XmlStream.toXML(payPackage);
        WeixinResponse response = weixinExecutor.post(
                getRequestUri("micropay_uri"), para);
        MICROPayRequest microPayRequest = response
                .getAsObject(new TypeReference<MICROPayRequest>() {
                });
        microPayRequest.setPaymentAccount(weixinAccount);
        return microPayRequest;
    }
    PrePay prePay = createPrePay(payPackage);
    if (TradeType.APP.name().equals(tradeType)) {
        return new APPPayRequest(prePay.getPrepayId(), weixinAccount);
    } else if (TradeType.JSAPI.name().equals(tradeType)) {
        return new JSAPIPayRequest(prePay.getPrepayId(), weixinAccount);
    } else if (TradeType.NATIVE.name().equals(tradeType)) {
        return new NATIVEPayRequest(prePay.getPrepayId(),
                prePay.getCodeUrl(), weixinAccount);
    } else if (TradeType.WAP.name().equals(tradeType)) {
        return new WAPPayRequest(prePay.getPrepayId(), weixinAccount);
    } else {
        throw new WeixinException("unknown tradeType:" + tradeType);
    }
}

结果:com.foxinmy.weixin4j.exception.WeixinException: -1 >> tradeType not be empty >> 系统繁忙,请稍后再试

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/foxinmy/weixin4j","title":"foxinmy/weixin4j","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/foxinmy/weixin4j"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"刷卡支付无法进行下去 (#92)"}],"action":{"name":"View Issue","url":"https://github.com/foxinmy/weixin4j/issues/92"}}}

谢谢回复,还有另一个问题,已经提了

请问maven有更新吗?

maven仓库暂时还没有,计划在下个月upgrade。:-D

好的,谢谢了