Java Code Examples for com.alipay.api.AlipayApiException#printStackTrace()

The following examples show how to use com.alipay.api.AlipayApiException#printStackTrace() . 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: AliPayApi.java    From AlipayWechatPlatform with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 该方法实现了支付宝手机网页的支付功能;
 * 方法将调用支付宝支付页面需要用到的数据拼接和设置好,然后,写到响应中,前台会自动弹出支付宝支付页面;
 * 其中,支付金额要求大于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 2
Source File: AliMain.java    From wish-pay with Apache License 2.0 6 votes vote down vote up
static boolean testQuery(String seriaNo) {
    AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();//创建API对应的request类
    request.setBizContent("{" +
            "\"out_trade_no\":\"" + seriaNo + "\"}");// +  //out_trade_no 支付时传入的商户订单号,与trade_no必填一个
    //"\"trade_no\":\"" + trade_no + "\"}"); //trade_no支付宝交易号,与商户订单号out_trade_no不能同时为空
    try {
        System.out.println(request.getBizContent());
        AlipayTradeQueryResponse response = alipayClient.execute(request);
        System.out.println(response.getBody());
        if (response.getCode().equals(AliPayConstants.SUCCESS)) {
            return true;
        }
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 3
Source File: AliMain.java    From wish-pay with Apache License 2.0 6 votes vote down vote up
static boolean testPrecreate(String seriaNo) {
    //阿里预下单接口
    AlipayTradePrecreateRequest precreateReques = new AlipayTradePrecreateRequest();


    precreateReques.setBizContent("{" + "    \"out_trade_no\":\"" + seriaNo + "\"," +
            "    \"scene\":\"bar_code\"," +
            "    \"auth_code\":\"28763443825664394\"," +
            "    \"subject\":\"手机\"," +
            "    \"store_id\":\"NJ_001\"," +
            //"    \"alipay_store_id\":\"2088102169682535\"," +
            "    \"timeout_express\":\"2m\"," + //2分钟
            "    \"total_amount\":\"0.11\"," +
            "    \"body\":\"购买手机模型预付费\"" +
            "  }"); //设置业务参数

    try {
        AlipayTradePrecreateResponse precreateResponse = alipayClient.execute(precreateReques);
        System.out.println(precreateResponse.getBody());
        return precreateResponse.getCode().equals(AliPayConstants.SUCCESS);
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 4
Source File: AliPayUtil.java    From wish-pay with Apache License 2.0 6 votes vote down vote up
/**
 * 返回验签结果
 *
 * @param params
 * @param aliPublicKey
 * @return
 */
public static boolean verifySignWithRSA(Map<String, String> params, String aliPublicKey) {
   /* String content = createStringUrl(params);
    String sign = params.get("sign");*/
    String sign_type = params.get("sign_type");
    try {
        return  AlipaySignature.rsaCheckV1(params, aliPublicKey, "UTF-8", sign_type);
        //return AlipaySignature.rsaCheckV2(params, aliPublicKey, UTF_8);
    } catch (AlipayApiException e) {
        e.printStackTrace();
        return false;
    }
    //String sign_type = params.get("sign_type");
   /* try {
        AlipaySignature.rsaSign(content,aliPublicKey,"UTF-8",sign_type);
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return verify(content, sign, aliPublicKey, "UTF-8");*/
}
 
Example 5
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 6
Source File: AlipayUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 单笔转账到支付宝账户  结果查询 
 * @param query  查询参数
 * @return return
 */ 
public AlipayTransferQueryResult transferQuery(AlipayTransferQuery query) { 
	AlipayTransferQueryResult result = null; 
	AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest(); 
	String json = BeanUtil.object2json(query); 
	request.setBizContent(json); 
	try { 
		AlipayFundTransOrderQueryResponse res = client.execute(request); 
		result = new AlipayTransferQueryResult(res); 
	} catch (AlipayApiException e) { 
		result = new AlipayTransferQueryResult(); 
		e.printStackTrace(); 
	}finally{ 
		log.warn("[单笔转账到支付宝账户查询][data:{}][result:{}]", json,BeanUtil.object2json(result)); 
	} 
	return result; 
}
 
Example 7
Source File: AlipayUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * 交易状态查询 
 * @param query 查询参数
 * @return return
 */ 
public AlipayTradeQueryResult tradeQuery(AlipayTradeQuery query){ 
	AlipayTradeQueryResult result = null;  
	AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); 
	String json = BeanUtil.object2json(query); 
	request.setBizContent(json); 
	try { 
		AlipayTradeQueryResponse res = client.execute(request); 
		result = new AlipayTradeQueryResult(res); 
	} catch (AlipayApiException e) { 
		result = new AlipayTradeQueryResult(); 
		e.printStackTrace(); 
	}finally{ 
		log.warn("[单笔转账到支付宝账户][data:{}][result:{}]", json,BeanUtil.object2json(result)); 
	} 
	return result; 
}
 
Example 8
Source File: AlipayUtil.java    From anyline with Apache License 2.0 6 votes vote down vote up
/** 
 * app支付 
 *  
 * @param subject 支付标题 
 * @param body  支付明细 
 * @param price  支付价格(元) 
 * @param order  系统订单号 
 * @return String
 */ 
public String createAppOrder(String subject, String body, String price, String order) { 
	String result = ""; 
	AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); 
	AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); 
	model.setBody(body); 
	model.setSubject(subject); 
	model.setOutTradeNo(order); 
	model.setTimeoutExpress("30m"); 
	model.setTotalAmount(price); 
	request.setBizModel(model); 
	request.setNotifyUrl(config.getString("NOTIFY_URL")); 
	try { 
		AlipayTradeAppPayResponse response = client.sdkExecute(request); 
		result = response.getBody(); 
	} catch (AlipayApiException e) { 
		e.printStackTrace(); 
	} 

	return result; 
}
 
Example 9
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 10
Source File: AlipayGzuserinfoServiceImpl.java    From jeewx with Apache License 2.0 5 votes vote down vote up
@Override
public void syncGzuserinfos() {
	// TODO Auto-generated method stub
	try {
		//update-begin--author:zhangjiaqiang Date:20161108 for:#1487 【开源项目】开源支付窗服务窗单公众号项目
		AlipayMobilePublicFollowListResponse response = JwGetUserInforMationAPI.followlistQuery(null, new GetUserInfoMateon(),alipayAccountService.getAlipayConfig());
		//update-begin--author:zhangjiaqiang Date:20161108 for:#1487 【开源项目】开源支付窗服务窗单公众号项目
		Data data  = response.getData();
		List<String> useridlist = data.getUserIdList();
		for(String id :useridlist){
			//update-begin--author:zhangjiaqiang Date:20161108 for:#1487 【开源项目】开源支付窗服务窗单公众号项目
			AlipayGzuserinfo tempUser = alipayGzuserinfoDao.getByUserid(id);
			if(tempUser == null){
				AlipayGzuserinfo user = new AlipayGzuserinfo();
				user.setAccountid(SystemUtil.getOnlieAlipayAccountId());
				user.setUserid(id);
				user.setSubscribeStatus("1");
				String randomSeed = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
				user.setId(randomSeed);
				user.setCreateDate(new Date());
				alipayGzuserinfoDao.insert(user);
			}
			//update-end--author:zhangjiaqiang Date:20161108 for:#1487 【开源项目】开源支付窗服务窗单公众号项目
		}
	} catch (AlipayApiException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 11
Source File: PayAction.java    From AppServiceRestFul with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 支付宝回调接口
 * @param request
 * @param resp
 * @return
 */
@ResponseBody
@RequestMapping(value="/verifyalipayresult.do", method=RequestMethod.POST)
public String verifyAliPayRight(HttpServletRequest request, HttpServletResponse resp)
{
    synchronized (alilock) {
        Map<String,String> params = new HashMap<String,String>();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i]
                        : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
        }
        try {
            boolean flag = AlipaySignature.rsaCheckV1(params, PayService.ALI_PUBLIC_KEY, "utf-8", "RSA2");
            if(flag)
            {
                if(params.get("trade_status").equals("TRADE_SUCCESS") && params.get("app_id").equals(PayService.ALI_APPID) && params.get("seller_id").equals("****************"))
                {
                    return payService.verifyAliPay(params);
                }
            }
        } catch (AlipayApiException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "fail";
        }
    }
    return "fail";
}
 
Example 12
Source File: PayAction.java    From AppServiceRestFul with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 支付宝回调接口
 * @param request
 * @param resp
 * @return
 */
@ResponseBody
@RequestMapping(value="/verifyalipayresult.do", method=RequestMethod.POST)
public String verifyAliPayRight(HttpServletRequest request, HttpServletResponse resp)
{
    synchronized (alilock) {
        Map<String,String> params = new HashMap<String,String>();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i]
                        : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
        }
        try {
            boolean flag = AlipaySignature.rsaCheckV1(params, PayService.ALI_PUBLIC_KEY, "utf-8", "RSA2");
            if(flag)
            {
                if(params.get("trade_status").equals("TRADE_SUCCESS") && params.get("app_id").equals(PayService.ALI_APPID) && params.get("seller_id").equals("2088621136650617"))
                {
                    return payService.verifyAliPay(params);
                }
            }
        } catch (AlipayApiException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "fail";
        }
    }
    return "fail";
}
 
