Ejemplo n.º 1
0
    def Query(self):
        if not self.data.get("businessid"):
            raise PubErrorCustom("商户ID为空!")
        if not self.data.get("down_ordercode"):
            raise PubErrorCustom("商户订单号为空!")
        if not self.data.get("nonceStr"):
            raise PubErrorCustom("随机数!")

        md5params = "{}{}{}{}{}".format(self.user.google_token,
                                        str(self.data.get("down_ordercode")),
                                        str(self.data.get("businessid")),
                                        self.data.get("nonceStr"),
                                        self.user.google_token)
        md5params = md5params.encode("utf-8")

        logger.info("代付查询待签数据:{}".format(md5params))
        sign = hashlib.md5(md5params).hexdigest()
        logger.info("代付查询签名:{}-----{}".format(sign, self.data.get("sign")))
        if sign != self.data.get("sign"):
            raise PubErrorCustom("验签失败!")

        request = {}
        # request['dfordercode'] = "DF%08d%s" % (self.user.userid,self.data.get("down_ordercode"))
        request['dfordercode'] = self.data.get("down_ordercode")
        request['userid'] = self.user.userid
        request["paypassid"] = self.paypasslinktype.passid

        return daifuOrderQuery(request)
Ejemplo n.º 2
0
    def check_params(self):
        if not self.data.get("businessid"):
            raise PubErrorCustom("商户ID为空!")
        if not self.data.get("down_ordercode"):
            raise PubErrorCustom("商户订单号为空!")
        if not self.data.get("nonceStr"):
            raise PubErrorCustom("随机数!")
        if not self.data.get("amount"):
            raise PubErrorCustom("金额不能为空!")

        if float(self.data.get("amount")) <= 0:
            raise PubErrorCustom("请输入正确的提现金额!")

        if not self.data.get("accountNo"):
            raise PubErrorCustom("银行卡号不能为空!")
        if not self.data.get("bankName"):
            raise PubErrorCustom("银行名称不能为空!")
        if not self.data.get("accountName"):
            raise PubErrorCustom("账户名称不能为空!")
        if not self.data.get("sign"):
            raise PubErrorCustom("签名不能为空!")

        md5params = "{}{}{}{}{}{}{}{}{}{}".format(
            self.user.google_token, str(self.data.get("down_ordercode")),
            str(self.data.get("businessid")), self.user.google_token,
            str(self.data.get("nonceStr")), str(self.data.get("amount")),
            str(self.data.get("accountNo")), str(self.data.get("bankName")),
            str(self.data.get("accountName")), self.user.google_token)
        md5params = md5params.encode("utf-8")

        logger.info("代付待签数据:{}".format(md5params))
        sign = hashlib.md5(md5params).hexdigest()
        logger.info("代付签名:{}-----{}".format(sign, self.data.get("sign")))
        if sign != self.data.get("sign"):
            raise PubErrorCustom("验签失败!")
