springboot⽀付⾥的app⽀付坑注意,requestPayment,⽀付
报错,。。。
@RequestMapping(value="/toPay4App",method= {RequestMethod.POST, RequestMethod.GET})
@ApiOperation(value = "去⽀付. ⽤于app")
@ApiImplicitParams({
@ApiImplicitParam(name = "money", value = "⾦额", required = false, paramType = "query", dataType = "string"),
@ApiImplicitParam(name = "type",value = "类型6=⼀年会员", required = true,paramType = "query",dataType = "int"),
@ApiImplicitParam(name = "memberid", value = "⽤户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);
return ret;
}catch (Exception e){
throw new RestMainException(e);
}
}
/**连接apple id服务器时出错
* app端⽀付专⽤的下单
* @return
* @throws Exception
*/
public Map doUnifiedOrder(HttpServletRequest request,Trade trade,HrRechargeOrder hrRechargeOrder) throws Exception {
try {
//WXConfigUtil config = new WXConfigUtil();
//System.out.println("wxPayAppConfigtoString:"+String()+"字符串"+Key()+"appid"+AppID());
WXPay wxpay = new WXPay(wxPayAppConfig);
Map<String, String> data = new HashMap<>();
data.put("appid", AppID());
//System.out.println("打印appid"+("appid"));
data.put("mch_id", MchID());
//System.out.println("打印mch_id"+("mch_id"));
data.put("nonce_str", ateNonceStr());
//System.out.println("打印nonce_str"+("nonce_str"));
data.put("body", Body());
//System.out.println("打印body"+("body"));
data.put("out_trade_no", OutTradeNo());
//System.out.println("打印out_trade_no"+("out_trade_no"));
data.put("total_fee",Money().multiply(new BigDecimal(100)).toString());
//data.put("total_fee",Money().toString());
//System.out.println("打印total_fee和money"+("total_fee"));
//⾃⼰的服务器IP地址
data.put("spbill_create_ip", RemoteAddr());
//System.out.println("打印spbill_create_ip"+("spbill_create_ip"));
//异步通知地址(请注意必须是外⽹)
data.put("notify_url", ProjectDomain()+"/rest/wxpay/notify");
/
/System.out.println("打印notify_url"+("notify_url"));
//交易类型
data.put("trade_type", "APP");
//System.out.println("打印trade_type"+("trade_type"));
//附加数据,在查询API和⽀付通知中原样返回,该字段主要⽤于商户携带订单的⾃定义数据
//data.put("attach", "");
//System.out.println("进⼊sign前"+String()+"Key()"+"0ba2e528d876e0ef66ca5344debb3eac");
//System.out.println("进⼊sign前再次打印data"+String());
data.put("sign", ateSignature(data, Key(),
WXPayConstants.SignType.MD5));
//System.out.println("请求前最后打印data"+String());
//使⽤官⽅API请求预付订单
Map<String, String> response = wxpay.unifiedOrder(data);
//System.out.println("打印(\"return_code\")"+("return_code"));
//System.out.println("打印response"+String());
if ("SUCCESS".("return_code"))) {//主要返回以下5个参数
//System.out.println("进⼊success");
Map<String, String> param = new HashMap<>();
param.put("appid",AppID());
param.put("partnerid",("mch_id"));
param.put("prepayid",("prepay_id"));
param.put("package","Sign=WXPay");
param.put("noncestr",ateNonceStr());
param.put("timestamp",System.currentTimeMillis()/1000+"");
param.put("sign",ateSignature(param, Key(),
WXPayConstants.SignType.MD5));
//System.out.println("进⼊第⼆次sign"+("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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论