用curl方法在服务器访问webservice接口,避免了开发新程序。

来源:互联网 发布:万达告别房地产 知乎 编辑:程序博客网 时间:2024/06/07 05:30

程序应急情况:

       为 某银行开发的程序上线几个月后,第三方发现他们的数据库未保存资金信息,最后排查为金额格式的原因,已解决,但第三方需要为数据库补录原来的金额信息,三方数据库不可变更,只能通过接口修改,但若银行重新发起会产生资金交易。

现解决方案:

1、第三方直接改数据库,被拒绝。

2、开发两个新交易。只发三方,不走银行核心,冲正和补录(费时)。

3、后台写java程序,访问三方;但不够灵活,

4、用soupUI工具发送三方报文;但只有固定的服务器与三方网络想通,无法使用工具。

5、在服务器使用curl访问接口,直接组报文传完成数据交互(最方便,但对curl不熟)。


技术总结:

curl技术参考:http://www.cnblogs.com/gbyukg/p/3326825.html

http://www.cnblogs.com/sunada2005/p/3829772.html

http://m.blog.csdn.net/qiao_198911/article/details/74396189

自己对于curl访问webservice的学习:

在之前知道使用 curl http://********************.asmx可以打开网页,curl http://********************.asmx?op=xxxx可打开具体接口,里面包含传递参数格式的设置。

一、在网上找免费的webservice接口测试curl,我随便找了:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx

注:webservice请求报文格式:

POST /WebServices/MobileCodeWS.asmx HTTP/1.1Host: ws.webxml.com.cnContent-Type: text/xml; charset=utf-8Content-Length: lengthSOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  <soap:Body>    <getMobileCodeInfo xmlns="http://WebXml.com.cn/">      <mobileCode>string</mobileCode>      <userID>string</userID>    </getMobileCodeInfo>  </soap:Body></soap:Envelope>
经测试分析,curl访问脚本未:curl -H 'Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"' -d '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><getMobileCodeInfo xmlns="http://WebXml.com.cn/"><mobileCode>000000000</mobileCode><userID> </userID></getMobileCodeInfo></soap:Body></soap:Envelope>' http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx

模仿写出业务需求的curl脚本!