搜索插件、代码仓与 APP 分类

插件详情v5.0.2

wp_json_api

适用于Flutter移动应用的WordPress和WooCommerce JSON API。该API支持登录、注册新用户、获取用户信息等更多功能。

AndroidiOSmacOS
近 30 天下载
354
喜欢数
44
Pub 分数
160

安装插件

flutter pub add wp_json_api

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

wp_json_api 包提供了一个与 WordPress 和 WooCommerce 的 JSON REST API 兼容的 Flutter 接口。它使用户能够执行登录和注册等身份验证任务,获取用户信息,并管理基于 WordPress 的站点数据。专为移动应用程序设计,支持 Android、iOS 和 macOS 平台。该包简化了与无头 WordPress 配置的集成,非常适合电子商务和内容驱动的应用程序。由 Woosignal 维护,并可通过 pub.dev 获取。

适合场景

  • 移动应用用户身份验证
  • WooCommerce 产品和订单检索
  • Flutter 应用中的用户资料管理
  • 无头 WordPress 内容展示
  • 电子商务应用程序与WooCommerce集成

主要特点

  • 内置登录和注册
  • 支持 WordPress 和 WooCommerce API
  • 跨平台(Android、iOS、macOS)
  • 用户数据访问的简单 API
  • 开源且积极维护

适合对象

  • Flutter 开发人员构建基于 WordPress 的应用程序
  • 使用 WooCommerce 的电子商务应用
  • 需要用户账户管理的应用程序
  • 使用无头 WordPress 的项目
  • 与 RESTful WordPress API 集成的开发者

使用建议

  • 需要一个启用了 REST API 的 WordPress 站点
  • 身份验证令牌必须安全处理
  • 仅限 WordPress/WooCommerce 生态系统
  • 依赖外部服务器配置
  • 可能需要额外的错误处理来应对网络问题

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

WordPress and WooCommerce JSON API Dart package for Flutter

You can download the WordPress plugin here WP JSON API.

Install the WordPress plugin to use this Flutter package.

API features:

WordPress

  • Register/Sign Up API for Users
  • Login (with email or username)
  • Get Users Info
  • Update Users Info
  • Update Users Password
  • Add role to a user
  • Remove role from a user
  • Delete a user

WooCommerce

  • Get Customers Info (Billing and Shipping)
  • Update Customers details

To use this API you must have the WP JSON API Plugin installed first on your WordPress site, you can download it via the WooSignal website.

Getting Started

In your flutter project add the dependency:

dependencies:
  ...
  wp_json_api: ^4.3.8
Usage example

Import wp_json_api.dart

import 'package:wp_json_api/wp_json_api.dart';
Example using Wp JSON API
import 'package:wp_json_api/wp_json_api.dart';
...

