简体   繁体   English

WooCommerce Rest API 用于登录和注册

[英]WooCommerce Rest API for Login and Registration

I enable WooCommerce rest API and generate consumer_key and consumer_secret.我启用 WooCommerce rest API 并生成 consumer_key 和 consumer_secret。 I am developing a WooCommerce shop native mobile application.我正在开发一个 WooCommerce 商店原生移动应用程序。 I do research for the WooCommerce rest API for My Account page login and registration form but can't see the solution.我为“我的帐户”页面登录和注册表单的 WooCommerce rest API 进行研究,但看不到解决方案。 So if anyone has an idea about My Account page login and registration API then please suggest the solution for this.因此,如果有人对我的帐户页面登录和注册 API 有任何想法,请为此提出解决方案。

Best regard, Ketan.最好的问候,凯坦。

==> First install this https://wordpress.org/plugins/json-api-user/ plugin ==> 首先安装这个https://wordpress.org/plugins/json-api-user/插件

==> Registration API: ==>注册API:

  1. Before the registration call, following API for New nonce generate:在注册调用之前,按照 API 生成新的随机数:

    https://site_URL/api/get_nonce/?controller=user&method=register https://site_URL/api/get_nonce/?controller=user&method=register

  2. After that use following API for registration:之后使用以下 API 进行注册:

    https://site_URL/api/user/register/?username=john&email=john1@gmail.com&user_pass=123456789&nonce=HERE_INSERT_ABOVE_GENERATED_RANDOM_NONCE_STRING&display_name=username https://site_URL/api/user/register/?username=john&email=john1@gmail.com&user_pass=123456789&nonce=HERE_INSERT_ABOVE_GENERATED_RANDOM_NONCE_STRING&display_name=username

==> Login API: ==>登录 API:

  1. Insert the following code in your child theme functions.php file:在您的子主题 functions.php 文件中插入以下代码:



    add_action( 'rest_api_init', 'register_api_hooks' );
    function register_api_hooks() {
      register_rest_route(
        'custom-plugin', '/login/',
        array(
          'methods'  => 'GET',
          'callback' => 'login',
        )
      );
    }


function login($request){
    $creds = array();
    $creds['user_login'] = $request["username"];
    $creds['user_password'] =  $request["password"];
    $creds['remember'] = true;
    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) )
      echo $user->get_error_message();
    return $user;
}
add_action( 'after_setup_theme', 'custom_login' );
  1. After that use following API for login:之后使用以下 API 进行登录:

    https://site_URL/wp-json/custom-plugin/login?username=USERNAME_OR_EMAIL-ID&password=PASSWORD https://site_URL/wp-json/custom-plugin/login?username=USERNAME_OR_EMAIL-ID&password=PASSWORD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM