use super::{get_send, post_send};
use crate::{wechat::WxApiRequestBuilder, SdkResult};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct AddAssistant {
pub room_id: i64,
pub users: Vec<User>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
pub username: String,
pub nickname: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AddRoomGoods {
pub room_id: i64,
pub ids: Vec<i64>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UserRole {
pub username: String,
pub role: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateRoom {
pub name: String,
pub cover_img: String,
pub start_time: i64,
pub end_time: i64,
pub anchor_name: String,
pub anchor_wechat: String,
#[serde(default)]
pub sub_anchor_wechat: Option<String>,
#[serde(default)]
pub creater_wechat: Option<String>,
pub share_img: String,
pub feeds_img: String,
#[serde(default)]
pub is_feeds_public: Option<i32>,
#[serde(rename = "type")]
pub type_: i32,
pub close_like: i32,
pub close_goods: i32,
pub close_comment: i32,
#[serde(default)]
pub close_replay: Option<i32>,
#[serde(default)]
pub close_share: Option<i32>,
#[serde(default)]
pub close_kf: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateRoomRes {
pub room_id: i64,
pub qrcode_url: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryLiveInfo {
pub start: i64,
pub limit: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RoomInfos {
pub total: i64,
pub room_info: Vec<RoomInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RoomInfo {
pub name: String,
pub roomid: i64,
pub cover_img: String,
pub share_img: String,
pub live_status: i32,
pub start_time: i64,
pub end_time: i64,
pub anchor_name: String,
pub goods: Vec<RoomGoodsInfo>,
pub live_type: i32,
pub close_like: i32,
pub close_goods: i32,
pub close_comment: i32,
pub close_kf: i32,
pub close_replay: i32,
pub is_feeds_public: i32,
pub creater_openid: String,
pub feeds_img: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RoomGoodsInfo {
pub cover_img: String,
pub url: String,
pub name: String,
pub price: f64,
pub price2: f64,
pub price_type: i32,
pub goods_id: i64,
pub third_party_appid: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryLiveReplay {
pub action: String,
pub room_id: i64,
pub start: i64,
pub limit: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LiveReplayRes {
pub live_replay: Vec<LiveReplay>,
pub total: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LiveReplay {
pub expire_time: String,
pub create_time: String,
pub media_url: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EditRoom {
pub id: i64,
pub name: String,
pub cover_img: String,
pub start_time: i64,
pub end_time: i64,
pub anchor_name: String,
pub anchor_wechat: String,
pub share_img: String,
pub feeds_img: String,
#[serde(default)]
pub is_feeds_public: Option<i32>,
pub close_like: i32,
pub close_goods: i32,
pub close_comment: i32,
#[serde(default)]
pub close_replay: Option<i32>,
#[serde(default)]
pub close_share: Option<i32>,
#[serde(default)]
pub close_kf: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PushAddr {
pub push_addr: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QuerySharedCode {
pub room_id: i64,
#[serde(default)]
pub params: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SharedCodeRes {
pub cdn_url: String,
pub page_path: String,
pub poster_url: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModifyAssistant {
pub room_id: i64,
pub username: String,
pub nickname: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RemoveAssistant {
pub room_id: i32,
pub username: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AssistantList {
pub list: Vec<Assistant>,
pub count: i64,
pub max_count: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Assistant {
pub timestamp: i64,
pub headimg: String,
pub nickname: String,
pub alias: String,
pub openid: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Subanchor {
pub room_id: i32,
pub username: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Username {
pub username: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomFnFeedPublic {
pub room_id: i64,
pub is_feeds_public: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomFnReplay {
pub room_id: i64,
pub close_replay: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomFnKf {
pub room_id: i64,
pub close_kf: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomFnComment {
pub room_id: i64,
pub ban_comment: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomFnGoodsOnsale {
pub room_id: i64,
pub goods_id: i64,
pub on_sale: i32,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomGoods {
pub room_id: i64,
pub goods_id: i64,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoomGoodsList {
pub room_id: i64,
pub goods: Vec<GoodsId>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GoodsId {
pub goods_id: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UrlRes {
pub url: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AddGoods {
pub cover_img_url: String,
pub name: String,
pub price_type: i32,
pub price: f64,
#[serde(default)]
pub price2: Option<f64>,
pub url: String,
#[serde(default)]
pub third_party_appid: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GoodsInfo {
pub cover_img: String,
pub url: String,
pub name: String,
pub price: f64,
pub price2: f64,
pub price_type: i32,
pub goods_id: i64,
pub third_party_appid: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GoodsAudit {
pub goods_id: i64,
pub audit_id: i64,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AuditId {
pub audit_id: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GoodsWarehouseList {
pub total: i32,
pub goods: Vec<GoodsStatusInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GoodsStatusInfo {
pub goods_id: i64,
pub cover_img: String,
pub url: String,
pub name: String,
pub price: f64,
pub price2: f64,
pub price_type: i32,
pub audit_status: i32,
pub third_party_tag: i32,
pub third_party_appid: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryGoodsApproved {
pub offset: i32,
#[serde(default)]
pub limit: Option<i32>,
pub status: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GoodsApprovedList {
pub total: i64,
pub goods: Vec<GoodsApprovedInfo>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GoodsApprovedInfo {
pub goods_id: i64,
pub cover_img: String,
pub url: String,
pub name: String,
pub price: f64,
pub price2: f64,
pub price_type: i32,
pub third_party_tag: i32,
pub third_party_appid: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryRoleList {
#[serde(default)]
pub role: Option<i32>,
#[serde(default)]
pub offset: Option<i32>,
#[serde(default)]
pub limit: Option<i32>,
#[serde(default)]
pub keyword: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RoleList {
pub total: i64,
pub list: Vec<Role>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Role {
pub headingimg: String,
pub nickname: String,
pub openid: String,
pub role_list: Vec<i64>,
pub update_timestamp: String,
pub username: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PushMessage {
pub room_id: i32,
pub user_openid: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MessageId {
pub room_id: i32,
pub message_id: String,
}
pub struct LiveBroadcastModule<'a, T: WxApiRequestBuilder>(pub(crate) &'a T);
impl<'a, T: WxApiRequestBuilder> LiveBroadcastModule<'a, T> {
pub async fn create_room(&self, data: &CreateRoom) -> SdkResult<CreateRoomRes> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/create";
post_send(self.0, url, data).await
}
pub async fn get_live_info(&self, data: &QueryLiveInfo) -> SdkResult<RoomInfos> {
let url = "https://api.weixin.qq.com/wxa/business/getliveinfo";
post_send(self.0, url, data).await
}
pub async fn get_live_replay(&self, data: &QueryLiveInfo) -> SdkResult<LiveReplayRes> {
let url = "https://api.weixin.qq.com/wxa/business/getliveinfo";
post_send(self.0, url, data).await
}
pub async fn add_room_goods(&self, data: &AddRoomGoods) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods";
post_send(self.0, url, data).await
}
pub async fn delete_room(&self, room_id: i64) -> SdkResult<()> {
let data = &serde_json::json!({ "id": room_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/deleteroom";
post_send(self.0, url, data).await
}
pub async fn edit_room(&self, data: &EditRoom) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/editroom";
post_send(self.0, url, data).await
}
pub async fn get_push_url(&self, room_id: i64) -> SdkResult<PushAddr> {
let data = &serde_json::json!({ "roomId": room_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getpushurl";
get_send(self.0, url, data).await
}
pub async fn get_shared_code(&self, data: &QuerySharedCode) -> SdkResult<SharedCodeRes> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsharedcode";
get_send(self.0, url, data).await
}
pub async fn add_assistant(&self, data: &AddAssistant) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant";
post_send(self.0, url, data).await
}
pub async fn modify_assistant(&self, data: &ModifyAssistant) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant";
post_send(self.0, url, data).await
}
pub async fn remove_assistant(&self, data: &RemoveAssistant) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant";
post_send(self.0, url, data).await
}
pub async fn get_assistant_list(&self, room_id: i64) -> SdkResult<AssistantList> {
let data = &serde_json::json!({ "roomId": room_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist";
get_send(self.0, url, data).await
}
pub async fn add_subanchor(&self, data: &Subanchor) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addsubanchor";
post_send(self.0, url, data).await
}
pub async fn modify_subanchor(&self, data: &Subanchor) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifysubanchor";
post_send(self.0, url, data).await
}
pub async fn delete_subanchor(&self, room_id: i64) -> SdkResult<()> {
let data = &serde_json::json!({ "roomId": room_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/deletesubanchor";
post_send(self.0, url, data).await
}
pub async fn get_subanchor(&self, room_id: i64) -> SdkResult<Username> {
let data = &serde_json::json!({ "roomId": room_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsubanchor";
get_send(self.0, url, data).await
}
pub async fn update_feed_public(&self, data: &RoomFnFeedPublic) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatefeedpublic";
post_send(self.0, url, data).await
}
pub async fn update_replay(&self, data: &RoomFnReplay) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatereplay";
post_send(self.0, url, data).await
}
pub async fn update_kf(&self, data: &RoomFnKf) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatekf";
post_send(self.0, url, data).await
}
pub async fn update_comment(&self, data: &RoomFnComment) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatecomment";
post_send(self.0, url, data).await
}
pub async fn update_goods_onsale(&self, data: &RoomFnGoodsOnsale) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/onsale";
post_send(self.0, url, data).await
}
pub async fn delete_room_goods(&self, data: &RoomGoods) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom";
post_send(self.0, url, data).await
}
pub async fn push_room_goods(&self, data: &RoomGoods) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/push";
post_send(self.0, url, data).await
}
pub async fn sort_room_goods(&self, data: &RoomGoodsList) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/sort";
post_send(self.0, url, data).await
}
pub async fn get_goods_video(&self, data: &RoomGoods) -> SdkResult<UrlRes> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo";
post_send(self.0, url, data).await
}
pub async fn add_goods(&self, data: &AddGoods) -> SdkResult<GoodsAudit> {
let data = &serde_json::json!({ "goodsInfo": data });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add";
post_send(self.0, url, data).await
}
pub async fn reset_audit(&self, data: &AddGoods) -> SdkResult<GoodsAudit> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit";
post_send(self.0, url, data).await
}
pub async fn audit_goods(&self, goods_id: i64) -> SdkResult<AuditId> {
let data = &serde_json::json!({ "goodsId": goods_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit";
post_send(self.0, url, data).await
}
pub async fn delete_goods(&self, goods_id: i64) -> SdkResult<()> {
let data = &serde_json::json!({ "goodsId": goods_id });
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete";
post_send(self.0, url, data).await
}
pub async fn update_goods(&self, data: &GoodsInfo) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update";
post_send(self.0, url, data).await
}
pub async fn get_goods_warehouse(&self, goods_ids: &[i64]) -> SdkResult<GoodsWarehouseList> {
let data = &serde_json::json!({ "goods_ids": goods_ids });
let url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse";
post_send(self.0, url, data).await
}
pub async fn get_goods_approved(
&self,
data: &QueryGoodsApproved,
) -> SdkResult<GoodsApprovedList> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved";
post_send(self.0, url, data).await
}
pub async fn add_role(&self, data: &UserRole) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/role/addrole";
post_send(self.0, url, data).await
}
pub async fn delete_role(&self, data: &UserRole) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/role/deleterole";
post_send(self.0, url, data).await
}
pub async fn get_role_list(&self, data: &QueryRoleList) -> SdkResult<RoleList> {
let url = "https://api.weixin.qq.com/wxaapi/broadcast/role/getrolelist";
post_send(self.0, url, data).await
}
pub async fn push_message(&self, data: &PushMessage) -> SdkResult<MessageId> {
let url = "https://api.weixin.qq.com/wxa/business/push_message";
post_send(self.0, url, data).await
}
}