基本上大部分接口传参都是json字符串,少数接口参数比较简单,直接传。
返回数据都是Result
由于access_token是在内部维护更新的,所以agent变量必须是可变的mut
目前可用的接口比较少,会陆续更新上,敬请期待...
git地址:https://gitee.com/gandilong/weixin_rust.git
更新详细文档地址:https://gitee.com/gandilong/weixin_rust/wikis/Home
可能通过weixin_rust中的工具方法自己实现接口调用,例如
```rust use agent::tools;
pub fn someweixininterface(agent:&mut Agent,sonparams:String){ agent.freshtoken(); let url=format!("https://qyapi.weixin.qq.com/cgi-bin/*?accesstoken={}",agent.getaccesstoken()); tools::postjson(url,json_params) }
pub fn someweixininterface(agent:&mut Agent,id:String){ agent.freshtoken(); let url=format!("https://qyapi.weixin.qq.com/cgi-bin/***?accesstoken={}&id={}",agent.getaccesstoken(),id); tools::get_json(url) }
```
rust
use weixin_rust::agent;//引入应用模块
fn main(){
//由于access_token是内部自动维护的,需要定时更新,所以ag必须是mut 可变的
let mut ag= agent::Agent::new("corpid".to_string(),"agent_secret".to_string());
ag.fresh_token();//这个方法一般情况下是不需要手动调用的。只有在刚new出来的agent的情况下才需要。
println!("token={}",ag.get_access_token());//这个方法额外提供的,返回的是&str
}
```rust use weixin_rust::agent;
fn main(){
let mut ag= agent::Agent::new("corpid".tostring(),"agentsecret".tostring());
let r=ag.getapidomainip();//所有接口方法内部会自动刷新accesstoken
println!("{}",r["iplist"]);
//注意:所有接口返回的类型都是:Result
```rust use weixinrust::agent; fn main(){ let mut ag= agent::Agent::new("corpid".tostring(),"agentsecret".tostring()); let paramsjson=json!({ "openuseridlist":["xxx", "yyy"], "sourceagentid":100001 });
//也可以把一个struct转成json字符串
let params_json_str=serde_json::to_string(¶ms_json).unwrap();
let r=ag.openuserid_to_userid(params_json_str);
} ```
```rust use weixinrust::agent; use weixinrust::mail_list;
fn main(){ let mut ag= agent::Agent::new("corpid".tostring(),"agentsecret".tostring()); let mut userservice=ag.getuserservice();//获取用户服务对象 let ur=userservice.getuser(String::from("123456")); println!("{:?}",ur); } ```