支付宝生成二维码在本地测试正常,放到Tomcat服务器上总是报异常?

  1. 列表项目

clipboard.png

clipboard.png

clipboard.png
是服务器的tomcat哪块的配置不对么
这是生成二维码的代码
public String qrPay(Yyopregist_PC yy) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

//逾期时间

String time_expire= sdf.format(System.currentTimeMillis()+24*60*60*1000);

StringBuilder sb = new StringBuilder();

sb.append("{\"out_trade_no\":\"" + yy.getOutTradeNo() + "\",");

sb.append("\"total_amount\":\""+yy.getMoney()+"\",\"discountable_amount\":\"0.00\",");

sb.append("\"subject\":\""+yy.getPayName()+"\",\"body\":\"\",");

sb.append("\"goods_detail\":[{\"goods_id\":\""+yy.getOutTradeNo() +"\",\"goods_name\":\""+yy.getPayName()+"\",\"goods_category\":\"\",\"price\":\""+yy.getMoney()+"\",\"quantity\":\"1\"},{\"goods_id\":\""+yy.getOutTradeNo()+"\",\"goods_name\":\""+yy.getPayName()+"\",\"goods_category\":\"\",\"price\":\""+yy.getMoney()+"\",\"quantity\":\"1\"}],");

sb.append("\"operator_id\":\"\",\"store_id\":\"\",\"terminal_id\":\"\",");

sb.append("\"time_expire\":\""+time_expire+"\"}");

logger.info("支付宝生成二维码的参数"+sb.toString());

// AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();

    AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClientRSA2();

// 使用SDK,构建群发请求模型

AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();

request.setBizContent(sb.toString());//plus.reallycare.cn/sdey_pc

request.setNotifyUrl(url+"/backend/api/v1/taizhouPcBookingOrder/alipayNotify");

// request.putOtherTextParam("ws_service_url", "http://unitradeprod.t15032aqcn.alipay.net:8080");

    AlipayTradePrecreateResponse response = null;

try {

// 使用SDK,调用交易下单接口

logger.info("支付宝生成二维码的包含回调的参数"+request);

response = alipayClient.execute(request);

logger.info("支付宝生成二维码的body为:"+response.getBody());

logger.info("支付宝生成二维码得到成功:"+response.isSuccess()+"");

logger.info("支付宝生成二维码的返回信息为:"+response.getMsg());

// 这里只是简单的打印,请开发者根据实际情况自行进行处理

if (null != response && response.isSuccess()) {

if (response.getCode().equals("10000")) {

logger.info("商户订单号:"+response.getOutTradeNo());

logger.info("二维码值:"+response.getQrCode());//商户将此二维码值生成二维码,然后展示给用户,用户用支付宝手机钱包扫码完成支付

return response.getQrCode();

//二维码的生成,网上有许多开源方法,可以参看:http://blog.csdn.net/feiyu84/article/details/9089497

} else {

//打印错误码

logger.info("错误码:"+response.getSubCode());

logger.info("错误描述:"+response.getSubMsg());

}

}

} catch (AlipayApiException e) {

e.printStackTrace();

logger.info("错误描述:"+e.getErrMsg());

logger.info("支付宝生成二维码接口进入异常:---"+e.getMessage()+"====异常case为===="+e.getCause());

}

return null;

}

回答:

你最后一个是socketTimeoutException,优先考虑下网络问题,比如内外网,防火墙,是否将一些特殊端口的请求拦截了

回答:

尝试加大timeout时间

回答:

 connection timeout = 5000(创建连接超时时间)

read timeout = 3000 (返回读取超时时间)

贴个工具类给你:

 private static String post(HttpPost post, Integer connTimeout, Integer readTimeout) throws Exception {

Object client = null;

String result = "";

try {

Builder customReqConf = RequestConfig.custom();

if(connTimeout != null) {

customReqConf.setConnectTimeout(connTimeout.intValue());

}

if(readTimeout != null) {

customReqConf.setSocketTimeout(readTimeout.intValue());

}

post.setConfig(customReqConf.build());

HttpResponse res;

if(post.getURI().toString().startsWith("https")) {

client = createSSLInsecureClient();

res = ((HttpClient)client).execute(post);

} else {

client = client;

res = ((HttpClient)client).execute(post);

}

result = IOUtils.toString(res.getEntity().getContent(), Consts.UTF_8.toString());

} finally {

post.releaseConnection();

if(post.getURI().toString().startsWith("https") && client != null && client instanceof CloseableHttpClient) {

((CloseableHttpClient)client).close();

}

}

return result;

}

------------------补充

可以试试通过设置tomcat下conf文件夹的server.xml文件,对请求超时时间进行设置。

<Connector port="8080" protocol="HTTP/1.1" 

connectionTimeout="20000"

redirectPort="8443" acceptCount="500" maxThreads="400" />

以上是 支付宝生成二维码在本地测试正常,放到Tomcat服务器上总是报异常? 的全部内容, 来源链接: utcz.com/p/169394.html

回到顶部