1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! 微信小程序用户信息模块
//!
//! 该模块提供了获取和处理微信小程序用户信息的功能,包括用户基本信息和手机号信息。
//!
//! # 登录信息
//!
//! ```no_run
//! use wechat_minapp::client::WechatMinappSDK;
//! use wechat_minapp::user::{User, Contact};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = WechatMinappSDK::new("app_id", "secret");
//! let user = User::new(client);
//! let code = "0816abc123def456";
//! let credential = user.login(code).await?;
//!
//! println!("用户OpenID: {}", credential.open_id());
//! println!("会话密钥: {}", credential.session_key());
//!
//! Ok(())
//! }
//! ```
//!
//! 解析用户基本信息(需要前端传递加密数据)
//! ```no_run
//! use wechat_minapp::client::WechatMinappSDK;
//! use wechat_minapp::user::{User, Contact};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = WechatMinappSDK::new("app_id", "secret");
//! let user = User::new(client);
//! let code = "0816abc123def456";
//! let credential = user.login(code).await?;
//! let info = credential.decrypt(&encrypted_data, &iv)?;
//! println!("昵称: {}", info.nickname());
//! println!("性别: {}", info.gender());
//! println!("地区: {}-{}-{}", info.country(), info.province(), info.city());
//! println!("头像: {}", info.avatar());
//! println!("AppID: {}", info.app_id());
//! println!("时间戳: {}", info.timestamp());
//!
//! Ok(())
//! }
//! ```
//!
//! 获取用户手机号
//! ```no_run
//! use wechat_minapp::client::WechatMinappSDK;
//! use wechat_minapp::user::{User, Contact};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = WechatMinappSDK::new("app_id", "secret");
//! let user = User::new(client);
//! let code = "0816abc123def456";
//! let contact = user.get_contact(code, None).await?;
//! let info = credential.decrypt(&encrypted_data, &iv)?;
//! println!("用户手机号: {}", contact.phone_number());
//!
//! Ok(())
//! }
//! ```
//!
use crateWechatMinappSDK;