Ejemplo n.º 3
0
    def run(self):
        #3倍冻结,写死
        self.amount *= 3
        logger.info("解冻")
        self.AccountListInsert("解冻")

        self.user.stop_bal = float(self.user.stop_bal) + self.amount * -1

        self.user.today_bal = float(self.user.today_bal) + self.amount
        self.user.bal = float(self.user.bal) + self.amount
        self.user.save()

        logger.info(
            """动账后: userid:{} upd_bal_date:{} amount:{} ordercode:{} bal:{} cashout_bal:{} stop_bal:{} lastday_bal:{} today_bal:{} lastday_pay_amount:{} 
                        today_pay_amount:{} tot_pay_amount:{} lastday_cashout_amount:{} today_cashout_amount:{} tot_cashout_amount:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.user.cashout_bal,
                self.user.stop_bal,
                self.user.lastday_bal,
                self.user.today_bal,
                self.user.lastday_pay_amount,
                self.user.today_pay_amount,
                self.user.tot_pay_amount,
                self.user.lastday_cashout_amount,
                self.user.today_cashout_amount,
                self.user.tot_cashout_amount,
            ))

        return self.user
Ejemplo n.º 4
0
    def BalQuery(self):
        if not self.data.get("businessid"):
            raise PubErrorCustom("商户ID为空!")
        if not self.data.get("nonceStr"):
            raise PubErrorCustom("随机数!")

        md5params = "{}{}{}{}".format(self.user.google_token,
                                      str(self.data.get("businessid")),
                                      self.data.get("nonceStr"),
                                      self.user.google_token)
        md5params = md5params.encode("utf-8")

        logger.info("代付查询待签数据:{}".format(md5params))
        sign = hashlib.md5(md5params).hexdigest()
        logger.info("代付查询签名:{}-----{}".format(sign, self.data.get("sign")))
        if sign != self.data.get("sign"):
            raise PubErrorCustom("验签失败!")

        # user = AccountBase(userid=self.user.userid,amount=1).query()

        ok_bal = self.get_ok_bal()

        return {
            "data": {
                "bal": round(float(self.user.bal), 2),
                "stop_bal": round(float(self.user.stop_bal), 2),
                "ok_bal": round(ok_bal, 2)
            }
        }
Ejemplo n.º 5
0
    def run(self):
        logger.info("提现拒绝")
        self.user.cashout_bal = float(self.user.cashout_bal) + self.amount * -1
        self.user.save()

        logger.info(
            """动账后: userid:{} upd_bal_date:{} amount:{} ordercode:{} bal:{} cashout_bal:{} stop_bal:{} lastday_bal:{} today_bal:{} lastday_pay_amount:{} 
                        today_pay_amount:{} tot_pay_amount:{} lastday_cashout_amount:{} today_cashout_amount:{} tot_cashout_amount:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.user.cashout_bal,
                self.user.stop_bal,
                self.user.lastday_bal,
                self.user.today_bal,
                self.user.lastday_pay_amount,
                self.user.today_pay_amount,
                self.user.tot_pay_amount,
                self.user.lastday_cashout_amount,
                self.user.today_cashout_amount,
                self.user.tot_cashout_amount,
            ))
