spring boot 下支付宝的开箱既用环境
sdk-alipay
springboot下支付宝的开箱既用环境
使用场景
springboot应用中需要接入支付宝
开始使用
pom.xml中引入依赖
net.guerlab sdk-alipay-starter 1.0.3
bootstrap.yml中增加配置
sdk: alipay: dev:true/false#默认false,为true表示使用沙箱环境 sign-type:RSA2#签名算法 app-id:#应用ID private-key:#应用私钥 alipay-public-key:#支付宝公钥
增加控制器实现
importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.springframework.beans.factory.annotation.Autowired; importorg.springframework.web.bind.annotation.GetMapping; importorg.springframework.web.bind.annotation.PathVariable; importorg.springframework.web.bind.annotation.PostMapping; importorg.springframework.web.bind.annotation.RequestMapping; importcom.alibaba.fastjson.JSONObject; importcom.alipay.api.AlipayClient; importcom.alipay.api.request.AlipayTradeAppPayRequest; importcom.alipay.api.request.AlipayTradePagePayRequest; importcom.alipay.api.request.AlipayTradeWapPayRequest; importnet.guerlab.sdk.alipay.controller.AlipayAbstractController; @RequestMapping("/pay/alipay") publicclassAlipayControllerextendsAlipayAbstractController{ @Autowired privateAlipayClientclient;//支付宝请求sdk客户端 /** *支付请求 */ @GetMapping("/app/{orderId}") publicStringapp( @PathVariableLongorderId, HttpServletResponsehttpResponse){ JSONObjectdata=newJSONObject(); data.put("out_trade_no","201701010000001234");//商户订单号 data.put("product_code","QUICK_MSECURITY_PAY");//产品码,APP支付QUICK_MSECURITY_PAY,PC支付FAST_INSTANT_TRADE_PAY,移动H5支付QUICK_WAP_PAY data.put("total_amount","0.01");//订单金额 data.put("subject","测试订单");//订单标题 //APP支付 AlipayTradeAppPayRequestrequest=newAlipayTradeAppPayRequest(); //PC支付 //AlipayTradePagePayRequestrequest=newAlipayTradePagePayRequest(); //移动H5支付 //AlipayTradeWapPayRequestrequest=newAlipayTradeWapPayRequest(); request.setNotifyUrl("http://demo/pay/alipay/notify/1");//异步通知地址 request.setBizContent(data.toJSONString());//业务参数 returnclient.sdkExecute(request).getBody(); } @PostMapping("/notify/{orderId}") publicStringnotify( @PathVariableLongorderId, HttpServletRequestrequest){ if(!notify0(request.getParameterMap())){ //这里处理验签失败 } request.getParameter("trade_no");//获取请求参数中的商户订单号 return"success"; } }
总结
以上所述是小编给大家介绍的springboot下支付宝的开箱既用环境,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!