| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | 
							- # -*- encoding: utf-8 -*-
 
- """
 
- @File    : TelecomObject.py
 
- @Time    : 2024/1/11 10:40
 
- @Author  : stephen
 
- @Email   : zhangdongming@asj6.wecom.work
 
- @Software: PyCharm
 
- """
 
- import json
 
- import requests
 
- from requests import RequestException
 
- from Ansjer.config import CT_USER_ID, CT_PASSWORD, CT_SECRET_KEY, LOGGER
 
- from Object.utils.DesUtils import DesUtils
 
- class TelecomObject:
 
-     def __init__(self):
 
-         self.user_id = CT_USER_ID
 
-         self.password = CT_PASSWORD
 
-         self.secret_key = CT_SECRET_KEY
 
-         self.key1 = CT_SECRET_KEY[0:3]
 
-         self.key2 = CT_SECRET_KEY[3:6]
 
-         self.key3 = CT_SECRET_KEY[6:9]
 
-         self.session = requests.Session()
 
-     def query_card_main_status(self, iccid):
 
-         """
 
-         卡主状态查询接口
 
-         :param iccid: 卡的ICCID号。
 
-         :return: 包含卡状态的结果字典。
 
-         :raises ValueError: 如果响应为空或HTTP请求失败。
 
-         """
 
-         try:
 
-             if not iccid:
 
-                 raise ValueError("*****TelecomObject.query_card_main_status error****ICCID不能为空")
 
-             url = 'http://api.ct10649.com:9001/m2m_ec/query.do'
 
-             method = 'queryCardMainStatus'
 
-             arr = [iccid, self.user_id, self.password, method]
 
-             # 密码加密
 
-             password_enc = DesUtils.str_enc(self.password, self.key1, self.key2, self.key3)
 
-             sign = DesUtils.str_enc(DesUtils.natural_ordering(arr), self.key1, self.key2, self.key3)
 
-             re_params = {'method': method, 'iccid': iccid,
 
-                          'user_id': self.user_id,
 
-                          'passWord': password_enc,
 
-                          'sign': sign}
 
-             response = self.session.get(url, params=re_params)
 
-             if response.status_code != 200:
 
-                 raise ValueError(f"*****TelecomObject.query_card_main_status error HTTP请求失败,状态码: {response.status_code}")
 
-             result = response.json()
 
-             LOGGER.info(f'*****TelecomObject.query_card_main_status****iccid:{iccid},result:{result}')
 
-             return result
 
-         except RequestException:
 
-             raise
 
-         except json.JSONDecodeError:
 
-             raise
 
 
  |