# `LibWechat.Core`
[🔗](https://github.com/tt67wq/lib-wechat/blob/main/lib/lib_wechat/core.ex#L1)

LibWechat 核心模块，提供对各 API 模块功能的访问。

此模块作为 LibWechat 库的核心接口层，负责将调用委托给相应的具体 API 模块。
为了保持向后兼容性，此模块提供了与原有调用方式相同的接口，但内部实现已重构为更模块化的结构。

# `err_t`

```elixir
@type err_t() :: {:error, LibWechat.Error.t()}
```

# `ok_t`

```elixir
@type ok_t(m) :: {:ok, m}
```

# `child_spec`

# `generate_scheme`

```elixir
@spec generate_scheme(module(), binary(), LibWechat.Typespecs.dict()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

获取小程序 scheme 码。

委托给 `LibWechat.API.MiniProgram.WxaCode.generate_scheme/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `payload` - 请求参数

## 返回值
  * `{:ok, map()}` - 获取成功，返回 scheme 信息
  * `{:error, error}` - 获取失败

# `get`

获取应用实例的配置信息。

## 参数
  * `name` - 应用实例名称

## 返回值
  * `config` - 配置信息的关键字列表

# `get_access_token`

```elixir
@spec get_access_token(module()) :: {:ok, LibWechat.Typespecs.dict()} | err_t()
```

获取 access_token。

委托给 `LibWechat.API.Auth.AccessToken.get/1` 处理。

## 参数
  * `name` - 应用实例名称

## 返回值
  * `{:ok, %{"access_token" => token, "expires_in" => expires}}` - 获取成功
  * `{:error, error}` - 获取失败

# `get_phone_number`

```elixir
@spec get_phone_number(module(), binary(), binary()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

获取用户手机号。

委托给 `LibWechat.API.MiniProgram.PhoneNumber.get/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `code` - 手机号获取凭证

## 返回值
  * `{:ok, map()}` - 获取成功，返回手机号信息
  * `{:error, error}` - 获取失败

# `get_unlimited_wxacode`

```elixir
@spec get_unlimited_wxacode(module(), binary(), LibWechat.Typespecs.dict()) ::
  {:ok, binary()} | err_t()
```

获取小程序码。

委托给 `LibWechat.API.MiniProgram.WxaCode.get_unlimited/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `payload` - 请求参数

## 返回值
  * `{:ok, binary()}` - 获取成功，返回图片二进制数据
  * `{:error, error}` - 获取失败

# `get_urllink`

```elixir
@spec get_urllink(module(), binary(), LibWechat.Typespecs.dict()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

获取小程序 URL Link。

委托给 `LibWechat.API.MiniProgram.WxaCode.get_urllink/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `payload` - 请求参数

## 返回值
  * `{:ok, map()}` - 获取成功，返回 URL Link 信息
  * `{:error, error}` - 获取失败

# `jscode_to_session`

```elixir
@spec jscode_to_session(module(), binary()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

小程序登录凭证校验。

委托给 `LibWechat.API.Auth.AccessToken.code2session/2` 处理。

## 参数
  * `name` - 应用实例名称
  * `code` - 小程序登录时获取的 code

## 返回值
  * `{:ok, %{"openid" => openid, "session_key" => session_key}}` - 获取成功
  * `{:error, error}` - 获取失败

# `msg_sec_check`

```elixir
@spec msg_sec_check(module(), binary(), LibWechat.Typespecs.dict()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

检查文本是否含有违法违规内容。

委托给 `LibWechat.API.MiniProgram.Security.msg_sec_check/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `payload` - 请求参数

## 返回值
  * `{:ok, map()}` - 检测成功，返回检测结果
  * `{:error, error}` - 检测失败

# `start_link`

启动 LibWechat 核心模块的 Agent 进程。

## 参数
  * `name` - 应用实例名称
  * `finch` - Finch HTTP 客户端实例
  * `config` - 配置信息

## 返回值
  * `{:ok, pid}` - 启动成功
  * `{:error, reason}` - 启动失败

# `subscribe_send`

```elixir
@spec subscribe_send(module(), binary(), LibWechat.Typespecs.dict()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

发送订阅消息。

委托给 `LibWechat.API.Message.Subscribe.send/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `payload` - 请求参数

## 返回值
  * `{:ok, map()}` - 发送成功，返回结果
  * `{:error, error}` - 发送失败

# `uniform_send`

> This function is deprecated. This API has been unsupported. For more details, please view https://developers.weixin.qq.com/community/develop/doc/000ae8d6348af08e7030bc2546bc01?blockType=1.

```elixir
@spec uniform_send(module(), binary(), LibWechat.Typespecs.dict()) ::
  {:ok, LibWechat.Typespecs.dict()} | err_t()
```

下发统一消息。

委托给 `LibWechat.API.Message.Subscribe.uniform_send/3` 处理。

## 参数
  * `name` - 应用实例名称
  * `token` - 接口调用凭证
  * `payload` - 请求参数

## 返回值
  * `{:ok, map()}` - 发送成功，返回结果
  * `{:error, error}` - 发送失败

---

*Consult [api-reference.md](api-reference.md) for complete listing*