Ejemplo n.º 6
0
    def __init__(self, **kwargs):
        # 是否充值
        self.isPay = kwargs.get('isPay', False)

        # 是否提现
        self.isCashout = kwargs.get('isCashout', False)

        # 是否提现拒绝
        self.isCashoutCanle = kwargs.get('isCashoutCanle', False)

        # 是否提现确认
        self.isCashoutConfirm = kwargs.get('isCashoutConfirm', False)

        # 是否冻结
        self.isStop = kwargs.get('isStop', False)

        # 是否解冻
        self.isStopCanle = kwargs.get('isStopCanle', False)

        userid = kwargs.get('userid', None)
        if not userid:
            raise PubErrorCustom("用户代码不能为空!")

        self.amount = kwargs.get('amount', None)
        if not self.amount:
            raise PubErrorCustom("交易金额不能为空!")
        else:
            self.amount = float(self.amount)

        self.ordercode = kwargs.get('ordercode', 0)

        try:
            self.user = Users.objects.select_for_update().get(userid=userid)
        except Users.DoesNotExist:
            raise PubErrorCustom("无对应用户信息({})".format(userid))

        logger.info(
            """动账前: userid:{} upd_bal_date:{} amount:{} ordercode:{} bal:{} cashout_bal:{} stop_bal:{} lastday_bal:{} today_bal:{} lastday_pay_amount:{} 
                        today_pay_amount:{} tot_pay_amount:{} lastday_cashout_amount:{} today_cashout_amount:{} tot_cashout_amount:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.user.cashout_bal,
                self.user.stop_bal,
                self.user.lastday_bal,
                self.user.today_bal,
                self.user.lastday_pay_amount,
                self.user.today_pay_amount,
                self.user.tot_pay_amount,
                self.user.lastday_cashout_amount,
                self.user.today_cashout_amount,
                self.user.tot_cashout_amount,
            ))

        self.today = UtilTime().arrow_to_string(format_v="YYYYMMDD")

        self.RunUpdDate()
Ejemplo n.º 7
0
    def __init__(self, **kwargs):

        #规则
        self.rules = kwargs.get("rules", None)

        #传入数据
        self.data = kwargs.get("data", None)

        #渠道ID
        self.passid = kwargs.get("passid", None)

        logger.info("规则:{}".format(self.rules))

        #请求数据
        self.request_data = {}

        #确定请求的字典key集合
        self.request_keys = []

        #参加签名数据
        self.request_data_sign = {}

        #参加加密的数据
        self.request_data_pass = {}

        #返回数据
        self.response = None
Ejemplo n.º 8
0
    def callback(self,data):

        iData = dict()
        for item in data:
            iData[item] = data[item]

        logger.info("支付宝回调数据=>{}".format(iData))
        sign = iData.pop("sign",None)
        if not self.alipay.verify(iData,sign):
            raise PubErrorCustom("验签失败!")

        if iData.get("trade_status",None) != 'TRADE_SUCCESS':
            raise PubErrorCustom("交易状态异常!")
        #
        # try:
        #     orderObj = Order.objects.select_for_update().get(orderid=iData.get("out_trade_no",""))
        #     if orderObj.status == '1':
        #         logger.info("订单{}已处理".format(orderObj.orderid))
        #         raise PubErrorCustom("订单{}已处理".format(orderObj.orderid))
        # except Order.DoesNotExist:
        #     raise PubErrorCustom("订单不存在!")
        #
        # orderObj.status = '1'
        # orderObj.save()
        #
        # user = Users.objects.select_for_update().get(userid=orderObj.userid)
        #
        # logger.info("用户{}积分余额{}使用积分{}获得积分{}".format(user.mobile,user.jf,orderObj.use_jf,orderObj.get_jf))
        # user.jf -= orderObj.use_jf
        # user.jf += orderObj.get_jf
        # user.save()
        #
        logger.info("支付宝回调订单处理成功!=>{}".format(iData))
Ejemplo n.º 9
0
    def __init__(self, **kwargs):
        """
        回调类
        :param kwargs:
            name : 名称
            amount : 金额
        self :
            qrcode_obj : 二维码对象
            order_obj : 订单对象
            flag : 处理标志
                True : 成功
                False: 失败
            memo : 处理说明
        """
        self.amount = float(kwargs.get('amount',0.0))
        self.name = kwargs.get('name',None)
        self.type = kwargs.get('type')

        self.qrcode_obj = None
        self.order_obj = None

        self.flag = True
        self.memo = ''
        self.stand_rate = 0.0

        self.qr_class = Choices_to_Dict('qrtype_link_qrClass')[self.type]() if self.type else None
        logger.info("回调开始: 名称{}金额{}类型{}".format(self.name,self.amount,self.type))
Ejemplo n.º 10
0
    def run(self, fee=0.0):
        logger.info("手工下发手续费")
        self.amount = float(fee)
        # if self.user.fee_rule <= 0.0:
        #     self.amount = get_fee_rule_forSys()
        # else:
        #     self.amount = float(self.user.fee_rule)
        self.amount = self.amount * -1
        self.AccountListInsert("手工下发手续费")

        self.user.today_fee_amount = float(
            self.user.today_fee_amount) + self.amount * -1
        self.user.tot_fee_amount = float(
            self.user.tot_fee_amount) + self.amount * -1

        self.user.today_bal = float(self.user.today_bal) + self.amount
        self.user.bal = float(self.user.bal) + self.amount
        self.user.save()

        self.userBal.bal = float(self.userBal.bal) + self.amount
        self.userBal.save()

        logger.info(
            """动账后: userid:{} amount:{} ordercode:{} totbal:{} bal:{} cashout_bal:{} stop_bal:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.userBal.bal,
                self.userBal.cashout_bal,
            ))

        return self.user
Ejemplo n.º 11
0
    def run(self):
        logger.info("提现完成")
        self.amount = self.amount * -1
        self.AccountListInsert("提现")

        self.user.today_cashout_amount = float(
            self.user.today_cashout_amount) + self.amount * -1
        self.user.tot_cashout_amount = float(
            self.user.tot_cashout_amount) + self.amount * -1

        self.user.cashout_bal = float(self.user.cashout_bal) + self.amount
        self.user.today_bal = float(self.user.today_bal) + self.amount
        self.user.bal = float(self.user.bal) + self.amount
        self.user.save()

        self.userBal.cashout_bal = float(
            self.userBal.cashout_bal) + self.amount
        self.userBal.bal = float(self.userBal.bal) + self.amount
        self.userBal.save()

        logger.info(
            """动账后: userid:{} amount:{} ordercode:{} totbal:{} bal:{} cashout_bal:{} stop_bal:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.userBal.bal,
                self.userBal.cashout_bal,
            ))

        return self.user
Ejemplo n.º 12
0
    def requestHandlerForHtml(self):

        logger.info("向上游请求的值:{}".format(self.request_data))
        html="""

            <html lang="zh-CN"><head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>傲银支付</title>
            </head>
                <body>
                    <div class="container">
                        <div class="row" style="margin:15px;">
                            <div class="col-md-12">
                                <form class="form-inline" method="{}" action="{}">
            """.format(self.rules['request']['method'],self.rules['request']['url'])
        for key,value in self.request_data.items():
            html+="""<input type="hidden" name="{}" value="{}">""".format(key,value)

        html += """
                                </form>
                            </div>
                        </div>
                    </div>

                    <script src="http://47.75.120.33//static/jquery-1.4.1.min.js"></script>

                    <script>
                        $(function(){document.querySelector('form').submit();})
                    ;</script>
                </body>
            </html>
        """
        RedisOrderCreate().redis_insert(md5pass(str(self.data['ordercode'])),html)
Ejemplo n.º 13
0
    def run(self, fee):
        logger.info("提现申请")
        self.user.cashout_bal = float(self.user.cashout_bal) + self.amount
        self.user.save()

        if float(self.userBal.bal) - abs(float(
                self.userBal.cashout_bal)) - fee < self.amount:
            raise PubErrorCustom("可提余额不足!")

        if self.amount <= 0:
            raise PubErrorCustom("请输入正确的提现金额!")

        self.userBal.cashout_bal = float(
            self.userBal.cashout_bal) + self.amount
        self.userBal.save()

        logger.info(
            """动账后: userid:{} amount:{} ordercode:{} totbal:{} bal:{} cashout_bal:{} stop_bal:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.userBal.bal,
                self.userBal.cashout_bal,
            ))

        return self.user
