tychxn / jd-assistant

京东抢购助手:包含登录,查询商品库存/价格,添加/清空购物车,抢购商品(下单),查询订单等功能
MIT License
5.18k stars 1.92k forks source link

现在京东都是定金预约了,现有的抢购模式都没用了 #191

Open AmazingEcho opened 3 years ago

AmazingEcho commented 3 years ago

定金模式下,支付定金后需要勾选同意定金协议后才能提交订单,这个不知道怎么修改

MoraxCloud commented 3 years ago

+1

h496022202 commented 3 years ago

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py

    def __init__(self):
        use_random_ua = global_config.getboolean('config', 'random_useragent')

        self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent()
        self.headers = {'User-Agent': self.user_agent}
        self.eid = global_config.get('config', 'eid')
        self.fp = global_config.get('config', 'fp')
        self.track_id = global_config.get('config', 'track_id')
        self.risk_control = global_config.get('config', 'risk_control')
        #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了
        if not self.eid or not self.fp :
            raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题')
        self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT)
        self.send_message = global_config.getboolean('messenger', 'enable')
        self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None

        self.item_cat = dict()
        self.item_vender_ids = dict()  # 记录商家id

        self.seckill_init_info = dict()
        self.seckill_order_data = dict()
        self.seckill_url = dict()

        self.username = ''
        self.nick_name = ''
        self.is_login = False
        self.sess = requests.session()
        try:
            self._load_cookies()
        except Exception:
            pass

    @check_login
    def submit_order_pre_sale(self):
        """提交定金订单
        :return: True/False 订单提交结果
        """
        url = 'https://trade.jd.com/shopping/order/submitOrder.action'
        # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091

        data = {
            'overseaPurchaseCookies': '',
            'vendorRemarks': '[]',
            'submitOrderParam.sopNotPutInvoice': 'false',
            'submitOrderParam.trackID': 'TestTrackId',
            'submitOrderParam.ignorePriceChange': '0',
            'submitOrderParam.btSupport': '0',
            'submitOrderParam.jxj': 1,
            'submitOrderParam.eid': self.eid,
            'submitOrderParam.fp': self.fp,
            'submitOrderParam.payType4YuShou': 2,
            'flowType':15,
            'preSalePaymentTypeInOptional':2,
        }

        # add payment password when necessary
        payment_pwd = global_config.get('account', 'payment_pwd')
        if payment_pwd:
            data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd)

        headers = {
            'User-Agent': self.user_agent,
            'Host': 'trade.jd.com',
            'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action',
        }

        try:
            resp = self.sess.post(url=url, data=data, headers=headers)
            resp_json = json.loads(resp.text)

            if resp_json.get('success'):
                order_id = resp_json.get('orderId')
                logger.info('订单提交成功! 订单号:%s', order_id)
                if self.send_message:
                    self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id)
                return True
            else:
                message, result_code = resp_json.get('message'), resp_json.get('resultCode')
                if result_code == 0:
                    self._save_invoice()
                    message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)'
                elif result_code == 60077:
                    message = message + '(可能是购物车为空 或 未勾选购物车中商品)'
                elif result_code == 60123:
                    message = message + '(需要在config.ini文件中配置支付密码)'
                logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message)
                logger.info(resp_json)
                return False
        except Exception as e:
            logger.error(e)
            return False
    @check_login
    def buy_presale_in_stock(self, sku_ids, area):
        """根据库存对预定商品下单
        :param sku_ids: 商品id
        :param area: 地区id
        :return:
        """
        while True:
            if self.get_single_item_stock(sku_ids,1,area):
                logger.info('检测到库存信息:%s,开始尝试下单',sku_ids)
                if self.submit_order_pre_sale():
                    logger.info('congratulation !!!!下单成功!!!!')
                    break
            time.sleep(self.timeout)

最后在main里执行:以抢购ps5为例:


from jd_assistant import Assistant

if __name__ == '__main__':
    """
    重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
    https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
    """

    sku_ids = '100019378198'  # 商品id
    area = '15-1213-1214-52670'  # 区域id
    asst = Assistant()  # 初始化
    asst.login_by_QRcode()  # 扫码登陆
    asst.buy_presale_in_stock(sku_ids,area)

我自己虽然改了,但是一直刷不出库存,祝你好运 image

