com.alipay.api.DefaultAlipayClient Java Examples

The following examples show how to use com.alipay.api.DefaultAlipayClient. 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: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 订单查询接口
 * @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 #2
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 订单查询接口
 * @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 #3
Source File: PayController.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 退款接口
 * @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 #5
Source File: AliPayServiceImpl.java    From common-project with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: AliAppTradePayImpl.java    From common-project with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 关闭订单
 * @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 #8
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 撤销订单
 * @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 #9
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 通过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 #10
Source File: AlipayConfig_PC.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 更新数据
 */
private synchronized void update(Integer interfaceProduct,Integer version){
	if(version.equals(this.version)){
		return;
	}
	List<OnlinePaymentInterface> onlinePaymentInterfaceList = paymentService.findAllEffectiveOnlinePaymentInterface_cache();
	for(OnlinePaymentInterface onlinePaymentInterface : onlinePaymentInterfaceList){
		//接口产品 
		if(onlinePaymentInterface.getInterfaceProduct().equals(interfaceProduct)){
			if(onlinePaymentInterface.getDynamicParameter() != null && !"".equals(onlinePaymentInterface.getDynamicParameter().trim())){
				Alipay alipay = JsonUtils.toObject(onlinePaymentInterface.getDynamicParameter(), Alipay.class);
				
				this.version = onlinePaymentInterface.getVersion();
				this.ALIPAY_PUBLIC_KEY = alipay.getAlipay_public_key();
				this.client = new DefaultAlipayClient(this.URL, alipay.getApp_id(), alipay.getRsa_private_key(), this.FORMAT, this.CHARSET, alipay.getAlipay_public_key(),this.SIGNTYPE);
				
			}
		}
	}
	
}
 
Example #11
Source File: AlipayConfig_Mobile.java    From bbs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 更新数据
 */
private synchronized void update(Integer interfaceProduct,Integer version){
	if(version.equals(this.version)){
		return;
	}
	List<OnlinePaymentInterface> onlinePaymentInterfaceList = paymentService.findAllEffectiveOnlinePaymentInterface_cache();
	for(OnlinePaymentInterface onlinePaymentInterface : onlinePaymentInterfaceList){
		//接口产品 
		if(onlinePaymentInterface.getInterfaceProduct().equals(interfaceProduct)){
			if(onlinePaymentInterface.getDynamicParameter() != null && !"".equals(onlinePaymentInterface.getDynamicParameter().trim())){
				Alipay alipay = JsonUtils.toObject(onlinePaymentInterface.getDynamicParameter(), Alipay.class);
				this.version = onlinePaymentInterface.getVersion();
				this.ALIPAY_PUBLIC_KEY = alipay.getAlipay_public_key();
				this.client = new DefaultAlipayClient(this.URL, alipay.getApp_id(), alipay.getRsa_private_key(), this.FORMAT, this.CHARSET, alipay.getAlipay_public_key(),this.SIGNTYPE);
				
			}
		}
	}
	
}
 
Example #12
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 刷新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 #13
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 查询订单状态
 * @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 #14
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 退款接口
 * @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 #15