Ejemplo n.º 14
0
    def aesPass(self):
        signData = self.hashBeforeHandler()
        logger.info("请求待加密字符串:{}".format(signData))

        res = AES.new(key=self.signRules['Gpass'].encode('utf-8'),mode=AES.MODE_CBC,iv=self.signRules['cheap'].encode('utf-8')). \
                    encrypt(getattr(self, self.signRules['tianchong'])(signData).encode('utf-8'))

        return str(base64.b64encode(res),"utf-8") if self.signRules['Pout'] == 'base64' else str(res.hex(),"utf-8")
Ejemplo n.º 15
0
 def redisdataCall(self, error=None):
     if error:
         logger.info(error)
     self.redis_client.lpush(
         self.lKey,
         "{}|allwin|{}|allwin|{}".format(self.ordercode, self.session,
                                         self.endtime))
     time.sleep(1)
Ejemplo n.º 16
0
    def _request(self):
        result = request(method='POST',
                         url=self.create_order_url,
                         data=self.data,
                         verify=True)

        self.response = result.text
        logger.info(self.response)
Ejemplo n.º 17
0
    def requestHandlerForJson(self):
        """
        "request":{
            "url":"http://localhost:8000",
            "method" : "POST",
            "type":"json",
        },
        """
        logger.info("向上游请求的值:{}".format(json.dumps(self.request_data)))

        try:
            if self.rules.get("request").get("type") == 'json':
                result = request(
                    url=self.rules.get("request").get("url"),
                    method=self.rules.get("request").get("method"),
                    json=self.request_data,
                    headers={"Content-Type": 'application/json'},
                    verify=False,
                    timeout=5)
            elif self.rules.get("request").get("type") == 'body':
                result = request(
                    url=self.rules.get("request").get("url"),
                    method=self.rules.get("request").get("method"),
                    data=self.request_data,
                    verify=False,
                    timeout=5)
            elif self.rules.get("request").get("type") == 'params':
                if self.passid == 76:
                    url = self.rules.get("request").get(
                        "url") + "?params={}".format(
                            json.dumps(self.request_data))
                    # data['params'] = self.request_data
                    print(url)
                    result = request(
                        url=url,
                        method=self.rules.get("request").get("method"),
                        verify=False,
                        timeout=5)
                else:
                    result = request(
                        url=self.rules.get("request").get("url"),
                        method=self.rules.get("request").get("method"),
                        params=self.request_data,
                        verify=False,
                        timeout=5)
            else:
                raise PubErrorCustom("请求参数错误!")
        except Exception as e:
            logger.error(str(e))
            raise PubErrorCustom(
                "上游系统很慢,超时了,麻烦别找我,发给上游,谢谢!!!!!!!(慢到什么程度 5秒没有反应,5秒是什么概念,基本上系统已经瘫痪了!!!!!)"
            )

        try:
            self.response = json.loads(result.content.decode('utf-8'))
            logger.info("上游返回值:{}".format(result.content.decode('utf-8')))
        except Exception as e:
            raise PubErrorCustom("返回JSON错误!{}".format(result.text))