FWiner commented 3 years ago

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py

    def __init__(self):
        use_random_ua = global_config.getboolean('config', 'random_useragent')

        self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent()
        self.headers = {'User-Agent': self.user_agent}
        self.eid = global_config.get('config', 'eid')
        self.fp = global_config.get('config', 'fp')
        self.track_id = global_config.get('config', 'track_id')
        self.risk_control = global_config.get('config', 'risk_control')
        #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了
        if not self.eid or not self.fp :
            raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题')
        self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT)
        self.send_message = global_config.getboolean('messenger', 'enable')
        self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None

        self.item_cat = dict()
        self.item_vender_ids = dict()  # 记录商家id

        self.seckill_init_info = dict()
        self.seckill_order_data = dict()
        self.seckill_url = dict()

        self.username = ''
        self.nick_name = ''
        self.is_login = False
        self.sess = requests.session()
        try:
            self._load_cookies()
        except Exception:
            pass

    @check_login
    def submit_order_pre_sale(self):
        """提交定金订单
        :return: True/False 订单提交结果
        """
        url = 'https://trade.jd.com/shopping/order/submitOrder.action'
        # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091

        data = {
            'overseaPurchaseCookies': '',
            'vendorRemarks': '[]',
            'submitOrderParam.sopNotPutInvoice': 'false',
            'submitOrderParam.trackID': 'TestTrackId',
            'submitOrderParam.ignorePriceChange': '0',
            'submitOrderParam.btSupport': '0',
            'submitOrderParam.jxj': 1,
            'submitOrderParam.eid': self.eid,
            'submitOrderParam.fp': self.fp,
            'submitOrderParam.payType4YuShou': 2,
            'flowType':15,
            'preSalePaymentTypeInOptional':2,
        }

        # add payment password when necessary
        payment_pwd = global_config.get('account', 'payment_pwd')
        if payment_pwd:
            data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd)

        headers = {
            'User-Agent': self.user_agent,
            'Host': 'trade.jd.com',
            'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action',
        }

        try:
            resp = self.sess.post(url=url, data=data, headers=headers)
            resp_json = json.loads(resp.text)

            if resp_json.get('success'):
                order_id = resp_json.get('orderId')
                logger.info('订单提交成功! 订单号:%s', order_id)
                if self.send_message:
                    self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id)
                return True
            else:
                message, result_code = resp_json.get('message'), resp_json.get('resultCode')
                if result_code == 0:
                    self._save_invoice()
                    message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)'
                elif result_code == 60077:
                    message = message + '(可能是购物车为空 或 未勾选购物车中商品)'
                elif result_code == 60123:
                    message = message + '(需要在config.ini文件中配置支付密码)'
                logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message)
                logger.info(resp_json)
                return False
        except Exception as e:
            logger.error(e)
            return False
    @check_login
    def buy_presale_in_stock(self, sku_ids, area):
        """根据库存对预定商品下单
        :param sku_ids: 商品id
        :param area: 地区id
        :return:
        """
        while True:
            if self.get_single_item_stock(sku_ids,1,area):
                logger.info('检测到库存信息:%s,开始尝试下单',sku_ids)
                if self.submit_order_pre_sale():
                    logger.info('congratulation !!!!下单成功!!!!')
                    break
            time.sleep(self.timeout)

最后在main里执行:以抢购ps5为例:


from jd_assistant import Assistant

if __name__ == '__main__':
    """
    重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
    https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
    """

    sku_ids = '100019378198'  # 商品id
    area = '15-1213-1214-52670'  # 区域id
    asst = Assistant()  # 初始化
    asst.login_by_QRcode()  # 扫码登陆
    asst.buy_presale_in_stock(sku_ids,area)

我自己虽然改了,但是一直刷不出库存,祝你好运 image

@h496022202 大佬 一直显示 您当前的收货人信息不正确,请修改后再提交 是怎么肥事。。

