| | |
| | | /** |
| | | * 支付宝支付 |
| | | */ |
| | | public ResultUtil alipay(String body, String subject, String outTradeNo, String amount, String notifyUrl){ |
| | | public ResultUtil<String> alipay(String body, String subject, String outTradeNo, String amount, String notifyUrl){ |
| | | //实例化客户端 |
| | | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipayPublicKey, "RSA2"); |
| | | //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay |
| | |
| | | try { |
| | | //这里和普通的接口调用不同,使用的是sdkExecute |
| | | AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("orderString", response.getBody()); |
| | | System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。 |
| | | return ResultUtil.success(map); |
| | | System.out.println(response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。 |
| | | return ResultUtil.success(response.getBody()); |
| | | } catch (AlipayApiException e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.error("调起支付异常", ""); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ResultUtil queryALIOrder(String out_trade_no) throws Exception{ |
| | | public ResultUtil<Map<String, String>> queryALIOrder(String out_trade_no) throws Exception{ |
| | | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliAppid, appPrivateKey,"json","UTF-8", alipay_public_key,"RSA2"); |
| | | AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); |
| | | request.setBizContent("{" + |
| | |
| | | AlipayTradeQueryResponse response = alipayClient.execute(request); |
| | | if(response.isSuccess()){ |
| | | String tradeStatus = response.getTradeStatus();//交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)、TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、TRADE_SUCCESS(交易支付成功)、TRADE_FINISHED(交易结束,不可退款) |
| | | return ResultUtil.success(tradeStatus); |
| | | String tradeNo = response.getTradeNo(); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("tradeStatus", tradeStatus); |
| | | map.put("tradeNo", tradeNo); |
| | | return ResultUtil.success(map); |
| | | } else { |
| | | return ResultUtil.error(response.getMsg()); |
| | | } |
| | |
| | | if("SUCCESS".equals(result_code)){ |
| | | Map<String, String> map1 = new HashedMap(); |
| | | map1.put("nonce_str", map.get("nonce_str")); |
| | | map1.put("out_trade_no", map.get("out_trade_no").split("_")[1]);//存储的订单code |
| | | map1.put("attach", map.get("attach"));//存储订单id |
| | | map1.put("out_trade_no", map.get("out_trade_no")); |
| | | map1.put("attach", map.get("attach")); |
| | | map1.put("total_fee", map.get("total_fee")); |
| | | map1.put("transaction_id", map.get("transaction_id"));//微信支付订单号 |
| | | String result = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"; |