def payCardRequest(self, rparam, datas): cardUrl = TuyouPayTuyou.szf_url + '?' + self.createLinkString4Get( rparam) TyContext.ftlog.info('TuYouPayTuyou->requestUrl=', cardUrl) response, cardUrl = TyContext.WebPage.webget(cardUrl) TyContext.ftlog.info('TuYouPayTuyou->requestUrl=', cardUrl, 'response=', response) status = 0 try: status = int(response) except: status = 0 mo = TyContext.Cls_MsgPack() from tysdk.entity.pay.pay import TuyouPay if status == 200: TuyouPay.makeBuyChargeMessage(mo, datas) else: mo.setResult('code', 1) mo.setResult('tuyou.card.code', status) info = '' if status in TuyouPayTuyou.szf_request_code: info = TuyouPayTuyou.szf_request_code[status] else: info = '充值卡支付失败' info = info.decode('utf-8') mo.setResult('info', info) return mo
def getPayResult(self, ret, datas): r0_Cmd = ""; # 业务类型 r1_Code = ""; # 支付结果 r2_TrxId = ""; # 易宝支付交易流水号 r6_Order = ""; # 商户订单号 rq_ReturnMsg = ""; # 返回信息 rethmac = ""; # 签名数据 unkonw = ""; # 未知错误 result = ret.split("\n") for data in result: dsp = data.split('=') if len(dsp) != 2: continue sKey, Svalue = dsp if sKey == 'r0_Cmd': r0_Cmd = Svalue elif sKey == 'r1_Code': r1_Code = Svalue elif sKey == 'r2_TrxId': r2_TrxId = Svalue elif sKey == 'r6_Order': r6_Order = Svalue elif sKey == 'rq_ReturnMsg': rq_ReturnMsg = Svalue elif sKey == 'hmac': rethmac = Svalue else: unkonw = Svalue mo = TyContext.Cls_MsgPack() mo.setResult('r0_Cmd', r0_Cmd) mo.setResult('r1_Code', r1_Code) mo.setResult('r2_TrxId', r2_TrxId) mo.setResult('r6_Order', r6_Order) mo.setResult('rq_ReturnMsg', rq_ReturnMsg) mo.setResult('unkonw', unkonw) sbOld = str(r0_Cmd) + str(r1_Code) + str(r6_Order) + str(rq_ReturnMsg) hmacStr = self.getHmacString(sbOld) if (rethmac == hmacStr): if r1_Code == '1': info = '提交成功!' from tysdk.entity.pay.pay import TuyouPay TuyouPay.makeBuyChargeMessage(mo, datas) elif r1_Code == '2': info = '充值交易失败,卡密成功处理过或者提交卡号过于频繁' elif r1_Code == '11': info = '充值交易失败,订单号重复' elif r1_Code == '66': info = '充值交易失败,支付金额有误' else: info = '充值交易失败,请检查后重新测试支付' else: info = '充值交易失败,' + rq_ReturnMsg info = info.decode('utf-8') mo.setResult('info', info) return mo
def doPayRequestAliDone(self, page, rparam, datas): # 成功的返回如下,可以发回客户端,由客户端调用支付宝 # {"code":"success","paydata":"partner=\"2088701816336850\"&seller=\"[email protected]\"&out_trade_no=\"0830120418153417112\"&subject=\"360Coin\"&body=\"360Coin\"&total_fee=\"10\"¬ify_url=\"https%3A%2F%2Fapi.360pay.cn%2Freturn%2Fnotify%2FchannelId%2F10005\"&sign=\"IPYiJda%2Br%2BLqTLBwJ%2FJKlj8EPzy6k%2Bxhv4DDxRsQOvV81StDZHuro%2Fgl2UlAUidskqSVgwsJ6jEd1uw4maLQ72N65EZ6KIzObvI7rzXxFhQV%2BY0ReyCcxqp7DvdWUGT1T8O32ckpgXHi1N41Nv%2FbMQB1hTp3Xr%2Bw6zLgIckuLBE%3D\"&sign_type=\"RSA\""} jsons = None try: jsons = json.loads(page) if 'code' in jsons: if not jsons['code'] == 'success': jsons = {'code': 'error', 'info': 'net work error'} else: jsons = {'code': 'error', 'info': 'net work error'} except: jsons = {'code': 'error', 'info': 'net work error'} mo = TyContext.Cls_MsgPack() from tysdk.entity.pay.pay import TuyouPay TuyouPay.makeBuyChargeMessage(mo, datas) if jsons['code'] == 'success': mo.setResult('payData', jsons['paydata']) else: mo.setResult('payData', '') mo.setResult('code', 1) if 'info' in jsons: mo.setResult('info', jsons['info']) else: mo.setResult('info', 'net work error') return mo
def doMsgYdGsRequest(self, datas): TyContext.ftlog.info('TuYouPayMsgYdGs.doMsgYdGsRequest in datas=', datas) mo = TyContext.Cls_MsgPack() from tysdk.entity.pay.pay import TuyouPay TuyouPay.makeBuyChargeMessage(mo, datas) return mo
def doPayRequestCardDone(self, page, rparam, datas): mo = TyContext.Cls_MsgPack() from tysdk.entity.pay.pay import TuyouPay if page[0:7] == 'success': TuyouPay.makeBuyChargeMessage(mo, datas) else: mo.setResult('code', 1) # mo.setResult('info', 'pay/charge/360/card error') mo.setResult('info', '卡号和密码验证失败') return mo
def doPayRequestXiaomiCommon(self, params): mo = TyContext.Cls_MsgPack() from tysdk.entity.pay.pay import TuyouPay TuyouPay.makeBuyChargeMessage(mo, params) return mo
def doPayRequestCaiFuTong(self, datas): TyContext.ftlog.info('TuYouPayTuyou.doPayRequestCaiFuTong->datas=', datas) httpdomain = PayHelper.getSdkDomain() charge = int(float(datas['orderPrice'])) * CHARGE_RATE_RMB rparam = { 'ver': '2.0', # 版本号,ver默认值是1.0,目前版本ver取值应为2.0 'charset': '1', # 1 UTF-8, 2 GB2312, 默认为1 'bank_type': '0', # 银行类型:财付通支付填0 'desc': 'TYB' + str(charge), # 商品描述,32个字符以内 # 'purchaser_id' :'', # 用户(买方)的财付通帐户(QQ )。若商户没有传该参数,则在财付通支付页面,买家需要输入其财付通帐户 'bargainor_id': TuyouPayTuyou.cft_merId, # 商户号 'sp_billno': datas['orderPlatformId'], # 商户系统内部的定单号,32个字符内、可包含字母 'total_fee': charge * 100, # 总金额,以分为单位,不允许包含任何字、符号 'fee_type': '1', # 现金支付币种,目前只支持人民币,默认值是1:人民币 'notify_url': httpdomain + TuyouPayTuyou.cft_notify_url, # 接收财付通通知的URL,需给绝对路径 'callback_url': httpdomain + TuyouPayTuyou.cft_callback_url, # 交易完成后跳转的URL,需给绝对路径 # 'attach': datas['orderPlatformId'] # 商户附加信息,可做扩展参数,255字符内 # 'time_start' : '' # 订单生成时间 # 'time_expire' : '' # 订单失效时间 # 'sign':'' # MD5签名结果 } sk = rparam.keys() sk.sort() queryStr = "" for k in sk: queryStr = queryStr + str(k) + '=' + str(rparam[k]) + '&' signData = queryStr + 'key=' + TuyouPayTuyou.cft_key m = hashlib.md5() m.update(signData) sign = m.hexdigest().upper() rparam['sign'] = sign initUrl = TuyouPayTuyou.cft_init_url + '?' + urlencode(rparam) TyContext.ftlog.info('TuYouPayTuyou.doPayRequestCaiFuTong->initUrl=', initUrl) response, initUrl = TyContext.WebPage.webget(initUrl, {}, None, '', 'GET', { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0', 'Accept-Encoding': 'deflate', 'Connection': 'keep-alive', 'Host': 'wap.tenpay.com', }) TyContext.ftlog.info('TuYouPayTuyou.doPayRequestCaiFuTong->initUrl=', initUrl, 'response=', response) if response.find('gb2312') > 0: response = response.replace('gb2312', 'utf-8') response = unicode(response, encoding='gb2312').encode('utf-8') err_info = '财付通初始化失败' token_id = None xmlroot = ElementTree.fromstring(response) xmlnode = xmlroot.find('token_id') if xmlnode != None: token_id = xmlnode.text errnode = xmlroot.find('err_info') if errnode != None: err_info = errnode.text mo = TyContext.Cls_MsgPack() if token_id != None: from tysdk.entity.pay.pay import TuyouPay TuyouPay.makeBuyChargeMessage(mo, datas) mo.setResult('payUrl', TuyouPayTuyou.cft_pay_url + '?token_id=' + token_id) else: mo.setResult('code', 1) mo.setResult('info', err_info) return mo
def doPayRequestAli(self, datas): mo = TyContext.Cls_MsgPack() from tysdk.entity.pay.pay import TuyouPay TuyouPay.makeBuyChargeMessage(mo, datas) return mo