/*
* 创建日期 2017-4-7
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package com.enfo.intrust.command;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.*;
import net.sf.json.JSONObject;
import java.util.Properties;
import java.io.IOException; /**
* @author tapt
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/ public class BankCommandService {
private static String rootURL="";//银企直联平台服务器地址
private static Properties commandProperties=new Properties();
//读取银企直联平台配置文件的属性
static{
try {
commandProperties.load(BankCommandService.class.getResourceAsStream("BankCommand.properties"));
rootURL=commandProperties.getProperty("rootURL");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} /**
* @TODO 通用方法,传入一个json,连接银企直联平台,返回平台响应的json
* */
public String sendCommand(String commandURL,String sendJson){
String resultJson="银企直连平台返回异常";
try {
// 新建HttpClient对象,用于访问银企直联平台;
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(commandURL);
// 让post请求携带json数据
RequestEntity requestEntity = new StringRequestEntity(sendJson,"application/json", "UTF-8");
postMethod.setRequestEntity(requestEntity);
// 发送post请求
httpClient.executeMethod(postMethod);
// 得到从银企直联响应的json数据
resultJson = new String(postMethod.getResponseBody());
} catch (Exception e) {
e.printStackTrace();
}
return resultJson;
} /**
* @TODO 直接划款
* */
public String directPay(String sendJson){
String commandURL=rootURL+commandProperties.getProperty("directPayCommand");
return sendCommand(commandURL,sendJson);
} /**
* @TODO 批量查询余额
* */
public String getBalanceBatch(String sendJson){
String commandURL=rootURL+commandProperties.getProperty("getBalanceBatchCommand");
return sendCommand(commandURL,sendJson);
} /**
* @TODO 查询账户列表
* */
public String getAccountList(String sendJson){
String commandURL=rootURL+commandProperties.getProperty("getAccountListCommand");
return sendCommand(commandURL,sendJson);
} /**
* @TODO 用于测试银企直联返回数据的方法-查询所有账户列表
* */
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
JSONObject headvalue=new JSONObject();
JSONObject bodyvalue=new JSONObject();
JSONObject infovalue=new JSONObject();
headvalue.put("request_no", "");
headvalue.put("device_type", "");
headvalue.put("cust_id", "");
headvalue.put("router", "");
headvalue.put("channel", "");
headvalue.put("app_id", "");
headvalue.put("charset", "UTF-8");
headvalue.put("version", "1.0.0.1");
headvalue.put("sign", "MScRd7GM52W41VpRGxn7BtNWsSLM/RZPzbIGjxQFiChQcN8CXTjFU9MVtDP7NXxgZZddVc+NOc+P91anV9fQ1TjtdYZJr5hg1xPP/CAokB5LlxANnc+UfBcGQWGRGjXa/wijRPvdu7hiHEKW4dNt6giQgQMlcH/1eobXY5Z4pmU=");
headvalue.put("language", "CN"); jsonObject.put("head", headvalue); infovalue.put("buscod", "n03010");
infovalue.put("busmod", ""); bodyvalue.put("info", infovalue); jsonObject.put("body", bodyvalue);
//创建查询账户列表的发送json
System.out.println("要传入到银企直联的json数据是:\n"+jsonObject.toString());
System.out.println("从银企直联平台查询账号列表,接收到的响应是:");
//调用业务逻辑方法,取得返回的json并打印
String resultString=new BankCommandService().getAccountList(jsonObject.toString());
System.out.println(resultString);
}
}

