コード例 #1
0
ファイル: gateway.py プロジェクト: mengtest/legend_game
 def _on_http_response(user_data, res):
     succeed = False
     if not res.error:
         if res.body == "200":
             # succeed
             succeed = True
             self.update_order_notification(app_id,
                                            params["my_order_id"],
                                            constant.SUCCEED)
             self.update_order_status(app_id, params["my_order_id"],
                                      constant.SUCCEED)
             NotifyUrl.instance().delete(packet.szGameOrder)
         else:
             # error
             self.log_error("pay_notice_invoke: res failed,%s",
                            res.body)
     else:
         self.log_error("pay_notice_invoke: failed,%s,%s", res.error,
                        res.body)
     if not succeed:
         # save to queue
         status = constant.NOTIFYING
         self.update_order_notification(app_id, params["my_order_id"],
                                        status)
         self.update_order_status(app_id, params["my_order_id"], status)
コード例 #2
0
                def my_order_id_updated(result, ex):
                    if ex:
                        if hasattr(self, 'request_handler'):
                            self.request_handler.set_status(constant.HTTP_422, reason='unprocessable request')
                        self.log_error("creating_order_with_http_params:sql:%s" % create_order_sql,exc_info=ex)
                    else:
                        self.log_info("creating_order_with_http_params: my_order_id:%s", real_my_order_id)

                    NotifyUrl.instance().set(real_my_order_id,data_to_cache)
                    on_created(real_my_order_id,ex)
コード例 #3
0
ファイル: order_mixin.py プロジェクト: du-debug/tornado_SDK
 def _on_upsert(result, ex):
     if not ex:
         params['notify_url_id'] = result
         insert_creating_orders()  # 往creating_orders 表中插入数据
         NotifyUrl.instance().set(
             params['my_order_id'], data_cahe
         )  # 维护了一个缓存的字典,讲my_order_id于notify_url对应起来,这里面的数据在支付回调的时候会取出来的
     else:
         print(
             '**insert into notify_urls ERROR:sql_str:{}**'.format(
                 notify_url_sql))
     pass
コード例 #4
0
ファイル: game_server.py プロジェクト: du-debug/tornado_SDK
        def _on_http_response(user_data, res):
            succeed = False
            game_order, plat_order = send_info.get('game_order', ''), send_info.get('plat_order', '')

            if (not res.error) and str(res.body).strip() == '200':
                succeed = True
                NotifyUrl.instance().delete(my_order_id)  # 从缓存中删除
                # TODO 跟新数据库里面的数据,orders
                # 推送订单到数据中心
                self.send_order_to_data_center(kwargs['order_info'], kwargs['created_at'], succeed,
                                               save_func=self.save_tj_data)

            if not succeed:
                # TODO 不成功,触发重发机制,此功能后续在写
                pass
コード例 #5
0
        def _on_created(create_order_sql, result,ex):
            if ex:
                self.log_error("creating_order_with_http_params:sql:%s" % create_order_sql,exc_info=ex)
                if hasattr(self, 'request_handler'):
                    self.request_handler.set_status(constant.HTTP_422, reason='unprocessable request')
                on_created(None,ex)
            else:
                real_my_order_id = "%s%s%s" % ( datetime.now().strftime("%Y%m%d%H%M%S"), result, int(time.time()) )
                update_sql = construct_update_sql(table_name,{'my_order_id': real_my_order_id},[" id = {0}" , result] )
                def my_order_id_updated(result, ex):
                    if ex:
                        if hasattr(self, 'request_handler'):
                            self.request_handler.set_status(constant.HTTP_422, reason='unprocessable request')
                        self.log_error("creating_order_with_http_params:sql:%s" % create_order_sql,exc_info=ex)
                    else:
                        self.log_info("creating_order_with_http_params: my_order_id:%s", real_my_order_id)

                    NotifyUrl.instance().set(real_my_order_id,data_to_cache)
                    on_created(real_my_order_id,ex)
                if params['my_order_id'].startswith('fake-'):
                    self._mysql.update(update_sql,callback=my_order_id_updated)
                else:
                    NotifyUrl.instance().set(params['my_order_id'], data_to_cache)
                    on_created(params['my_order_id'],None)