Ejemplo n.º 18
0
    def __init__(self, **kwargs):

        self.amount = kwargs.get('amount', None)
        if not self.amount:
            raise PubErrorCustom("交易金额不能为空!")
        else:
            self.amount = float(self.amount)

        self.ordercode = kwargs.get('ordercode', 0)
        self.memo = kwargs.get("memo", "")

        userid = kwargs.get('userid', None)
        user = kwargs.get('user', None)
        if not (userid or user):
            raise PubErrorCustom("用户代码不能为空!")

        if not user:
            try:
                self.user = Users.objects.select_for_update().get(
                    userid=userid)
            except Users.DoesNotExist:
                raise PubErrorCustom("无对应用户信息({})".format(userid))
        else:
            self.user = user

        paypassid = kwargs.get("paypassid", None)
        userbal = kwargs.get('userbal', None)
        if not (paypassid or userbal):
            raise PubErrorCustom("渠道ID不能为空!")

        if not userbal:
            try:
                self.userBal = UserBal.objects.select_for_update().get(
                    userid=userid, paypassid=paypassid)
            except UserBal.DoesNotExist:
                self.userBal = UserBal.objects.create(**{
                    "userid": userid,
                    "paypassid": paypassid,
                })
        else:
            self.userBal = userbal

        logger.info(
            """动账前: userid:{} amount:{} ordercode:{} totbal:{} bal:{} cashout_bal:{} stop_bal:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.userBal.bal,
                self.userBal.cashout_bal,
            ))

        self.today = UtilTime().arrow_to_string(format_v="YYYYMMDD")

        self.RunUpdDate()
Ejemplo n.º 19
0
 def rsa_ecb_pkcs1padding(self):
     signData = self.hashBeforeHandler()
     logger.info("请求待签名字符串:{}".format(signData))
     self.signRules[
         'Spass'] = "******" + self.signRules[
             'Spass'] + "\n-----END RSA PRIVATE KEY-----"
     return str(
         base64.b64encode(
             PKCS1_v1_5.new(RSA.importKey(self.signRules['Spass'])).sign(
                 SHA.new(signData.encode("utf-8")))), 'utf-8')
Ejemplo n.º 20
0
    def get_qrcode(self, order=None):
        """
        #获取有效二维码
        :param
        :return:
        """
        #二维码轮询
        self.last_qr = get_sysnumber(self.type)
        qrcodes = Qrcode.objects.filter(status='0',
                                        type=self.type).order_by('id')
        if not qrcodes.exists():
            raise InnerErrorCustom("10010", "码池正在加紧制作二维码,请稍等刷新!")
        qrids = [item.id for item in qrcodes]
        qrids.sort()

        qrids_exists = [ item.qr_id for item in Order.objects.select_for_update().filter(qr_id__in=qrids,status=1,createtime__gte=self.get_valid_time()) \
                                if item.amount == order.amount ]

        logger.info("\n 二维码列表:{} \n 已存在相同金额的二维码列表:{}".format(
            qrids, qrids_exists))

        def check_valid_index_qrcode(index):
            max_qrids = len(qrids) - 1
            index += 1
            index = 0 if index > max_qrids else index

            while index <= max_qrids:
                if qrids[index] not in qrids_exists:
                    return qrids[index]
                else:
                    index += 1

            return False

        #开始轮询检查
        res = check_valid_index_qrcode(
            qrids.index(int(self.last_qr.last_qrcode)
                        ) if int(self.last_qr.last_qrcode) in qrids else -1)
        if not res:
            res = check_valid_index_qrcode(-1)
        if not res:
            raise InnerErrorCustom("10010", "码池正在加紧制作二维码,请稍等刷新!")
        else:
            self.last_qr.last_qrcode = res

        useing_qrcode_obj = [
            item for item in qrcodes if item.id == self.last_qr.last_qrcode
        ][0]

        useing_qrcode_obj.updtime = self.ut.timestamp
        useing_qrcode_obj.save()
        self.last_qr.save()

        return useing_qrcode_obj
Ejemplo n.º 21
0
    def __init__(self,**kwargs):
        self.amount = float(kwargs.get('amount',0.0))
        self.name = kwargs.get('name',None)
        self.type = kwargs.get('type',None)

        self.qrcode_obj = None
        self.order_obj = None

        self.flag = True
        self.memo = ''

        logger.info("回调开始: 名称{}金额{}类型{}".format(self.name,self.amount,self.type))
Ejemplo n.º 22
0
    def create(self,order_id,amount,subject=None):

        order_string = self.alipay.api_alipay_trade_wap_pay(
            out_trade_no=order_id,
            total_amount=str(Decimal(str(amount)).quantize(Decimal('0.00'))),
            subject='支付订单:%s' % order_id if not subject else subject,
            return_url=None,
            notify_url=None,
        )

        pay_url = '{}?{}'.format(AliPay_way,order_string)
        logger.info(pay_url)
        return pay_url
Ejemplo n.º 23
0
    def run(self):
        print("红包回调处理开启!")
        while True:
            redisRes = self.redis_client.brpop(self.lKey)[1]
            if not redisRes:
                continue

            self.ordercode = redisRes.decode('utf-8').split("|")[0]
            self.other_ordercode = redisRes.decode('utf-8').split("|")[1]
            self.session = redisRes.decode('utf-8').split("|")[2]
            self.endtime = redisRes.decode('utf-8').split("|")[3]

            if UtilTime().timestamp >= int(self.endtime):
                continue
            try:
                ut = UtilTime()
                start_time = ut.arrow_to_string(format_v="YYYY-MM-DD")
                end_time = ut.arrow_to_string(ut.today.shift(days=-3),format_v="YYYY-MM-DD")
                flag,s= WeiboCallBack(sessionRes=json.loads(self.session),cookieKey='pccookie',isSession=True)\
                    .queryOrderForWeibo(ordercode=self.ordercode,start_time=start_time,end_time=end_time)

                if not flag:
                    self.redisdataCall("查询失败!{}".format(s))
                    continue
                else:
                    if not len(s):
                        self.redisdataCall("查询无数据!{}".format(s))
                        continue
                    else:
                        if s[0]['status'] == '2':
                            pass
                        elif s[0]['status'] == '4':
                            self.redisdataCall("交易关闭!{}".format(s))
                            continue
                        elif s[0]['status'] == '1':
                            self.redisdataCall()
                            continue
                        else:
                            self.redisdataCall("未知状态!{}".format(s))
                            continue

                request_data = {"orderid": self.ordercode}
                result = request('POST', url=urllib.parse.unquote(
                    '{}/callback_api/lastpass/jingdong_callback'.format(url_join())), data=request_data,json=request_data, verify=False)
                if result.text != 'success':
                    logger.info("请求对方服务器错误! {}".format(self.ordercode))
            except Exception as e:
                self.redisdataCall(str(e))
                continue
Ejemplo n.º 24
0
    def __init__(self, **kwargs):

        self.amount = kwargs.get('amount', None)
        if not self.amount:
            raise PubErrorCustom("交易金额不能为空!")
        else:
            self.amount = float(self.amount)

        self.ordercode = kwargs.get('ordercode', 0)

        userid = kwargs.get('userid', None)
        user = kwargs.get('user', None)
        if not (userid or user):
            raise PubErrorCustom("用户代码不能为空!")

        if not user:
            try:
                self.user = Users.objects.select_for_update().get(
                    userid=userid)
            except Users.DoesNotExist:
                raise PubErrorCustom("无对应用户信息({})".format(userid))
        else:
            self.user = user

        logger.info(
            """动账前: userid:{} upd_bal_date:{} amount:{} ordercode:{} bal:{} cashout_bal:{} stop_bal:{} lastday_bal:{} today_bal:{} lastday_pay_amount:{} 
                        today_pay_amount:{} tot_pay_amount:{} lastday_cashout_amount:{} today_cashout_amount:{} tot_cashout_amount:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.user.cashout_bal,
                self.user.stop_bal,
                self.user.lastday_bal,
                self.user.today_bal,
                self.user.lastday_pay_amount,
                self.user.today_pay_amount,
                self.user.tot_pay_amount,
                self.user.lastday_cashout_amount,
                self.user.today_cashout_amount,
                self.user.tot_cashout_amount,
            ))

        self.today = UtilTime().arrow_to_string(format_v="YYYYMMDD")

        self.RunUpdDate()
