WooCommerce Rest API用于登录和注册

我启用WooCommerce rest API,并生成consumer_key和consumer_secret。我正在开发WooCommerce商店本地移动应用程序。我正在研究“我的帐户” WooCommerce rest API登录页面和注册表格,但看不到解决方案。因此,如果有人对“我的帐户”页面登录和注册API有想法,请提出解决方案。

最诚挚的问候, Ketan。

zhubinlove 回答:WooCommerce Rest API用于登录和注册

==>首先安装此https://wordpress.org/plugins/json-api-user/插件

==> 注册API:

  1. 在注册调用之前,将生成以下用于New nonce的API:

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

  2. 之后,使用以下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

==> 登录API:

  1. 在子主题的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. 之后,使用以下API登录:

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

本文链接:https://www.f2er.com/3168494.html

大家都在问