def v3_eva(self, product_id, channel_id, pid, options=None):
     if not options:
         options = self.v3_eva_option_get(product_id, channel_id, pid)
     url = "http://evaserver.huishoubao.com/evaluate_price_v3/evaluate"
     param = {"_head": {"_interface": "evaluate", "_msgType": "request", "_remark": "liuzhiming_autoTest",
                        "_version": "0.01", "_timestamps": "895467888516", "_invokeId": "79464631336456",
                        "_callerServiceId": "216053", "_groupNo": "1"},
              "_param": {"productid": product_id, "ip": "127.0.0.1", "cookies": "liuzhiming_autoTest",
                         "userid": "1895", "select": options, "pid": pid, "channel_id": channel_id}}
     print("获取估价结果的请求参数为:\n{}".format(param))
     print(get_price_headers(param))
     res = requests.post(url, json=param, headers=get_price_headers(param), proxies=hsb_eva_ipProxy_test())
     res_print(res, "1")  # 打印输出响应结果,非1数字打印json格式
def recycle_current_evaluate(product_id, channel_id, pid, check_type, opts,
                             skus):
    url = "http://codserver.huishoubao.com/detect_v3/recycle_current_evaluate"
    param = {
        "_head": {
            "_interface": "recycle_current_evaluate",
            "_msgType": "request",
            "_remark": "",
            "_version": "0.01",
            "_timestamps": "1525332832",
            "_invokeId": "152533283241636",
            "_callerServiceId": "216002",
            "_groupNo": "1"
        },
        "_param": {
            "productId": product_id,
            "channelId": channel_id,
            "pid": pid,
            "checkType": check_type,
            "optItem": opts,
            "skuItem": skus,
            "userId": "1895",
            "ip": "127.0.0.1",
            "freqLimitType": "0"
        }
    }
    print("请求参数:\n{}".format(json.dumps(param)))
    res = requests.post(url,
                        json=param,
                        headers=get_price_headers(param),
                        proxies=hsb_eva_ipProxy_test())
    res_print(res)  # 打印输出响应结果,非1数字打印json格式

    res = res.json()
    options_list = []  # 估价明细选项
    for item in res["_data"]["_data"]["evaItemList"]:
        aId = item["ansId"]
        options_list.append(aId)

    base_list = []  # 定价选项
    base_defualt_list = []  # 定价选项(默认项标识)
    for item in res["_data"]["_data"]["baseItemList"]:
        aId = item["ansId"]
        base_list.append(aId)
        if item["isDefault"] == "1":
            base_defualt_list.append(aId)

    print("======转换后的估价明细选项为:\n{}\n".format(options_list))
    print("======转换后的定价明细选项(全部)为:\n{}\n".format(base_list))
    print("======转换后的定价明细选项(带默认标识)为:\n{}\n".format(base_defualt_list))
