com.alipay.api.AlipayClient Java Examples
The following examples show how to use
com.alipay.api.AlipayClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AliPayUtil.java From roncoo-pay with Apache License 2.0 | 6 votes |
/** * 订单查询 * * @return */ public static Map<String, Object> tradeQuery(String outTradeNo) { logger.info("======>支付宝交易查询"); String charset = "UTF-8"; String format = "json"; String signType = "RSA2"; AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfigUtil.trade_query_url, AlipayConfigUtil.app_id, AlipayConfigUtil.mch_private_key, format, charset, AlipayConfigUtil.ali_public_key, signType); SortedMap<String, Object> bizContentMap = new TreeMap<>(); bizContentMap.put("out_trade_no", outTradeNo); AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); request.setBizContent(JSONObject.toJSONString(bizContentMap)); try { AlipayTradeQueryResponse response = alipayClient.execute(request); JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response)); logger.info("支付宝订单查询返回结果:{}", responseJSON); return responseJSON; } catch (AlipayApiException e) { logger.error("支付宝交易查询异常:{}", e); return null; } }
Example #2
Source File: AliPayApi.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
/** * 该方法实现了支付宝手机网页的支付功能; * 方法将调用支付宝支付页面需要用到的数据拼接和设置好,然后,写到响应中,前台会自动弹出支付宝支付页面; * 其中,支付金额要求大于0.01,并且小于100000000,需要调用者自己检查该值再传进来,否则页面会报获取不到订单信息错误; * * @param aliAccountInfo 保存了支付宝账户的信息,包括appId、用户私钥、支付宝公钥和回调地址等,具体参考AliAccountInfo类的属性说明 * @param payBizContent 保存了订单信息,包括本地订单号、金额等,具体参考BizContent类的属性说明 * Create by quandong */ public static void wapPay(AliAccountInfo aliAccountInfo, PayBizContent payBizContent, HttpServerResponse httpResponse) throws IOException { AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 从客户端工厂中获取AlipayClient AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest(); // 创建API对应的request String form = ""; alipayRequest.setReturnUrl(aliAccountInfo.getReturnUrl()); // 设置回跳地址 alipayRequest.setNotifyUrl(aliAccountInfo.getNotifyUrl()); // 设置通知地址 alipayRequest.setBizContent(payBizContent.toString()); // 填充业务参数 try { form = alipayClient.pageExecute(alipayRequest).getBody(); // 调用SDK生成表单 } catch (AlipayApiException e) { e.printStackTrace(); } httpResponse.putHeader("Content-Type", "text/html;charset=" + AlipayConstants.CHARSET_UTF8); // 设置文本类型及编码 httpResponse.end(form); // 直接将完整的表单html输出到页面 }
Example #3
Source File: AlipayImpl.java From cola with MIT License | 6 votes |
@Override public AlipayUserInfo getUserInfo() { AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", appId, properties.getPrivateKey(), properties.getFormat(), properties.getCharset(), properties.getPublicKey(), properties.getSignType()); AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest(); AlipayUserInfoShareResponse response = null; try { response = alipayClient.execute(request, this.accessToken); if (response.isSuccess()) { AlipayUserInfo alipayUserInfo = new AlipayUserInfo(); alipayUserInfo.setAvatar(response.getAvatar()); alipayUserInfo.setNickName(response.getNickName()); alipayUserInfo.setUserId(response.getUserId()); return alipayUserInfo; } else { throw new IllegalArgumentException(response.getMsg()); } } catch (AlipayApiException e) { throw new IllegalArgumentException(e.getMessage()); } }
Example #4
Source File: AlipayOAuth2Template.java From cola with MIT License | 6 votes |
@Override protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) { AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", properties.getAppId(), properties.getPrivateKey(), properties.getPrivateKey(), properties.getCharset(), properties.getPublicKey(), properties.getSignType()); AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); request.setCode(parameters.getFirst("credential")); request.setGrantType("authorization_code"); try { AlipaySystemOauthTokenResponse oauthTokenResponse = alipayClient.execute(request); if (oauthTokenResponse.isSuccess()) { return new AccessGrant(oauthTokenResponse.getAccessToken(), null, oauthTokenResponse.getRefreshToken(), Long.valueOf(oauthTokenResponse.getExpiresIn())); }else{ throw new IllegalArgumentException(oauthTokenResponse.getCode() + ":" + oauthTokenResponse.getMsg()); } } catch (AlipayApiException e) { //处理异常 throw new IllegalArgumentException(e.getMessage()); } }
Example #5
Source File: PayController.java From sdb-mall with Apache License 2.0 | 6 votes |
@RequestMapping("/refund/{no}") public void testTradeRefund(@PathVariable String no) throws Exception { AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGNTYPE); AlipayTradeRefundModel model = new AlipayTradeRefundModel(); model.setOutTradeNo(no); //与预授权转支付商户订单号相同,代表对该笔交易退款 model.setRefundAmount("0.01"); model.setRefundReason("预授权退款测试"); model.setOutRequestNo("refund0000001");//标识一次退款请求,同一笔交易多次退款需要保证唯一,如部分退款则此参数必传。 AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); request.setBizModel(model); AlipayTradeRefundResponse response = client.execute(request); log.info("response: {}"+response.getBody()); //退款失败的"fund_change":"N" // {"alipay_trade_refund_response":{"code":"10000","msg":"Success","buyer_logon_id":"mqv***@sandbox.com","buyer_user_id":"2088102171383132","fund_change":"N","gmt_refund_pay":"2018-08-30 15:39:03","out_trade_no":"13c7b574-5f54-42da-8165-e9fc0602f74e","refund_fee":"0.01","send_back_fee":"0.00","trade_no":"2018083021001004130500297310"},"sign":"LgzBU1K7056OLY0AAvFAZBVcZuXXt7PTbZDms5nB5qieslSKiKbYc22Jw4As/GdCJJuH7NVEtBABRM9UBXtTJBCGGn7By/H+vZfkulv43E4ASHvLC8OjXiPrypUO4SDleBTB4WW5h3Vnwk8q/SJ+UXv0lb5xrib84Zspsbz//3rrhzqGJ2sr/40YZIoIuevq/OAmLAkbNuAyIiC4ZxkJijF+mD3PbITTdYs/5e4cVEwriZcdLWnptblucSUtjKwEZvwaAuXuB+CEbqaMEBnpPgye0yqvY9tNb6PmVxHX7sc8sL9rfgDjK09xIXMhU9tgh0R/cgPZsRXvSs/HjHiqlA=="} //退款成功的"fund_change":"Y" // {"alipay_trade_refund_response":{"code":"10000","msg":"Success","buyer_logon_id":"mqv***@sandbox.com","buyer_user_id":"2088102171383132","fund_change":"Y","gmt_refund_pay":"2018-08-30 15:42:15","out_trade_no":"2936025a-73eb-4273-8b1c-dfa8d637ff70","refund_fee":"0.01","send_back_fee":"0.00","trade_no":"2018083021001004130500297311"},"sign":"Nr6WroDGtVfWVCvqSSY7Z2SPtV68UbN9eII9GSMIZ3D4xlMRd+NoEUPl8EB9h3z2T8rR7fUrjAAjfIfC5qamaW6LW9tGXI4d8GprgU0YGx+53ZqyXJIaz3LeSJ6+U7NsC3h62/jOmgow6qAqca/XHkjHXmDTeERC+D6nqJLY28E5EKbVZK2IvupCo4sJLih8nI6BS0H5IjVIsRztAjgosrqCHic32JUel4/uyouBfRGPp5pp+3fzbxdJ1yMbUeKjuipNFS9Bhdvdt3ngTJoOAF+o7vQn7DIsJZQn5zNNP3BCEeXZIiXEfF/yha2HBlAM/ush5yZBpjMhDLXYRGuJUQ=="} }
Example #6
Source File: AliPayServiceImpl.java From common-project with Apache License 2.0 | 6 votes |
@Override public boolean refund(String orderNum) { //TODO 根据实际业务参数填写 Integer orderFrom=0; AliPayConfig aliPayConfig= (AliPayConfig) getPayConfig(orderFrom); AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),"RSA2"); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); Map<String,String> bizContent = new HashMap<>(); bizContent.put("out_trade_no",orderNum); String refundAmount=""; bizContent.put("refund_amount",refundAmount); AlipayTradeRefundResponse response = null; try { response = alipayClient.execute(request); if(!response.isSuccess()){ return false; } } catch (AlipayApiException e) { logger.error("调用支付宝退款失败 ====> "+e.getErrMsg()); } return true; }
Example #7
Source File: AliAppTradePayImpl.java From common-project with Apache License 2.0 | 6 votes |
@Override public AliTradePayResponse createTradePay(AliTradeAppPayParams aliTradeAppPayParams) throws Exception { AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),aliPayConfig.getSignType()); AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); request.setNotifyUrl(aliTradeAppPayParams.getNotifyUrl()); Map<String,Object> bizContent = new HashMap<>(); bizContent.put("total_amount", aliTradeAppPayParams.getTotalAmount()); bizContent.put("subject", aliTradeAppPayParams.getSubject()); bizContent.put("out_trade_no", aliTradeAppPayParams.getOutTradeNo()); request.setBizContent(JSON.toJSONString(bizContent)); AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); if(!response.isSuccess()){ return null; } logger.info("支付宝APP统一下单成功"); return AliTradePayResponse.generator(response); }
Example #8
Source File: AlipayConfig_PC.java From bbs with GNU Affero General Public License v3.0 | 6 votes |
/** * 获取客户端 * 接口产品 1.支付宝电脑版 * @return */ public AlipayClient getAlipayClient(Integer interfaceProduct){ List<OnlinePaymentInterface> onlinePaymentInterfaceList = paymentService.findAllEffectiveOnlinePaymentInterface_cache(); for(OnlinePaymentInterface onlinePaymentInterface : onlinePaymentInterfaceList){ //接口产品 if(onlinePaymentInterface.getInterfaceProduct().equals(interfaceProduct)){ if(!onlinePaymentInterface.getVersion().equals(version)){ this.update(interfaceProduct,onlinePaymentInterface.getVersion()); } return client; } } return null; }
Example #9
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 订单查询接口 * @param payConfig 支付参数 * @param orderNo 订单号 * @return 订单详细 */ public static String queryOrder(AliPayConfig payConfig, String orderNo,String authToken) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\""+ " }"); AlipayTradeQueryResponse response = null; try { response = alipayClient.execute(request,null,authToken); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #10
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 退款接口 * @param payConfig 支付参数 * @param orderNo 订单号 * @param refundAmount 退款金额 * @return */ public static String refundOrder(AliPayConfig payConfig, String orderNo, String out_request_no, String authToken,String refundAmount) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\"," + "\"out_request_no\":\""+out_request_no+"\"," + "\"refund_amount\":"+refundAmount+"" + " }"); AlipayTradeRefundResponse response = null; try { response = alipayClient.execute(request,null,authToken); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #11
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 关闭订单 * @param payConfig 支付配置 * @param orderNo 订单号 * @return 订单信息 */ public static String closeOrder(AliPayConfig payConfig, String orderNo,String authToken) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\"" + " }"); AlipayTradeCloseResponse response = null; try { response = alipayClient.execute(request,null,authToken); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #12
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 撤销订单 * @param payConfig 支付配置 * @param orderNo 订单号 * @return 订单信息 */ public static String cancelOrder(AliPayConfig payConfig, String orderNo,String authToken) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\"" + " }"); AlipayTradeCancelResponse response = null; try { response = alipayClient.execute(request,null,authToken); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #13
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 刷新token * @param payConfig 支付配置 * @param token token * @return 订单信息 */ public static String refreshAccessToken(AliPayConfig payConfig, String token) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest(); request.setBizContent("{" + " \"grant_type\":\"refresh_token\"," + " \"refresh_token\":\""+token+"\"" + " }"); AlipayOpenAuthTokenAppResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #14
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 查询订单状态 * @param payConfig 支付信息 * @param token token * @return */ public static String queryAccessToken(AliPayConfig payConfig, String token) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayOpenAuthTokenAppQueryRequest request = new AlipayOpenAuthTokenAppQueryRequest(); request.setBizContent("{" + " \"app_auth_token\":\""+token+"\"" + " }"); AlipayOpenAuthTokenAppQueryResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #15
Source File: PayUtil.java From NutzSite with Apache License 2.0 | 6 votes |
/** * 查询 * * @param out_trade_no 商户订单号,商户网站订单系统中唯一订单号,必填 * @param trade_no 支付宝交易号 */ public static void TradeQuery(String out_trade_no, String trade_no) { /**********************/ // SDK 公共请求类,包含公共请求参数,以及封装了签名与验签,开发者无需关注签名与验签 AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE); AlipayTradeQueryRequest alipay_request = new AlipayTradeQueryRequest(); AlipayTradeQueryModel model = new AlipayTradeQueryModel(); model.setOutTradeNo(out_trade_no); model.setTradeNo(trade_no); alipay_request.setBizModel(model); AlipayTradeQueryResponse alipay_response = null; try { alipay_response = client.execute(alipay_request); } catch (AlipayApiException e) { e.printStackTrace(); } System.out.println(alipay_response.getBody()); }
Example #16
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 刷新token * @param payConfig 支付配置 * @param token token * @return 订单信息 */ public static String refreshAccessToken(AliPayConfig payConfig, String token) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest(); request.setBizContent("{" + " \"grant_type\":\"authorization_code\"," + " \"refresh_token\":\""+token+"\"" + " }"); AlipayOpenAuthTokenAppResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #17
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 通过code获取token * @param payConfig 支付配置 * @param code code * @return 订单信息 */ public static String getAccessToken(AliPayConfig payConfig, String code) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest(); request.setBizContent("{" + " \"grant_type\":\"authorization_code\"," + " \"code\":\""+code+"\"" + " }"); AlipayOpenAuthTokenAppResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #18
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 关闭订单 * @param payConfig 支付配置 * @param orderNo 订单号 * @return 订单信息 */ public static String closeOrder(AliPayConfig payConfig, String orderNo) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\"" + " }"); AlipayTradeCloseResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #19
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 退款接口 * @param payConfig 支付参数 * @param orderNo 订单号 * @param refundAmount 退款金额 * @return */ public static String refundOrder(AliPayConfig payConfig, String orderNo,String refundAmount) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\"," + "\"refund_amount\":"+refundAmount+"" + " }"); AlipayTradeRefundResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #20
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 订单查询接口 * @param payConfig 支付参数 * @param orderNo 订单号 * @return 订单详细 */ public static String queryOrder(AliPayConfig payConfig, String orderNo) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); request.setBizContent("{" + "\"out_trade_no\":\""+orderNo+"\""+ " }"); AlipayTradeQueryResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #21
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 查询订单状态 * @param payConfig 支付信息 * @param token token * @return */ public static String queryAccessToken(AliPayConfig payConfig, String token) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayOpenAuthTokenAppQueryRequest request = new AlipayOpenAuthTokenAppQueryRequest(); request.setBizContent("{" + " \"app_auth_token\":\""+token+"\"" + " }"); AlipayOpenAuthTokenAppQueryResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #22
Source File: AliPayUtils.java From pay with Apache License 2.0 | 6 votes |
/** * 通过code获取token * @param payConfig 支付配置 * @param code code * @return 订单信息 */ public static String getAccessToken(AliPayConfig payConfig, String code) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest(); request.setBizContent("{" + " \"grant_type\":\"authorization_code\"," + " \"code\":\""+code+"\"" + " }"); AlipayOpenAuthTokenAppResponse response = null; try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #23
Source File: AliPayServiceImpl.java From common-project with Apache License 2.0 | 5 votes |
@Override public OrderQueryResponse orderQuery(String orderNum) throws AlipayApiException { //TODO 根据实际业务参数填写 Integer orderFrom=0; AliPayConfig aliPayConfig= (AliPayConfig) getPayConfig(orderFrom); AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),"RSA2"); AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); request.setBizContent("{\"out_trade_no\":\""+orderNum+"\"}"); AlipayTradeQueryResponse response = alipayClient.execute(request); if(!response.isSuccess()){ return null; } return null; }
Example #24
Source File: AbsAlipayService.java From MeetingFilm with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) protected AlipayResponse getResponse(AlipayClient client, AlipayRequest request) { try { AlipayResponse response = client.execute(request); if (response != null) { log.info(response.getBody()); } return response; } catch (AlipayApiException e) { e.printStackTrace(); return null; } }
Example #25
Source File: AliPayServiceImpl.java From albedo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception { if (alipay.getId() == null) { throw new BadRequestException("请先添加相应配置,再操作"); } AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType()); // 创建API对应的request(电脑网页版) AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); // 订单完成后返回的页面和异步通知地址 request.setReturnUrl(alipay.getReturnUrl()); request.setNotifyUrl(alipay.getNotifyUrl()); // 填充订单参数 request.setBizContent("{" + " \"out_trade_no\":\"" + trade.getOutTradeNo() + "\"," + " \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," + " \"total_amount\":" + trade.getTotalAmount() + "," + " \"subject\":\"" + trade.getSubject() + "\"," + " \"body\":\"" + trade.getBody() + "\"," + " \"extend_params\":{" + " \"sys_service_provider_id\":\"" + alipay.getSysServiceProviderId() + "\"" + " }" + " }");//填充业务参数 // 调用SDK生成表单, 通过GET方式,口可以获取url return alipayClient.pageExecute(request, "GET").getBody(); }
Example #26
Source File: AlipayConfiguration.java From springboot-pay-example with Apache License 2.0 | 5 votes |
/** * alipay-sdk-java * @return */ @Bean public AlipayClient alipayClient(){ return new DefaultAlipayClient(properties.getGatewayUrl(), properties.getAppid(), properties.getAppPrivateKey(), properties.getFormate(), properties.getCharset(), properties.getAlipayPublicKey(), properties.getSignType()); }
Example #27
Source File: AliPayUtils.java From pay with Apache License 2.0 | 5 votes |
/** * 当面付 : 条码支付 * @param orderNo 商户订单id * @param payCode 用户支付码 * @param title 订单标题 * @param storeId 商户id * @param totalAmount 总金额 * @return 支付结果 */ public static String barcodePay(AliPayConfig payConfig, String orderNo ,String authToken, String payCode , String title , String storeId , String totalAmount,String sys_service_provider_id , String timeoutExpress) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradePayRequest request = new AlipayTradePayRequest(); //创建API对应的request类 request.setBizContent("{" + " \"out_trade_no\":\""+orderNo+"\"," + " \"scene\":\"bar_code\"," + " \"auth_code\":\""+payCode+"\"," + " \"subject\":\""+title+"\"," + " \"store_id\":\""+storeId+"\"," + " \"timeout_express\":\""+timeoutExpress+"\"," + " \"extend_params\":{" + " \"sys_service_provider_id\":\""+sys_service_provider_id+"\"" + " }," + " \"total_amount\":\""+totalAmount+"\"" + " }"); //设置业务参数 AlipayTradePayResponse response = null; //通过alipayClient调用API,获得对应的response类 try { response = alipayClient.execute(request,null,authToken); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #28
Source File: AliPayUtils.java From pay with Apache License 2.0 | 5 votes |
/** * 当面付 : 条码支付 * @param orderNo 商户订单id * @param payCode 用户支付码 * @param title 订单标题 * @param storeId 商户id * @param totalAmount 总金额 * @return 支付结果 */ public static String barcodePay(AliPayConfig payConfig, String orderNo ,String authToken, String payCode , String title , String storeId , String totalAmount) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradePayRequest request = new AlipayTradePayRequest(); //创建API对应的request类 request.setBizContent("{" + " \"out_trade_no\":\""+orderNo+"\"," + " \"scene\":\"bar_code\"," + " \"auth_code\":\""+payCode+"\"," + " \"subject\":\""+title+"\"," + " \"store_id\":\""+storeId+"\"," + " \"timeout_express\":\"2m\"," + " \"total_amount\":\""+totalAmount+"\"" + " }"); //设置业务参数 AlipayTradePayResponse response = null; //通过alipayClient调用API,获得对应的response类 try { response = alipayClient.execute(request,null,authToken); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }
Example #29
Source File: AliPayUtil.java From wish-pay with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) protected static AlipayResponse getResponse(AlipayClient client, AlipayRequest request) { try { AlipayResponse response = client.execute(request); if (response != null) { log.info(response.getBody()); } return response; } catch (AlipayApiException e) { e.printStackTrace(); return null; } }
Example #30
Source File: AliPayUtils.java From pay with Apache License 2.0 | 5 votes |
/** * 当面付 : 条码支付 * @param orderNo 商户订单id * @param payCode 用户支付码 * @param title 订单标题 * @param storeId 商户id * @param totalAmount 总金额 * @return 支付结果 */ public static String barcodePay(AliPayConfig payConfig, String orderNo , String payCode , String title , String storeId , String totalAmount , String timeoutExpress) { AlipayClient alipayClient = new DefaultAlipayClient( AliPayConfig.URL, payConfig.getAppId(), payConfig.getAppPrivateKey(), AliPayConfig.FORMAT, AliPayConfig.CHARSET, payConfig.getAlipayPublicKey(), payConfig.getSignType()); AlipayTradePayRequest request = new AlipayTradePayRequest(); //创建API对应的request类 request.setBizContent("{" + " \"out_trade_no\":\""+orderNo+"\"," + " \"scene\":\"bar_code\"," + " \"auth_code\":\""+payCode+"\"," + " \"subject\":\""+title+"\"," + " \"store_id\":\""+storeId+"\"," + " \"timeout_express\":\""+timeoutExpress+"\"," + " \"total_amount\":\""+totalAmount+"\"" + " }"); //设置业务参数 System.out.println(request.getBizContent()); AlipayTradePayResponse response = null; //通过alipayClient调用API,获得对应的response类 try { response = alipayClient.execute(request); } catch (AlipayApiException e) { logger.error(e.getMessage()); return null; } return response.getBody(); }