|
|
|
@@ -1,73 +1,84 @@
|
|
|
|
|
_Al='queryYear'
|
|
|
|
|
_Ak='provinceCode'
|
|
|
|
|
_Aj='sceneType'
|
|
|
|
|
_Ai='consNoSrc'
|
|
|
|
|
_Ah='access_token'
|
|
|
|
|
_Ag='businessType'
|
|
|
|
|
_Af='qrCodeSerial'
|
|
|
|
|
_Ae='redirect_url'
|
|
|
|
|
_Ad='_access_token'
|
|
|
|
|
_Ac='refresh_interval'
|
|
|
|
|
_Ab='doorAccountDict'
|
|
|
|
|
_Aa='refreshToken'
|
|
|
|
|
_AZ='accessToken'
|
|
|
|
|
_AY='/osg-web0004/member/c24/f01'
|
|
|
|
|
_AX='BCP_00026'
|
|
|
|
|
_AW='serviceCode_smt'
|
|
|
|
|
_AV='WEBA10070900'
|
|
|
|
|
_AU='serviceType'
|
|
|
|
|
_AT='jM_custType'
|
|
|
|
|
_AS='jM_busiTypeCode'
|
|
|
|
|
_AR='consType'
|
|
|
|
|
_AQ='constType'
|
|
|
|
|
_AP='powerUserList'
|
|
|
|
|
_AO='publicKey'
|
|
|
|
|
_AN='WEBA10070800'
|
|
|
|
|
_AM='timeDay'
|
|
|
|
|
_AL='WEBA10070700'
|
|
|
|
|
_AK='0101143'
|
|
|
|
|
_AJ='channelNo'
|
|
|
|
|
_AI='latestBillMonth'
|
|
|
|
|
_AH='yearTotalCost'
|
|
|
|
|
_AG='userAccountId'
|
|
|
|
|
_AF='0000'
|
|
|
|
|
_AE='refresh_token'
|
|
|
|
|
_AD='skey'
|
|
|
|
|
_AC='userInfo'
|
|
|
|
|
_AB='0101046'
|
|
|
|
|
_AA='proCode'
|
|
|
|
|
_A9='loginAccount'
|
|
|
|
|
_A8='keyCode'
|
|
|
|
|
_A7='querytypeCode'
|
|
|
|
|
_A6='01010049'
|
|
|
|
|
_A5='doorNumberManeger'
|
|
|
|
|
_A4='monthBillList'
|
|
|
|
|
_A3='accountBalance'
|
|
|
|
|
_A2='list'
|
|
|
|
|
_A1='userName'
|
|
|
|
|
_A0='acctId'
|
|
|
|
|
_z='resultCode'
|
|
|
|
|
_y='quInfo'
|
|
|
|
|
_x='BCP_000026'
|
|
|
|
|
_w='app'
|
|
|
|
|
_v='WEBALIPAY_01'
|
|
|
|
|
_u='order'
|
|
|
|
|
_t='state_grid'
|
|
|
|
|
_s=False
|
|
|
|
|
_r='authFlag'
|
|
|
|
|
_q='09'
|
|
|
|
|
_p='0101183'
|
|
|
|
|
_o='stepelect'
|
|
|
|
|
_n='account'
|
|
|
|
|
_m='consNo_dst'
|
|
|
|
|
_l='token'
|
|
|
|
|
_k='0101154'
|
|
|
|
|
_j='getday'
|
|
|
|
|
_i='consNo'
|
|
|
|
|
_h='bizrt'
|
|
|
|
|
_g='clearCache'
|
|
|
|
|
_f='timestamp'
|
|
|
|
|
_e='errmsg'
|
|
|
|
|
_Aw='get_door_ladder_api'
|
|
|
|
|
_Av='queryDate'
|
|
|
|
|
_Au='queryYear'
|
|
|
|
|
_At='access_token'
|
|
|
|
|
_As='businessType'
|
|
|
|
|
_Ar='qrCodeSerial'
|
|
|
|
|
_Aq='redirect_url'
|
|
|
|
|
_Ap='_access_token'
|
|
|
|
|
_Ao='dataVersion'
|
|
|
|
|
_An='refresh_interval'
|
|
|
|
|
_Am='doorAccountDict'
|
|
|
|
|
_Al='refreshToken'
|
|
|
|
|
_Ak='accessToken'
|
|
|
|
|
_Aj='/osg-web0004/member/c24/f01'
|
|
|
|
|
_Ai='BCP_00026'
|
|
|
|
|
_Ah='serviceCode_smt'
|
|
|
|
|
_Ag='WEBA10070900'
|
|
|
|
|
_Af='serviceType'
|
|
|
|
|
_Ae='jM_custType'
|
|
|
|
|
_Ad='jM_busiTypeCode'
|
|
|
|
|
_Ac='doorNumberManeger'
|
|
|
|
|
_Ab='month_t_ele_num'
|
|
|
|
|
_Aa='month_n_ele_num'
|
|
|
|
|
_AZ='month_v_ele_num'
|
|
|
|
|
_AY='month_p_ele_num'
|
|
|
|
|
_AX='month_ele_num'
|
|
|
|
|
_AW='constType'
|
|
|
|
|
_AV='provinceCode'
|
|
|
|
|
_AU='elecTypeCode'
|
|
|
|
|
_AT='powerUserList'
|
|
|
|
|
_AS='publicKey'
|
|
|
|
|
_AR='WEBA10070800'
|
|
|
|
|
_AQ='timeDay'
|
|
|
|
|
_AP='WEBA10070700'
|
|
|
|
|
_AO='channelNo'
|
|
|
|
|
_AN='month'
|
|
|
|
|
_AM='yearTotalCost'
|
|
|
|
|
_AL='consType'
|
|
|
|
|
_AK='provinceId'
|
|
|
|
|
_AJ='proCode'
|
|
|
|
|
_AI='userAccountId'
|
|
|
|
|
_AH='0000'
|
|
|
|
|
_AG='refresh_token'
|
|
|
|
|
_AF='skey'
|
|
|
|
|
_AE='userInfo'
|
|
|
|
|
_AD='0101046'
|
|
|
|
|
_AC='billYear'
|
|
|
|
|
_AB='loginAccount'
|
|
|
|
|
_AA='keyCode'
|
|
|
|
|
_A9='querytypeCode'
|
|
|
|
|
_A8='01010049'
|
|
|
|
|
_A7='account'
|
|
|
|
|
_A6='daily_bill_list'
|
|
|
|
|
_A5='userName'
|
|
|
|
|
_A4='acctId'
|
|
|
|
|
_A3='resultCode'
|
|
|
|
|
_A2='quInfo'
|
|
|
|
|
_A1='BCP_000026'
|
|
|
|
|
_A0='app'
|
|
|
|
|
_z='WEBALIPAY_01'
|
|
|
|
|
_y='order'
|
|
|
|
|
_x='state_grid'
|
|
|
|
|
_w='latestBillMonth'
|
|
|
|
|
_v='account_balance'
|
|
|
|
|
_u='list'
|
|
|
|
|
_t='authFlag'
|
|
|
|
|
_s='09'
|
|
|
|
|
_r='0101183'
|
|
|
|
|
_q='consNo'
|
|
|
|
|
_p='token'
|
|
|
|
|
_o=True
|
|
|
|
|
_n='0101154'
|
|
|
|
|
_m='getday'
|
|
|
|
|
_l='monthBillList'
|
|
|
|
|
_k='bizrt'
|
|
|
|
|
_j='timestamp'
|
|
|
|
|
_i=False
|
|
|
|
|
_h='month_ele'
|
|
|
|
|
_g='consNo_dst'
|
|
|
|
|
_f='errmsg'
|
|
|
|
|
_e='clearCache'
|
|
|
|
|
_d='promotCode'
|
|
|
|
|
_c='01'
|
|
|
|
|
_b='SGAPP'
|
|
|
|
@@ -76,7 +87,7 @@ _Z='devciceIp'
|
|
|
|
|
_Y='orgNo'
|
|
|
|
|
_X='tenant'
|
|
|
|
|
_W='member'
|
|
|
|
|
_V='daily_bill_list'
|
|
|
|
|
_V='stepelect'
|
|
|
|
|
_U='proNo'
|
|
|
|
|
_T='promotType'
|
|
|
|
|
_S='target'
|
|
|
|
@@ -88,23 +99,24 @@ _N='serialNo'
|
|
|
|
|
_M='0902'
|
|
|
|
|
_L='srvCode'
|
|
|
|
|
_K='uscInfo'
|
|
|
|
|
_J=None
|
|
|
|
|
_I='busiTypeCode'
|
|
|
|
|
_J='busiTypeCode'
|
|
|
|
|
_I='channelCode'
|
|
|
|
|
_H='code'
|
|
|
|
|
_G='channelCode'
|
|
|
|
|
_F='1'
|
|
|
|
|
_G='1'
|
|
|
|
|
_F=None
|
|
|
|
|
_E='source'
|
|
|
|
|
_D='funcCode'
|
|
|
|
|
_C='serviceCode'
|
|
|
|
|
_B='errcode'
|
|
|
|
|
_A='data'
|
|
|
|
|
import json,time,aiohttp,urllib.parse,datetime
|
|
|
|
|
from.const import VERSION
|
|
|
|
|
from.utils.logger import LOGGER
|
|
|
|
|
from.utils.store import async_save_to_store
|
|
|
|
|
from.utils.crypt import a,b,c,d,e
|
|
|
|
|
configuration={_K:{_W:_M,_Z:'',_a:'',_X:_x},_E:_b,_S:'32101',_I:_M,_AO:_M,'toPublish':_c,'siteId':'2012000000033700',_L:'',_N:'',_D:'',_C:{_y:_n,'uploadPic':'0101296','pauseSCode':'0101250','pauseTCode':'0101251','listconsumers':'0101093','messageList':'0101343','submit':'0101003','sbcMsg':'0101210','powercut':'0104514','BkAuth01':'f15','BkAuth02':'f18','BkAuth03':'f02','BkAuth04':'f17','BkAuth05':'f05','BkAuth06':'f16','BkAuth07':'f01','BkAuth08':'f03'},'electricityArchives':{'servicecode':'0104505',_E:_M},'subscriptionList':{_L:'APP_SGPMS_05_030',_N:'22',_I:_M,_D:'22',_S:'-1'},'userInformation':{_C:'01008183',_E:_b},'userInform':{_C:_r,_E:_b},'elesum':{_I:_M,_D:_z,_d:_G,_T:_G,_C:'0101143',_E:_A0},_A7:{_I:_M,_D:'WEBA1007200'},_Ac:{_E:_M,_S:'-1',_I:_s,_AO:_s,_C:_A8,_D:'WEBA40050000',_K:{_W:_M,_Z:'',_a:'',_X:_x}},'doorAuth':{_E:_b,_C:'f04'},'xinZ':{_O:'101',_Ad:'101','fJ_busiTypeCode':'102',_Ae:'03','fJ_custType':'02',_Af:_c,_P:'',_D:_AP,_y:_n,_E:_b,_A9:_G},'onedo':{_C:_AD,_E:_b,_D:_AP,'queryType':'03'},'xinHuTongDian':{_O:'110',_J:'211',_P:'21102',_D:'WEBA10071200',_I:_M,_E:_s,_C:_r},'company':{_O:'104',_D:_AP,_Af:'02',_A9:_G,_t:_G,_E:_b,_y:_n},'charge':{_I:_s,_D:'WEBA10071300',_AO:'0901',_O:'102',_Ae:_c,_Ad:'102'},'other':{_I:_s,_D:'WEBA10079700',_O:'129',_J:'999',_P:'21501',_C:_A1,_L:'',_N:''},'vatchange':{'submit':'0101003',_J:'320',_P:'',_O:'115',_D:'WEBA10074000',_t:_G},'bill':{_e:_G,_D:_z,_T:_G,_C:_A1},_V:{_I:_M,_D:_z,_T:_G,_e:_s,_C:_A1,_E:_A0},_m:{_I:_M,_e:'11',_D:_z,_d:_G,_T:_G,_C:_A1,_E:_A0},'mouthOut':{_I:_M,_e:'11',_D:_z,_d:_G,_T:_G,_C:_A1,_E:_A0},'meter':{_O:'114',_J:'304',_D:'WEBA10071000',_P:'',_C:_AD,_N:''},'complaint':{_J:'005','srvMode':_M,'anonymousFlag':'0','replyMode':_c,'retvisitFlag':_c},'report':{_J:'006'},'tradewinds':{_J:'019'},'somesay':{_J:'091'},'faultrepair':{_D:_Ag,_C:_r,_O:'111',_J:'001',_P:'21505'},'electronicInvoice':{_O:'105',_J:'0'},'rename':{_C:_AD,_D:'WEBA10076100',_J:'210',_O:'109',_t:_G,'gh_busiTypeCode':'211','gh_subusi':'21101',_N:'',_L:''},'pause':{_P:'',_C:_A8,_D:'WEBA10073600',_O:'107',_J:'203','jr_busi':'201',_N:'',_L:''},'capacityRecovery':{_C:_A8,_E:_b,_L:'',_N:'',_D:'WEBA10073700','busiTypeCode_stop':'204','busiTypeCode_less':'202',_J:'202',_P:'',_O:'108',_AQ:'5',_t:_G},'electricityPriceChange':{_C:_r,_J:'215',_P:'21502',_O:'113',_t:_G,_AQ:'15',_D:'WEBA10073900WEB',_L:'',_N:''},'electricityPriceStrategyChange':{_C:'01008183',_J:'215',_P:'21506',_O:'160',_D:'WEBV00000517WEB',_L:'',_N:''},'eemandValueAdjustment':{_C:_r,_L:'',_N:'',_O:'112',_D:'WEBA10073800',_J:'215',_P:'21504',_t:_G,_AQ:'5','getMonthServiceCode':_AD},'businessProgress':{_C:_r,_L:_c,_D:'WEB01'},'increase':{_E:_b,_N:'',_L:'',_Ah:_A8,_C:_n,_y:_n,_D:_AR,_A9:_G,_O:'106',_J:'111',_P:''},'fjincrea':{_O:'105',_J:'110',_P:'',_E:_b,_D:_AR,_N:'',_L:'',_Ah:_A8,_C:_n,_y:_n,_A9:_G},'persIncrea':{_O:'105',_J:'109',_y:_n,_P:'',_E:_b,_D:_AR,_A9:_G},'fgdChange':{_C:_r,_L:_c,_I:_s,_D:_Ag,_J:'215',_P:'21505',_O:'111',_t:_G},'createOrder':{_I:_M,_D:_z,_L:'BCP_000001','chargeMode':'02','conType':_c,'bizTypeId':'BT_ELEC'},'largePopulation':{_J:'383',_D:'WEBA10076800',_P:'',_L:'',_T:'',_d:'',_I:'0901',_O:'383',_C:'',_N:''},'biaoJiCode':{_C:'0104507',_E:'1704',_I:'1704'},'twoGuar':{_J:'402',_P:'40201',_D:'web_twoGuar'},'electTrend':{_C:_Ai,_I:_M},'emergency':{_C:_Ai,_D:'A10000000',_I:_M},'infoPublic':{_C:'2545454',_E:_A0}}
|
|
|
|
|
appKey='3def6c365d284881bf1a9b2b502ee68c'
|
|
|
|
|
appSecret='ab7357dae64944a197ace37398897f64'
|
|
|
|
|
configuration={_K:{_W:_M,_Z:'',_a:'',_X:_t},_E:_b,_S:'32101',_G:_M,_AJ:_M,'toPublish':_c,'siteId':'2012000000033700',_L:'',_N:'',_D:'',_C:{_u:_k,'uploadPic':'0101296','pauseSCode':'0101250','pauseTCode':'0101251','listconsumers':'0101093','messageList':'0101343','submit':'0101003','sbcMsg':'0101210','powercut':'0104514','BkAuth01':'f15','BkAuth02':'f18','BkAuth03':'f02','BkAuth04':'f17','BkAuth05':'f05','BkAuth06':'f16','BkAuth07':'f01','BkAuth08':'f03'},'electricityArchives':{'servicecode':'0104505',_E:_M},'subscriptionList':{_L:'APP_SGPMS_05_030',_N:'22',_G:_M,_D:'22',_S:'-1'},'userInformation':{_C:'01008183',_E:_b},'userInform':{_C:_p,_E:_b},'elesum':{_G:_M,_D:_v,_d:_F,_T:_F,_C:_AK,_E:_w},_n:{_G:_M,_D:'WEBA1007200'},_A5:{_E:_M,_S:'-1',_G:_q,_AJ:_q,_C:_A6,_D:'WEBA40050000',_K:{_W:_M,_Z:'',_a:'',_X:_t}},'doorAuth':{_E:_b,_C:'f04'},'xinZ':{_O:'101',_AS:'101','fJ_busiTypeCode':'102',_AT:'03','fJ_custType':'02',_AU:_c,_P:'',_D:_AL,_u:_k,_E:_b,_A7:_F},'onedo':{_C:_AB,_E:_b,_D:_AL,'queryType':'03'},'xinHuTongDian':{_O:'110',_I:'211',_P:'21102',_D:'WEBA10071200',_G:_M,_E:_q,_C:_p},'company':{_O:'104',_D:_AL,_AU:'02',_A7:_F,_r:_F,_E:_b,_u:_k},'charge':{_G:_q,_D:'WEBA10071300',_AJ:'0901',_O:'102',_AT:_c,_AS:'102'},'other':{_G:_q,_D:'WEBA10079700',_O:'129',_I:'999',_P:'21501',_C:_x,_L:'',_N:''},'vatchange':{'submit':'0101003',_I:'320',_P:'',_O:'115',_D:'WEBA10074000',_r:_F},'bill':{_g:_F,_D:_v,_T:_F,_C:_x},_o:{_G:_M,_D:_v,_T:_F,_g:_q,_C:_x,_E:_w},_j:{_G:_M,_g:'11',_D:_v,_d:_F,_T:_F,_C:_x,_E:_w},'mouthOut':{_G:_M,_g:'11',_D:_v,_d:_F,_T:_F,_C:_x,_E:_w},'meter':{_O:'114',_I:'304',_D:'WEBA10071000',_P:'',_C:_AB,_N:''},'complaint':{_I:'005','srvMode':_M,'anonymousFlag':'0','replyMode':_c,'retvisitFlag':_c},'report':{_I:'006'},'tradewinds':{_I:'019'},'somesay':{_I:'091'},'faultrepair':{_D:_AV,_C:_p,_O:'111',_I:'001',_P:'21505'},'electronicInvoice':{_O:'105',_I:'0'},'rename':{_C:_AB,_D:'WEBA10076100',_I:'210',_O:'109',_r:_F,'gh_busiTypeCode':'211','gh_subusi':'21101',_N:'',_L:''},'pause':{_P:'',_C:_A6,_D:'WEBA10073600',_O:'107',_I:'203','jr_busi':'201',_N:'',_L:''},'capacityRecovery':{_C:_A6,_E:_b,_L:'',_N:'',_D:'WEBA10073700','busiTypeCode_stop':'204','busiTypeCode_less':'202',_I:'202',_P:'',_O:'108',_AM:'5',_r:_F},'electricityPriceChange':{_C:_p,_I:'215',_P:'21502',_O:'113',_r:_F,_AM:'15',_D:'WEBA10073900WEB',_L:'',_N:''},'electricityPriceStrategyChange':{_C:'01008183',_I:'215',_P:'21506',_O:'160',_D:'WEBV00000517WEB',_L:'',_N:''},'eemandValueAdjustment':{_C:_p,_L:'',_N:'',_O:'112',_D:'WEBA10073800',_I:'215',_P:'21504',_r:_F,_AM:'5','getMonthServiceCode':_AB},'businessProgress':{_C:_p,_L:_c,_D:'WEB01'},'increase':{_E:_b,_N:'',_L:'',_AW:_A6,_C:_k,_u:_k,_D:_AN,_A7:_F,_O:'106',_I:'111',_P:''},'fjincrea':{_O:'105',_I:'110',_P:'',_E:_b,_D:_AN,_N:'',_L:'',_AW:_A6,_C:_k,_u:_k,_A7:_F},'persIncrea':{_O:'105',_I:'109',_u:_k,_P:'',_E:_b,_D:_AN,_A7:_F},'fgdChange':{_C:_p,_L:_c,_G:_q,_D:_AV,_I:'215',_P:'21505',_O:'111',_r:_F},'createOrder':{_G:_M,_D:_v,_L:'BCP_000001','chargeMode':'02','conType':_c,'bizTypeId':'BT_ELEC'},'largePopulation':{_I:'383',_D:'WEBA10076800',_P:'',_L:'',_T:'',_d:'',_G:'0901',_O:'383',_C:'',_N:''},'biaoJiCode':{_C:'0104507',_E:'1704',_G:'1704'},'twoGuar':{_I:'402',_P:'40201',_D:'web_twoGuar'},'electTrend':{_C:_AX,_G:_M},'emergency':{_C:_AX,_D:'A10000000',_G:_M},'infoPublic':{_C:'2545454',_E:_w}}
|
|
|
|
|
baseApi='https://www.95598.cn/api'
|
|
|
|
|
get_request_key_api='/oauth2/outer/c02/f02'
|
|
|
|
|
get_qr_code_api='/osg-open-uc0001/member/c8/f24'
|
|
|
|
@@ -120,51 +132,63 @@ get_door_number_api='/osg-open-uc0001/member/c9/f02'
|
|
|
|
|
get_door_balance_api='/osg-open-bc0001/member/c05/f01'
|
|
|
|
|
get_door_bill_api='/osg-open-bc0001/member/c01/f02'
|
|
|
|
|
get_door_ladder_api='/osg-open-bc0001/member/c04/f03'
|
|
|
|
|
getJiaoFeiRecordApi=_AY
|
|
|
|
|
get_door_daily_bill_api=_AY
|
|
|
|
|
getJiaoFeiRecordApi=_Aj
|
|
|
|
|
get_door_daily_bill_api=_Aj
|
|
|
|
|
sessionIdControlApiList=[get_qr_code_api,get_qr_code_status_api,get_qr_code_token_api,send_code_api,code_login_api]
|
|
|
|
|
keyCodeControlApiList=[get_qr_code_status_api,get_qr_code_token_api,send_code_api,code_login_api,getCertificationApi,get_request_authorize_api,get_web_token_api,refresh_web_token_api,get_door_number_api,get_door_balance_api,get_door_bill_api,get_door_ladder_api,getJiaoFeiRecordApi,get_door_daily_bill_api]
|
|
|
|
|
authControlApiList=[get_door_number_api,get_door_balance_api,get_door_bill_api,get_door_ladder_api,getJiaoFeiRecordApi,get_door_daily_bill_api]
|
|
|
|
|
tControlApiList=[getCertificationApi,get_door_balance_api,get_door_bill_api,get_door_ladder_api,getJiaoFeiRecordApi,get_door_daily_bill_api]
|
|
|
|
|
def json_dumps(data):return json.dumps(data,separators=(',',':'),ensure_ascii=_s)
|
|
|
|
|
def json_dumps(data):return json.dumps(data,separators=(',',':'),ensure_ascii=_i)
|
|
|
|
|
def normal_round(num,ndigits=0):
|
|
|
|
|
A=ndigits
|
|
|
|
|
if A==0:return int(num+.5)
|
|
|
|
|
else:B=10**A;return int(num*B+.5)/B
|
|
|
|
|
def catchFloat(data,key):
|
|
|
|
|
if key in data:
|
|
|
|
|
try:return float(data[key])
|
|
|
|
|
try:return normal_round(float(data[key]),2)
|
|
|
|
|
except:return 0
|
|
|
|
|
else:return 0
|
|
|
|
|
class StateGridDataClient:
|
|
|
|
|
hass=_J;session=_J;keyCode=_J;publicKey=_J;need_login=_s;phone=_J;codeKey=_J;serialNo=_J;qrCodeSerial=_J;userInfo=_J;accountInfo=_J;powerUserList=_J;doorAccountDict={};cookie=[];timestamp=int(time.time()*1000);accessToken=_J;refreshToken=_J;token=_J;expirationDate=_J;refresh_interval=12;is_debug=_s
|
|
|
|
|
def __init__(A,hass,config=_J):
|
|
|
|
|
B=config;A.hass=hass;C=aiohttp.TCPConnector(ssl=_s);D=aiohttp.CookieJar(quote_cookie=True);A.session=aiohttp.ClientSession(cookie_jar=D,connector=C)
|
|
|
|
|
if B is not _J:
|
|
|
|
|
try:A.keyCode=B[_A8];A.publicKey=B[_AO];A.accessToken=B[_AZ];A.refreshToken=B[_Aa];A.token=B[_l];A.userInfo=B[_AC];A.powerUserList=B[_AP];A.doorAccountDict=B[_Ab];A.refresh_interval=B[_Ac];A.is_debug=B['is_debug']
|
|
|
|
|
hass=_F;coordinator=_F;session=_F;dataVersion=_F;keyCode=_F;publicKey=_F;need_login=_i;retry_times=0;phone=_F;codeKey=_F;serialNo=_F;qrCodeSerial=_F;userInfo=_F;accountInfo=_F;powerUserList=_F;doorAccountDict={};cookie=[];timestamp=int(time.time()*1000);accessToken=_F;refreshToken=_F;token=_F;expirationDate=_F;refresh_interval=6;is_debug=_i
|
|
|
|
|
def __init__(A,hass,config=_F):
|
|
|
|
|
B=config;A.hass=hass;C=aiohttp.TCPConnector(ssl=_i);D=aiohttp.CookieJar(quote_cookie=_o);A.session=aiohttp.ClientSession(cookie_jar=D,connector=C)
|
|
|
|
|
if B is not _F:
|
|
|
|
|
try:A.keyCode=B[_AA];A.publicKey=B[_AS];A.accessToken=B[_Ak];A.refreshToken=B[_Al];A.token=B[_p];A.userInfo=B[_AE];A.powerUserList=B[_AT];A.doorAccountDict=B[_Am];A.refresh_interval=B[_An];A.is_debug=B['is_debug'];A.dataVersion=B[_Ao]
|
|
|
|
|
except Exception as E:LOGGER.error(E)
|
|
|
|
|
async def save_data(A):B={};B[_A8]=A.keyCode;B[_AO]=A.publicKey;B[_AZ]=A.accessToken;B[_Aa]=A.refreshToken;B[_l]=A.token;B[_AC]=A.userInfo;B[_AP]=A.powerUserList;B[_Ab]=A.doorAccountDict;B[_Ac]=A.refresh_interval;B['is_debug']=A.is_debug;await async_save_to_store(A.hass,'state_grid.config',B)
|
|
|
|
|
def encrypt_post_data(A,data):B={_Ad:A.accessToken[len(A.accessToken)//2:]if A.accessToken else'','_t':A.token[len(A.token)//2:]if A.token else'','_data':data,_f:A.timestamp};return A.encrypt_wapper_data(B)
|
|
|
|
|
def encrypt_wapper_data(A,data):B=a(json_dumps(data),A.keyCode);return{_A:B+c(B+str(A.timestamp)),_AD:d(A.keyCode,A.publicKey),_f:str(A.timestamp)}
|
|
|
|
|
async def save_data(B):A={};A[_AA]=B.keyCode;A[_AS]=B.publicKey;A[_Ak]=B.accessToken;A[_Al]=B.refreshToken;A[_p]=B.token;A[_AE]=B.userInfo;A[_AT]=B.powerUserList;A[_Am]=B.doorAccountDict;A[_An]=B.refresh_interval;A['is_debug']=B.is_debug;A[_Ao]=VERSION;await async_save_to_store(B.hass,'state_grid.config',A)
|
|
|
|
|
def encrypt_post_data(A,data):B={_Ap:A.accessToken[len(A.accessToken)//2:]if A.accessToken else'','_t':A.token[len(A.token)//2:]if A.token else'','_data':data,_j:A.timestamp};return A.encrypt_wapper_data(B)
|
|
|
|
|
def encrypt_wapper_data(A,data):B=a(json_dumps(data),A.keyCode);return{_A:B+c(B+str(A.timestamp)),_AF:d(A.keyCode,A.publicKey),_j:str(A.timestamp)}
|
|
|
|
|
def handle_request_result_message(E,api,result):
|
|
|
|
|
D='message';C='resultMessage';A=result;B=_J
|
|
|
|
|
D='message';C='resultMessage';A=result;LOGGER.error(api+'-'+json_dumps(A));B=_F
|
|
|
|
|
if _A in A and _Q in A[_A]and C in A[_A][_Q]:B=A[_A][_Q][C]
|
|
|
|
|
elif _Q in A and C in A[_Q]:B=A[_Q][C]
|
|
|
|
|
elif D in A:B=A[D]
|
|
|
|
|
else:B=json_dumps(A)
|
|
|
|
|
if E.is_debug:LOGGER.error(api+': '+B);LOGGER.error(json_dumps(A))
|
|
|
|
|
return B
|
|
|
|
|
async def fetch(B,api,data,header=_J):
|
|
|
|
|
async def __fetch_safe(C,api,data):
|
|
|
|
|
B=await C.__fetch(api,data)
|
|
|
|
|
if _H not in B:return B
|
|
|
|
|
A=B[_H]
|
|
|
|
|
if 10015==A or 10108==A or 10009==A or 10207==A or 10005==A or 10010==A or 30010==A or 10002==A:
|
|
|
|
|
await C.__refresh_token()
|
|
|
|
|
if C.need_login is _o:return B
|
|
|
|
|
else:return await C.__fetch(api,data)
|
|
|
|
|
else:return B
|
|
|
|
|
async def __fetch(B,api,data,header=_F):
|
|
|
|
|
T='encryptData';S='464606a4-184c-4beb-b442-2ab7761d0796';R='key_code';Q='state';P='sign';O='grant_type';N='application/json;charset=UTF-8';M='Content-Type';L=header;K='client_secret';I='client_id';E=api;B.timestamp=int(time.time()*1000);D=B.timestamp
|
|
|
|
|
if B.keyCode is _J:B.keyCode=e(32,16,2)
|
|
|
|
|
F=B.keyCode;G={'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Mobile Safari/537.36','Accept':N,M:N,'version':'1.0',_E:'0901',_f:str(D),'wsgwType':'web','appKey':appKey};A=data
|
|
|
|
|
if E==get_request_key_api:A={I:appKey,K:appSecret};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AD:d(F,'042BC7AD510BF9793B7744C8854C56A8C95DD1027EE619247A332EC6ED5B279F435A23D62441FE861F4B0C963347ECD5792F380B64CA084BE8BE41151F8B8D19C8'),I:appKey,_f:str(D)}
|
|
|
|
|
elif E==get_qr_code_api:A={_Ad:'','_t':'','_data':A,_f:D}
|
|
|
|
|
if B.keyCode is _F:B.keyCode=e(32,16,2)
|
|
|
|
|
F=B.keyCode;G={'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Mobile Safari/537.36','Accept':N,M:N,'version':'1.0',_E:'0901',_j:str(D),'wsgwType':'web','appKey':appKey};A=data
|
|
|
|
|
if E==get_request_key_api:A={I:appKey,K:appSecret};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AF:d(F,'042BC7AD510BF9793B7744C8854C56A8C95DD1027EE619247A332EC6ED5B279F435A23D62441FE861F4B0C963347ECD5792F380B64CA084BE8BE41151F8B8D19C8'),I:appKey,_j:str(D)}
|
|
|
|
|
elif E==get_qr_code_api:A={_Ap:'','_t':'','_data':A,_j:D}
|
|
|
|
|
elif E==get_request_authorize_api:
|
|
|
|
|
A={I:appKey,'response_type':_H,_Ae:'/test',_f:D,'rsi':B.token};A=urllib.parse.urlencode(A);G[M]='application/x-www-form-urlencoded; charset=UTF-8';G[_A8]=F
|
|
|
|
|
A={I:appKey,'response_type':_H,_Aq:'/test',_j:D,'rsi':B.token};A=urllib.parse.urlencode(A);G[M]='application/x-www-form-urlencoded; charset=UTF-8';G[_AA]=F
|
|
|
|
|
async with B.session.post(baseApi+E,data=A,headers=G)as J:B.session.cookie_jar.update_cookies(J.cookies);C=await J.json();C=b(C[_A],B.token);C=json.loads(C);return C
|
|
|
|
|
elif E==get_web_token_api:A={O:'authorization_code',P:c(appKey+str(D)),K:appSecret,Q:S,R:F,I:appKey,_f:D,_H:A[_H]};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AD:d(F,B.publicKey),_f:str(D)}
|
|
|
|
|
elif E==refresh_web_token_api:A={O:_AE,P:c(appKey+str(D)),K:appSecret,Q:S,R:F,I:appKey,_f:D,_AE:B.refreshToken};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AD:d(F,B.publicKey),_f:str(D)};E=get_web_token_api
|
|
|
|
|
elif E==get_web_token_api:A={O:'authorization_code',P:c(appKey+str(D)),K:appSecret,Q:S,R:F,I:appKey,_j:D,_H:A[_H]};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AF:d(F,B.publicKey),_j:str(D)}
|
|
|
|
|
elif E==refresh_web_token_api:A={O:_AG,P:c(appKey+str(D)),K:appSecret,Q:S,R:F,I:appKey,_j:D,_AG:B.refreshToken};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AF:d(F,B.publicKey),_j:str(D)};E=get_web_token_api
|
|
|
|
|
else:A=B.encrypt_post_data(A)
|
|
|
|
|
if L is not _J:G.update(L)
|
|
|
|
|
if L is not _F:G.update(L)
|
|
|
|
|
if E in sessionIdControlApiList:G['sessionId']='web'+str(D)
|
|
|
|
|
if E in keyCodeControlApiList:G[_A8]=F
|
|
|
|
|
if E in keyCodeControlApiList:G[_AA]=F
|
|
|
|
|
if E in authControlApiList:G['Authorization']='Bearer '+B.accessToken[:len(B.accessToken)//2]
|
|
|
|
|
if E in tControlApiList:G['t']=B.token[:len(B.token)//2]
|
|
|
|
|
async with B.session.post(baseApi+E,json=A,headers=G)as J:
|
|
|
|
@@ -174,72 +198,101 @@ class StateGridDataClient:
|
|
|
|
|
if T in C:C=b(C[T],F);C=json.loads(C)
|
|
|
|
|
return C
|
|
|
|
|
async def __get_request_key(A):
|
|
|
|
|
A.keyCode=_J;B=await A.fetch(get_request_key_api,{});C=A.handle_request_result_message('get_request_key_api',B)
|
|
|
|
|
if B[_H]==_F:A.keyCode=B[_A][_A8];A.publicKey=B[_A][_AO];return{_B:0}
|
|
|
|
|
return{_B:1,_e:C}
|
|
|
|
|
A.keyCode=_F;B=await A.__fetch(get_request_key_api,{});C=A.handle_request_result_message('get_request_key_api',B)
|
|
|
|
|
if B[_H]==_G:A.keyCode=B[_A][_AA];A.publicKey=B[_A][_AS];return{_B:0}
|
|
|
|
|
return{_B:1,_f:C}
|
|
|
|
|
async def __get_qr_code(B):
|
|
|
|
|
C={_K:{_Z:'',_X:_t,_W:_M,_a:''},_y:{'optType':_c,_N:e(28,10,1)}};A=await B.fetch(get_qr_code_api,C);D=B.handle_request_result_message('get_qr_code_api',A)
|
|
|
|
|
C={_K:{_Z:'',_X:_x,_W:_M,_a:''},_A2:{'optType':_c,_N:e(28,10,1)}};A=await B.__fetch(get_qr_code_api,C);D=B.handle_request_result_message('get_qr_code_api',A)
|
|
|
|
|
if A[_H]==1:
|
|
|
|
|
if A[_A]and A[_A][_Q]and A[_A][_Q][_z]==_AF:B.qrCodeSerial=A[_A][_h][_Af];E=A[_A][_h]['qrCode'];return{_B:0,_A:E}
|
|
|
|
|
return{_B:1,_e:D}
|
|
|
|
|
if A[_A]and A[_A][_Q]and A[_A][_Q][_A3]==_AH:B.qrCodeSerial=A[_A][_k][_Ar];E=A[_A][_k]['qrCode'];return{_B:0,_A:E}
|
|
|
|
|
return{_B:1,_f:D}
|
|
|
|
|
async def __get_qr_code_status(B):
|
|
|
|
|
C={_h:{_Af:B.qrCodeSerial}};D={_l:'98'+e(10,10,1)};A=await B.fetch(get_qr_code_status_api,C,D);E=B.handle_request_result_message('get_qr_code_status_api',A)
|
|
|
|
|
C={_k:{_Ar:B.qrCodeSerial}};D={_p:'98'+e(10,10,1)};A=await B.__fetch(get_qr_code_status_api,C,D);E=B.handle_request_result_message('get_qr_code_status_api',A)
|
|
|
|
|
if _H in A and A[_H]==1:
|
|
|
|
|
if _A in A and A[_A]!='null':B.token=A[_A];return{_B:0}
|
|
|
|
|
else:return{_B:1,_e:'未使用网上国网 App 扫码或确认登录'}
|
|
|
|
|
return{_B:1,_e:E}
|
|
|
|
|
else:return{_B:1,_f:'未使用网上国网 App 扫码或确认登录'}
|
|
|
|
|
return{_B:1,_f:E}
|
|
|
|
|
async def __get_qr_code_token(B):
|
|
|
|
|
C={_K:{_X:_t,_W:_M,'isEncrypt':True},_l:B.token};A=await B.fetch(get_qr_code_token_api,C);D=B.handle_request_result_message('get_qr_code_token_api',A)
|
|
|
|
|
if _Q in A and _z in A[_Q]and A[_Q][_z]==_AF:B.userInfo=A[_h][_AC];return{_B:0}
|
|
|
|
|
return{_B:1,_e:D}
|
|
|
|
|
C={_K:{_X:_x,_W:_M,'isEncrypt':_o},_p:B.token};A=await B.__fetch(get_qr_code_token_api,C);D=B.handle_request_result_message('get_qr_code_token_api',A)
|
|
|
|
|
if _Q in A and _A3 in A[_Q]and A[_Q][_A3]==_AH:B.userInfo=A[_k][_AE];return{_B:0}
|
|
|
|
|
return{_B:1,_f:D}
|
|
|
|
|
async def __send_code(B,phone):
|
|
|
|
|
C=phone;B.phone=C;D={_K:{_Z:'',_X:_t,_W:_M,_a:''},_y:{'sendType':'0',_n:C,_Ag:'login','accountType':''},'Channels':'web'};A=await B.fetch(send_code_api,D);E=B.handle_request_result_message('send_code_api',A)
|
|
|
|
|
C=phone;B.phone=C;D={_K:{_Z:'',_X:_x,_W:_M,_a:''},_A2:{'sendType':'0',_A7:C,_As:'login','accountType':''},'Channels':'web'};A=await B.__fetch(send_code_api,D);E=B.handle_request_result_message('send_code_api',A)
|
|
|
|
|
if A[_H]==1:
|
|
|
|
|
if A[_A]and A[_A][_Q]and A[_A][_Q][_z]==_AF:B.codeKey=A[_A][_h]['codeKey'];return{_B:0}
|
|
|
|
|
return{_B:1,_e:E}
|
|
|
|
|
if A[_A]and A[_A][_Q]and A[_A][_Q][_A3]==_AH:B.codeKey=A[_A][_k]['codeKey'];return{_B:0}
|
|
|
|
|
return{_B:1,_f:E}
|
|
|
|
|
async def __verfiy_code(A,code):
|
|
|
|
|
C={_K:{_Z:'',_X:_t,_W:_M,_a:''},_y:{_n:A.phone,_Ag:'login',_H:code,'optSys':'ios','pushId':'00000','codeKey':A.codeKey},'Channels':'web'};B=await A.fetch(code_login_api,C);D=A.handle_request_result_message('code_login_api',B)
|
|
|
|
|
if _Q in B and _z in B[_Q]and B[_Q][_z]==_AF:A.token=B[_h][_l];A.userInfo=B[_h][_AC][0];return{_B:0}
|
|
|
|
|
return{_B:1,_e:D}
|
|
|
|
|
C={_K:{_Z:'',_X:_x,_W:_M,_a:''},_A2:{_A7:A.phone,_As:'login',_H:code,'optSys':'ios','pushId':'00000','codeKey':A.codeKey},'Channels':'web'};B=await A.__fetch(code_login_api,C);D=A.handle_request_result_message('code_login_api',B)
|
|
|
|
|
if _Q in B and _A3 in B[_Q]and B[_Q][_A3]==_AH:A.token=B[_k][_p];A.userInfo=B[_k][_AE][0];return{_B:0}
|
|
|
|
|
return{_B:1,_f:D}
|
|
|
|
|
async def __get_request_authorize(B):
|
|
|
|
|
A=await B.fetch(get_request_authorize_api,{});E=B.handle_request_result_message('get_request_authorize_api',A)
|
|
|
|
|
if _H in A and A[_H]==_F:C=A[_A][_Ae];D=C.rfind('code=');B.authorizeCode=C[D+5:D+5+32];return{_B:0}
|
|
|
|
|
return{_B:1,_e:E}
|
|
|
|
|
A=await B.__fetch(get_request_authorize_api,{});E=B.handle_request_result_message('get_request_authorize_api',A)
|
|
|
|
|
if _H in A and A[_H]==_G:C=A[_A][_Aq];D=C.rfind('code=');B.authorizeCode=C[D+5:D+5+32];return{_B:0}
|
|
|
|
|
return{_B:1,_f:E}
|
|
|
|
|
async def __get_web_token(A):
|
|
|
|
|
C={_H:A.authorizeCode};B=await A.fetch(get_web_token_api,C);D=A.handle_request_result_message('get_web_token_api',B)
|
|
|
|
|
if _H in B and B[_H]==_F:A.accessToken=B[_A][_Ah];A.refreshToken=B[_A][_AE];return{_B:0}
|
|
|
|
|
return{_B:1,_e:D}
|
|
|
|
|
C={_H:A.authorizeCode};B=await A.__fetch(get_web_token_api,C);D=A.handle_request_result_message('get_web_token_api',B)
|
|
|
|
|
if _H in B and B[_H]==_G:A.accessToken=B[_A][_At];A.refreshToken=B[_A][_AG];return{_B:0}
|
|
|
|
|
return{_B:1,_f:D}
|
|
|
|
|
async def __refresh_web_token(B):
|
|
|
|
|
A=await B.fetch(refresh_web_token_api,{});C=B.handle_request_result_message('refresh_web_token_api',A)
|
|
|
|
|
if _H in A and A[_H]==_F:B.accessToken=A[_A][_Ah];B.refreshToken=A[_A][_AE];return{_B:0}
|
|
|
|
|
return{_B:1,_e:C}
|
|
|
|
|
async def __get_door_number(B):
|
|
|
|
|
C={_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_A5][_K][_W],_Z:configuration[_A5][_K][_Z],_a:configuration[_A5][_K][_a],_X:configuration[_A5][_K][_X]},_y:{_R:B.userInfo[_R]},_l:B.token};A=await B.fetch(get_door_number_api,C);D=B.handle_request_result_message('get_door_number_api',A)
|
|
|
|
|
if _H in A and A[_H]==1 and _A in A and _h in A[_A]:B.powerUserList=A[_A][_h][_AP];return{_B:0}
|
|
|
|
|
return{_B:1,_e:D}
|
|
|
|
|
async def __get_door_balance(C,door_account):
|
|
|
|
|
A=door_account;E={_A:{_L:'',_N:'',_G:configuration[_n][_G],_D:configuration[_n][_D],_A0:C.userInfo[_R],_A1:C.userInfo[_A9],_T:_F,_d:_F,_AG:C.userInfo[_R],_A2:[{_Ai:A[_m],_AA:A[_U],_Aj:A[_AQ],_i:A[_i],_Y:A[_Y]}]},_C:_AK,_E:configuration[_E],_S:A[_U]};B=await C.fetch(get_door_balance_api,E);C.handle_request_result_message('get_door_balance_api',B)
|
|
|
|
|
if _H in B and B[_H]==1 and _A in B and _A2 in B[_A]:
|
|
|
|
|
D=B[_A][_A2]
|
|
|
|
|
if len(D)!=0:A[_A3]=D[0]
|
|
|
|
|
async def __get_door_bill(C,door_account,year):
|
|
|
|
|
F='dataInfo';D='mothEleList';A=door_account;E={_A:{_L:'',_N:'',_G:configuration[_n][_G],_D:configuration[_n][_D],_A0:C.userInfo[_R],_A1:C.userInfo[_A9],_T:_F,_d:_F,_AG:C.userInfo[_R],_A2:[{_Ai:A[_m],_AA:A[_U],_Aj:A['consSortCode'],_i:A[_i],_Y:A[_Y]}]},_C:_AK,_E:configuration[_E],_S:A[_U]};E={_A:{_A0:C.userInfo[_R],_G:configuration[_G],_g:'11',_AR:A[_AQ],_D:'ALIPAY_01',_Y:A[_Y],_AA:A[_U],_d:_F,_T:_F,_N:'',_L:'',_A1:'',_Ak:A[_U],_AG:C.userInfo[_R],_i:A[_i],_Al:year},_C:_x,_E:_w,_S:A[_U]};B=await C.fetch(get_door_bill_api,E);C.handle_request_result_message('get_door_bill_api',B)
|
|
|
|
|
A=await B.__fetch(refresh_web_token_api,{});C=B.handle_request_result_message('refresh_web_token_api',A)
|
|
|
|
|
if _H in A and A[_H]==_G:B.accessToken=A[_A][_At];B.refreshToken=A[_A][_AG];return{_B:0}
|
|
|
|
|
return{_B:1,_f:C}
|
|
|
|
|
async def __get_door_number(A):
|
|
|
|
|
B=configuration[_Ac];G={_C:B[_C],_E:B[_E],_S:B[_S],_K:{_W:B[_K][_W],_Z:B[_K][_Z],_a:B[_K][_a],_X:B[_K][_X]},_A2:{_R:A.userInfo[_R]},_p:A.token};C=await A.__fetch_safe(get_door_number_api,G);H=A.handle_request_result_message('get_door_number_api',C)
|
|
|
|
|
if _H in C and C[_H]==1 and _A in C and _k in C[_A]:
|
|
|
|
|
E={}
|
|
|
|
|
if A.powerUserList is not _F:E={A[_g]:A for A in A.powerUserList}
|
|
|
|
|
F=[]
|
|
|
|
|
for D in C[_A][_k][_AT]:
|
|
|
|
|
if D[_g]in E:F.append(E[D[_g]])
|
|
|
|
|
elif _AU in D and D[_AU]!='05':F.append(D)
|
|
|
|
|
A.powerUserList=F;return{_B:0}
|
|
|
|
|
return{_B:1,_f:H}
|
|
|
|
|
async def __get_door_balance(B,door_account):
|
|
|
|
|
A=door_account;E={_A:{_L:'',_N:'',_I:configuration[_A7][_I],_D:configuration[_A7][_D],_A4:B.userInfo[_R],_A5:B.userInfo.get(_AB,B.userInfo.get('nickname',_F)),_T:_G,_d:_G,_AI:B.userInfo[_R],_u:[{'consNoSrc':A[_g],_AJ:A.get(_U,A.get(_AK,_F)),'sceneType':A.get('consSortCode',A.get(_AU,_F)),_q:A[_q],_Y:A[_Y]}]},_C:'0101143',_E:configuration[_E],_S:A.get(_U,A.get(_AK,_F))};C=await B.__fetch_safe(get_door_balance_api,E);B.handle_request_result_message('get_door_balance_api',C)
|
|
|
|
|
if _H in C and C[_H]==1 and _A in C and _u in C[_A]:
|
|
|
|
|
D=C[_A][_u]
|
|
|
|
|
if len(D)!=0:A[_v]=D[0]
|
|
|
|
|
async def __get_door_bill(C,door_account,monthDate):
|
|
|
|
|
I='dataInfo';G='mothEleList';E=monthDate;A=door_account;J={_A:{_A4:C.userInfo[_R],_I:configuration[_I],_e:'11',_AL:A[_AW],_D:'ALIPAY_01',_Y:A[_Y],_AJ:A[_U],_d:_G,_T:_G,_N:'',_L:'',_A5:'',_AV:A[_U],_AI:C.userInfo[_R],_q:A[_q],_Au:E.year},_C:_A1,_E:_A0,_S:A[_U]};B=await C.__fetch_safe(get_door_bill_api,J);C.handle_request_result_message('get_door_bill_api',B)
|
|
|
|
|
if _H in B and B[_H]==1 and _A in B:
|
|
|
|
|
if F in B[_A]:A[_AH]=B[_A][F]
|
|
|
|
|
if D in B[_A]:A[_A4]=B[_A][D];A[_AI]=B[_A][D][-1]['month']
|
|
|
|
|
async def __get_door_ladder(B,door_account,month):
|
|
|
|
|
F='ladder_flag';E=month;A=door_account;G=A[_m];H={_A:{_G:configuration[_o][_G],_D:configuration[_o][_D],_T:configuration[_o][_T],_g:configuration[_o][_g],_i:A[_m],_d:A[_U],_Y:A[_Y],'queryDate':E,_Ak:A[_U],_AR:A[_AQ],_AG:B.userInfo[_R],_N:'',_L:'',_A1:B.userInfo[_A9],_A0:B.userInfo[_R]},_C:configuration[_o][_C],_E:configuration[_o][_E],_S:A[_U]};C=await B.fetch(get_door_ladder_api,H);I=B.handle_request_result_message('get_door_ladder_api',C)
|
|
|
|
|
if _H in C and C[_H]==1 and _A in C and _A2 in C[_A]:
|
|
|
|
|
D=C[_A][_A2]
|
|
|
|
|
if len(D)!=0:
|
|
|
|
|
D=D[0];D['month']=E
|
|
|
|
|
if D['electricParticulars']['levelFlag']=='2':A[F]=1
|
|
|
|
|
else:A[F]=0
|
|
|
|
|
B.doorAccountDict[G]['ladder']=D
|
|
|
|
|
async def __get_door_daily_bill(A,door_account,year,start_date,end_date):
|
|
|
|
|
D='sevenEleList';C=door_account;E={'params1':{_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_K][_W],_Z:configuration[_K][_Z],_a:configuration[_K][_a],_X:configuration[_K][_X]},_y:{_R:A.userInfo[_R]},_l:A.token},'params3':{_A:{_A0:A.userInfo[_R],_i:C[_m],_AR:_c,'endTime':end_date,_Y:C[_Y],_Al:year,_AA:C[_U],_N:'',_L:'','startTime':start_date,_A1:A.userInfo[_A9],_D:configuration[_j][_D],_G:configuration[_j][_G],_g:configuration[_j][_g],_d:configuration[_j][_d],_T:configuration[_j][_T]},_C:configuration[_j][_C],_E:configuration[_j][_E],_S:C[_U]},'params4':'010103'};B=await A.fetch(get_door_daily_bill_api,E);F=A.handle_request_result_message('get_door_daily_bill_api',B)
|
|
|
|
|
if _H in B and B[_H]==1 and _A in B and D in B[_A]:C[_V]=B[_A][D]
|
|
|
|
|
async def __get_door_pay_record(A,door_account):B=door_account;D=B[_m];C={'params1':{_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_K][_W],_Z:configuration[_K][_Z],_a:configuration[_K][_a],_X:configuration[_K][_X]},_y:{_R:A.userInfo[_R]},_l:A.token},'params3':{_A:{_A0:A.userInfo[_R],'bgnPayDate':'2023-04-24',_G:configuration[_G],_i:B[_m],'endPayDate':'2024-04-24',_D:'webALIPAY_01','number':100,_Y:B[_Y],'page':_F,_AA:B[_U],_d:_F,_T:_F,_N:'',_L:'',_A1:A.userInfo[_A9]},_C:'0101051',_E:_c,_S:B[_U]},'params4':'010104'};E=await A.fetch(getJiaoFeiRecordApi,C)
|
|
|
|
|
if I in B[_A]:A[_AM]=B[_A][I]
|
|
|
|
|
if G in B[_A]:
|
|
|
|
|
if _AC not in A or A[_AC]!=E.year:A[_l]=B[_A][G];A[_AC]=E.year
|
|
|
|
|
else:
|
|
|
|
|
F={A.month:A for A in A[_l]};H=B[_A][G]
|
|
|
|
|
for D in H:
|
|
|
|
|
if D.month in F and _h in F[D.month]:D[_h]=F[D.month][_h]
|
|
|
|
|
A[_l]=H
|
|
|
|
|
if len(A[_l])>0:A[_w]=A[_l][-1]
|
|
|
|
|
async def __get_door_ladder(C,door_account,monthBill):
|
|
|
|
|
E=monthBill;A=door_account;I=A[_g];F=datetime.datetime.strptime(E[_AN],'%Y%m');G=f"{F.year}-{F.month:02d}";H={_A:{_I:configuration[_V][_I],_D:configuration[_V][_D],_T:configuration[_V][_T],_e:configuration[_V][_e],_q:A[_g],_d:A[_U],_Y:A[_Y],_Av:G,_AV:A[_U],_AL:A[_AW],_AI:C.userInfo[_R],_N:'',_L:'',_A5:C.userInfo[_AB],_A4:C.userInfo[_R]},_C:configuration[_V][_C],_E:configuration[_V][_E],_S:A[_U]};B=await C.__fetch(get_door_ladder_api,H);J=C.handle_request_result_message(_Aw,B)
|
|
|
|
|
if _H in B and B[_H]==1 and _A in B and _u in B[_A]:
|
|
|
|
|
D=B[_A][_u]
|
|
|
|
|
if len(D)!=0:D=D[0];E['ladder']=D
|
|
|
|
|
async def __get_door_mouth_bill(I,door_account,monthBill):
|
|
|
|
|
S=monthBill;O='quantity';N='priceName';K='amtGroupList';H='readList';E=door_account;C='amtList';B='pointList';T=datetime.datetime.strptime(S[_AN],'%Y%m');V=f"{T.year}-{T.month:02d}";W={_A:{_I:configuration[_V][_I],_D:configuration[_V][_D],_T:configuration[_V][_T],_e:configuration[_V][_e],_q:E[_g],_d:E[_U],_Y:E[_Y],_Av:V,_AV:E[_U],_AL:E[_AW],_AI:I.userInfo[_R],_N:'',_L:'',_A5:I.userInfo[_AB],_A4:I.userInfo[_R]},_C:configuration[_V][_C],_E:configuration[_V][_E],_S:E[_U]};F=await I.__fetch(get_door_ladder_api,W);X=I.handle_request_result_message(_Aw,F)
|
|
|
|
|
if _H in F and F[_H]==1 and _A in F and _u in F[_A]:
|
|
|
|
|
A=F[_A][_u][0];U=0;P=0;Q=0;L=0;R=0;M=[]
|
|
|
|
|
if H in A and len(A[H])>0:M=A[H]
|
|
|
|
|
elif B in A and len(A[B])>0 and H in A[B][0]and len(A[B][0][H])>0:M=A[B][0][H]
|
|
|
|
|
if len(M)>0:U=catchFloat(M[0],'activeCount')
|
|
|
|
|
J=[]
|
|
|
|
|
if C in A and len(A[C])>0:J=A[C]
|
|
|
|
|
elif B in A and len(A[B])>0 and C in A[B][0]and len(A[B][0][C])>0:J=A[B][0][C]
|
|
|
|
|
elif B in A and len(A[B])>0 and K in A[B][0]and len(A[B][0][K])>0 and C in A[B][0][K][0]and len(A[B][0][K][0][C])>0:J=A[B][0][K][0][C]
|
|
|
|
|
if len(J)>0:
|
|
|
|
|
for D in J:
|
|
|
|
|
if D[N]=='峰':P=catchFloat(D,O)
|
|
|
|
|
elif D[N]=='谷':Q=catchFloat(D,O)
|
|
|
|
|
elif D[N]=='平':L=catchFloat(D,O)
|
|
|
|
|
elif D[N]=='尖':R=catchFloat(D,O)
|
|
|
|
|
if L==0:L=P+Q+R
|
|
|
|
|
G={};G[_AX]=normal_round(U,2);G[_AY]=normal_round(P,2);G[_AZ]=normal_round(Q,2);G[_Aa]=normal_round(L,2);G[_Ab]=normal_round(R,2);S[_h]=G
|
|
|
|
|
async def __get_door_daily_bill(B,door_account,year,start_date,end_date):
|
|
|
|
|
D='sevenEleList';A=door_account;E={'params1':{_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_K][_W],_Z:configuration[_K][_Z],_a:configuration[_K][_a],_X:configuration[_K][_X]},_A2:{_R:B.userInfo[_R]},_p:B.token},'params3':{_A:{_A4:B.userInfo[_R],_q:A[_g],_AL:_c,'endTime':end_date,_Y:A[_Y],_Au:year,_AJ:A.get(_U,A.get(_AK,_F)),_N:'',_L:'','startTime':start_date,_A5:B.userInfo[_AB],_D:configuration[_m][_D],_I:configuration[_m][_I],_e:configuration[_m][_e],_d:configuration[_m][_d],_T:configuration[_m][_T]},_C:configuration[_m][_C],_E:configuration[_m][_E],_S:A.get(_U,A.get(_AK,_F))},'params4':'010103'};C=await B.__fetch_safe(get_door_daily_bill_api,E);F=B.handle_request_result_message('get_door_daily_bill_api',C)
|
|
|
|
|
if _H in C and C[_H]==1 and _A in C and D in C[_A]:A[_A6]=C[_A][D]
|
|
|
|
|
async def __get_door_pay_record(A,door_account):B=door_account;D=B[_g];C={'params1':{_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_K][_W],_Z:configuration[_K][_Z],_a:configuration[_K][_a],_X:configuration[_K][_X]},_A2:{_R:A.userInfo[_R]},_p:A.token},'params3':{_A:{_A4:A.userInfo[_R],'bgnPayDate':'2023-04-24',_I:configuration[_I],_q:B[_g],'endPayDate':'2024-04-24',_D:'webALIPAY_01','number':100,_Y:B[_Y],'page':_G,_AJ:B[_U],_d:_G,_T:_G,_N:'',_L:'',_A5:A.userInfo[_AB]},_C:'0101051',_E:_c,_S:B[_U]},'params4':'010104'};E=await A.__fetch(getJiaoFeiRecordApi,C)
|
|
|
|
|
async def get_qr_code(B):
|
|
|
|
|
A=await B.__get_request_key()
|
|
|
|
|
if _B in A and A[_B]!=0:return A
|
|
|
|
@@ -267,65 +320,77 @@ class StateGridDataClient:
|
|
|
|
|
if _B in A and A[_B]!=0:return A
|
|
|
|
|
A=await B.__get_door_number()
|
|
|
|
|
if _B in A and A[_B]!=0:return A
|
|
|
|
|
B.need_login=_s;await B.save_data();return{_B:0,_A:B.powerUserList}
|
|
|
|
|
async def refresh_data(B,setup=_s):
|
|
|
|
|
n='daily_t_ele_num';m='daily_n_ele_num';l='daily_v_ele_num';k='daily_p_ele_num';j='last_month_ele_cost';i='year_ele_cost';h='monthEleNum';g='thisTPq';f='thisNPq';e='thisVPq';d='thisPPq';U='daily_ele_num';T='last_month_ele_num';S='year_ele_num';R='ladder_level_num';Q='ladder_level';L='%Y%m%d';K='day';I='balance';H='dayElePq'
|
|
|
|
|
if B.need_login is True:LOGGER.error('国家电网需要重新登录!');return
|
|
|
|
|
o=setup or int(time.time()*1000)-B.timestamp>B.refresh_interval*3600*1000
|
|
|
|
|
if o is _s:return
|
|
|
|
|
D=await B.__get_door_number()
|
|
|
|
|
if _B in D and D[_B]!=0:
|
|
|
|
|
LOGGER.warning('刷新 Token');D=await B.__get_request_key()
|
|
|
|
|
if _B in D and D[_B]!=0:return
|
|
|
|
|
D=await B.__refresh_web_token()
|
|
|
|
|
if _B in D and D[_B]==0:await B.save_data()
|
|
|
|
|
else:B.need_login=True;LOGGER.error('刷新 Token 失败');return
|
|
|
|
|
D=await B.__get_door_number()
|
|
|
|
|
if _B in D and D[_B]!=0:B.need_login=True;LOGGER.error('重新请求失败');return
|
|
|
|
|
M=datetime.datetime.now();J=M-datetime.timedelta(days=1);p=f"{J.year}-{J.month:02d}-{J.day:02d}";N=J-datetime.timedelta(days=40);q=f"{N.year}-{N.month:02d}-{N.day:02d}"
|
|
|
|
|
B.need_login=_i;await B.save_data();return{_B:0,_A:B.powerUserList}
|
|
|
|
|
async def __refresh_token(A):
|
|
|
|
|
B=await A.__get_request_key()
|
|
|
|
|
if _B in B and B[_B]!=0:return
|
|
|
|
|
B=await A.__refresh_web_token()
|
|
|
|
|
if _B in B and B[_B]==0:A.need_login=_i;A.retry_times=0;await A.save_data()
|
|
|
|
|
elif A.retry_times>=3:A.need_login=_o
|
|
|
|
|
else:A.retry_times=A.retry_times+1
|
|
|
|
|
async def refresh_data(B,setup=_i,force_refresh=_i):
|
|
|
|
|
t='last_month_ele_cost';s='year_ele_cost';r='thisTPq';q='thisNPq';p='thisVPq';o='thisPPq';n='%Y%m%d';m='day';l='refresh_time';f=setup;e='last_month_ele_num';d='dayElePq';U='year_ele_num';G='balance'
|
|
|
|
|
if f is _o:
|
|
|
|
|
if B.dataVersion!=VERSION:B.powerUserList=_F
|
|
|
|
|
g=await B.__get_door_number()
|
|
|
|
|
if _B in g and g[_B]!=0:B.need_login=_o
|
|
|
|
|
if B.need_login is _o:
|
|
|
|
|
if B.powerUserList is not _F:
|
|
|
|
|
for A in B.get_door_account_list():A[l]='Token刷新失败,请重新登录'
|
|
|
|
|
LOGGER.error('国家电网 - Token刷新失败,请重新登录!');return
|
|
|
|
|
u=f or force_refresh or int(time.time()*1000)-B.timestamp>B.refresh_interval*3600*1000
|
|
|
|
|
if u is _i:return
|
|
|
|
|
V=datetime.datetime.now();H=V-datetime.timedelta(days=1);v=f"{H.year}-{H.month:02d}-{H.day:02d}";W=H-datetime.timedelta(days=40);w=f"{W.year}-{W.month:02d}-{W.day:02d}"
|
|
|
|
|
for A in B.powerUserList:
|
|
|
|
|
r=A[_m];B.doorAccountDict[r]=A;await B.__get_door_balance(A);await B.__get_door_daily_bill(A,M.year,q,p);O=A[_V][0]
|
|
|
|
|
try:float(O[H])
|
|
|
|
|
except:A[_V].pop(0)
|
|
|
|
|
O=A[_V][0];E=datetime.datetime.strptime(O[K],L);V=0;W=0;X=0;Y=0;Z=0
|
|
|
|
|
for C in A[_V]:
|
|
|
|
|
G=datetime.datetime.strptime(C[K],L)
|
|
|
|
|
if G.month!=E.month:break
|
|
|
|
|
V+=catchFloat(C,H);W+=catchFloat(C,d);X+=catchFloat(C,e);Y+=catchFloat(C,f);Z+=catchFloat(C,g)
|
|
|
|
|
P=E-datetime.timedelta(days=E.day);a=f"{P.year}-{P.month:02d}"
|
|
|
|
|
if _AI not in A or A[_AI]!=a:await B.__get_door_bill(A,P.year);await B.__get_door_ladder(A,a)
|
|
|
|
|
s=datetime.datetime.strptime(A[_AI],'%Y%m')
|
|
|
|
|
if s.month==12:
|
|
|
|
|
F=0
|
|
|
|
|
for C in A[_V]:
|
|
|
|
|
G=datetime.datetime.strptime(C[K],L)
|
|
|
|
|
if G.month!=12:break
|
|
|
|
|
F+=catchFloat(C,H)
|
|
|
|
|
x=A[_g];B.doorAccountDict[x]=A;await B.__get_door_balance(A)
|
|
|
|
|
if B.retry_times!=0:return
|
|
|
|
|
if _v in A:
|
|
|
|
|
y=catchFloat(A[_v],'accountBalance');z=catchFloat(A[_v],'estiAmt');X=catchFloat(A[_v],'prepayBal');Y=catchFloat(A[_v],'sumMoney')
|
|
|
|
|
if y!=0:A[G]=Y
|
|
|
|
|
elif X==0 or X==Y:A[G]=Y
|
|
|
|
|
else:A[G]=X-z
|
|
|
|
|
h=catchFloat(A[_v],'historyOwe')
|
|
|
|
|
if h>0:A[G]=-h
|
|
|
|
|
else:LOGGER.error('国家电网账户余额获取失败!')
|
|
|
|
|
if G not in A:A[G]=0
|
|
|
|
|
await B.__get_door_daily_bill(A,V.year,w,v)
|
|
|
|
|
if _A6 not in A:LOGGER.error('国家电网无法获取日用电数据!');continue
|
|
|
|
|
Z=0;L=_i
|
|
|
|
|
for i in range(10):
|
|
|
|
|
D=A[_A6][i]
|
|
|
|
|
try:float(D[d]);L=_o;break
|
|
|
|
|
except:Z=Z+1
|
|
|
|
|
j=0;a=0;b=0;M=0;c=0
|
|
|
|
|
if L:
|
|
|
|
|
for i in range(Z):A[_A6].pop(0)
|
|
|
|
|
D=A[_A6][0];E=datetime.datetime.strptime(D[m],n);A['daily_lasted_date']=f"{E.year}-{E.month:02d}-{E.day:02d}";j=catchFloat(D,d);a=catchFloat(D,o);b=catchFloat(D,p);M=catchFloat(D,q);c=catchFloat(D,r)
|
|
|
|
|
if M==0:M=a+b+c
|
|
|
|
|
A['daily_ele_num']=normal_round(j,2);A['daily_p_ele_num']=normal_round(a,2);A['daily_v_ele_num']=normal_round(b,2);A['daily_n_ele_num']=normal_round(M,2);A['daily_t_ele_num']=normal_round(c,2);N=0;I=0;J=0;F=0;K=0
|
|
|
|
|
if L:
|
|
|
|
|
for C in A[_A6]:
|
|
|
|
|
A0=datetime.datetime.strptime(C[m],n)
|
|
|
|
|
if A0.month!=E.month:break
|
|
|
|
|
N+=catchFloat(C,d);I+=catchFloat(C,o);J+=catchFloat(C,p);F+=catchFloat(C,q);K+=catchFloat(C,r)
|
|
|
|
|
if F==0:F=I+J+K
|
|
|
|
|
A[_AX]=normal_round(N,2);A[_AY]=normal_round(I,2);A[_AZ]=normal_round(J,2);A[_Aa]=normal_round(F,2);A[_Ab]=normal_round(K,2)
|
|
|
|
|
if L:
|
|
|
|
|
O=E-datetime.timedelta(days=E.day);A1=f"{O.year}{O.month:02d}"
|
|
|
|
|
if _AC not in A or A[_AC]!=O.year or _w not in A or A[_w][_AN]!=A1:await B.__get_door_bill(A,O)
|
|
|
|
|
if _l in A:
|
|
|
|
|
for C in A[_l]:
|
|
|
|
|
if _h not in C:await B.__get_door_mouth_bill(A,C)
|
|
|
|
|
if _AM in A:A[U]=catchFloat(A[_AM],'totalEleNum');A[s]=catchFloat(A[_AM],'totalEleCost')
|
|
|
|
|
if U not in A:A[U]=0;A[s]=0
|
|
|
|
|
if _w in A:A[e]=catchFloat(A[_w],'monthEleNum');A[t]=catchFloat(A[_w],'monthEleCost');k=datetime.datetime.strptime(A[_w][_AN],'%Y%m')
|
|
|
|
|
if e not in A:A[e]=0;A[t]=0;k=H
|
|
|
|
|
P=0;Q=0;R=0;S=0;T=0
|
|
|
|
|
if k.month==12:P=N;Q=I;R=J;S=F;T=K
|
|
|
|
|
else:
|
|
|
|
|
F=0
|
|
|
|
|
for C in A[_A4]:F+=catchFloat(C,h)
|
|
|
|
|
t=len(A[_A4])
|
|
|
|
|
for C in A[_V]:
|
|
|
|
|
G=datetime.datetime.strptime(C[K],L)
|
|
|
|
|
if G.month<=t:break
|
|
|
|
|
F+=catchFloat(C,H)
|
|
|
|
|
if F<=2760:A[Q]='第一阶梯';A[R]=1
|
|
|
|
|
elif F<=4800:A[Q]='第二阶梯';A[R]=2
|
|
|
|
|
else:A[Q]='第三阶梯';A[R]=3
|
|
|
|
|
if _A3 in A:
|
|
|
|
|
u=catchFloat(A[_A3],'estiAmt');b=catchFloat(A[_A3],'prepayBal');v=catchFloat(A[_A3],'sumMoney')
|
|
|
|
|
if b==0:A[I]=v
|
|
|
|
|
else:A[I]=b-u
|
|
|
|
|
c=catchFloat(A[_A3],'historyOwe')
|
|
|
|
|
if c>0:A[I]=-c
|
|
|
|
|
elif I not in A:A[I]=0
|
|
|
|
|
if _AH in A:A[S]=catchFloat(A[_AH],'totalEleNum');A[i]=catchFloat(A[_AH],'totalEleCost')
|
|
|
|
|
elif S not in A:A[S]=0;A[i]=0
|
|
|
|
|
if _A4 in A:A[T]=catchFloat(A[_A4][-1],h);A[j]=catchFloat(A[_A4][-1],'monthEleCost')
|
|
|
|
|
elif T not in A:A[T]=0;A[j]=0
|
|
|
|
|
if _V in A:A[U]=catchFloat(A[_V][0],H);A[k]=catchFloat(A[_V][0],d);A[l]=catchFloat(A[_V][0],e);A[m]=catchFloat(A[_V][0],f);A[n]=catchFloat(A[_V][0],g)
|
|
|
|
|
elif U not in A:A[U]=0;A[k]=0;A[l]=0;A[m]=0;A[n]=0
|
|
|
|
|
A['month_ele_num']=V;A['month_p_ele_num']=W;A['month_v_ele_num']=X;A['month_n_ele_num']=Y;A['month_t_ele_num']=Z;A['daily_lasted_date']=f"{E.year}-{E.month:02d}-{E.day:02d}";A['refresh_time']=datetime.datetime.strftime(M,'%Y-%m-%d %H:%M:%S')
|
|
|
|
|
if _l in A:
|
|
|
|
|
for C in A[_l]:
|
|
|
|
|
if _h in C:P+=C[_h][_AX];Q+=C[_h][_AY];R+=C[_h][_AZ];S+=C[_h][_Aa];T+=C[_h][_Ab]
|
|
|
|
|
P+=N;Q+=I;R+=J;S+=F;T+=K
|
|
|
|
|
A[U]=normal_round(P,2);A['year_p_ele_num']=normal_round(Q,2);A['year_v_ele_num']=normal_round(R,2);A['year_n_ele_num']=normal_round(S,2);A['year_t_ele_num']=normal_round(T,2);A[l]=datetime.datetime.strftime(V,'%Y-%m-%d %H:%M:%S')
|
|
|
|
|
await B.save_data()
|
|
|
|
|
async def get_door_account_list(A):return list(A.doorAccountDict.values())
|
|
|
|
|
def get_door_account_list(A):return list(A.doorAccountDict.values())
|
|
|
|
|
def get_door_account(A):return A.doorAccountDict
|