Java Code Examples for com.alipay.api.domain.AlipayTradeAppPayModel#setProductCode()

The following examples show how to use com.alipay.api.domain.AlipayTradeAppPayModel#setProductCode() . 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: AliPayService.java    From java-pay with Apache License 2.0 6 votes vote down vote up
/**
 * 支付宝App支付
 *
 * @param orderId
 * @param servletRequest
 * @return
 */
public String appPay(Long orderId, HttpServletRequest servletRequest) {
    Order order = orderService.findOne(orderId);
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    // SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
    AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
    model.setBody("描述");
    model.setSubject("商品名称");
    model.setOutTradeNo(order.getOutTradeNo());
    model.setTimeoutExpress("30m");
    model.setTotalAmount(order.getTotalFee().toString());
    model.setProductCode("QUICK_MSECURITY_PAY");
    request.setBizModel(model);
    request.setNotifyUrl(appProperties.getAli().getNotify_url());
    try {
        // 这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        //就是orderString 可以直接给客户端请求,无需再做处理。
        log.info("orderString:{}", response.getBody());
        return response.getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: LoadTestAlipayClientTest.java    From alipay-sdk-java-all with Apache License 2.0 6 votes vote down vote up
@Ignore
public void should_get_app_id_with_load_test_flag_when_call_sdk_execute() throws AlipayApiException {
    //given
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
    model.setBody("我是测试数据");
    model.setSubject("App支付测试");
    model.setTotalAmount("0.01");
    model.setProductCode("QUICK_MSECURITY_PAY");
    model.setOutTradeNo("20170216test01");
    model.setTimeExpire("30m");
    request.setBizModel(model);
    request.setNotifyUrl("http://www.test.notify");
    //when
    AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
    String orderString = response.getBody();
    //then
    assertThat(orderString, containsString("app_id=2021000100600007_TEST_1A"));
}
 
Example 3
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;
}
 
Example 4
Source File: SDKExecuteTest.java    From alipay-sdk-java-all with Apache License 2.0 5 votes vote down vote up
private AlipayTradeAppPayRequest getTradeAppPayRequest() {
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
    model.setBody("我是测试数据");
    model.setSubject("App支付测试");
    model.setTotalAmount("0.01");
    model.setProductCode("QUICK_MSECURITY_PAY");
    model.setOutTradeNo("20170216test01");
    model.setTimeoutExpress("30m");
    request.setBizModel(model);
    request.setNotifyUrl("http://www.test.notify");
    return request;
}
 
Example 5
Source File: PayChannel4AliServiceImpl.java    From xxpay-master with MIT License 4 votes vote down vote up
@Override
public Map doAliPayMobileReq(String jsonParam) {
    String logPrefix = "【支付宝APP支付下单】";
    BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
    Map<String, Object> bizParamMap = baseParam.getBizParamMap();
    if (ObjectValidUtil.isInvalid(bizParamMap)) {
        _log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
    }
    JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
    PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
    if (ObjectValidUtil.isInvalid(payOrder)) {
        _log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
    }
    String payOrderId = payOrder.getPayOrderId();
    String mchId = payOrder.getMchId();
    String channelId = payOrder.getChannelId();
    PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
    alipayConfig.init(payChannel.getParam());
    AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
    AlipayTradeAppPayRequest alipay_request = new AlipayTradeAppPayRequest();
    // 封装请求支付信息
    AlipayTradeAppPayModel model=new AlipayTradeAppPayModel();
    model.setOutTradeNo(payOrderId);
    model.setSubject(payOrder.getSubject());
    model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
    model.setBody(payOrder.getBody());
    model.setProductCode("QUICK_MSECURITY_PAY");
    alipay_request.setBizModel(model);
    // 设置异步通知地址
    alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
    // 设置同步地址
    alipay_request.setReturnUrl(alipayConfig.getReturn_url());
    String payParams = null;
    try {
        payParams = client.sdkExecute(alipay_request).getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    super.baseUpdateStatus4Ing(payOrderId, null);
    _log.info("{}生成请求支付宝数据,payParams={}", logPrefix, payParams);
    _log.info("###### 商户统一下单处理完成 ######");
    Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
    map.put("payOrderId", payOrderId);
    map.put("payParams", payParams);
    return RpcUtil.createBizResult(baseParam, map);
}
 
Example 6
Source File: PayChannel4AlipayController.java    From xxpay-master with MIT License 4 votes vote down vote up
/**
 * 支付宝APP支付,生产签名及请求支付宝的参数(注:不会向支付宝发请求)
 * 文档: https://docs.open.alipay.com/204/105465/
 * @param jsonParam
 * @return
 */
@RequestMapping(value = "/pay/channel/ali_mobile")
public String doAliPayMobileReq(@RequestParam String jsonParam) {
    String logPrefix = "【支付宝APP支付下单】";
    JSONObject paramObj = JSON.parseObject(new String(MyBase64.decode(jsonParam)));
    PayOrder payOrder = paramObj.getObject("payOrder", PayOrder.class);
    String payOrderId = payOrder.getPayOrderId();
    String mchId = payOrder.getMchId();
    String channelId = payOrder.getChannelId();
    MchInfo mchInfo = mchInfoService.selectMchInfo(mchId);
    String resKey = mchInfo == null ? "" : mchInfo.getResKey();
    if("".equals(resKey)) return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001));
    PayChannel payChannel = payChannelService.selectPayChannel(channelId, mchId);
    alipayConfig.init(payChannel.getParam());
    AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
    AlipayTradeAppPayRequest alipay_request = new AlipayTradeAppPayRequest();
    // 封装请求支付信息
    AlipayTradeAppPayModel model=new AlipayTradeAppPayModel();
    model.setOutTradeNo(payOrderId);
    model.setSubject(payOrder.getSubject());
    model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
    model.setBody(payOrder.getBody());
    model.setProductCode("QUICK_MSECURITY_PAY");
    alipay_request.setBizModel(model);
    // 设置异步通知地址
    alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
    // 设置同步地址
    alipay_request.setReturnUrl(alipayConfig.getReturn_url());
    String payParams = null;
    try {
        payParams = client.sdkExecute(alipay_request).getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    payOrderService.updateStatus4Ing(payOrderId, null);
    _log.info("{}生成请求支付宝数据,payParams={}", logPrefix, payParams);
    _log.info("###### 商户统一下单处理完成 ######");
    Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
    map.put("payOrderId", payOrderId);
    map.put("payParams", payParams);
    return XXPayUtil.makeRetData(map, resKey);
}