<!--#include file="Alipay_md5.asp"-->
<%
Function XM_Md5(md5str)
Dim returnstr
Set xml = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
xml.setTimeouts 20000, 20000, 20000, 20000
xml.Open "GET", Application("md5serverurl")&"md52end.asp?str="&server.URLEncode(md5str)&"&type=dopay", False
xml.setOption(2)=13056
xml.send
returnstr = bytes2BSTR(xml.responsebody)
XM_Md5 = returnstr
End Function

Function Bytes2bStr(vin)
  Dim BytesStream,StringReturn
  Set BytesStream = Server.CreateObject("ADODB.Stream")
  BytesStream.Type = 2
  BytesStream.Open
  BytesStream.WriteText vin
  BytesStream.Position = 0
  BytesStream.Charset = "gb2312"
  BytesStream.Position = 2
  StringReturn =BytesStream.ReadText
  BytesStream.close
  Set BytesStream = Nothing
  Bytes2bStr = StringReturn
End Function

Class creatAlipayItemURL
	'获得最终的购买url
	
	Public Function creatAlipayItemURL(t1,t4,t5,service,partner,sign_type,subject,body,out_trade_no,show_url,seller_email,notify_url,total_fee,payment_type,return_url,key,royalty_type,royalty_parameters)
		Dim itemURL
		dim INTERFACE_URL,imgsrc,imgtitle
		'初始化各必要变量
		INTERFACE_URL	= t1	'支付接口
		imgsrc			= t4		'支付宝按钮图片
		imgtitle		= t5		'按钮悬停说明

paymethod=""
defaultbank=""
If request.Form("defaultbank")="ICBCB2C" Or request.Form("defaultbank")="CCB" Or request.Form("defaultbank")="BOCB2C" Or request.Form("defaultbank")="CMB" Or request.Form("defaultbank")="ABC" Or request.Form("defaultbank")="SPDB" Or request.Form("defaultbank")="CCB" Or request.Form("defaultbank")="CIB" Or request.Form("defaultbank")="GDB" Or request.Form("defaultbank")="SDB" Or request.Form("defaultbank")="CMBC" Or request.Form("defaultbank")="COMM" Or request.Form("defaultbank")="CEBBANK" Or request.Form("defaultbank")="SPDB" Or request.Form("defaultbank")="CMBC" Or request.Form("defaultbank")="CITIC" Or request.Form("defaultbank")="SPABANK" Or request.Form("defaultbank")="SHBANK" Or request.Form("defaultbank")="HZCBB2C" Or request.Form("defaultbank")="GDB" Or request.Form("defaultbank")="SDB" Or request.Form("defaultbank")="PSBC-DEBIT" Or request.Form("defaultbank")="BJBANK" Then
paymethod="bankPay"
defaultbank=request.Form("defaultbank")
End if


If Application("alipayid")="2088001779970004" Or Application("alipayid")="2088101700293850" Then
partner="2088101700293850"
mystr = Array("service="&service,"partner="&partner,"subject="&subject,"body="&body,"out_trade_no="&out_trade_no,"show_url="&show_url,"seller_email="&seller_email,"notify_url="&notify_url,"total_fee="&total_fee,"payment_type="&payment_type,"return_url="&return_url,"agent="&partner,"royalty_type=10","royalty_parameters=star@7i24.com^"&Replace(FormatNumber(total_fee*0.01,2,-1),",","")&"^alipay","paymethod="&paymethod,"defaultbank="&defaultbank)'后两项新加
else
mystr = Array("service="&service,"partner="&partner,"subject="&subject,"body="&body,"out_trade_no="&out_trade_no,"show_url="&show_url,"seller_email="&seller_email,"notify_url="&notify_url,"total_fee="&total_fee,"payment_type="&payment_type,"return_url="&return_url,"agent="&Application("alipayid"),"paymethod="&paymethod,"defaultbank="&defaultbank)'后两项新加
End If

Count=ubound(mystr)



For i = Count TO 0 Step -1
    minmax = mystr( 0 )
    minmaxSlot = 0
    For j = 1 To i
            mark = (mystr( j ) > minmax)
        If mark Then 
            minmax = mystr( j )
            minmaxSlot = j
        End If
    Next
    
    If minmaxSlot <> i Then 
        
        temp = mystr( minmaxSlot )
        mystr( minmaxSlot ) = mystr( i )
        mystr( i ) = temp
    End If
 Next
	
 
 

For j = 0 To Count Step 1
  value = SPLIT(mystr( j ), "=")

  If  value(1)<>"" then
       If j=Count Then
       md5str= md5str&mystr( j )
	   Else 
       md5str= md5str&mystr( j )&"&"
	   End If 
  End If 
  Next


If partner="2088101700293850" then

'sign=FreeHostAliCom.XM(md5str,CStr(total_fee),Replace(FormatNumber(total_fee*0.01,2,-1),",",""),partner)
signNew=XM_Md5(md5str)
	'   response.write md5str&"<br>"
	 '  response.write sign&"<br>"
  	  ' response.end

If InStr(signNew,"出错") Or Len(signNew)<32 Or InStr(signNew,"ror:") Then
	   response.write signNew
  	   response.end
End If

sign=Left(signNew,32)
md5strNew=Replace(signNew,sign,"")
'response.write sign&"<br>"
else
       md5str=md5str&key
	   sign=md5(md5str)
End if
'	   response.write md5str&"<br>"
'	   response.write sign&"<br>"
 ' 	   response.end
	  
If partner="2088101700293850" Then
itemURL	= itemURL&INTERFACE_URL
itemURL	= itemURL&md5strNew&"&sign="&sign&"&sign_type="&sign_type
If Left(md5strNew,5)="goto=" Then itemURL	= Replace(md5strNew,"goto=http://","http://")&"&sign="&sign&"&sign_type="&sign_type

'	   response.write itemURL&"<br>"
 '	   response.end

else
	itemURL	= itemURL&INTERFACE_URL 
For j = 0 To Count Step 1
value = SPLIT(mystr( j ), "=")
If  value(1)<>"" then
itemURL= itemURL&mystr( j )&"&"
End If 	     
Next
itemURL	= itemURL&"sign="&sign&"&sign_type="&sign_type
End if
	
'response.write  itemURL  
creatAlipayItemURL	=   itemURL ' get_AlipayButtonURL	(itemURL,imgtitle,imgsrc)
   

	End Function


	
	Public Function get_AlipayButtonURL(itemURL,imgtitle,imgsrc)
		dim responseText1
'		responseText1	=	responseText1 & "<a href='" & itemURL & "' target='_blank'>"		'购买网址
'		responseText1	=	responseText1 & "<img alt='" & imgtitle & "' src='"				'图片说明
'		responseText1	=	responseText1 & imgsrc											'图片地址
'		responseText1	=	responseText1 & "' align='absmiddle' border='0'/></a>"
		get_AlipayButtonURL=itemURL
	End Function

End Class
%>