<!-- #Include File="../Include/Channel_Shop.asp" -->
<!-- #Include File="Common.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

tit="AliPay在线支付反馈"

call DoWebHead(0,0)
Call Channel_Load(0)
tit_fir=Cls.ChannelName
call pay_true()
Call Channel_End(0)
call DoWebEnd()

sub pay_true()
  Dim msg_id,order_no,gross,buyer_email,buyer_name,buyer_address,buyer_zipcode,buyer_tel,buyer_mobile,action,s_date,ac,notify_type
  dim myAlipayObj,ResponseTxt
  Set myAlipayObj		= New AsaiMHalipay
  myAlipayObj.myAlipay_Initialize()
	msg_id			= DelStr(Request("msg_id"))
	order_no		= DelStr(Request("order_no"))
	gross			= DelStr(Request("gross"))
	buyer_email		= DelStr(Request("buyer_email"))
	buyer_name		= DelStr(Request("buyer_name"))
	buyer_address	= DelStr(Request("buyer_address"))
	buyer_zipcode	= DelStr(Request("buyer_zipcode"))
	buyer_tel		= DelStr(Request("buyer_tel"))
	buyer_mobile	= DelStr(Request("buyer_mobile"))
	action			= DelStr(Request("action"))
	s_date			= DelStr(Request("date"))
	ac				= DelStr(Request("ac"))
	notify_type  	= DelStr(Request("notify_type"))
	ResponseTxt = myAlipayObj.ReturnState(msg_id,order_no)
	if Cstr(ResponseTxt)<> "true" then exit sub
    myAlipayObj.alipayNotifyURL	= myAlipayObj.alipayNotifyURL & "msg_id=" & msg_id & "&email=" & myalipayEmail & "&order_no=" & order_no
	ResponseTxt		= myAlipayObj.getHTTPURL(alipayNotifyURL)
	if gross="" or buyer_email="" or buyer_name="" or ac="" then
		exit sub
	end if
	dim v_types,dis_remark,errstr,accept_u,msg_word,msg_tit,tmp_oid,ispayment,tmp_types
		accept_u=web_dim(3)
		msg_word="订单详情：" & chr(13) & "通知编号：" & msg_id & _
					chr(13) & "订单编号：" & order_no & _
					chr(13) & "价格：" & gross & _
					chr(13) & "买家邮件：" & buyer_email & _
					chr(13) & "买家姓名：" & buyer_name & _
					chr(13) & "买家地址：" & buyer_address & _
					chr(13) & "买家邮编：" & buyer_zipcode & _
					chr(13) & "买家电话：" & buyer_tel & _
					chr(13) & "买家手机：" & buyer_mobile & _
					chr(13) & "通知操作：" & action & _
					chr(13) & "通知日期：" & s_date & _
					chr(13) & "MD5摘要：" & ac
	sql="select id,types from AsaiMHShopOrders where ordernum='"&order_no&"'"
	set rs=Cls.exec(sql,1)
	if rs.eof then
		rs.close
		tmp_oid=0
	else
		tmp_oid=rs(0)
		tmp_types=rs(1)
		rs.close0
	end if
if  notify_type="web" then  '“支付后定向至商户平台”的网页转向处理
	tit="在线支付反馈"
	call web_head(0,0,-1,0,0)
	call shop_load(0,0,0)
	response.write shop_tm_body_left()
	if tmp_oid=0 then
		msg_tit="支付宝订单不存在"
	    call pay_true_err("支付宝返回的订单："&order_no&"不存在，请联系网站管理员！！")
	else
		v_types=2
		dis_remark="订单待处理中，若有疑问请联系网站管理员！"
		pay_true_err(dis_remark)
		sql="update AsaiMHShopOrders set types="&v_types&",dis_tim='"&Cls.now_time&"',dis_remark='"&dis_remark&"' where id="&tmp_oid
		call Cls.exec(sql,0)
		msg_tit="支付宝订单通知"
	end if
        sql="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
	    "values('"&login_username&"','"&accept_u&"','"&msg_tit&"','"&msg_word&"','"&Cls.now_time&"',1,0)"
		call Cls.exec(sql,0)
	else
	'测试商户网站URL是否正确安装
	If action = "test" Then
		returnTxt	= "Y"
	End If
	'发货通知
	If action = "sendOff" Then
		returnTxt		= "N"
		If (ResponseTxt = "true") Then
			if tmp_oid=0 then
				returnTxt = "N"
				msg_tit="支付宝发货通知，但订单不存在"
			else
				if tmp_types=5 then
					returnTxt = "Y"
					v_types=tmp_types
				else
					v_types=3
					returnTxt = "N"
					dis_remark="已收到支付宝通知，卖家正在发货。"
					msg_tit="已收到支付宝通知，请尽快发货。"
				end if
				ispayment=true
				pay_tim=Cls.now_time
				sql="update AsaiMHShopOrders set types="&v_types&",dis_tim='"&Cls.now_time&"',dis_remark='"&dis_remark&"',ispayment="&ispayment&", pay_tim='"&pay_tim&"' where id="&tmp_oid
				call Cls.exec(sql,0)
			end if
		        sql="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
			    "values('"&login_username&"','"&accept_u&"','"&msg_tit&"','"&msg_word&"','"&Cls.now_time&"',1,0)"
				call Cls.exec(sql,0)
      	Else
	'非法数据，不做更新
	End If
	End If
	'交易完成通知
	If action = "checkOut" Then
		returnTxt	= "Y"
		If (ResponseTxt = "true")Then
			if tmp_types=5 then
				returnTxt	= "Y"
			else
				returnTxt	= "N"
			end if
		Else
			returnTxt	= "N"
		End If
	End If
	Response.Write returnTxt
	End If
end sub

Function DelStr(Str)
	If IsNull(Str) Or IsEmpty(Str) Then
		Str	= ""
	End If
	DelStr	= Replace(Str,";","")
	DelStr	= Replace(DelStr,"'","")
	DelStr	= Replace(DelStr,"&","")
	DelStr	= Replace(DelStr," ","")
	DelStr	= Replace(DelStr,"　","")
	DelStr	= Replace(DelStr,"%20","")
	DelStr	= Replace(DelStr,"--","")
	DelStr	= Replace(DelStr,"==","")
	DelStr	= Replace(DelStr,"<","")
	DelStr	= Replace(DelStr,">","")
	DelStr	= Replace(DelStr,"%","")
End Function
%>
