执着追求
执着追求
  • 发布:2015-09-04 12:15
  • 更新:2015-10-21 16:31
  • 阅读:2048

对接微信支付服务端遇到的问题

分类:HTML5+

我们之前的一个项目是用cordova做的,微信支付OK,现在我拿那个服务端对接payment时候跳转到微信的时候只有一个确定按钮,应该说参数出现了问题,但是检查了好多遍都没看出问题,有遇到这种情况的朋友嘛 求助

参数结果示例:

{"reqCode":{"sign":"3DB4B6C20895454047A0FAA27699A075","timestamp":"1441342474","noncestr":"fd2c5e4680d9a01dba3aada5ece22270","partnerid":"1255284101","prepayid":"wx201509041244342124f2db000815243835","package":"Sign=WXPay","appid":"wx6633a5c45669f132"}}

部分代码:

private ReturnResult buildWXpayResponse(OrderInfo orderInfo)
throws Exception {
ReturnResult returnResult = new ReturnResult();
// 订单名称
String orderName = AlipayConfig.orderName;
// 付款金额
int price = orderInfo.getRentalAll();
// 支付类型
// 必填,不能修改
// 把请求参数打包成数组
Map<String, String> sParaTemp = new HashMap<String, String>();
sParaTemp.put("appid", WXPayConfig.weixinappid);
sParaTemp.put("body", orderName);
sParaTemp.put("mch_id", WXPayConfig.partnerId);
String nonceStr = WXUtil.getNonceStr();
sParaTemp.put("nonce_str", nonceStr);
sParaTemp.put("device_info", "APP001");
sParaTemp.put("notify_url", WXPayConfig.notifyUrl);
sParaTemp.put("out_trade_no", orderInfo.getPayNumber());
sParaTemp.put("spbill_create_ip", "127.0.0.1");
sParaTemp.put("trade_type", "APP");
if (testModel) {
sParaTemp.put("total_fee", "1");// 测试价格
} else {
sParaTemp.put("total_fee", price * 10 + "");// 测试价格
}
//交易时间
String sign = WXUtil.signRequest(sParaTemp);
sParaTemp.put("sign", sign);
String xmlStr = WXUtil.buildXml(sParaTemp);
String result = HttpUtils.postJsonString(WXPayConfig.submitUrl, xmlStr);
if (StringUtils.isNotBlank(result)) {
WXResult wXResult = (WXResult) XMLUtil.getObjectFromXML(result,
WXResult.class);
if ("SUCCESS".equals(wXResult.getResult_code())
&& "SUCCESS".equals(wXResult.getReturn_code())) {
Map<String, String> clientMap = this.wxResultToClient(wXResult
.getPrepay_id());
Map<String, Object> resMap = new HashMap<String, Object>();
resMap.put("reqCode", clientMap);
returnResult.setReturnContent(resMap);
} else {
returnResult.setErrno(10025);
returnResult.setError("error.10025");
}
} else {
returnResult.setErrno(10025);
returnResult.setError("error.10025");
}
return returnResult;
}

   private Map<String, String> wxResultToClient(String prepayId) {  
    // 组织参数签名  
    Map<String, String> resultMap = new HashMap<String, String>();  
    resultMap.put("appid", WXPayConfig.weixinappid);  
    resultMap.put("partnerid", WXPayConfig.partnerId);  
    resultMap.put("prepayid", prepayId);  
    String nonceStr = WXUtil.getNonceStr();  
    String timeStamp = WXUtil.getTimeStamp();  
    resultMap.put("noncestr", nonceStr);  
    resultMap.put("timestamp", timeStamp);  
    resultMap.put("package", WXPayConfig.wxpackage);  
    String sign = WXUtil.signRequest(resultMap);  
    // 输出支付请求参数  
    Map<String, String> outMap = new HashMap<String, String>();  
    outMap.put("sign", sign);  
    outMap.put("timestamp", timeStamp);  
    outMap.put("prepayid",prepayId);  
    outMap.put("partnerid",WXPayConfig.partnerId);  
    outMap.put("package", WXPayConfig.wxpackage);  
    outMap.put("noncestr", nonceStr);  
    outMap.put("appid", WXPayConfig.weixinappid);  
    outMap.put("retmsg", "OK");  
    outMap.put("retcode", "0");  
    return outMap;  
}  

public static String signRequest(Map<String, String> sPara){
sPara = paraFilter(sPara);
String prestr = createLinkString(sPara);
prestr = prestr + "&key=" + WXPayConfig.partner_key;
String mysign = "";
if(StringUtils.isNotBlank(prestr)){
mysign = MD5Util.MD5Encode(prestr, "utf-8").toUpperCase();
}
return mysign;
}

2015-09-04 12:15 负责人:无 分享
已邀请:
winicafe

winicafe

也是出现了这样的问题 请问楼主解决了吗?

执着追求

执着追求 (作者)

还没有那

好烟

好烟

调试微信支付需要打包之后安装才能测,不然会一直报乱七八糟的错误!

该问题目前已经被锁定, 无法添加新回复