V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lintoy
V2EX  ›  问与答

求助 怎么接收sns服务器返回的xml数据

  •  
  •   lintoy · 2011-07-04 09:02:18 +08:00 · 5272 次点击
    这是一个创建于 4686 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在submit.html表单提交请求到sns服务器
    <form name="form1" method="post" action="http://api.xiaonei.com/restserver.do">
    <input name="api_key" type="hidden" value="22b92c5a5d1a4b02b695bd7851ac6111">
    <input name="method" type="hidden" value="xiaonei.pay.regOrder">
    <input name="v" type="hidden" value="1.0">
    <input name="order_id" type="hidden" value="528695">
    <input name="amount" type="hidden" value="20">
    <input name="" type="submit" value="添加">
    </form>

    返回一些xml数据
    <?xml version="1.0" encoding="UTF-8" ?>
    - <error_response>
    <error_code>452</error_code>
    <error_msg>Session key 无效.可能传入的sessionKey格式出现错误</error_msg>
    - <request_args>
    - <arg>
    <key>method</key>
    <value>xiaonei.pay.regOrder</value>
    </arg>
    - <arg>
    <key>order_id</key>
    <value>528695</value>
    </arg>
    </request_args>
    </error_response>
    .............................
    怎么用变量去接受这些数据

    问了一些朋友,有人建议下面的方法。先把表单提交到xxxx.php,xxxx.php负责向http://api.xiaonei.com/restserver.do传递参数,
    然后获取返回的xml串,用simplexml解析,处理.


    不知道XXXX.PHP当中的过程要怎么写。
    4 条回复    1970-01-01 08:00:00 +08:00
    lyoe
        1
    lyoe  
       2011-07-04 11:22:44 +08:00
    js提交表单,js处理结果
    manhere
        2
    manhere  
       2011-07-04 11:34:49 +08:00
    curl或者socket把请求POST过去,获取返回的内容,至于xml解析就有很多方法了。
    lintoy
        3
    lintoy  
    OP
       2011-07-04 12:17:28 +08:00
    @manhere xxxx.php文件当中这样写



    <?php

    $ch = curl_init("http://api.xiaonei.com/restserver.do?api_key=$_POST["api_key"]&method=$_POST["method"]&v=$_POST["v"]");

    curl_exec($ch);

    curl_close($ch);

    ?>
    不行,不知道怎么回事下面


    <?php

    $ch = curl_init("http://api.xiaonei.com/restserver.do?api_key=22b92c5a5d1a4b02b695bd7851ac6111&method=xiaonei.pay.regOrder&v=1.0");

    curl_exec($ch);

    curl_close($ch);

    ?>

    这样写的可发送出去。也可以显示内容,但是有个问题就是表单提交过来的内容就显的无用了。
    Sunyanzi
        4
    Sunyanzi  
       2011-07-04 20:17:41 +08:00
    <?php
    $ch = curl_init();

    curl_setopt_array( $ch, array(
    CURLOPT_URL => 'http://api.xiaonei.com/restserver.do',
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
    'api_key' => '22b92c5a5d1a4b02b695bd7851ac6111',
    'method' => 'xiaonei.pay.regOrder',
    'v' => '1.0'
    ),
    CURLOPT_RETURNTRANSFER => true,
    ) );

    print_r( simplexml_load_string( curl_exec( $ch ) ) );

    curl_close( $ch );

    /*
    @see http://php.net/curl
    @see http://php.net/simpleXML
    */
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2191 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.