Ejemplo n.º 25
0
    def requestHandlerForJson(self):
        """
        "request":{
            "url":"http://localhost:8000",
            "method" : "POST",
            "type":"json",
        },
        """
        logger.info("向上游请求的值:{}".format(json.dumps(self.request_data)))
        if self.rules.get("request").get("type") == 'json':
            result = request(
                url=self.rules.get("request").get("url"),
                method=self.rules.get("request").get("method"),
                json = self.request_data,
                headers={
                    "Content-Type": 'application/json'
                }
            )
        elif self.rules.get("request").get("type") == 'body':
            result = request(
                url = self.rules.get("request").get("url"),
                method = self.rules.get("request").get("method"),
                data=self.request_data,
            )
        elif self.rules.get("request").get("type") == 'params':
            if self.passid == 76:
                url = self.rules.get("request").get("url") + "?params={}".format(json.dumps(self.request_data))
                # data['params'] = self.request_data
                print(url)
                result = request(
                    url = url,
                    method = self.rules.get("request").get("method"),
                )
            else:
                result = request(
                    url = self.rules.get("request").get("url"),
                    method = self.rules.get("request").get("method"),
                    params = self.request_data
                )
        else:
            raise PubErrorCustom("请求参数错误!")

        try :
            self.response = json.loads(result.content.decode('utf-8'))
            logger.info("上游返回值:{}".format(result.content.decode('utf-8')))
        except Exception as e:
            raise PubErrorCustom("返回JSON错误!{}".format(result.text))
