use super::post_send;
use crate::{wechat::WxApiRequestBuilder, SdkResult};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct DelayFn {
pub env: String,
pub function_name: String,
pub delay_time: i32,
pub data: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PressureTask {
pub task_url: String,
pub run_count: i32,
pub run_time: i32,
pub source_type: f64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PressureId {
pub pressure_id: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SmsTask {
pub env: String,
pub file_url: String,
pub template_id: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryId {
pub query_id: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct FilesInfo {
pub extension_files: Vec<FileInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct FileInfo {
pub file_type: String,
pub file_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FilesData {
#[serde(rename = "FilesData")]
pub files_data: Vec<FileData>,
#[serde(rename = "RequestId")]
pub request_id: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct FileData {
pub code_uri: String,
pub upload_url: String,
pub custom_key: String,
pub max_size: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct QuerySmsRecord {
pub env_id: String,
pub start_date: String,
pub end_date: String,
#[serde(default)]
pub mobile: Option<String>,
#[serde(default)]
pub query_id: Option<String>,
#[serde(default)]
pub page_number: Option<i32>,
#[serde(default)]
pub page_size: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SmsRecords {
#[serde(rename = "SmsRecords")]
pub sms_records: Vec<SmsRecord>,
#[serde(rename = "TotalCount")]
pub total_count: i64,
#[serde(rename = "RequestId")]
pub request_id: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct SmsRecord {
pub mobile: String,
pub content: String,
pub content_size: i32,
pub fee: i32,
pub create_time: String,
pub received_time: String,
pub status: String,
pub remarks: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryOpenData {
pub openid: String,
pub cloudid_list: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OpenDataList {
pub data_list: Vec<OpenData>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OpenData {
pub cloud_id: String,
pub json: OpenDataJson,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OpenDataJson {
#[serde(rename = "cloudID")]
pub cloud_id: String,
pub data: StepInfoList,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct StepInfoList {
pub step_info_list: Vec<StepInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct StepInfo {
pub timestamp: i64,
pub step: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PressureTestReport {
pub report: PTestReport,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PTestReport {
pub blankpage_pencent: f64,
pub aver_time_cost: i32,
pub max_time_cost: i32,
pub total_launch_cnt: i32,
pub total_request_cnt: i32,
pub network_list: Vec<Network>,
pub appid: String,
pub task_url: String,
pub run_time: i32,
pub pressure_id: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Network {
pub path: String,
pub aver_time_cost: f64,
pub max_time_cost: i32,
pub total_request_cnt: i32,
pub succ_percent: f64,
pub top_time_cost_list: Vec<TopTimeCost>,
pub over_count: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TopTimeCost {
pub time_cost: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PressureTestStatus {
pub status: String,
pub beg_time: i64,
pub end_time: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryStatistics {
pub action: String,
pub begin_date: i64,
pub end_date: i64,
#[serde(default)]
pub page_offset: Option<i32>,
#[serde(default)]
pub page_limit: Option<i32>,
pub condition: StatisticCondition,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct StatisticCondition {
pub env_id: String,
pub activity_id: String,
pub by_channel_id: String,
pub act_type: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Statistics {
pub data_column: Vec<DataColumn>,
pub data_value: Vec<DataValue>,
pub total_num: i32,
pub env_id: Option<String>,
pub activity_id: Option<String>,
#[serde(default)]
pub by_channel_id: Option<String>,
#[serde(default)]
pub channel_id: Option<String>,
#[serde(default)]
pub act_type: Option<String>,
pub errcode: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DataColumn {
pub col_id: String,
pub col_name: String,
pub col_data_type: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DataValue {
pub data_value: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryVoIPSign {
pub openid: String,
pub group_id: String,
pub nonce: String,
pub timestamp: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VoIPSign {
pub signature: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Report {
pub report_action: String,
pub env_id: String,
pub activity_id: String,
#[serde(default)]
pub task_id: Option<String>,
#[serde(default)]
pub phone_count: Option<String>,
#[serde(default)]
pub channel_id: Option<String>,
#[serde(default)]
pub session_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SendSms {
pub env: String,
pub phone_number_list: Vec<String>,
pub sms_type: String,
#[serde(default)]
pub content: Option<String>,
#[serde(default)]
pub path: Option<String>,
#[serde(default)]
pub template_id: Option<String>,
#[serde(default)]
pub template_param_list: Option<Vec<String>>,
#[serde(default)]
pub use_short_name: Option<bool>,
#[serde(default)]
pub resource_appid: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SendStatusList {
pub send_status_list: Vec<SendStatus>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SendStatus {
pub serial_no: String,
pub phone_number: String,
pub code: String,
pub message: String,
pub iso_code: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SendSmsV2 {
pub env: String,
pub url_link: String,
pub template_id: String,
pub template_param_list: Vec<String>,
pub phone_number_list: Vec<String>,
#[serde(default)]
pub use_short_name: Option<bool>,
#[serde(default)]
pub resource_appid: Option<String>,
}
pub struct CloudbaseModule<'a, T: WxApiRequestBuilder>(pub(crate) &'a T);
impl<'a, T: WxApiRequestBuilder> CloudbaseModule<'a, T> {
pub async fn add_delayed_function_task(&self, data: &DelayFn) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/tcb/adddelayedfunctiontask";
post_send(self.0, url, data).await
}
pub async fn create_pressure_test(&self, data: &PressureTask) -> SdkResult<PressureId> {
let url = "https://api.weixin.qq.com/tcb/createpressuretesttask";
post_send(self.0, url, data).await
}
pub async fn create_send_sms_task(&self, data: &SmsTask) -> SdkResult<QueryId> {
let url = "https://api.weixin.qq.com/tcb/createsendsmstask";
post_send(self.0, url, data).await
}
pub async fn describe_extension_upload_info(&self, data: &FilesInfo) -> SdkResult<FilesData> {
let url = "https://api.weixin.qq.com/tcb/describeextensionuploadinfo";
post_send(self.0, url, data).await
}
pub async fn describe_sms_records(&self, data: &QuerySmsRecord) -> SdkResult<SmsRecords> {
let url = "https://api.weixin.qq.com/tcb/describesmsrecords";
post_send(self.0, url, data).await
}
pub async fn get_open_data(&self, data: &QueryOpenData) -> SdkResult<OpenDataList> {
let url = "https://api.weixin.qq.com/wxa/getopendata";
post_send(self.0, url, data).await
}
pub async fn get_pressure_test_report(
&self,
pressure_id: i64,
) -> SdkResult<PressureTestReport> {
let url = "https://api.weixin.qq.com/tcb/getpressuretestreport";
let data = &serde_json::json!({ "pressure_id": pressure_id });
post_send(self.0, url, data).await
}
pub async fn get_pressure_test_status(
&self,
pressure_id: i64,
) -> SdkResult<PressureTestStatus> {
let url = "https://api.weixin.qq.com/tcb/getpressureteststatus";
let data = &serde_json::json!({ "pressure_id": pressure_id });
post_send(self.0, url, data).await
}
pub async fn get_statistics(&self, data: &QueryStatistics) -> SdkResult<Statistics> {
let url = "https://api.weixin.qq.com/tcb/getstatistics";
post_send(self.0, url, data).await
}
pub async fn get_voipsign(&self, data: &QueryVoIPSign) -> SdkResult<VoIPSign> {
let url = "https://api.weixin.qq.com/wxa/getvoipsign";
post_send(self.0, url, data).await
}
pub async fn report(&self, data: &Report) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/tcb/cloudbasereport";
post_send(self.0, url, data).await
}
pub async fn send_sms(&self, data: &SendSms) -> SdkResult<SendStatusList> {
let url = "https://api.weixin.qq.com/tcb/sendsms";
post_send(self.0, url, data).await
}
pub async fn send_sms_v2(&self, data: &SendSmsV2) -> SdkResult<SendStatusList> {
let url = "https://api.weixin.qq.com/tcb/sendsmsv2";
post_send(self.0, url, data).await
}
}