Example 13
Source File: AliPayUtil.java    From wish-pay with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: AlipayUtil.java    From anyline with Apache License 2.0 5 votes vote down vote up
public String createWapOrder(AlipayTradeOrder order){ 
	String result = ""; 
	AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();//创建API对应的request 
    alipayRequest.setReturnUrl(config.RETURN_URL); 
    alipayRequest.setNotifyUrl(config.NOTIFY_URL); 
    alipayRequest.setBizContent(BeanUtil.object2json(order));//填充业务参数 
    try { 
        result = client.pageExecute(alipayRequest).getBody(); //调用SDK生成表单 
    } catch (AlipayApiException e) { 
        e.printStackTrace(); 
    } 
	return result; 
}
 
Example 15
Source File: AbsAlipayService.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
@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 16
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);
}
 
Example 17
Source File: AlipayTradeWithHBServiceImpl.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
private AlipayTradePayResponse getResponse(AlipayClient client, AlipayTradePayRequest request,
                                             final String outTradeNo, final long beforeCall) {
    try {
        AlipayTradePayResponse response = client.execute(request);
        if (response != null) {
            log.info(response.getBody());
        }
        return response;

    } catch (AlipayApiException e) {
        // 获取异常真实原因
        Throwable cause = e.getCause();

        if (cause instanceof ConnectException ||
                cause instanceof NoRouteToHostException) {
            // 建立连接异常
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    listener.onConnectException(outTradeNo, beforeCall);
                }
            });

        } else if (cause instanceof SocketException) {
            // 报文上送异常
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    listener.onSendException(outTradeNo, beforeCall);
                }
            });

        } else if (cause instanceof SocketTimeoutException) {
            // 报文接收异常
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    listener.onReceiveException(outTradeNo, beforeCall);
                }
            });
        }

        e.printStackTrace();
        return null;
    }
}
 