void main() {

WPJsonAPI.instance.init(baseUrl: "https://mysite.com");

...
Call a method from the request callback
try {
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
          .api((request) => request.wpLogin(
            email: email,
            password: password
          ));
} on Exception catch (e) {
    print(e);
}
Available API Requests
WordPress - Get Nonce
  • Used for returning a valid nonce
WPNonceResponse wpNonceResponse = await WPJsonAPI.instance
          .api((request) => request.wpNonce());
WordPress - Verify Nonce
  • Used for verifying register and login request
WPNonceVerifiedResponse wpNonceVerifiedResponse = await WPJsonAPI.instance
          .api((request) => request.wpNonceVerify(
            nonce: nonce
          ));
WordPress - Login with email
  • Used to login a user
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
      .api((request) => request.wpLogin(
          email: email,
          password: password,
          authType: WPAuthType.WpEmail
      ));
WordPress - Login with username
  • Used to login a user
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
      .api((request) => request.wpLogin(
          username: username,
          password: password,
          authType: WPAuthType.WpUsername
      ));
WordPress - Register
  • Used to register a user
  • The username parameter is required, ensure that this is unique
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
      .api((request) => request.wpRegister(
          email: email,
          password: password,
          // username: username // optional - the library will automatically generate a username if not provided
      ));
WordPress - Get Users Info
  • Used to get a WordPress users info
  • After you login/register, you can all this method to get the users info
WPUserInfoResponse wpUserInfoResponse = await WPJsonAPI.instance
        .api((request) => request.wpGetUserInfo());
WordPress - Update Users Info
  • Used to update a WordPress users info
  • After you login/register, you can all this method to update the users info
WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance
        .api((request) => request.wpUpdateUserInfo(
          firstName: firstName,
          lastName: lastName,
          displayName: displayName
      ));
WordPress - Update users password
  • Used to update a users password
  • After you login/register, you can all this method to update the users password
WPUserResetPasswordResponse wpUserResetPasswordResponse = await WPJsonAPI.instance
        .api((request) => request.wpResetPassword(
            password: password
        ));
WordPress - Add a role to a user
  • Used to add a role to a user in WordPress
  • After you login/register, you can all this method to add a role to the user
WPUserAddRoleResponse wpUserAddRoleResponse = await WPJsonAPI.instance
        .api((request) => request.wpUserAddRole(
            role: "customer" // e.g. customer, subscriber
        ));
WordPress - Remove a role from a user
  • Used to remove a role from a user in WordPress
  • After you login/register, you can all this method to remove a role from the user
WPUserRemoveRoleResponse wpUserRemoveRoleResponse = await WPJsonAPI.instance
        .api((request) => request.wpUserRemoveRole(
            role: "customer" // e.g. customer, subscriber
        ));
WordPress - Delete a user
  • Used to delete a user in WordPress
  • After you login/register, you can all this method to delete the user
  • You can pass an optional argument 'reassign' to reassign posts and links to new User ID.
WPUserDeleteResponse wpUserDeleteResponse = await WPJsonAPI.instance
        .api((request) => request.wpUserDelete());
WooCommerce - Register
  • Used to register a user
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
      .api((request) => request.wpRegister(
          email: email,
          password: password
      ));
WooCommerce - Get users info in WooCommerce
  • Used to get WooCommerce info for a given user
  • After you login/register, you can all this method to get the users WooCommerce info
WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
          .api((request) => request.wcCustomerInfo(
          userToken
      ));
WooCommerce - Update users info in WooCommerce
  • Used to update a users WooCommerce details
  • All the parameter are optional so if you wanted to just update the name, you could just add first_name and last_name
  • After you login/register, you can all this method to update the users WooCommerce info
WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
        .api((request) => request.wcUpdateCustomerInfo(
            firstName: firstName,
            lastName: lastName,
            displayName: displayName,
            billingFirstName: billingFirstName,
            billingLastName: billingLastName,
            billingCompany: billingCompany,
            billingAddress1: billingAddress1,
            billingAddress2: billingAddress2,
            billingCity: billingCity,
            billingState: billingState,
            billingPostcode: billingPostcode,
            billingCountry: billingCountry,
            billingEmail: billingEmail,
            billingPhone: billingPhone,
            shippingFirstName: shippingFirstName,
            shippingLastName: shippingLastName,
            shippingCompany: shippingCompany,
            shippingAddress1: shippingAddress1,
            shippingAddress2: shippingAddress2,
            shippingCity: shippingCity,
            shippingState: shippingState,
            shippingPostcode: shippingPostcode,
            shippingCountry: shippingCountry,
            shippingEmail: shippingEmail,
            shippingPhone: shippingPhone
        ));
WooCommerce Points and Rewards - Get user's points
  • This is used to get the user's current points in the WooCommerce Points and Rewards plugin
  • After you login/register, you can all this method to get the users points
WcPointsAndRewardUser wcPointsAndRewardUser = await WPJsonAPI.instance
          .api((request) => request.wcPointsAndRewardsUser());
WooCommerce Points and Rewards - Calculate the value of points
  • This is used to calculate the value of points in the WooCommerce Points and Rewards plugin
  • After you login/register, you can all this method to calculate the value of points
WcPointsAndRewardCalculatePoints wcPointsAndRewardsCalculatePoints = await WPJsonAPI.instance
          .api((request) => request.wcPointsAndRewardsCalculatePoints(
          points: 100
      ));

For help getting started with WooSignal, view our online documentation, which offers a more detailed guide.

Usage

To use this plugin, add wp_json_api as a dependency in your pubspec.yaml file.

Note

Install our WordPress plugin "WP JSON API" v3.4.0 to use this flutter plugin.

Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目