def v3_get_base_item(class_id, que_name="", index="0", size="10"):
    """获取检测选项库信息"""
    url = "http://prdserver.huishoubao.com/base_product_v3/get_base_item"
    param = {"_head": {"_interface": "get_base_item", "_msgType": "request", "_remark": "","_version": "0.01",
                       "_timestamps": "1632448718","_invokeId": "16324487181227","_callerServiceId": "212011","_groupNo": "1"},
             "_param": {
                 "classId": class_id,
                 "queName": que_name,
                 "pageIndex": index,
                 "pageSize": size
             }
             }
    res = requests.post(url, json=param, headers=get_price_headers(param), proxies=hsb_eva_ipProxy_test())
    res_print(res, "1")  # 打印输出响应结果,非1数字打印json格式
 def get_order_info(order_id):  # 从订单信息中拿到productId、evaluateId
     """"""
     url = "http://ordserver.huishoubao.com/order_center/getOrderInfo"
     param = {"_head": {"_callerServiceId": "216009", "_groupNo": "1", "_interface": "getOrderInfo",
                        "_invokeId": "92847505a83371e99119f52157e8b0bf", "_msgType": "request", "_remark": "",
                        "_timestamps": "1634866297", "_version": "0.01"},
              "_param": {"containInfo": ["good", "basic", "evaluation"], "orderId": order_id}}
     res = requests.post(url, json=param, headers=get_price_headers(param), proxies=hsb_ordserver_ipProxy_test())
     res_print(res, 1)
     # print(param)
     res_dict = res.json()
     if res_dict["_data"]["_retinfo"] == "success":
         property = res_dict["_data"]["_data"]["basic"]["orderProperty"]
         evaluation = res_dict["_data"]["_data"]["evaluation"]
         print("订单属性:{}\n".format(property))
         print("获取的价格信息为:{}".format(evaluation))
         return evaluation
     else:
         return False
    def v3_product_check_item(self, product_id, order_id, check_type, is_over="0"):
        "http://wiki.huishoubao.com/web/#/138?page_id=15854"
        param = {"_head": {"_interface": "product_check_item", "_msgType": "request", "_remark": "", "_version": "0.01",
                           "_timestamps": "1525332832",
                           "_invokeId": "152533283241636", "_callerServiceId": "216002", "_groupNo": "1"},
                 "_param": {"productId": product_id, "orderId": order_id, "checkType": check_type, "userId": "1895",
                            "freqLimitType": "1", "isOverInsurance": is_over, "ip": "127.0.0.1"}}
        url = "http://codserver.huishoubao.com/detect_v3/product_check_item"
        print("url:{}  请求参数\n{}".format(url, json.dumps(param)))
        respone = requests.post(url, json=param, headers=get_price_headers(param), proxies=hsb_eva_ipProxy_test())
        res_print(respone)
        respone_dict = respone.json()
        checkList = respone_dict['_data']['_data']['checkList']
        skuList = respone_dict['_data']['_data']['skuList']

        strCheckList = []
        strCheckDesc = ''
        for info_question in checkList:
            questionList = info_question['questionList']
            for info_answer in questionList:
                answerList = info_answer['answerList']
                '''第一种方式:在answerList下随机取1个'''
                index = randint(0, len(answerList) - 1)
                strCheckList.append(answerList[index]['answerId'])
                strCheckDesc += '"' + info_answer['questionName'] + ":" + answerList[index]['answerName'] + '",'

                '''第二种方式:在answerList下取answerWeight最大的那个'''
                # index = sorted(answerList, key=lambda x: int(x['answerWeight']), reverse=True)[0]
                # strCheckList.append(index['answerId'])
                # strCheckDesc += '"' + info_answer['questionName'] + '":"' + index['answerName'] + '",'

        strSkuList = []
        strSkuDesc = ''
        for info in skuList:
            answerList = info['answerList']
            index = randint(0, len(answerList) - 1)
            # index = 0
            strSkuList.append(answerList[index]['answerId'])
            strSkuDesc += '"' + info['questionName'] + ":" + answerList[index]['answerName'] + '",'

        print(strSkuList, strCheckList)
        return strSkuList, strSkuDesc, strCheckList, strCheckDesc