Example 18
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 19
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 = JSON.toJavaObject(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 = baseService4PayOrder.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();
    }
    baseService4PayOrder.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 20
Source File: AliPayApi.java    From AlipayWechatPlatform with GNU General Public License v3.0 4 votes vote down vote up
/**
     * 该方法是用户确定授权后的获取用户信息的方法;
     * 方法先解析请求参数,获取auth_code;
     * 获取到auth_code后,用auth_code换取auth_token和openId;
     * 然后,判断用户是否需要获取用户详细信息,如果需要,则用auth_token获取用户详细信息,并返回AlipayUserInfoShareResponse响应对象;
     * 如果不需要,直接返回AlipaySystemOauthTokenResponse响应对象;
     * 其他的意外情况均返回null;
     *
     * @param aliAccountInfo 封装了获取用户详细信息需要用到的数据的对象
     * @param isNeedDetail 是否需要获取详细信息的标识
     * @param request http请求体
     * @return AlipayResponse类型,调用者根据是否需要获取详细信息的标识强转成不同类型的对象,false强转成AlipaySystemOauthTokenResponse,true强转成AlipayUserInfoShareResponse,意外情况返回空
     * Create by quandong
     */
    private static AlipayResponse getUserInfo(AliAccountInfo aliAccountInfo, boolean isNeedDetail, HttpServerRequest request) {
        Map<String, String> params = AliPayApi.getRequestParams(request); // 解析请求参数
        String authCode = params.get("auth_code"); // 获得authCode

        try {
            // 判断是否能获取到authCode
            if(null != authCode && !authCode.equals("")) { // 能获取到authCode
                AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 获取支付宝连接
                // 利用authCode获得authToken
                AlipaySystemOauthTokenRequest oauthTokenRequest = new AlipaySystemOauthTokenRequest(); // 创建支付宝系统授权token请求对象
                oauthTokenRequest.setCode(authCode); // 设置auth_code
                oauthTokenRequest.setGrantType("authorization_code"); // 设置同意类型,值为authorization_code时,代表用code换取;值为refresh_token时,代表用refresh_token换取
                AlipaySystemOauthTokenResponse oauthTokenResponse = alipayClient.execute(oauthTokenRequest); // 向支付宝发送请求并获得响应

                // 判断是否换取到authToken
                if(null != oauthTokenResponse && oauthTokenResponse.isSuccess()) { // 成功获得authToken
                    // 判断是否需要获取用户的详细信息
                    if(isNeedDetail) { // 需要获取用户的详细信息
                        // 利用authToken获取用户信息
                        AlipayUserInfoShareRequest userinfoShareRequest = new AlipayUserInfoShareRequest(); // 创建用户信息共享请求对象
                        AlipayUserInfoShareResponse userinfoShareResponse = alipayClient.execute(userinfoShareRequest, oauthTokenResponse.getAccessToken()); // 向支付宝发送请求并获得响应
//                        AlipayUserUserinfoShareRequest userinfoShareRequest = new AlipayUserUserinfoShareRequest();
//                        AlipayUserUserinfoShareResponse userinfoShareResponse = alipayClient.execute(userinfoShareRequest, oauthTokenResponse.getAccessToken());
//                        LOG.debug("======================用户真实姓名={}======================", userinfoShareResponse.getRealName());

                        // 判断是否能获得用户信息
                        if(null != userinfoShareResponse && userinfoShareResponse.isSuccess()) { // 成功获得用户信息
                            LOG.info("获取用户信息成功:{}", userinfoShareResponse.getBody()); // 获取用户信息成功,打日志
                            return userinfoShareResponse; // 返回响应对象,调用者可以用该对象获取用户的详细信息
                        } else { // 获取用户信息失败
                            LOG.error("获取用户信息失败"); // 获取用户信息失败,打日志
                            return null; // 返回空
                        }
                    } else { // 不需要获取用户的详细信息
                        LOG.info("获取用户openId成功:{}", oauthTokenResponse.getUserId()); // 获取用户openId成功,打日志
                        return oauthTokenResponse; // 返回响应对象,调用者可以用该对象获取用户的openId
                    }
                } else { // 换取不到authToken
                    LOG.error("authCode换取authToken失败"); // authCode换取authToken失败,打日志
                    return null; // 返回空
                }
            } else { // 获取不到authCode
                LOG.error("authCode获取失败"); // authCode获取失败,打日志
                return null; // 返回空
            }
        } catch (AlipayApiException alipayApiException) {
            LOG.error("获取oauthToken或用户信息失败"); // 获取oauthToken或用户信息失败,打日志
            // 自行处理异常
            alipayApiException.printStackTrace();
        }
        return null; // 返回空,正常时不会执行此语句
    }