消息:Class 类型不存在 - WebAPI Magento 2.3

Message: Class type does not exist - WebAPI Magento 2.3

main.CRITICAL:报告编号:webapi-61d924815c991;消息:Class 类型不存在 {“异常”:[对象](异常(代码:-1):报告 ID:webapi-61d924815c991;消息:Class 类型不存在于 /var/www_magento/apimagento/vendor/magento/framework/Webapi/ErrorProcessor.php:208,ReflectionException(代码:-1):Class 类型不存在于 /var/www_magento/apimagento/vendor/magento/framework/Webapi/ServiceInputProcessor.php:264)"} []

etc/module.xml

<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
    <route url="/V1/manageuser/createuser" method="POST">
        <service class="MobileApi\PhoneUser\Api\PhoneUserManageInterface" method="registerPhoneUser"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
    </route>
    <route url="/V1/manageuser/get" method="POST">
        <service class="MobileApi\PhoneUser\Api\PhoneUserManageInterface" method="getUserByMobile"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
    </route>
    <route url="/V1/manageuser/login" method="POST">
        <service class="MobileApi\PhoneUser\Api\PhoneUserManageInterface" method="doPhoneLogin"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
    </route>
</routes>

Api/PhoneUserManageInterface.php

<?php
namespace MobileApi\PhoneUser\Api;

/**
 * @api
 */
interface PhoneUserManageInterface
{
    /**
     * Make the login with user mobile number
     * @param string $phonenumber
     * @return string Token created
     * @throws \Magento\Framework\Exception\AuthenticationException
     */
    public function doPhoneLogin($phonenumber);
    
    /**
     * get details of user using mobile number
     * @param string $phonenumber
     * @return string user_email
     * @throws \Magento\Framework\Exception\AuthenticationException
     */
    public function getUserByMobile($phonenumber);
    
    /**
     * create new user
     * @param type $firstName
     * @param type $lastName
     * @param type $email
     * @param type $phonenumber
     * @return mixed token
     * @throws \Magento\Framework\Exception\AlreadyExistsException
     */
    public function registerPhoneUser($firstName, $lastName, $email, $phonenumber);
    
}

model/PhoneUserManage.php

<?php
namespace MobileApi\PhoneUser\Model;
use MobileApi\PhoneUser\Api\PhoneUserManageInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Model\Customer;
use Magento\Customer\Model\CustomerFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\State\InputMismatchException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Integration\Model\Oauth\TokenFactory as TokenModelFactory;
use Magento\Customer\Api\Data\CustomerExtensionFactory;
use Magento\Framework\Webapi\ServiceInputProcessor;
use Magento\Framework\Webapi\ErrorProcessor;

class PhoneUserManage implements PhoneUserManageInterface
{
    /**
     * Token Model
     *
     * @var TokenModelFactory
     */
    private $tokenModelFactory;

    /**
     * @type StoreManagerInterface
     */
    protected $storeManager;
    /**
     * @type CustomerFactory
     */
    protected $customerFactory;
    /**
     * @var CustomerInterfaceFactory
     */
    protected $customerDataFactory;
    /**
     * @var CustomerRepositoryInterface
     */
    protected $customerRepository;
    /**
     * @var CustomerExtensionFactory
     */
    protected $customerExtensionFactory;
    /**
     * user constructor.
     * @param CustomerFactory $customerFactory
     * @param CustomerInterfaceFactory $customerDataFactory
     * @param CustomerRepositoryInterface $customerRepository
     * @param StoreManagerInterface $storeManager
     * @param TokenModelFactory $tokenModelFactory
     */
    public function __construct(
        CustomerFactory $customerFactory,
        CustomerInterfaceFactory $customerDataFactory,
        CustomerRepositoryInterface $customerRepository,
        StoreManagerInterface $storeManager,
        TokenModelFactory $tokenModelFactory,
        CustomerExtensionFactory $customerExtensionFactory
    ) {
        $this->customerFactory = $customerFactory;
        $this->customerRepository = $customerRepository;
        $this->customerDataFactory = $customerDataFactory;
        $this->storeManager = $storeManager;
        $this->tokenModelFactory = $tokenModelFactory;
        $this->customerExtensionFactory = $customerExtensionFactory;
    }

    /**
     * 
     * @param type $firstName
     * @param type $lastName
     * @param type $email
     * @param type $phonenumber
     * @return string
     * @throws AlreadyExistsException
     */
    public function createPhoneUser($firstName, $lastName, $email, $phonenumber){
        
        return "createPhoneUser {$phonenumber} on ".date('d/m/Y H:i:s');
        
    }
    
    public function doPhoneLogin($phonenumber)
    {
        return "doPhoneLogin {$phonenumber} on ".date('d/m/Y H:i:s');
    }
    
    public function getUserByMobile($phonenumber)
    {
        return "getUserByMobile {$phonenumber} on ".date('d/m/Y H:i:s');
    }
}

奇怪的是 doPhoneLogin 和 getUserByMobile 工作正常。但是当我尝试 createPhoneUser 时,我遇到了上述错误。

请指导我解决这个问题。

/**
 * create new user
 * @param type $firstName
 * @param type $lastName
 * @param type $email
 * @param type $phonenumber
 * @return mixed token
 * @throws \Magento\Framework\Exception\AlreadyExistsException
 */
public function registerPhoneUser($firstName, $lastName, $email, $phonenumber);

应该是(IIRC 你也应该删除生成的,至少,在更改之后)

/**
 * create new user
 * @param string $firstName
 * @param string $lastName
 * @param string $email
 * @param string $phonenumber
 * @return mixed
 * @throws \Magento\Framework\Exception\AlreadyExistsException
 */
public function registerPhoneUser($firstName, $lastName, $email, $phonenumber);

服务是从接口中的文档块定义的,其中的任何错别字或错误都会破坏一切。 Read more at devdocs for rules and details