h496022202 commented 3 years ago

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py

    def __init__(self):
        use_random_ua = global_config.getboolean('config', 'random_useragent')

        self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent()
        self.headers = {'User-Agent': self.user_agent}
        self.eid = global_config.get('config', 'eid')
        self.fp = global_config.get('config', 'fp')
        self.track_id = global_config.get('config', 'track_id')
        self.risk_control = global_config.get('config', 'risk_control')
        #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了
        if not self.eid or not self.fp :
            raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题')
        self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT)
        self.send_message = global_config.getboolean('messenger', 'enable')
        self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None

        self.item_cat = dict()
        self.item_vender_ids = dict()  # 记录商家id

        self.seckill_init_info = dict()
        self.seckill_order_data = dict()
        self.seckill_url = dict()

        self.username = ''
        self.nick_name = ''
        self.is_login = False
        self.sess = requests.session()
        try:
            self._load_cookies()
        except Exception:
            pass

    @check_login
    def submit_order_pre_sale(self):
        """提交定金订单
        :return: True/False 订单提交结果
        """
        url = 'https://trade.jd.com/shopping/order/submitOrder.action'
        # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091

        data = {
            'overseaPurchaseCookies': '',
            'vendorRemarks': '[]',
            'submitOrderParam.sopNotPutInvoice': 'false',
            'submitOrderParam.trackID': 'TestTrackId',
            'submitOrderParam.ignorePriceChange': '0',
            'submitOrderParam.btSupport': '0',
            'submitOrderParam.jxj': 1,
            'submitOrderParam.eid': self.eid,
            'submitOrderParam.fp': self.fp,
            'submitOrderParam.payType4YuShou': 2,
            'flowType':15,
            'preSalePaymentTypeInOptional':2,
        }

        # add payment password when necessary
        payment_pwd = global_config.get('account', 'payment_pwd')
        if payment_pwd:
            data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd)

        headers = {
            'User-Agent': self.user_agent,
            'Host': 'trade.jd.com',
            'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action',
        }

        try:
            resp = self.sess.post(url=url, data=data, headers=headers)
            resp_json = json.loads(resp.text)

            if resp_json.get('success'):
                order_id = resp_json.get('orderId')
                logger.info('订单提交成功! 订单号:%s', order_id)
                if self.send_message:
                    self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id)
                return True
            else:
                message, result_code = resp_json.get('message'), resp_json.get('resultCode')
                if result_code == 0:
                    self._save_invoice()
                    message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)'
                elif result_code == 60077:
                    message = message + '(可能是购物车为空 或 未勾选购物车中商品)'
                elif result_code == 60123:
                    message = message + '(需要在config.ini文件中配置支付密码)'
                logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message)
                logger.info(resp_json)
                return False
        except Exception as e:
            logger.error(e)
            return False
    @check_login
    def buy_presale_in_stock(self, sku_ids, area):
        """根据库存对预定商品下单
        :param sku_ids: 商品id
        :param area: 地区id
        :return:
        """
        while True:
            if self.get_single_item_stock(sku_ids,1,area):
                logger.info('检测到库存信息:%s,开始尝试下单',sku_ids)
                if self.submit_order_pre_sale():
                    logger.info('congratulation !!!!下单成功!!!!')
                    break
            time.sleep(self.timeout)

最后在main里执行:以抢购ps5为例:


from jd_assistant import Assistant

if __name__ == '__main__':
    """
    重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
    https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
    """

    sku_ids = '100019378198'  # 商品id
    area = '15-1213-1214-52670'  # 区域id
    asst = Assistant()  # 初始化
    asst.login_by_QRcode()  # 扫码登陆
    asst.buy_presale_in_stock(sku_ids,area)

我自己虽然改了,但是一直刷不出库存,祝你好运 image

@h496022202 大佬 一直显示 您当前的收货人信息不正确,请修改后再提交 是怎么肥事。。

没遇到过,你可以去app上看看你是否有默认收获地址,或者重新编辑下默认地址

