Browse Source

修改调用停卡接口

zhangdongming 3 years ago
parent
commit
6ef5a96182

+ 2 - 0
Controller/UnicomCombo/UnicomComboController.py

@@ -322,6 +322,8 @@ class UnicomComboView(View):
                             return response.json(0, 'Thirty minutes later to visit again take effect')
                             return response.json(0, 'Thirty minutes later to visit again take effect')
                         cls.user_activate_flow(iccid)
                         cls.user_activate_flow(iccid)
                     return response.json(0)
                     return response.json(0)
+                if sim == 0:
+                    return response.json(0, '外置卡不保存相关信息{}'.format(serial_no))
                 unicom_obj = UnicomObjeect()
                 unicom_obj = UnicomObjeect()
                 result = unicom_obj.verify_device(iccid=iccid)
                 result = unicom_obj.verify_device(iccid=iccid)
                 if result.status_code == 200 and result.text:
                 if result.status_code == 200 and result.text:

+ 1 - 2
Controller/UnicomCombo/UnicomComboTaskController.py

@@ -133,8 +133,6 @@ class UnicomComboTaskView(View):
                 flow_total = combo_qs['flow_total']
                 flow_total = combo_qs['flow_total']
                 # 队列已使用总流量总量
                 # 队列已使用总流量总量
                 flow_total_usage = unicom_api.get_flow_usage_total(iccid)
                 flow_total_usage = unicom_api.get_flow_usage_total(iccid)
-                logger.info('--->iccid:{};套餐总值:{},激活时队列已用总流量:{},当前最新套餐队列已使用流量量:{}'
-                            .format(iccid, flow_total, activate_usage_flow, flow_total_usage))
                 is_expire = False
                 is_expire = False
                 flow = activate_usage_flow + flow_total
                 flow = activate_usage_flow + flow_total
                 if flow_total_usage > 0:
                 if flow_total_usage > 0:
@@ -152,6 +150,7 @@ class UnicomComboTaskView(View):
                         .update(status=2, updated_time=now_time, flow_exceed=flow_exceed)
                         .update(status=2, updated_time=now_time, flow_exceed=flow_exceed)
                     activate_status = cls.query_unused_combo_and_activate(iccid, year, month,
                     activate_status = cls.query_unused_combo_and_activate(iccid, year, month,
                                                                           flow_total_usage)
                                                                           flow_total_usage)
+                    logger.info('-->当前卡{}流量已用完,是否有生效套餐:{}'.format(iccid, activate_status))
                     if not activate_status:
                     if not activate_status:
                         # 停用
                         # 停用
                         unicom_api.change_device_to_disable(iccid)
                         unicom_api.change_device_to_disable(iccid)

+ 9 - 52
Object/UnicomObject.py

@@ -7,9 +7,8 @@
 @Software: PyCharm
 @Software: PyCharm
 """
 """
 import base64
 import base64
-import datetime
 import json
 import json
-from decimal import Decimal
+import logging
 
 
 import requests
 import requests
 from Crypto.Cipher import AES
 from Crypto.Cipher import AES
@@ -26,6 +25,8 @@ from Object.utils.SymmetricCryptoUtil import AESencrypt
 https://www.showdoc.com.cn/unicomJYHapi/8158648460007467
 https://www.showdoc.com.cn/unicomJYHapi/8158648460007467
 """
 """
 
 
+logger = logging.getLogger('info')
+
 
 
 class UnicomObjeect:
 class UnicomObjeect:
     def __init__(self):
     def __init__(self):
@@ -292,60 +293,16 @@ class UnicomObjeect:
         """
         """
         if iccid:
         if iccid:
             re_data = {"iccid": iccid, "status": 2}
             re_data = {"iccid": iccid, "status": 2}
-            UnicomObjeect().update_device_state(**re_data)
+            response = UnicomObjeect().update_device_state(**re_data)
+            logger.info('停用iccid响应结果:{}'.format(response.text))
             # 查询是否停用成功
             # 查询是否停用成功
             re_data.pop('status')
             re_data.pop('status')
             result = UnicomObjeect().query_device_status(**re_data)
             result = UnicomObjeect().query_device_status(**re_data)
             res_dict = UnicomObjeect().get_text_dict(result)
             res_dict = UnicomObjeect().get_text_dict(result)
+            logger.info('查询iccid状态:{}'.format(res_dict))
             if res_dict['data']['status'] != 3:
             if res_dict['data']['status'] != 3:
-                UnicomObjeect().update_device_state(**re_data)
+                re_data['status'] = 2
+                response = UnicomObjeect().update_device_state(**re_data)
+                logger.info('再次停卡:{}'.format(response.text))
             return True
             return True
         return None
         return None
-
-
-if __name__ == '__main__':
-
-    today = datetime.datetime.today()
-    year = today.year
-    month = today.month
-    print(year)
-    print(month)
-    print(type(year))
-    if not '':
-        print('为空')
-    price = '12.13'
-    print(float(price))
-    discount = '6'
-    dd = Decimal(price) - Decimal(discount)
-    print(dd.quantize(Decimal('0.00')))
-
-    unicom_api = UnicomObjeect()
-    data = {'foo': 1, 'bar': 2, 'baz': 3}
-    print(unicom_api.createSign(**data))
-    # result = unicom_api.generate_token()
-    # result = unicom_api.refresh_token('5d0c0f30-99bd-4f17-9614-3524495b05d4')
-    params = {'iccid': '89860621330065433774', 'status': 2}
-    # response = unicom_api.verify_device(**params)
-    # response = unicom_api.query_device_status(**params)
-    response = unicom_api.update_device_state(**params)
-    # response = unicom_api.query_device_usage_history(**params)
-    # response = unicom_api.query_current_renew_list_usage_details(**params)
-    # unicom_api.get_device_batch_detail()
-    # response = unicom_api.query_package_list(**params)
-    # response = unicom_api.query_renewal_list(**params)
-
-    if response.status_code == 200:
-        res = json.loads(response.text)
-        print(res)
-    response_json = {
-        "success": True,
-        "msg": "操作成功",
-        "code": 0,
-        "data": {
-            "iccid": "8986062018007784202",
-            "completeIccid": "89860620180077842020",
-            "status": 1
-        }
-    }
-    print(response_json['data']['iccid'])
-    print(response.status_code)