评论

高手帮我看看这套ASP平台的微信支付有什么问题吗?

文章中展示ASP版的微信支付主要的3个文件,请高手帮忙看看哪里有问题?在此拜谢!!!

index.asp支付主页文件

pay_V3.asp跳转页

payapi.php调用PHP的API页面

Class.asp传输数据页面

哪位高手帮我看看以下页面哪里错了?

1\《pay_V3.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!--#include file="lib/Config.asp"-->

<!--#include file="lib/md5.asp"-->

<!--#include file="lib/Class.asp"-->

<%  

  

dim out_trade_no,body,total_fee,openid,prepay_id,paySign

'获取金额加以判断

if not IsNumeric(request("total_fee")) then

response.Write "<script>alert('金额格式填写错误!');history.go(-1);</script>"

  response.End()

end if

if request("total_fee")=0 or request("total_fee")<0 then

response.Write "<script>alert('金额必须大于0!');history.go(-1);</script>"

  response.End()

end if

%>

<%

'下面三个参数,需要在商城转过来,包括唯一的订单号,商品名称,总金额


'out_trade_no= request("out_trade_no")

body = request("body")

    total_fee        = request("total_fee") *100               '传递金额 

out_trade_no= getStrNow & getStrRandNumber(9999,1000) '唯一订单号,可以自行生成

'body = "中文商品名称" '商品名称

openid = GetOpenId

prepay_id = get_prepay_id

paySign = get_paySign()

%>

<!DOCTYPE html>

<html>

<head>

<title>微信支付</title>

<script Language="javascript">

var prepay_id="<%=prepay_id%>";

var paySign="<%=paySign%>";

function Pay_ok()

alert ("支付成功");

self.location='<%=redirect_url%>?body=<%=body%>&total_fee=<%=total_fee%>&out_trade_no=<%=out_trade_no%>&openid=<%=openid%>'; 

function callpay()

WeixinJSBridge.invoke('getBrandWCPayRequest',{"appId":"<%=getAppId%>","timeStamp":"<%=timeStamp%>","nonceStr":"<%=nonce_str%>","package":"prepay_id=<%=prepay_id%>","signType":"MD5","paySign":"<%=paySign%>"},function(res){if(res.err_msg=="get_brand_wcpay_request:ok"){Pay_ok();}else{alert(res.err_code+res.err_desc+res.err_msg);}});

</script>

<meta http-equiv="content-type" content="text/html;charset=utf-8"/>

<meta id="viewport" name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1; user-scalable=no;" />

<style>

