<%
	Dim mctSDK
	Dim nodeAuthorizationURL
	Dim messageType

	nodeAuthorizationURL = "https://www.yeepay.com/selfservice/AgentService.action"	'子商户注册URL 无需更改
	messageType="AgentRegister"			'消息类型
	
Function getReqHmacString(SubordinatesId,merchantCallbackURL)
	Dim sbOld
	'进行加密串处理，一定按照下列顺序进行
	sbOld=""
	sbOld = sbOld + messageType
	sbOld = sbOld + merchantId
	sbOld = sbOld + SubordinatesId
	sbOld = sbOld + merchantCallbackURL		
	getReqHmacString = HMAC(sbOld,keyValue) 
End Function

Function getCallbackHmacString(sCmd,sErrorCode,CustomerNumber,CustomerName,RegDate)
	Dim sbOld
	'取得加密前的字符串
	sbOld = ""
	sbOld = sbOld + CStr(merchantId)
	sbOld = sbOld + sCmd
	sbOld = sbOld + sErrorCode
	sbOld = sbOld + CustomerNumber
	sbOld = sbOld + CustomerName
	sbOld = sbOld + RegDate
	getCallbackHmacString = HMAC(sbOld,keyValue)
End Function

Function CheckHmac(sCmd,sErrorCode,CustomerNumber,CustomerName,RegDate,hmac)
	if(hmac=getCallbackHmacString(sCmd,sErrorCode,CustomerNumber,CustomerName,RegDate)) Then
		CheckHmac = True
	ELSE
		CheckHmac = False
	END IF
End Function

'取得返回串中的所有参数
Sub getCallBackValue(ByRef sCmd,ByRef sErrorCode,ByRef CustomerNumber,ByRef CustomerName,ByRef RegDate,ByRef svrHmac)
	sCmd = Request.QueryString("r0_Cmd")
	sErrorCode = Request.QueryString("r1_Code")
	CustomerNumber = Request.QueryString("r2_CustomerNumber")
	CustomerName = Request.QueryString("r3_CustomerName")
	RegDate = Request.QueryString("r4_Date")
	svrHmac = Request.QueryString("hmac")
End Sub

'callback方式:子商户注册服务器点对点通讯
'写入 AgentRegister.log 这里用来调试接口
Sub createLog(ByRef returnMsg)
    filename = "./AgentRegister.log"
    content = now()&" "&request.ServerVariables("REMOTE_ADDR")
    content = content + returnMsg
    content = content + " 注册成功的商户编号: " + CustomerNumber
    content = content + " 注册成功的商户名称: " + CustomerName
    content = content + " 注册日期: " + RegDate
    
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")   
    Set TS = FSO.OpenTextFile(Server.MapPath(filename),8,true) 
    TS.write content   
    TS.Writeline ""
    TS.Writeline ""
    Set TS = Nothing   
    Set FSO = Nothing   
End Sub

%>