def GetPreSignStr(self, inputPara): sPara = {} #过滤空值、sign与sign_type参数 sPara = Core.FilterPara(inputPara) #获取待签名字符串 preSignStr = Core.CreateLinkString(sPara) return preSignStr
def GetResponseMysign(self, inputPara): sPara = {} #过滤空值、sign与sign_type参数 sPara = Core.FilterPara(inputPara) #获得签名结果 mysign = Core.BuildMysign(sPara, self.key, self.sign_type, self.input_charset) return mysign
def BuildRequestParaToString(self, sParaTemp): #待签名请求参数数组 sPara = {} sPara = BuildRequestPara(sParaTemp) #把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 strRequestData = Core.CreateLinkString(sPara) return strRequestData
def BuildRequestPara(self, sParaTemp): #待签名请求参数数组 sPara = {} #签名结果 mysign = "" #过滤签名参数数组 sPara = Core.FilterPara(sParaTemp) #获得签名结果 ########################################################################################## mysign = Core.BuildMysign(sPara, self.key, self.sign_type, self.input_charset) #签名结果与签名方式加入请求提交参数组中 sPara["sign"] = mysign sPara["sign_type"] = self.sign_type return sPara
def Verify(self, inputPara, notify_id, sign): #获取返回回来的待签名数组签名后结果 mysign = self.GetResponseMysign(inputPara) #获取是否是支付宝服务器发来的请求的验证结果 responseTxt = "true" if notify_id != "": responseTxt = self.GetResponseTxt(notify_id) #写日志记录(若要调试,请取消下面两行注释) sWord ="responseTxt=%s\n sign=%s & mysign=%s\n return paras:%s\n" %\ (responseTxt,sign,mysign,self.GetPreSignStr(inputPara)) Core.LogResult(sWord) #验证 #responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 #mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 if responseTxt == "true" and sign == mysign: #验证成功 return True else: #验证失败 return False