springboot 微信支付里的app支付坑注意,requestPayment,支付报错,"errMsg":"requestPayment:fail:[payment微
登山则情满于山,观海则意溢于海。这篇文章主要讲述springboot 微信支付里的app支付坑注意,requestPayment,支付报错,"
errMsg"
:"
requestPayment:fail:[payment微相关的知识,希望能为你提供帮助。
@RequestMapping(value="https://www.songbingjia.com/toPay4App",method= {RequestMethod.POST, RequestMethod.GET}) @ApiOperation(value = "https://www.songbingjia.com/android/去支付. 用于app") @ApiImplicitParams({ @ApiImplicitParam(name = "money", value = "https://www.songbingjia.com/android/金额", required = false, paramType = "query", dataType = "string"), @ApiImplicitParam(name = "type",value = "https://www.songbingjia.com/android/类型6=一年会员", required = true,paramType = "query",dataType = "int"), @ApiImplicitParam(name = "memberid", value = "https://www.songbingjia.com/android/用户id", required = true, paramType = "query", dataType = "string"), }) public BasicMapDataRet toPay4App( HttpServletRequest request, @RequestParam(required = false)BigDecimal money, Integer type,@RequestParam(required = false) Integer num,Integer memberid ) throws RestMainException { try { BasicMapDataRet ret = new BasicMapDataRet(); //业务逻辑和校验Map map = doUnifiedOrder(request,trade,hrRechargeOrder); ret.setResult(BasicRet.SUCCESS); ret.getData().put("result",map); return ret; }catch (Exception e){ throw new RestMainException(e); } }
/** * 微信app端支付专用的 下单 * @return * @throws Exception */ public Map doUnifiedOrder(HttpServletRequest request,Trade trade,HrRechargeOrder hrRechargeOrder) throws Exception { try { //WXConfigUtil config = new WXConfigUtil(); //System.out.println("wxPayAppConfigtoString:"+wxPayAppConfig.toString()+"字符串"+wxPayAppConfig.getKey()+"appid"+wxPayAppConfig.getAppID()); WXPay wxpay = new WXPay(wxPayAppConfig); Map< String, String> data = https://www.songbingjia.com/android/new HashMap< > (); data.put("appid", wxPayAppConfig.getAppID()); //System.out.println("打印appid"+data.get("appid")); data.put("mch_id", wxPayAppConfig.getMchID()); //System.out.println("打印mch_id"+data.get("mch_id")); data.put("nonce_str", WXPayUtil.generateNonceStr()); //System.out.println("打印nonce_str"+data.get("nonce_str")); data.put("body", trade.getBody()); //System.out.println("打印body"+data.get("body")); data.put("out_trade_no", trade.getOutTradeNo()); //System.out.println("打印out_trade_no"+data.get("out_trade_no")); data.put("total_fee",hrRechargeOrder.getMoney().multiply(new BigDecimal(100)).toString()); //data.put("total_fee",hrRechargeOrder.getMoney().toString()); //System.out.println("打印total_fee和money"+data.get("total_fee")); //自己的服务器IP地址 data.put("spbill_create_ip", request.getRemoteAddr()); //System.out.println("打印spbill_create_ip"+data.get("spbill_create_ip")); //异步通知地址(请注意必须是外网) data.put("notify_url", webConfBean.getProjectDomain()+"/rest/wxpay/notify"); //System.out.println("打印notify_url"+data.get("notify_url")); //交易类型 data.put("trade_type", "APP"); //System.out.println("打印trade_type"+data.get("trade_type")); //附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 //data.put("attach", ""); //System.out.println("进入sign前"+data.toString()+"wxPayAppConfig.getKey()"+"0ba2e528d876e0ef66ca5344debb3eac"); //System.out.println("进入sign前再次打印data"+data.toString()); data.put("sign", WXPayUtil.generateSignature(data, wxPayAppConfig.getKey(), WXPayConstants.SignType.MD5)); //System.out.println("请求前最后打印data"+data.toString()); //使用官方API请求预付订单 Map< String, String> response = wxpay.unifiedOrder(data); //System.out.println("打印response.get("return_code")"+response.get("return_code")); //System.out.println("打印response"+response.toString()); if ("SUCCESS".equals(response.get("return_code"))) {//主要返回以下5个参数 //System.out.println("进入success"); Map< String, String> param = new HashMap< > (); param.put("appid",wxPayAppConfig.getAppID()); param.put("partnerid",response.get("mch_id")); param.put("prepayid",response.get("prepay_id")); param.put("package","Sign=WXPay"); param.put("noncestr",WXPayUtil.generateNonceStr()); param.put("timestamp",System.currentTimeMillis()/1000+""); param.put("sign",WXPayUtil.generateSignature(param, wxPayAppConfig.getKey(), WXPayConstants.SignType.MD5)); //System.out.println("进入第二次sign"+param.get("sign")); return param; } } catch (Exception e) { e.printStackTrace(); throw new MyException("下单失败"); } throw new MyException("下单失败"); }
最大的坑在加红的位置,引入用的@Value 不用
@Component
@ConfigurationProperties("mod.wechat.pay")
①原因在于不支持驼峰的会空指针
②另外一个坑在于 app支付不同于PC和H5的JSAPI和NATIVE它需要二次验签名,而H5和PC的可以直接request和result
【springboot 微信支付里的app支付坑注意,requestPayment,支付报错," errMsg" :" requestPayment:fail:[payment微】参考博客 https://www.jianshu.com/p/59baa5a280b7
推荐阅读
- Android9.0 Settings 修改踩坑记录
- react app相关知识
- 微信中域名被封-页面添加遮罩层提示用户使用浏览器打开(或下载APP)
- create-react-app兼容ie9配置
- Spring Boot中配置文件application.properties里面配置项的引用
- 浅谈Mybatis通用Mapper使用方法_java - JAVA
- application.properties和application.yml文件的区别
- ClassPathXmlApplicationContext源码分析
- Android前后台切换的监听