Ejemplo n.º 26
0
    def get_qrcode(self):
        """
        #获取有效二维码
        :param
        :return:
        """
        print(self.get_valid_max_time())
        qrcodes = TbDFPool.objects.filter(status='0',amount=self.amount,createtime__gte=self.get_valid_max_time()).order_by('id')

        if not qrcodes.exists():
            raise InnerErrorCustom("10010", "码池正在加紧上码,请稍等刷新!")
        qrids = [ item.id for item in qrcodes ]

        print(self.get_valid_time())
        qrids_exists = [ item.qr_id for item in Order.objects.select_for_update().filter(Q(qr_id__in=qrids,status=0) | Q(qr_id__in=qrids,status=1 ,createtime__gte=self.get_valid_time())) ]

        logger.info("\n 二维码列表:{} \n 已在订单表里存在的二维码列表:{}".format(qrids,qrids_exists))

        valid_ids = [ item for item in qrids if item not in qrids_exists ]

        if not valid_ids:
            raise InnerErrorCustom("10010", "码池正在加紧上码,请稍等刷新!")

        #筛选出有效二维码
        valid_id = random.sample(valid_ids,1)[0]

        valid_obj = None

        for item in qrcodes:
            print(item.id,valid_id)
            if item.id == valid_id:
                valid_obj = item

        if not valid_obj:
            raise InnerErrorCustom("10010", "码池正在加紧上码,请稍等刷新!")

        valid_obj.updtime = self.ut.timestamp
        print(valid_obj.updtime)
        valid_obj.save()

        return valid_obj