Kaier33 commented 3 years ago

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py

    def __init__(self):
        use_random_ua = global_config.getboolean('config', 'random_useragent')

        self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent()
        self.headers = {'User-Agent': self.user_agent}
        self.eid = global_config.get('config', 'eid')
        self.fp = global_config.get('config', 'fp')
        self.track_id = global_config.get('config', 'track_id')
        self.risk_control = global_config.get('config', 'risk_control')
        #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了
        if not self.eid or not self.fp :
            raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题')
        self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT)
        self.send_message = global_config.getboolean('messenger', 'enable')
        self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None

        self.item_cat = dict()
        self.item_vender_ids = dict()  # 记录商家id

        self.seckill_init_info = dict()
        self.seckill_order_data = dict()
        self.seckill_url = dict()

        self.username = ''
        self.nick_name = ''
        self.is_login = False
        self.sess = requests.session()
        try:
            self._load_cookies()
        except Exception:
            pass

    @check_login
    def submit_order_pre_sale(self):
        """提交定金订单
        :return: True/False 订单提交结果
        """
        url = 'https://trade.jd.com/shopping/order/submitOrder.action'
        # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091

        data = {
            'overseaPurchaseCookies': '',
            'vendorRemarks': '[]',
            'submitOrderParam.sopNotPutInvoice': 'false',
            'submitOrderParam.trackID': 'TestTrackId',
            'submitOrderParam.ignorePriceChange': '0',
            'submitOrderParam.btSupport': '0',
            'submitOrderParam.jxj': 1,
            'submitOrderParam.eid': self.eid,
            'submitOrderParam.fp': self.fp,
            'submitOrderParam.payType4YuShou': 2,
            'flowType':15,
            'preSalePaymentTypeInOptional':2,
        }

        # add payment password when necessary
        payment_pwd = global_config.get('account', 'payment_pwd')
        if payment_pwd:
            data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd)

        headers = {
            'User-Agent': self.user_agent,
            'Host': 'trade.jd.com',
            'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action',
        }

        try:
            resp = self.sess.post(url=url, data=data, headers=headers)
            resp_json = json.loads(resp.text)

            if resp_json.get('success'):
                order_id = resp_json.get('orderId')
                logger.info('订单提交成功! 订单号:%s', order_id)
                if self.send_message:
                    self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id)
                return True
            else:
                message, result_code = resp_json.get('message'), resp_json.get('resultCode')
                if result_code == 0:
                    self._save_invoice()
                    message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)'
                elif result_code == 60077:
                    message = message + '(可能是购物车为空 或 未勾选购物车中商品)'
                elif result_code == 60123:
                    message = message + '(需要在config.ini文件中配置支付密码)'
                logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message)
                logger.info(resp_json)
                return False
        except Exception as e:
            logger.error(e)
            return False
    @check_login
    def buy_presale_in_stock(self, sku_ids, area):
        """根据库存对预定商品下单
        :param sku_ids: 商品id
        :param area: 地区id
        :return:
        """
        while True:
            if self.get_single_item_stock(sku_ids,1,area):
                logger.info('检测到库存信息:%s,开始尝试下单',sku_ids)
                if self.submit_order_pre_sale():
                    logger.info('congratulation !!!!下单成功!!!!')
                    break
            time.sleep(self.timeout)

最后在main里执行:以抢购ps5为例:


from jd_assistant import Assistant

if __name__ == '__main__':
    """
    重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
    https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
    """

    sku_ids = '100019378198'  # 商品id
    area = '15-1213-1214-52670'  # 区域id
    asst = Assistant()  # 初始化
    asst.login_by_QRcode()  # 扫码登陆
    asst.buy_presale_in_stock(sku_ids,area)

我自己虽然改了,但是一直刷不出库存,祝你好运 image

@h496022202 大佬 一直显示 您当前的收货人信息不正确,请修改后再提交 是怎么肥事。。

没遇到过,你可以去app上看看你是否有默认收获地址,或者重新编辑下默认地址

@h496022202 我也是同样的问题... 大佬你试下商品id(ps5)为 100021367452 的时候是怎么样的

AmazingEcho commented 3 years ago

感谢大佬,向你学习