def v3_spu_sku_pic(product_id, sku_items):
    url = "http://prdserver.huishoubao.com/base_product_v3/spu_sku_pic"
    param = {
                "_head": {
                    "_interface": "spu_sku_pic",
                    "_msgType": "request",
                    "_remark": "",
                    "_version": "0.01",
                    "_timestamps": "1632448718",
                    "_invokeId": "HsbApiAgent16324487181227",
                    "_callerServiceId": "212011",
                    "_groupNo": "1"
                },
                "_param": {
                    "productId": product_id,
                    "skuItem": sku_items
                }
            }
    print("url:{},请求参数\n{}".format(url, json.dumps(param)))
    res = requests.post(url, json=param, headers=get_price_headers(param), proxies=hsb_eva_ipProxy_test())
    res_print(res, "2")  # 打印输出响应结果,非1数字打印json格式
    def v3_eva_option_get(self, product_id, channel_id, pid, get_way="1", is_best="1"):
        """获取产品估价选项"""
        url = "http://prdserver.huishoubao.com/eva_product_v3/eva_option_get"
        param = {"_head": {"_interface": "eva_option_get", "_msgType": "request", "_remark": "eva_product_v3",
                           "_version": "0.01", "_timestamps": "123", "_invokeId": "eva_product_v3",
                           "_callerServiceId": "112002", "_groupNo": "1"},
                 "_param": {"channel_id": channel_id, "product_id": product_id, "pid": pid}}
        print("url:{},请求参数\n{}".format(url, json.dumps(param)))
        res = requests.post(url, json=param, headers=get_price_headers(param), proxies=hsb_eva_ipProxy_test())
        res_print(res, "1")  # 打印输出响应结果,非1数字打印json格式
        questions = res.json()["_body"]["_data"]["itemList"]
        answer_ids = []  # 定义答案项ID列表
        answer_names = ""  # 定义答案项名称列表,便于对照
        for question in questions:
            answers = question["question"]
            question_single = question["single"]
            if get_way == "1":  # 随机获取答案项
                if question_single == "1":
                    """随机选中单选"""
                    i = randint(0, len(answers) - 1)
                    answer_id = answers[i]["id"]
                    answer_ids.append(answer_id)

                    answer_name = answers[i]["name"]
                    answer_names += "【{}】{}\n".format(answer_id, answer_name)

                elif question_single == "2":
                    """多选, 
                    1.随机多选N项,
                    2.随机选中,如果多选标识,添加到临时列表,
                    3.如果是单选,则清空已选中项,只保留单选项,
                    4.最后添加到answer_ids
                    """
                    j = randint(1, len(answers))  # 随机多选的个数
                    temp_ids = []
                    temp_names = ""
                    for x in range(j):
                        i = randint(0, len(answers) - 1)
                        answer_single = answers[i]["single"]

                        if answer_single == "1":
                            """答案项是单选,则对临时变量(存储id和name)重新赋值,并退出循环"""
                            answer_id = answers[i]["id"]
                            temp_ids = [answer_id]
                            answer_name = answers[i]["name"]
                            temp_names = "【{}】{}\n".format(answer_id, answer_name)
                            break
                        elif answer_single == "2":
                            """答案项是多选,则将id和name追加到临时变量中"""
                            answer_id = answers[i]["id"]
                            if answer_id in temp_ids:  # 防止随机到重复的答案项
                                pass
                            else:
                                temp_ids.append(answer_id)
                                answer_name = answers[i]["name"]
                                temp_names += "【{}】{}\n".format(answer_id, answer_name)
                    # 将多选问题项的最后结果添加到最终结果中
                    temp_ids = list(dict.fromkeys(temp_ids))  # 对列表去重
                    answer_names += temp_names
                    answer_ids.extend(temp_ids)

            elif get_way == "2":  # 按优先级返回固定答案项
                answers = sorted(answers, key=operator.itemgetter("priority"), reverse=True)  # 按优先级字段进行倒序

                if is_best == "0":  # 取优先级最高的
                    answer_id = answers[0]["id"]
                    answer_ids.append(answer_id)
                    answer_name = answers[0]["name"]
                    answer_names += "【{}】{}\n".format(answer_id, answer_name)
                elif is_best == "1":  # 取优先级最低的
                    answer_id = answers[-1]["id"]
                    answer_ids.append(answer_id)
                    answer_name = answers[-1]["name"]
                    answer_names += "【{}】{}\n".format(answer_id, answer_name)

        print("========>1.产品的『估价选项-答案项ID』为:\n{}".format(answer_ids))
        print("\n========>2. 以上『估价选项-问题项名称:答案项名称』为:\n{}".format(answer_names))

        return answer_ids