The new communication SDK of Alibaba Cloud keeps reporting getProfile failure errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrea1701
    New Member
    • Nov 2017
    • 34

    The new communication SDK of Alibaba Cloud keeps reporting getProfile failure errors

    I used Alibaba Cloud’s new communication SDK by integrating the SDK to the composer for installation.
    Class loading worked fine, but an error was prompted at the following stage:
    //acsCleint of initialization access
    $profile = DefaultProfile: :getProfile($re gion, $accessKeyId, $accessKeySecre t);
    DefaultProfile: :addEndpoint("c n-hangzhou","cn-hangzhou", $product, $domain);
    Error message:

    It outputs the message. The self::$endpoint s value is “null”.
    The complete code of my function is as follows:
    public function smsNew($data=[]){
    //Replace the value here with your own AK
    $accessKeyId = Config::get('al idayu.appkey');
    $accessKeySecre t = Config::get('al idayu.secretKey ');
    //Name of the text message API product (The text message product name is fixed and does not require modification.)
    $product = "Dysmsapi";
    //Domain name of the text message API product (The interface address is fixed and does not require modification.)
    $domain = "dysmsapi.aliyu ncs.com";
    //Multiple regions are not supported yet (Only cn-hangzhou is supported for now. Do not change it.)
    $region = "cn-hangzhou";
    //acsCleint of initialization access
    $profile = DefaultProfile: :getProfile($re gion, $accessKeyId, $accessKeySecre t);
    DefaultProfile: :addEndpoint("c n-hangzhou","cn-hangzhou", $product, $domain);
    $acsClient= new DefaultAcsClien t($profile);
    $request = new SendSmsRequest( );
    $request->setPhoneNumber s($data['mobile']);
    //Required – text message signature
    $request->setSignName(Co nfig::get('alid ayu.FreeSignNam e'));
    //Required – text message template code
    $request->setTemplateCod e($data['template']);
    //Optional – required if the template contains a variable that should be replaced (JSON format)
    $request->setTemplatePar am(json_encode( $data['param']));
    //Optional – Send the text message serial number
    // $request->setOutId("1234 ");
    //Initiate an access request
    $acsResponse = $acsClient->getAcsResponse ($request);
    dump($acsRespon se);
    return $acsResponse;
    }
    My accesskey and secretKey are generated at the Access Key administration and are available.
    I ran a test just now and it turned out that text message could be sent in the demo but not so in the framework.
  • IvanH
    New Member
    • Nov 2017
    • 51

    #2
    The way I loaded classes is to put the SDK in vendor and let the framework load them automatically. The error cause has nothing to do with the loading method.
    The demo code that Alibaba Cloud - Cloud Communication provides in the Help Manual cannot be directly be copied and used. I made the same mistake.
    Compare the demo code in the Help Manual and the demo code in the SDK and you will find the difference:
    The SDK demo contains an item of loading region node configuration which is absent in the Help Manual demo.
    use Aliyun\Core\Con fig;
    use Aliyun\Core\Pro file\DefaultPro file;
    use Aliyun\Core\Def aultAcsClient;
    use Aliyun\Api\Sms\ Request\V201705 25\SendSmsReque st;
    use Aliyun\Api\Sms\ Request\V201705 25\QuerySendDet ailsRequest;

    // Loading region node configuration
    Config::load();
    So the leading part should be the manual setting of loading region node configuration in the erroneous code mentioned earlier:
    \Aliyun\Core\Co nfig::load();

    Comment

    Working...