------------------ 原始邮件 ------------------ 发件人: "tychxn/jd-assistant" @.>; 发送时间: 2021年5月30日(星期天) 中午11:52 @.>; @.**@.>; 主题: Re: [tychxn/jd-assistant] 现在京东都是定金预约了,现有的抢购模式都没用了 (#191)

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py def init(self): use_random_ua = global_config.getboolean('config', 'random_useragent') self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent() self.headers = {'User-Agent': self.user_agent} self.eid = global_config.get('config', 'eid') self.fp = global_config.get('config', 'fp') self.track_id = global_config.get('config', 'track_id') self.risk_control = global_config.get('config', 'risk_control') #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了 if not self.eid or not self.fp : raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题') self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT) self.send_message = global_config.getboolean('messenger', 'enable') self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None self.item_cat = dict() self.item_vender_ids = dict() # 记录商家id self.seckill_init_info = dict() self.seckill_order_data = dict() self.seckill_url = dict() self.username = '' self.nick_name = '' self.is_login = False self.sess = requests.session() try: self._load_cookies() except Exception: pass @check_login def submit_order_pre_sale(self): """提交定金订单 :return: True/False 订单提交结果 """ url = 'https://trade.jd.com/shopping/order/submitOrder.action' # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091 data = { 'overseaPurchaseCookies': '', 'vendorRemarks': '[]', 'submitOrderParam.sopNotPutInvoice': 'false', 'submitOrderParam.trackID': 'TestTrackId', 'submitOrderParam.ignorePriceChange': '0', 'submitOrderParam.btSupport': '0', 'submitOrderParam.jxj': 1, 'submitOrderParam.eid': self.eid, 'submitOrderParam.fp': self.fp, 'submitOrderParam.payType4YuShou': 2, 'flowType':15, 'preSalePaymentTypeInOptional':2, } # add payment password when necessary payment_pwd = global_config.get('account', 'payment_pwd') if payment_pwd: data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd) headers = { 'User-Agent': self.user_agent, 'Host': 'trade.jd.com', 'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action', } try: resp = self.sess.post(url=url, data=data, headers=headers) resp_json = json.loads(resp.text) if resp_json.get('success'): order_id = resp_json.get('orderId') logger.info('订单提交成功! 订单号:%s', order_id) if self.send_message: self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id) return True else: message, result_code = resp_json.get('message'), resp_json.get('resultCode') if result_code == 0: self._save_invoice() message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)' elif result_code == 60077: message = message + '(可能是购物车为空 或 未勾选购物车中商品)' elif result_code == 60123: message = message + '(需要在config.ini文件中配置支付密码)' logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message) logger.info(resp_json) return False except Exception as e: logger.error(e) return False @check_login def buy_presale_in_stock(self, sku_ids, area): """根据库存对预定商品下单 :param sku_ids: 商品id :param area: 地区id :return: """ while True: if self.get_single_item_stock(sku_ids,1,area): logger.info('检测到库存信息:%s,开始尝试下单',sku_ids) if self.submit_order_pre_sale(): logger.info('congratulation !!!!下单成功!!!!') break time.sleep(self.timeout)
最后在main里执行:以抢购ps5为例: from jd_assistant import Assistant if name == 'main': """ 重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇 https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95 """ sku_ids = '100019378198' # 商品id area = '15-1213-1214-52670' # 区域id asst = Assistant() # 初始化 asst.login_by_QRcode() # 扫码登陆 asst.buy_presale_in_stock(sku_ids,area)
我自己虽然改了,但是一直刷不出库存,祝你好运

@h496022202 大佬 一直显示 您当前的收货人信息不正确,请修改后再提交 是怎么肥事。。

没遇到过,你可以去app上看看你是否有默认收获地址,或者重新编辑下默认地址

我也是同样的问题... 大佬你试下商品id(ps5)为 100021367452 的时候是怎么样的

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

RomanticHW commented 3 years ago

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py

    def __init__(self):
        use_random_ua = global_config.getboolean('config', 'random_useragent')

        self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent()
        self.headers = {'User-Agent': self.user_agent}
        self.eid = global_config.get('config', 'eid')
        self.fp = global_config.get('config', 'fp')
        self.track_id = global_config.get('config', 'track_id')
        self.risk_control = global_config.get('config', 'risk_control')
        #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了
        if not self.eid or not self.fp :
            raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题')
        self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT)
        self.send_message = global_config.getboolean('messenger', 'enable')
        self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None

        self.item_cat = dict()
        self.item_vender_ids = dict()  # 记录商家id

        self.seckill_init_info = dict()
        self.seckill_order_data = dict()
        self.seckill_url = dict()

        self.username = ''
        self.nick_name = ''
        self.is_login = False
        self.sess = requests.session()
        try:
            self._load_cookies()
        except Exception:
            pass

    @check_login
    def submit_order_pre_sale(self):
        """提交定金订单
        :return: True/False 订单提交结果
        """
        url = 'https://trade.jd.com/shopping/order/submitOrder.action'
        # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091

        data = {
            'overseaPurchaseCookies': '',
            'vendorRemarks': '[]',
            'submitOrderParam.sopNotPutInvoice': 'false',
            'submitOrderParam.trackID': 'TestTrackId',
            'submitOrderParam.ignorePriceChange': '0',
            'submitOrderParam.btSupport': '0',
            'submitOrderParam.jxj': 1,
            'submitOrderParam.eid': self.eid,
            'submitOrderParam.fp': self.fp,
            'submitOrderParam.payType4YuShou': 2,
            'flowType':15,
            'preSalePaymentTypeInOptional':2,
        }

        # add payment password when necessary
        payment_pwd = global_config.get('account', 'payment_pwd')
        if payment_pwd:
            data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd)

        headers = {
            'User-Agent': self.user_agent,
            'Host': 'trade.jd.com',
            'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action',
        }

        try:
            resp = self.sess.post(url=url, data=data, headers=headers)
            resp_json = json.loads(resp.text)

            if resp_json.get('success'):
                order_id = resp_json.get('orderId')
                logger.info('订单提交成功! 订单号:%s', order_id)
                if self.send_message:
                    self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id)
                return True
            else:
                message, result_code = resp_json.get('message'), resp_json.get('resultCode')
                if result_code == 0:
                    self._save_invoice()
                    message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)'
                elif result_code == 60077:
                    message = message + '(可能是购物车为空 或 未勾选购物车中商品)'
                elif result_code == 60123:
                    message = message + '(需要在config.ini文件中配置支付密码)'
                logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message)
                logger.info(resp_json)
                return False
        except Exception as e:
            logger.error(e)
            return False
    @check_login
    def buy_presale_in_stock(self, sku_ids, area):
        """根据库存对预定商品下单
        :param sku_ids: 商品id
        :param area: 地区id
        :return:
        """
        while True:
            if self.get_single_item_stock(sku_ids,1,area):
                logger.info('检测到库存信息:%s,开始尝试下单',sku_ids)
                if self.submit_order_pre_sale():
                    logger.info('congratulation !!!!下单成功!!!!')
                    break
            time.sleep(self.timeout)

