1use crate::agent::Agent;
2use crate::agent::tools;
3
4pub struct MediaService{
5 pub agent:Agent
6}
7
8impl MediaService {
9
10 pub fn upload_temp_image(&mut self,file_name:&str,file_bytes:Vec<u8>)->Result<serde_json::Value, reqwest::Error>{
14 self.agent.fresh_token();
15 let url=format!("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={}&type=image",self.agent.get_access_token());
16 tools::upload(url,String::from(file_name),file_bytes)
17 }
18
19 pub fn upload_temp_voice(&mut self,file_name:&str,file_bytes:Vec<u8>)->Result<serde_json::Value, reqwest::Error>{
23 self.agent.fresh_token();
24 let url=format!("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={}&type=voice",self.agent.get_access_token());
25 tools::upload(url,String::from(file_name),file_bytes)
26 }
27
28 pub fn upload_temp_video(&mut self,file_name:&str,file_bytes:Vec<u8>)->Result<serde_json::Value, reqwest::Error>{
32 self.agent.fresh_token();
33 let url=format!("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={}&type=video",self.agent.get_access_token());
34 tools::upload(url,String::from(file_name),file_bytes)
35 }
36
37 pub fn upload_temp_file(&mut self,file_name:&str,file_bytes:Vec<u8>)->Result<serde_json::Value, reqwest::Error>{
41 self.agent.fresh_token();
42 let url=format!("https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={}&type=file",self.agent.get_access_token());
43 tools::upload(url,String::from(file_name),file_bytes)
44 }
45
46 pub fn upload_image(&mut self,file_name:&str,file_bytes:Vec<u8>)->Result<serde_json::Value, reqwest::Error>{
50 self.agent.fresh_token();
51 let url=format!("https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token={}",self.agent.get_access_token());
52 tools::upload(url,String::from(file_name),file_bytes)
53 }
54
55
56}