use std::sync::Arc;
use tokio::sync::Mutex as AsyncMutex;
use wx_rust_common::config::WxConfigStorage;
use crate::bean::{WxOpenAuthorizerAccessToken, WxOpenComponentAccessToken};
use crate::config::WxOpenHostConfig;
pub trait WxOpenConfigStorage: Send + Sync {
fn component_app_id(&self) -> Option<String>;
fn set_component_app_id(&self, component_app_id: &str);
fn component_app_secret(&self) -> Option<String>;
fn set_component_app_secret(&self, component_app_secret: &str);
fn component_token(&self) -> Option<String>;
fn set_component_token(&self, component_token: &str);
fn component_aes_key(&self) -> Option<String>;
fn set_component_aes_key(&self, component_aes_key: &str);
fn component_verify_ticket(&self) -> Option<String>;
fn set_component_verify_ticket(&self, component_verify_ticket: &str);
fn set_wx_open_info(
&self,
component_app_id: &str,
component_app_secret: &str,
component_token: &str,
component_aes_key: &str,
) {
self.set_component_app_id(component_app_id);
self.set_component_app_secret(component_app_secret);
self.set_component_token(component_token);
self.set_component_aes_key(component_aes_key);
}
fn component_access_token(&self) -> Option<String>;
fn is_component_access_token_expired(&self) -> bool;
fn expire_component_access_token(&self);
fn update_component_access_token(&self, component_access_token: &WxOpenComponentAccessToken) {
self.update_component_access_token_with_expiry(
component_access_token.component_access_token(),
component_access_token.expires_in(),
);
}
fn update_component_access_token_with_expiry(
&self,
component_access_token: &str,
expires_in_seconds: i32,
);
fn component_access_token_lock(&self) -> Arc<AsyncMutex<()>>;
fn lock_by_key(&self, key: &str) -> Arc<AsyncMutex<()>>;
fn auto_refresh_token(&self) -> bool {
true
}
fn authorizer_refresh_token(&self, app_id: &str) -> Option<String>;
fn set_authorizer_refresh_token(&self, app_id: &str, authorizer_refresh_token: &str);
fn update_authorizer_refresh_token(&self, app_id: &str, authorizer_refresh_token: &str) {
self.set_authorizer_refresh_token(app_id, authorizer_refresh_token);
}
fn authorizer_access_token(&self, app_id: &str) -> Option<String>;
fn is_authorizer_access_token_expired(&self, app_id: &str) -> bool;
fn expire_authorizer_access_token(&self, app_id: &str);
fn update_authorizer_access_token(
&self,
app_id: &str,
authorizer_access_token: &WxOpenAuthorizerAccessToken,
) {
self.update_authorizer_access_token_with_expiry(
app_id,
authorizer_access_token.authorizer_access_token(),
authorizer_access_token.expires_in(),
);
}
fn update_authorizer_access_token_with_expiry(
&self,
app_id: &str,
authorizer_access_token: &str,
expires_in_seconds: i32,
);
fn jsapi_ticket(&self, app_id: &str) -> Option<String>;
fn is_jsapi_ticket_expired(&self, app_id: &str) -> bool;
fn expire_jsapi_ticket(&self, app_id: &str);
fn update_jsapi_ticket(&self, app_id: &str, jsapi_ticket: &str, expires_in_seconds: i32);
fn card_api_ticket(&self, app_id: &str) -> Option<String>;
fn is_card_api_ticket_expired(&self, app_id: &str) -> bool;
fn expire_card_api_ticket(&self, app_id: &str);
fn update_card_api_ticket(&self, app_id: &str, card_api_ticket: &str, expires_in_seconds: i32);
fn wx_mp_config_storage(&self, _app_id: &str) -> Option<Arc<dyn WxConfigStorage>> {
None
}
fn wx_ma_config(&self, _app_id: &str) -> Option<Arc<dyn WxConfigStorage>> {
None
}
fn wx_open_host_config(&self) -> Option<WxOpenHostConfig> {
None
}
fn http_proxy_host(&self) -> Option<String>;
fn http_proxy_port(&self) -> i32;
fn http_proxy_username(&self) -> Option<String>;
fn http_proxy_password(&self) -> Option<String>;
fn retry_sleep_millis(&self) -> i32 {
1000
}
fn max_retry_times(&self) -> i32 {
5
}
fn component_api_signature_rsa_private_key(&self) -> Option<String>;
fn set_component_api_signature_rsa_private_key(&self, api_signature_rsa_private_key: &str);
fn component_api_signature_aes_key(&self) -> Option<String>;
fn set_component_api_signature_aes_key(&self, api_signature_aes_key: &str);
fn component_api_signature_rsa_private_key_sn(&self) -> Option<String>;
fn set_component_api_signature_rsa_private_key_sn(
&self,
api_signature_rsa_private_key_sn: &str,
);
fn component_api_signature_aes_key_sn(&self) -> Option<String>;
fn set_component_api_signature_aes_key_sn(&self, api_signature_aes_key_sn: &str);
}