袁来如此的工作笔记
袁来如此的工作笔记
竹杖芒鞋轻胜马,谁怕? 一蓑烟雨任平生。

asp微信扫码支付xmlhttp提交,PHP跳转法

浏览量:1153

用ASP做微信支付,最头痛的就是XML提交这一块。


(1)ASP直接提交法:


xmlhttp提交信息到微信端口,需要带证书,如果有自己的服务器,可以在服务器上面配置证书,提交的时候配置证书名:

Set https = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")  
https.setOption(3) = "地址\证书名"

详情请看 《ASP微信支付之扫码支付》,虚拟主机没法配置,所以不适用。


(2)PHP跳转法:


原理是先xmlhttp提交xml到PHP文件,PHP用curl提交给微信,并echo输出微信端口返回的xml数据,这样ASP的xmlhttp就能接收到。


这各方法要有一台PHP的主机。


ASP文件:


postData="<xml>"&_
"<appid><![CDATA["&getAppId&"]]></appid>"&_
"<attach><![CDATA["&attach&"]]></attach>"&_
"<body><![CDATA["&body&"]]></body>"&_
"<mch_id><![CDATA["&getMCHID&"]]></mch_id>"&_
"<nonce_str><![CDATA["&nonce_str&"]]></nonce_str>"&_
"<notify_url><![CDATA["&notify_url&"]]></notify_url>"&_
"<out_trade_no><![CDATA["&product_id&"]]></out_trade_no>"&_
"<spbill_create_ip><![CDATA["&create_ip&"]]></spbill_create_ip>"&_
"<total_fee><![CDATA["&total_fee&"]]></total_fee>"&_
"<trade_type><![CDATA["&trade_type&"]]></trade_type>"&_
"<sign><![CDATA["&signValue&"]]></sign>"&_
"</xml>"

post_url= " 

    returnXml=PostURL(post_url,postData) '提交给PHP文件并接收微信接口返回的xml

Function PostURL(url,PostStr) 'xml提交
dim http
Set http = Server.CreateObject(xmlhttp)
With http
.Open "POST", url, false ,"" ,""
.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
.Send(PostStr)
PostURL = .responseText
End With
On Error Resume Next 
If http.Status<>200 then 
 Exit function 
End if 
    Set http = Nothing
End Function


PHP文件:


<?php 
/**
     *     作用:以post方式提交xml到对应的接口url
     */
$url=$_GET['url'];
$xml = file_get_contents("php://input");
//echo $xml;
 function postXmlCurl($xml,$url,$second=30)
    {        
    //echo $xml;
        //初始化curl        
           $ch = curl_init();
        //设置超时
        //curl_setopt($ch, CURLOP_TIMEOUT, $second);
        //这里设置代理,如果有的话
        //curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');
        //curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
        //设置header
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //post提交方式
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        //运行curl
        $data = curl_exec($ch);
       
        curl_close($ch);
        //返回结果
     echo $data;//在这里就可以得到返回数据了
    }
    postXmlCurl($xml,$url,$second=30);
    
     ?>


打赏