最后在main里执行:以抢购ps5为例:


from jd_assistant import Assistant

if __name__ == '__main__':
    """
    重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
    https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
    """

    sku_ids = '100019378198'  # 商品id
    area = '15-1213-1214-52670'  # 区域id
    asst = Assistant()  # 初始化
    asst.login_by_QRcode()  # 扫码登陆
    asst.buy_presale_in_stock(sku_ids,area)

我自己虽然改了,但是一直刷不出库存,祝你好运 image

@h496022202 大佬 一直显示 您当前的收货人信息不正确,请修改后再提交 是怎么肥事。。

没遇到过,你可以去app上看看你是否有默认收获地址,或者重新编辑下默认地址

可以正常抢购吗

Daniel-ChenJH commented 3 years ago

我做了部分修改,以支持定金预购抢购,可以参考一下: jd_assistant.py

    def __init__(self):
        use_random_ua = global_config.getboolean('config', 'random_useragent')

        self.user_agent = DEFAULT_USER_AGENT if not use_random_ua else get_random_useragent()
        self.headers = {'User-Agent': self.user_agent}
        self.eid = global_config.get('config', 'eid')
        self.fp = global_config.get('config', 'fp')
        self.track_id = global_config.get('config', 'track_id')
        self.risk_control = global_config.get('config', 'risk_control')
        #因为定金预购中,用不到track_id 和 risk_control,所以这里的校验去掉了
        if not self.eid or not self.fp :
            raise AsstException('请在 config.ini 中配置 eid, fp, track_id, risk_control 参数,具体请参考 wiki-常见问题')
        self.timeout = float(global_config.get('config', 'timeout') or DEFAULT_TIMEOUT)
        self.send_message = global_config.getboolean('messenger', 'enable')
        self.messenger = Messenger(global_config.get('messenger', 'sckey')) if self.send_message else None

        self.item_cat = dict()
        self.item_vender_ids = dict()  # 记录商家id

        self.seckill_init_info = dict()
        self.seckill_order_data = dict()
        self.seckill_url = dict()

        self.username = ''
        self.nick_name = ''
        self.is_login = False
        self.sess = requests.session()
        try:
            self._load_cookies()
        except Exception:
            pass

    @check_login
    def submit_order_pre_sale(self):
        """提交定金订单
        :return: True/False 订单提交结果
        """
        url = 'https://trade.jd.com/shopping/order/submitOrder.action'
        # js function of submit order is included in https://trade.jd.com/shopping/misc/js/order.js?r=2018070403091

        data = {
            'overseaPurchaseCookies': '',
            'vendorRemarks': '[]',
            'submitOrderParam.sopNotPutInvoice': 'false',
            'submitOrderParam.trackID': 'TestTrackId',
            'submitOrderParam.ignorePriceChange': '0',
            'submitOrderParam.btSupport': '0',
            'submitOrderParam.jxj': 1,
            'submitOrderParam.eid': self.eid,
            'submitOrderParam.fp': self.fp,
            'submitOrderParam.payType4YuShou': 2,
            'flowType':15,
            'preSalePaymentTypeInOptional':2,
        }

        # add payment password when necessary
        payment_pwd = global_config.get('account', 'payment_pwd')
        if payment_pwd:
            data['submitOrderParam.payPassword'] = encrypt_payment_pwd(payment_pwd)

        headers = {
            'User-Agent': self.user_agent,
            'Host': 'trade.jd.com',
            'Referer': 'http://trade.jd.com/shopping/order/getOrderInfo.action',
        }

        try:
            resp = self.sess.post(url=url, data=data, headers=headers)
            resp_json = json.loads(resp.text)

            if resp_json.get('success'):
                order_id = resp_json.get('orderId')
                logger.info('订单提交成功! 订单号:%s', order_id)
                if self.send_message:
                    self.messenger.send(text='jd-assistant 订单提交成功', desp='订单号:%s' % order_id)
                return True
            else:
                message, result_code = resp_json.get('message'), resp_json.get('resultCode')
                if result_code == 0:
                    self._save_invoice()
                    message = message + '(下单商品可能为第三方商品,将切换为普通发票进行尝试)'
                elif result_code == 60077:
                    message = message + '(可能是购物车为空 或 未勾选购物车中商品)'
                elif result_code == 60123:
                    message = message + '(需要在config.ini文件中配置支付密码)'
                logger.info('订单提交失败, 错误码:%s, 返回信息:%s', result_code, message)
                logger.info(resp_json)
                return False
        except Exception as e:
            logger.error(e)
            return False
    @check_login
    def buy_presale_in_stock(self, sku_ids, area):
        """根据库存对预定商品下单
        :param sku_ids: 商品id
        :param area: 地区id
        :return:
        """
        while True:
            if self.get_single_item_stock(sku_ids,1,area):
                logger.info('检测到库存信息:%s,开始尝试下单',sku_ids)
                if self.submit_order_pre_sale():
                    logger.info('congratulation !!!!下单成功!!!!')
                    break
            time.sleep(self.timeout)

