use crate::config::{API_DEFAULT_HOST_URL, WxOpenConfigStorage};
fn url(config: &dyn WxOpenConfigStorage, path: &str) -> String {
let host = config
.wx_open_host_config()
.map(|h| h.api_host)
.unwrap_or_else(|| API_DEFAULT_HOST_URL.to_string());
format!("{host}{path}")
}
pub fn api_component_token_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_component_token")
}
pub fn api_start_push_ticket_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_start_push_ticket")
}
pub fn api_create_preauthcode_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_create_preauthcode")
}
pub fn api_query_auth_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_query_auth")
}
pub fn api_authorizer_token_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_authorizer_token")
}
pub fn api_get_authorizer_info_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_get_authorizer_info")
}
pub fn get_authorizer_option_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/get_authorizer_option")
}
pub fn set_authorizer_option_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/set_authorizer_option")
}
pub fn api_get_authorizer_list_url(config: &dyn WxOpenConfigStorage) -> String {
url(config, "/cgi-bin/component/api_get_authorizer_list")
}
pub fn component_login_page_url(
component_app_id: &str,
pre_auth_code: &str,
redirect_uri: &str,
) -> String {
format!(
"https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={}&pre_auth_code={}&redirect_uri={}&auth_type=xxx&biz_appid=xxx",
component_app_id, pre_auth_code, redirect_uri
)
}
pub fn component_mobile_login_page_url(
component_app_id: &str,
pre_auth_code: &str,
redirect_uri: &str,
) -> String {
format!(
"https://open.weixin.qq.com/wxaopen/safe/bindcomponent?action=bindcomponent&no_scan=1&component_appid={}&pre_auth_code={}&redirect_uri={}&auth_type=xxx&biz_appid=xxx#wechat_redirect",
component_app_id, pre_auth_code, redirect_uri
)
}
pub const API_HOST: &str = API_DEFAULT_HOST_URL;