<!--#include file="../../inc/payconn.asp"-->
<!-- #include file="asp_md5.asp" -->
<!--#include file="../payss.asp"-->
<%
'ON ERROR RESUME NEXT
SQL = "Select * From [L_pay] Where ptype='15173'"
Call ConnectionDatabase()
Set crs = Server.CreateObject("ADODB.Recordset")
crs.Open SQL,Conn,1,1
if crs.eof Then
 Response.Write "支付未设置！"
 Response.End()
End If
Response.Expires = 0
%>
<%
'取返回参数(15173支付将会用Post方式请求该页面)
pay_result	= Request("pay_result") '支付状态（成功，失败，不符）
transaction_id	= Request("transaction_id") '支付单号
bargainor_id = Request("bargainor_id") '商户id
sp_billno = Request("sp_billno") '商户单号
pay_info = Request("pay_info") '支付内容
total_fee = Request("total_fee") '支付金额
attach = Request("attach") '商户私有数据
md5_sign = Request("sign") 'md5
des=Request("bad_info")'支付提交过来的系统备注


if des="errorID=-5" then des="卡号或卡密码错误"
if des="errorID=-108" then des="卡号或卡密码错误"
if des="errorID=-118" then des="卡号或卡密码错误"
if des="账户不存在" then des="卡号不存在"
if des="账号密码错误" then des="卡号或卡密码错误"
if des="验证错误" then des="卡号或卡密码错误"
if des="您输入的点卡卡号与密码错误" then des="卡号或卡密码错误"
if des="您输入的充值卡密码不正确" then des="充值卡密码不正确"
if des="" then des="支付失败"

'本地参数
spid = crs("sId")	' 这里替换为您的实际商户号
sp_key = crs("sKey")	' sp_key是32位商户密钥, 请替换为您的实际密钥

'返回值定义
Private Const PAYOK  = 0				' 支付成功					
Private Const PAYSPERROR = 1			' 商户号错误
Private Const PAYMD5ERROR = 2			' 签名错误
Private Const PAYERROR	= 3				' 15173支付返回支付失败
Private Const PAYNOTALL	= 4				' 15173支付返回支付不符

'验签函数
Function verifyMd5Sign

	origText = "pay_result=" & pay_result & "&bargainor_id=" & bargainor_id &_ 
		     "&sp_billno=" & sp_billno & "&total_fee=" & total_fee &_
			   "&attach=" & attach & "&key=" & sp_key
	
	localSignText = UCase(ASP_MD5(origText)) ' 转换为大写
	verifyMd5Sign = (localSignText = UCase(md5_sign))
	
End Function

'返回值
Dim retValue
retValue = PAYOK 

'判断商户号
If bargainor_id <> spid Then
	retValue = PAYSPERROR
Else 
' 验签

	If verifyMd5Sign <> True Then
		retValue = PAYMD5ERROR
	Else
' 检查15173支付返回值
		If pay_result <> 0 Then
			retValue = PAYERROR
		End If
	End If
End If
If pay_result <> 0 Then
	retValue = PAYERROR
End If

' 业务处理,修改数据库,向客户发送通知...
Select Case retValue
	Case PAYOK 			pay_msg = "此单已成功支付!"
	Case PAYSPERROR	pay_msg = "错误的商户号!"	
	Case PAYMD5ERROR	pay_msg = "验证MD5签名失败!"
	Case Else			pay_msg = "此单未支付!"
End Select

	SQL = "select * from mobile1 Where num='"&sp_billno&"'"
	Set Res = Server.CreateObject("ADODB.Recordset")
	Res.Open SQL,Conn,1,3
	if not res.bof or not res.eof then
	if retValue=0 then res("stat")=1  '1表示成功
	if retValue=0 then res("des")="支付成功"  '1表示成功
	if retValue=0 then res("Okprice")=total_fee  '成功金额
	if retValue<>0 then res("stat")=2  '2表示失败
	if retValue<>0 then res("des")=des  '2表示失败
	res.update
	end if

if retValue=0 then
	
		Dim myPay
		Set myPay = New PayResult
		myPay.TruePrice = total_fee
		myPay.PayOK(sp_billno)	
End if

response.write pay_msg
response.End()

%>