最后在main里执行:以抢购ps5为例:


from jd_assistant import Assistant

if __name__ == '__main__':
    """
    重要提示:此处为示例代码之一,请移步下面的链接查看使用教程👇
    https://github.com/tychxn/jd-assistant/wiki/1.-%E4%BA%AC%E4%B8%9C%E6%8A%A2%E8%B4%AD%E5%8A%A9%E6%89%8B%E7%94%A8%E6%B3%95
    """

    sku_ids = '100019378198'  # 商品id
    area = '15-1213-1214-52670'  # 区域id
    asst = Assistant()  # 初始化
    asst.login_by_QRcode()  # 扫码登陆
    asst.buy_presale_in_stock(sku_ids,area)

我自己虽然改了,但是一直刷不出库存,祝你好运 image

你好,想问下运行你给的代码时一直这样报错,怎么办?运行的是预售定金商品。每次运行都是报这个错,删除cookie重新扫码登录也没能解决

sku_ids = '100015692266'  # 商品id
area = '2_2825_61085'  # 区域id

2021-06-06 15:49:15,000 INFO: 检测到库存信息:100015692266,开始尝试下单 2021-06-06 15:49:15,189 INFO: 订单提交失败, 错误码:60077, 返回信息:获取用户订单信息失败(可能是购物车为空 或 未勾选购物车中商品) 2021-06-06 15:49:15,189 INFO: {'cartXml': None, 'noStockSkuIds': '', 'reqInfo': None, 'hasJxj': False, 'addedServiceList': None, 'overSea': False, 'orderXml': None, 'sign': None, 'pin': 'jd_LOrHIOeduHLM', 'needCheckCode': False, 'success': False, 'overseaMerge': False, 'resultCode': 60077, 'addressVO': {'pin': None, 'selected': True, 'oldAddress': False, 'mapping': False, 'gcReliability': 0, 'gcReliabilitySource': 0, 'fullAddress': '上海闵行区江川路街道