Ejemplo n.º 27
0
    def run(self):
        logger.info("手工下发手续费")
        if self.user.fee_rule <= 0.0:
            self.amount = get_fee_rule_forSys()
        else:
            self.amount = float(self.user.fee_rule)
        self.amount = self.amount * -1
        self.AccountListInsert("手工下发手续费")

        self.user.today_fee_amount = float(
            self.user.today_fee_amount) + self.amount * -1
        self.user.tot_fee_amount = float(
            self.user.tot_fee_amount) + self.amount * -1

        self.user.today_bal = float(self.user.today_bal) + self.amount
        self.user.bal = float(self.user.bal) + self.amount
        self.user.save()

        logger.info(
            """动账后: userid:{} upd_bal_date:{} amount:{} ordercode:{} bal:{} cashout_bal:{} stop_bal:{} lastday_bal:{} today_bal:{} lastday_pay_amount:{} 
                        today_pay_amount:{} tot_pay_amount:{} lastday_cashout_amount:{} today_cashout_amount:{} tot_cashout_amount:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.user.cashout_bal,
                self.user.stop_bal,
                self.user.lastday_bal,
                self.user.today_bal,
                self.user.lastday_pay_amount,
                self.user.today_pay_amount,
                self.user.tot_pay_amount,
                self.user.lastday_cashout_amount,
                self.user.today_cashout_amount,
                self.user.tot_cashout_amount,
            ))

        return self.user
Ejemplo n.º 28
0
    def run(self):
        logger.info("提现拒绝")
        self.user.cashout_bal = float(self.user.cashout_bal) + self.amount * -1
        self.user.save()

        self.userBal.cashout_bal = float(
            self.userBal.cashout_bal) + self.amount * -1
        self.userBal.save()

        logger.info(
            """动账后: userid:{} amount:{} ordercode:{} totbal:{} bal:{} cashout_bal:{} stop_bal:{}"""
            .format(
                self.user.userid,
                self.user.upd_bal_date,
                self.amount,
                self.ordercode,
                self.user.bal,
                self.userBal.bal,
                self.userBal.cashout_bal,
            ))

        return self.user
Ejemplo n.º 29
0
    def __request_validate(self, request):

        logger.info("生成订单请求数据:{}".format(request.data))

        if not request.data.get("businessid"):
            raise PubErrorCustom('商户ID不能为空')

        try:
            request.user = Users.objects.get(
                userid=request.data.get("businessid"))
        except Users.DoesNotExist:
            raise PubErrorCustom("无效的商户!")

        if not request.data.get("businessid"):
            raise PubErrorCustom("商户ID为空!")
        if not request.data.get("paytypeid"):
            raise PubErrorCustom("支付方式为空!")
        if not request.data.get("down_ordercode"):
            raise PubErrorCustom("商户订单号为空!")
        if not request.data.get("client_ip"):
            raise PubErrorCustom("客户端IP为空!")
        if not request.data.get("amount"):
            raise PubErrorCustom("金额为空!")

        md5params = "{}{}{}{}{}{}{}".format(
            request.user.google_token, str(request.data.get("businessid")),
            str(request.data.get("paytypeid")),
            str(request.data.get("down_ordercode")),
            str(request.data.get("client_ip")),
            str(request.data.get("amount")), request.user.google_token)
        md5params = md5params.encode("utf-8")

        logger.info("待签数据:{}".format(md5params))
        sign = hashlib.md5(md5params).hexdigest()
        logger.info("签名:{}-----{}".format(sign, request.data.get("sign")))
        if sign != request.data.get("sign"):
            raise PubErrorCustom("验签失败!")
Ejemplo n.º 30
0
    def callback_request_to_server(self):
        """
        进行回调操作
        :return:
        """

        try:
            user = Users.objects.get(userid=self.order_obj.userid)
        except Users.DoesNotExist:
            logger.error("订单用户不存在! 用户:{}".format(self.order_obj.userid))
            raise PubErrorCustom("订单用户不存在!")

        if self.order_obj.lock == '0':

            data_request = {
                "rescode": "10000",
                "msg": "回调成功!",
                "data": {
                    "ordercode": self.order_obj.ordercode,
                    "status": '0',
                    "confirm_amount": float(self.amount),
                    "pay_time": time.mktime(timezone.now().timetuple()),
                    "keep_info": demjson.decode(self.order_obj.keep_info)
                },
                "ordercode":str(self.order_obj.down_ordercode)
            }

            headers={
                "token" : str(self.order_obj.userid),
                "ordercode": str(self.order_obj.down_ordercode)
            }

            #天宝报文不加密
            if user.userid != 4:
                data_request['data'] = encrypt(json.dumps(data_request['data'], cls=DjangoJSONEncoder),
                                               user.google_token).decode('utf-8')

            result = send_request(url=urllib.parse.unquote(self.order_obj.notifyurl), method='POST', data=data_request,headers=headers)
            if not result[0]:
                logger.error("请求对方服务器错误{}".format(str(result)))
                self.order_obj.down_status = '2'
            else:
                self.order_obj.down_status = '0'
        else:

            request_data = {
                "businessid" : str(user.userid),
                "ordercode" : str(self.order_obj.ordercode),
                "down_ordercode" : str(self.order_obj.down_ordercode),
                # "amount1": str(self.order_obj.amount),
                "amount" : str(self.amount),
                "pay_time" : str(UtilTime().timestamp),
                "status" : "00"
            }
            md5params = "{}{}{}{}{}{}{}".format(
                user.google_token,
                request_data['businessid'],
                request_data['ordercode'],
                request_data['down_ordercode'],
                request_data['amount'],
                request_data['pay_time'],
                user.google_token)
            md5params = md5params.encode("utf-8")
            request_data['sign'] = hashlib.md5(md5params).hexdigest()

            logger.info("验签回调参数:{}{}".format(self.order_obj.notifyurl,request_data))

            try:
                result = request('POST', url=urllib.parse.unquote(self.order_obj.notifyurl), data=request_data , json=request_data, verify=False)
                logger.info("返回值:{}".format(result.text))
                if result.text.strip() != 'SUCCESS':
                    logger.error("请求对方服务器错误{}".format(str(result.text)))
                    self.order_obj.down_status = '2'
                else:
                    self.order_obj.down_status = '0'

            except Exception as e:
                logger.info("下游错误:{}".format(str(e)))
                self.order_obj.down_status = '2'