使用HttpClient实现对第三方服务器的请求并接受返回数据的更多相关文章

  1. java 接口中模拟浏览器 请求webservice 接受返回数据

    使用HttpClient 所需jar:commons-codec-1.9.jar,commons-httpclient-3.1.jar try { HttpClient client = new Ht ...

  2. 使用new Image()可以针对单单请求,不要返回数据的情况

    使用new Image()可以针对单单请求,不要返回数据的情况,比如我这里写了一个Demo,请求百度的Logo一个示例: <html> <head> </head> ...

  3. httpclient post请求带参数返回数据乱码问题解决

    客户端代码: //带参数的post请求 @Test public void doPostWithParam() throws Exception { CloseableHttpClient httpC ...

  4. Fiddler -工具使用介绍(附:拦截请求并修改返回数据)(转)

    一.Fiddler 介绍 Fiddler 是一个使用 C# 编写的 http 抓包工具.它使用灵活,功能强大,支持众多的 http 调试任务,是 web.移动应用的开发调试利器. 1,功能特点 同 H ...

  5. axios 跨域请求允许带cookie,则服务器Access-Control-Allow-Origin应设置为具体域名,否则请求无法获得返回数据

    1.通过允许跨域访问实现了跨域请求,但为了使每个请求带上session信息,我设置了withCredentials ,即: axios.defaults.withCredentials = true ...

  6. okhttp 通过网关请求服务端返回数据

    1.启动类代码 package com.tycoon.service; import org.springframework.boot.SpringApplication; import org.sp ...

  7. PHP通过curl向其它服务器发请求并返回数据

    在很多时候,我们都需要请求第三方的服务器来获取一些数据,比如token,比如百度的主动推送,那么我们的php如何实现向第三方服务器发请求呢?我们可以通过curl来实现 首先定义请求的url,然后创建h ...

  8. HttpClient get和HttpClient Post请求的方式获取服务器的返回数据

    1.转自:https://blog.csdn.net/alinshen/article/details/78221567?utm_source=blogxgwz4 /*  * 演示通过HttpClie ...

  9. android中用get和post方式向服务器提交请求

    通过get和post方式向服务器发送请求首先说一下get和post的区别get请求方式是将提交的参数拼接在url地址后面,例如http://www.baidu.com/index.jsp?num=23 ...

随机推荐

  1. HDU 1964 Pipes (插头DP,变形)

    题意:给一个n*m的矩阵,每个格子都是必走的,且无障碍格子,每对格子之间都有一个花费,问哈密顿回路的最小花费. 思路: 这个和Formula1差不多,只是求得是最小花费,这只需要修改一下DP值为花费就 ...

  2. 洛谷 P1734 最大约数和

    题目描述 选取和不超过S的若干个不同的正整数,使得所有数的约数(不含它本身)之和最大. 输入输出格式 输入格式: 输入一个正整数S. 输出格式: 输出最大的约数之和. 输入输出样例 输入样例#1: 1 ...

  3. myeclipse报错MA

    以下问题萌新问了我很多次了,无奈写个随笔.之后问的我都在这个随笔里补充. 断电/自动关机导致的问题: Could not open the editor: the file does not exis ...

  4. Python学习日志9月16日

    刚才我差点睡着了,差资料的时候太费神,有些累. 今天早晨学习了<head first HTML and CSS>,今天把昨天没看了的关于字体和颜色的一章节看完了,真长.我详细的做了笔记,并 ...

  5. CSS3制作的一款按钮特效

    /*.btn { width:230px; height:70px; font-size:70px; font-weight:bold; overflow:hidden; font: "He ...

  6. ubuntu frp 自编译。本文不能按顺序来 请自己理解

    go run:go run 编译并直接运行程序,它会产生一个临时文件(但不会生成 .exe 文件),直接在命令行输出程序执行结果,方便用户调试. go build:go build 用于测试编译包,主 ...

  7. 在tomcat中配置连接池

    在tomcat的conf/Catalina/localhost目录下配置项目路径,tomcat启动是会直接根据配置去加载项目. 虽然配置就一句话,但经常忘,今天记下来. 如果你的项目成名是:mypro ...

  8. 用Kotlin开发android平台语音识别,语义理解应用(olamisdk)

    Kotlin是由JetBrains创建的基于JVM的编程语言,IntelliJ正是JetBrains的杰作,而android Studio是 基于IntelliJ修改而来的.Kotlin是一门包含很多 ...

  9. 【Java_多线程并发编程】基础篇——线程状态扭转函数

    1. wait() sleep() yield() join()用法与区别 本文提到的当前线程是指:当前时刻,获得CPU资源正在执行的线程. 1.1 wait()方法 wait()方法定义在Objec ...

  10. Linux-ngnix服务(二)

    Nginx介绍 特性: 模块化设计,较好的扩展性 高可靠性 支持热部署:不停机更新配置文件,升级版本,更换日志文件 低内存消耗:10000个keep-alive连接模式下的非活动连接,仅需2.5M内存 ...