コード例 #6
0
ファイル: game_server.py プロジェクト: du-debug/tornado_SDK
    def send(self, send_info, **kwargs):
        app_id, my_order_id = int(kwargs['app_id']), send_info['my_order_id']
        data_cahe = NotifyUrl.instance().get(my_order_id)  # 取出缓存在字典里面的notify_url,notify_url是在创建订单的时候存入进去的,有格式
        pay_notice_url = data_cahe['url'] if data_cahe else None

        def _on_http_response(user_data, res):
            succeed = False
            game_order, plat_order = send_info.get('game_order', ''), send_info.get('plat_order', '')

            if (not res.error) and str(res.body).strip() == '200':
                succeed = True
                NotifyUrl.instance().delete(my_order_id)  # 从缓存中删除
                # TODO 跟新数据库里面的数据,orders
                # 推送订单到数据中心
                self.send_order_to_data_center(kwargs['order_info'], kwargs['created_at'], succeed,
                                               save_func=self.save_tj_data)

            if not succeed:
                # TODO 不成功,触发重发机制,此功能后续在写
                pass

        def on_notice(result, error):
            params = {}
            keys = ['plat_id', 'game_order', 'plat_order', 'amount', 'server_id', 'role_id', 'ext']
            for key in keys:
                params[key] = send_info.get(key, '')

            params['amount'] = '%0.2f' % (float(send_info['amount']))
            params['sign'] = self.send_order_sign(params)
            # url = self._app['pay_notice_url'] if (err or not result) else result['url']
            url = ''  # TODO url从里面进行选择
            url = urllib.parse.quote(url)
            user_data = {'url': url_concat(url, params)}
            # 发送请求
            self.request_get(url, params=params, callback=_on_http_response, user_date=user_data)

        if pay_notice_url is None:
            self.find_notify_url(send_info['notify_url_id'], on_notice)
        else:
            pass
コード例 #7
0
ファイル: gateway.py プロジェクト: mengtest/legend_game
    def send(self, packet, **kwargs):
        # platform_info = kwargs["platform_info"]
        app = kwargs["app"]
        self._app = app
        app_id = int(app["id"])
        data_cached = NotifyUrl.instance().get(packet.szGameOrder)
        params = {
            'platform_id': packet.nPlatformID,
            'my_order_id': packet.szGameOrder,
            'theirs_order_id': packet.szPlatformOrder,
            'real_price': packet.fOrderMoney,
            'status': 200 if packet.nStatus == 2 else 402
        }
        pay_notice_url = None
        if data_cached:
            pay_notice_url = data_cached['url']
            ext = data_cached['ext']
            params['ext'] = ext

        #params['sign'] = self.calc_sign(params)

        def _on_http_response(user_data, res):
            succeed = False
            if not res.error:
                if res.body == "200":
                    # succeed
                    succeed = True
                    self.update_order_notification(app_id,
                                                   params["my_order_id"],
                                                   constant.SUCCEED)
                    self.update_order_status(app_id, params["my_order_id"],
                                             constant.SUCCEED)
                    NotifyUrl.instance().delete(packet.szGameOrder)
                else:
                    # error
                    self.log_error("pay_notice_invoke: res failed,%s",
                                   res.body)
            else:
                self.log_error("pay_notice_invoke: failed,%s,%s", res.error,
                               res.body)
            if not succeed:
                # save to queue
                status = constant.NOTIFYING
                self.update_order_notification(app_id, params["my_order_id"],
                                               status)
                self.update_order_status(app_id, params["my_order_id"], status)

        def on_created(ext, url, params):
            params['ext'] = ext
            params['sign'] = self.calc_sign(params)
            self.request_get(url, params, _on_http_response)

        def _on_notify_url_found(result, ex):
            if ex:
                pass
            else:
                pay_notice_url = result['url']
                ext = utils.to_utf8(result['ext']) or ''
                self.save_order_notification(
                    app, pay_notice_url, params,
                    functools.partial(on_created, ext))

        if pay_notice_url is None:
            NotifyUrl.instance().find_by_my_order_id(params['my_order_id'],
                                                     _on_notify_url_found)
        else:
            result = dict(url=pay_notice_url, ext=ext)
            _on_notify_url_found(result, None)
コード例 #8
0
ファイル: gateway.py プロジェクト: mengtest/legend_game
 def __init__(self, *args, **kwargs):
     self._mysql = kwargs['mysql']
     NotifyUrl.set_database_connection(self._mysql)