Source File: AlipayImpl.java    From cola with MIT License 6 votes vote down vote up
@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 #16
Source File: AlipayOAuth2Template.java    From cola with MIT License 6 votes vote down vote up
@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 #17
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 关闭订单
 * @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 #18
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 通过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 #19
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 刷新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 #20
Source File: AliPayUtils.java    From pay with Apache License 2.0 6 votes vote down vote up
/**
 * 查询订单状态
 * @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 #21
Source File: PayUtil.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 查询
 *
 * @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 #22
Source File: AliPayUtil.java    From roncoo-pay with Apache License 2.0 6 votes vote down vote up
/**
 * 订单查询
 *
 * @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 #23
Source File: AlipayUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
public static AlipayUtil getInstance(String key) { 
	if (BasicUtil.isEmpty(key)) { 
		key = "default"; 
	} 
	AlipayUtil util = instances.get(key); 
	if (null == util) { 
		util = new AlipayUtil(); 
		AlipayConfig config = AlipayConfig.getInstance(key); 
		util.config = config; 
		util.client = new DefaultAlipayClient( 
				"https://openapi.alipay.com/gateway.do", 
				config.getString("APP_ID"), 
				config.getString("APP_PRIVATE_KEY"), 
				config.getString("DATA_FORMAT"), 
				config.getString("ENCODE"), 
				config.getString("ALIPAY_PUBLIC_KEY"), 
				config.getString("SIGN_TYPE")); 
		instances.put(key, util); 
	} 

	return util; 
}
 
Example #24
Source File: AlipayTradeServiceImpl.java    From MeetingFilm with Apache License 2.0 6 votes vote down vote up
public AlipayTradeServiceImpl(ClientBuilder builder) {
    if (StringUtils.isEmpty(builder.getGatewayUrl())) {
        throw new NullPointerException("gatewayUrl should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getAppid())) {
        throw new NullPointerException("appid should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getPrivateKey())) {
        throw new NullPointerException("privateKey should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getFormat())) {
        throw new NullPointerException("format should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getCharset())) {
        throw new NullPointerException("charset should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getAlipayPublicKey())) {
        throw new NullPointerException("alipayPublicKey should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getSignType())) {
        throw new NullPointerException("signType should not be NULL!");
    }
    
    client = new DefaultAlipayClient(builder.getGatewayUrl(), builder.getAppid(), builder.getPrivateKey(),
            builder.getFormat(), builder.getCharset(), builder.getAlipayPublicKey(), builder.getSignType());
}
 
Example #25
Source File: AlipayMonitorServiceImpl.java    From MeetingFilm with Apache License 2.0 6 votes vote down vote up
public AlipayMonitorServiceImpl(ClientBuilder builder) {
    if (StringUtils.isEmpty(builder.getGatewayUrl())) {
        throw new NullPointerException("gatewayUrl should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getAppid())) {
        throw new NullPointerException("appid should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getPrivateKey())) {
        throw new NullPointerException("privateKey should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getFormat())) {
        throw new NullPointerException("format should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getCharset())) {
        throw new NullPointerException("charset should not be NULL!");
    }
    if (StringUtils.isEmpty(builder.getSignType())) {
        throw new NullPointerException("signType should not be NULL!");
    }

    // 此处不需要使用alipay public key,因为金融云不产生签名
    client = new DefaultAlipayClient(builder.getGatewayUrl(), builder.getAppid(), builder.getPrivateKey(),
            builder.getFormat(), builder.getCharset(), builder.getSignType());
}
 
Example #26
Source File: AliPayUtils.java    From pay with Apache License 2.0 5 votes vote down vote up
/**
 * 当面付 : 条码支付
 * @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 #27
Source File: AliPayServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toPayAsWeb(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());

	double money = Double.parseDouble(trade.getTotalAmount());
	double maxMoney = 5000;
	if (money <= 0 || money >= maxMoney) {
		throw new BadRequestException("测试金额过大");
	}
	// 创建API对应的request(手机网页版)
	AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
	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() + "\"" +
		"    }" +
		"  }");
	return alipayClient.pageExecute(request, "GET").getBody();
}
 
Example #28
Source File: AliPayUtils.java    From pay with Apache License 2.0 5 votes vote down vote up
/**
 * 当面付 : 条码支付
 * @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 #29
Source File: AliPayUtils.java    From pay with Apache License 2.0 5 votes vote down vote up
/**
 * 当面付 : 条码支付
 * @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();
}
 
Example #30
Source File: PayUtil.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 支付宝订单创建
 * @param out_trade_no 商户订单号,商户网站订单系统中唯一订单号,必填
 * @param subject      订单名称,必填
 * @param total_amount 付款金额,必填
 * @param body         商品描述,可空
 */
public static String createOrder(String out_trade_no, String subject, String total_amount, String body) throws Exception {
    if (Strings.isEmpty(out_trade_no) || Strings.isEmpty(subject) || Strings.isEmpty(total_amount)) {
        throw new Exception("支付宝参数异常");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY,
            AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
    //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
    AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
    model.setBody(body);
    model.setSubject(subject);
    model.setOutTradeNo(out_trade_no);
    model.setTimeoutExpress("30m");
    model.setTotalAmount(total_amount);
    model.setProductCode("QUICK_MSECURITY_PAY");
    request.setBizModel(model);
    request.setNotifyUrl(AlipayConfig.notify_url);
    try {
        //这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        System.out.println(response.getBody());
        return response.getBody();
        //就是orderString 可以直接给客户端请求,无需再做处理。
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return null;
}