body {

margin:0;

padding:0;

background:#23AC38;

body, p, table, td, th {

font-size:14px;

font-family:helvetica, Arial, Tahoma;

h1 {

font-family:Baskerville, HelveticaNeue-Bold, helvetica, Arial, Tahoma;

a {

text-decoration:none;

color:#ffffff;

.title h1 {

font-size:22px;

font-weight:bold;

padding:0;

margin:0;

line-height:1.2;

color:#ffffff;

</style>

</head>

<body>

<div style="margin:0 auto;TEXT-ALIGN: center;">

<p><br></p>

  <p  style="color: #FFFFFF;" id="test">商品名称:<%=body%></p>

  <p style="color: #FFFFFF;" >商品金额:<%=FormatNumber(total_fee*0.01,2,-1)%>元</p>

  <p></p>

  <p></p>

  <p></p>

   <p></p>

  <p></p>

  <p></p>

  <a href="javascript:callpay();">

  <h1 class="title">请点击确认支付</h1>

  </a><br>

</div>

</body>

</html>

2、《Class.asp

<%

dim phpapiurl,create_ip,nonce_str,timeStamp,xmlhttp,preCookies

phpapiurl       =  "http://www.tnbq.cn/wxpay/payapi.php"

preCookies = "ysdwl"'Cookie前缀,同一个网站下,多个支付需要修改

create_ip = Request.ServerVariables("REMOTE_ADDR")

nonce_str = GetRnd(10)

timeStamp = ToUnixTime(now())

xmlhttp = "Msxml2.ServerXMLHTTP.6.0"


'微信支付V3获取Prepay_Id

function get_prepay_id()

dim postData,signValue,post_url,sign,returnXml,xml_dom,return_code,result_code,openid

post_url= "https://api.mch.weixin.qq.com/pay/unifiedorder"

sign="appid="&getAppId&"&body="&body&"&mch_id="&getMCHID&"&nonce_str="&nonce_str&"&notify_url="&notify_url&"&openid="&openid&"&out_trade_no="&out_trade_no&"&spbill_create_ip="&create_ip&"&total_fee="&total_fee&"&trade_type=JSAPI&key="&getPartnerKey

signValue=UCase(MD5(sign,"UTF-8"))


postData="<xml>"&_

"<appid><![CDATA["&getAppId&"]]></appid>"&_

"<body><![CDATA["&body&"]]></body>"&_

"<mch_id><![CDATA["&getMCHID&"]]></mch_id>"&_

"<nonce_str><![CDATA["&nonce_str&"]]></nonce_str>"&_

"<notify_url><![CDATA["&notify_url&"]]></notify_url>"&_

"<openid><![CDATA["&openid&"]]></openid>"&_

"<out_trade_no><![CDATA["&out_trade_no&"]]></out_trade_no>"&_

"<spbill_create_ip><![CDATA["&create_ip&"]]></spbill_create_ip>"&_

"<total_fee><![CDATA["&total_fee&"]]></total_fee>"&_

"<trade_type><![CDATA[JSAPI]]></trade_type>"&_

"<sign><![CDATA["&signValue&"]]></sign>"&_

"</xml>"

returnXml=PostURL(phpapiurl&"?url="&post_url,postData)

set xml_dom=Server.CreateObject("MSXML2.DOMDocument")

xml_dom.loadXml(returnXml)

return_code=xml_dom.getelementsbytagname("return_code").item(0).text

if return_code="FAIL" then

'协议级错误

get_prepay_id=xml_dom.getelementsbytagname("return_msg").item(0).text

response.Write("协议级接口调用错误:"&get_prepay_id)

response.End()

else

result_code=xml_dom.getelementsbytagname("result_code").item(0).text

if result_code="FAIL" then

'业务级错误

get_prepay_id=xml_dom.getelementsbytagname("err_code_des").item(0).text

response.Write("业务级支付错误:"&get_prepay_id)

response.End()

else

if return_code="SUCCESS" and result_code="SUCCESS" then

'数据正常

get_prepay_id=xml_dom.getelementsbytagname("prepay_id").item(0).text

end if

end if

end if

end Function


'微信支付V3,返回最后提交的paySign

function get_paySign()



dim sign

sign="appId="&getAppId&"&nonceStr="&nonce_str&"&package=prepay_id="&prepay_id&"&signType=MD5&timeStamp="&timeStamp&"&key="&getPartnerKey

get_paySign=UCase(MD5(sign,"UTF-8"))

end function



function GetOpenId()

'获取用户OpenID

if request.Cookies(preCookies&"openid")="" then

dim code,myurl,url,strJson,access_token,openids

code=request("code")

myurl="http://"&Request.ServerVariables("Server_Name")&Request.ServerVariables("URL")

if request.ServerVariables("QUERY_STRING")<>"" then 

myurl = myurl &"?"& Request.ServerVariables("QUERY_STRING")

end if

myurl=Server.URLEncode(myurl)

if code="" then

response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid="&getAppId&"&redirect_uri="&myurl&"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect")

response.End()

else

url="https://api.weixin.qq.com/sns/oauth2/access_token?appid="&getAppId&"&secret="&getSecret&"&code="&code&"&grant_type=authorization_code"

strJson=GetURL(url)

dim objTest

Call InitScriptControl:Set objTest = getJSONObject(strJson)

if InStr(strJson,"errcode")>0 then

response.Write "获取Openid出错:"&strJson

response.End()

else

openids=objTest.openid'获取openid

Response.Cookies(preCookies&"openid")=openids

Response.Cookies(preCookies&"openid").Expires=DateAdd("m",60,now())

GetOpenId=openids

end if

end if

else

GetOpenId=request.Cookies(preCookies&"openid")

end if

End function


'返回当前日期20140105024523

Function getStrNow()

dim strNow:strNow = Now()

strNow = Year(strNow) & Right(("00" & Month(strNow)),2) & Right(("00" & Day(strNow)),2) & Right(("00" & Hour(strNow)),2) & Right(("00" &  Minute(strNow)),2) & Right(("00" & Second(strNow)),2)

getStrNow = strNow

End Function


'获取随机数,返回 [min,max]范围的数

Function getRandNumber(max, min)

Randomize 

getRandNumber = CInt((max-min+1)*Rnd()+min) 

End Function

'获取随机数字的字符串,返回[min,max]范围的数字字符串

Function getStrRandNumber(max, min)

dim randNumber:randNumber = getRandNumber(max, min)

getStrRandNumber = CStr(randNumber)

End Function


Function GetRnd(t0)

randomize

dim n1,n2,n3

do while len(getrnd)<t0 '随机字符位数 

n1=cstr(chrw((57-48)*rnd+48)) '0~9 

n2=cstr(chrw((90-65)*rnd+65)) 'a~z 

n3=cstr(chrw((122-97)*rnd+97)) 'a~z 

getrnd=getrnd&n1&n2&n3 

loop

End Function


'时间戳转换成普通日期

Function FromUnixTime(intTime) 

If IsEmpty(intTime) Or Not IsNumeric(intTime) Then 

FromUnixTime = Now() 

Exit Function 

End If

FromUnixTime = DateAdd("s", intTime, "1970-1-1 0:0:0") 

FromUnixTime = DateAdd("h", 8, FromUnixTime) 

End Function


'普通日期转换成时间戳

Function ToUnixTime(strTime)        

If IsEmpty(strTime) or Not IsDate(strTime) Then strTime = Now   

ToUnixTime = DateAdd("h",-8,strTime)        

ToUnixTime = DateDiff("s","1970-1-1 0:0:0", ToUnixTime)        

End Function

Dim sc4Json   

Sub InitScriptControl

Set sc4Json = Server.CreateObject("MSScriptControl.ScriptControl")    

sc4Json.Language = "JavaScript"    

sc4Json.AddCode "var itemTemp=null;function getJSArray(arr, index){itemTemp=arr[index];}"    

End Sub 

Function getJSONObject(strJSON)    

sc4Json.AddCode "var jsonObject = " & strJSON    

Set getJSONObject = sc4Json.CodeObject.jsonObject    

End Function 

Sub getJSArrayItem(objDest,objJSArray,index)    

On Error Resume Next    

sc4Json.Run "getJSArray",objJSArray, index    

Set objDest = sc4Json.CodeObject.itemTemp    

If Err.number=0 Then Exit Sub    

objDest = sc4Json.CodeObject.itemTemp    

End Sub


Function PostURL(url,PostStr)

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

Set http = Nothing

End Function


Function GetURL(url)

dim http

set http=server.createobject(xmlhttp)

http.open "GET",url,false

http.setRequestHeader "If-Modified-Since","0"

http.send()

GetURL=http.responsetext

set http=nothing

End Function


Function IsInstall(byval t0)

err.clear

on error resume next

IsInstall=false

dim obj

set obj=server.createobject(t0)

if err.number=0 then IsInstall=true

set obj=nothing

err.clear()

End Function


''转换HTML代码,过滤代码

Function enhtml(byval t0)

if isnull(t0) then enhtml="":exit function

if t0="<p>&nbsp;</p>" then enhtml="":exit function

t0=replace(t0,"&","&amp;")

t0=replace(t0,"'","&#39;")

t0=replace(t0,"""","&#34;")

t0=replace(t0,"<","&lt;")

t0=replace(t0,">","&gt;")

enhtml=t0

End Function


sub OutPutTxt(str)

dim FilePath,Fso,fopen

filepath=server.mappath("wx.txt")

Set fso = Server.CreateObject("scripting.FileSystemObject")

set fopen=fso.OpenTextFile(filepath, 8 ,true)

fopen.writeline(str)

set fso=nothing

set fopen=Nothing

end sub

%>

3、《payapi.php》

<?php


/*


url=要post的网址

data=要paost的内容



*/



header('Content-Type:text/html; charset=utf-8;');

if (isset($_GET['url'])){

$url=$_GET["url"];//接收传过来的post网址

$data = file_get_contents("php://input");//接收post过来的xml参数

$result = vpost($url,$data); //Post数据

echo $result;

}else{

echo "接口通讯正常";



function vpost($url,$data){ // 模拟提交数据函数

    $curl = curl_init(); // 启动一个CURL会话

    curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查

    //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在

    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器

   // curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转

curl_redir_exec($curl);

    curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer

    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求

    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包

    curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环

    curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回

    $tmpInfo = curl_exec($curl); // 执行操作

    if (curl_errno($curl)) {

       echo 'Errno'.curl_error($curl);//捕抓异常

    }

    curl_close($curl); // 关闭CURL会话

    return $tmpInfo; // 返回数据




function curl_redir_exec($ch,$debug="")


static $curl_loops = 0;

static $curl_max_loops = 20;

if ($curl_loops++ >= $curl_max_loops)


$curl_loops = 0;

return FALSE;


curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

$debbbb = $data;

list($header, $data) = explode("\n\n", $data, 2);

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($http_code == 301 || $http_code == 302) {

$matches = array();

preg_match('/Location:(.*?)\n/', $header, $matches);

$url = @parse_url(trim(array_pop($matches)));

//print_r($url);

if (!$url)


//couldn't process the url to redirect to

$curl_loops = 0;

return $data;


$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));

/*    if (!$url['scheme'])

$url['scheme'] = $last_url['scheme'];

if (!$url['host'])

$url['host'] = $last_url['host'];

if (!$url['path'])

$url['path'] = $last_url['path'];*/

$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');

curl_setopt($ch, CURLOPT_URL, $new_url);

//    debug('Redirecting to', $new_url);

return curl_redir_exec($ch);

} else {

$curl_loops=0;

return $debbbb;



?>

最后一次编辑于  2020-01-06  
点赞 0
收藏
评论
登录 后发表内容