微信支付报签名错误,各位大神帮忙看一下出在哪里

public BaseResp getPayParam(Long orderId, String ip, String domain,
String openId) {
BaseResp br = new BaseResp();
br.setCode(-1);
br.setMessage("系统异常");
// 查询订单信息
DbOrder order = dbOrderMapper.selectByPrimaryKey(orderId);
// 处理加密参数

    TreeMap<String, Object> treeMap = new TreeMap<String, Object>();
    treeMap.put("nonce_str", CommonUtil.getUUID());
    treeMap.put("body", "菜鲜邦-订单"
            + String.format("%5d", order.getId()).replace(" ", "0"));
    treeMap.put("out_trade_no", CommonUtil.getDateFormat("yyyyMMddHHmmss")
            .format(order.getOrderTime()) + order.getId());
    treeMap.put("total_fee",
    CommonUtil.moneyConvertY2F(order.getTotal().toString()));
    /*treeMap.put("total_fee", 1);*/
    treeMap.put("spbill_create_ip", ip);
    treeMap.put("notify_url", domain + "pay/notify");
    treeMap.put("trade_type", "JSAPI");

    treeMap.put("appid", ConfigUtils.getString("cxn.weixin.appid"));
    treeMap.put("mch_id", ConfigUtils.getString("cxn.weixin.mch_id"));
    treeMap.put("openid", openId);
    //treeMap.put("openid", "oWArBsz0rMkVI6_n4QY4T9H_Skew");
    String key = ConfigUtils.getString("cxn.weixin.appkey");
    String signStr = CommonUtil.treeMap2ascString(treeMap) + "&key=" + key;
    treeMap.put("sign", SecurityUtils.md5(signStr, "utf-8").toUpperCase());
    String param = CommonUtil.map2xml(treeMap);

    HttpResult hr = CommonUtil.getHtmlContent(
            "https://api.mch.weixin.qq.com/pay/unifiedorder", "POST",
            "utf-8", param);
    logger.info("getPayParam.Info:----------content=" + hr.getContent());

    br.setMessage(hr.getContent());
    if (StringUtils.isNotBlank(hr.getContent())) {
        Map<String, Object> map = CommonUtil.xml2map(hr.getContent());
        if (CommonUtil.map2string(map, "return_code").equals("SUCCESS")
                && CommonUtil.map2string(map, "result_code").equals(
                        "SUCCESS")) {
            treeMap.clear();
            String appid = CommonUtil.map2string(map, "appid");
            treeMap.put("appId", appid);
            logger.info("weixinPrepay .method return message about appid:---------"
                    + appid);
            treeMap.put("timeStamp",
                    String.valueOf(System.currentTimeMillis() / 1000));
            treeMap.put("nonceStr", CommonUtil.getUUID());
            treeMap.put("package",
                    "prepay_id=" + CommonUtil.map2string(map, "prepay_id"));
            treeMap.put("signType", "MD5");
            treeMap.put(
                    "paySign",
                    SecurityUtils.md5(
                            CommonUtil.treeMap2ascString(treeMap) + "&key="
                                    + key, "utf-8").toUpperCase());
            treeMap.put("packageInfo", treeMap.get("package"));
            treeMap.remove("package");
            br.setCode(0);
            br.setMessage("操作成功");
            br.setObject(treeMap);
            // 插入pay_record
            PayRecord pr = new PayRecord();
            pr.setOrderId(orderId);
            pr.setPayType(0);
            pr.setPayState(3);
            payRecordMapper.insert(pr);
        } else if (StringUtils.isNotBlank(CommonUtil.map2string(map,
                "err_code_des"))) {
            String message = CommonUtil.map2string(map, "err_code_des");
            br.setMessage(message);
            // 插prepay_record
            PrepayRecord prePr = new PrepayRecord();
            prePr.setCode(CommonUtil.map2string(map, "err_code"));// err_code
            prePr.setMsg(message);
            prePr.setReturnType(1);
            prePr.setOrderId(orderId);
            prepayRecordMapper.insert(prePr);
        } else if (StringUtils.isNotBlank(CommonUtil.map2string(map,
                "return_msg"))) {
            String message = CommonUtil.map2string(map, "return_msg");
            br.setMessage(message);
            // 插prepay_record
            PrepayRecord prePr = new PrepayRecord();
            prePr.setCode(CommonUtil.map2string(map, "return_code"));// return_code
            prePr.setMsg(message);
            prePr.setOrderId(orderId);
            prePr.setReturnType(0);
            prepayRecordMapper.insert(prePr);
        }
    }
    return br;
}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