×ðÁú¿­Ê±¹ÙÍøµÇ¼

ThinkPHP6ÖÐÔõÑù¾ÙÐжÌÐÅ·¢ËͲÙ×÷£¿

Ëæ×ÅÒƶ¯»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬¶ÌÐÅͨѶÒѾ­³ÉΪÈËÃÇÒ»Ñùƽ³£ÏàͬµÄÒ»ÖÖºÜÊÇÖ÷ÒªµÄ·½·¨¡£ÔÚÐí¶à³¡¾°Ï£¬ÎÒÃǶ¼ÐèҪʹÓöÌÐÅ·¢Ë͹¦Ð§£¬ÓÃÓÚÑéÖ¤Âë¡¢ÓªÏúµÈ²Ù×÷¡£¶øÔÚthinkphp6¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý¼òÆÓµÄÉèÖúÍŲÓã¬ÇáËÉʵÏÖ¶ÌÐÅ·¢ËͲÙ×÷¡£

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚÉèÖÃÎļþconfigĿ¼ÏµÄsms.phpÖУ¬¾ÙÐжÌÐÅƽ̨µÄÉèÖá£ÔÚ´ËÎÒÃÇÒÔ°¢ÀïÔƶÌÐÅЧÀÍΪÀý¡£ÔÚÉèÖÃÎļþÖУ¬ÐèÒªÉèÖöÌÐÅƽ̨µÄAccessKey ID¡¢AccessKey Secret¡¢ÊðÃûºÍÄ£°åµÈÄÚÈÝ¡£Ïêϸ´úÂëÈçÏ£º

<?php

return [
    'aliyun' => [
        'access_key_id' => 'ÌîдAccessKey',
        'access_key_secret' => 'ÌîдAccessKey Secret',
        'sign_name' => 'Ìîд¶ÌÐÅÊðÃû',
        'template_code' => [
            'verify' => 'Ìîд¶ÌÐÅÄ£°åCODE',
        ]
    ],
];

µÇ¼ºó¸´ÖÆ

½ÓÏÂÀ´£¬ÎÒÃÇÐèҪװÖÃSDKÀ©Õ¹°ü¡£ÓÉÓÚ°¢ÀïÔƶÌÐÅЧÀÍÐèÒªAlibaba Cloud SDK for PHPÖ§³Ö£¬ÒÔÊÇÎÒÃÇÐèҪͨ¹ýComposer¾ÙÐÐ×°Öá£ÔÚÏÂÁîÐÐÖÐÊäÈëÒÔÏÂÏÂÁ

composer require alibabacloud/sdk

µÇ¼ºó¸´ÖÆ

×°ÖÃÀֳɺó£¬ÎÒÃǾͿÉÒÔ×îÏÈŲÓöÌÐÅ·¢Ë͹¦Ð§ÁË¡£ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ´úÂëʵÏÖ¶ÌÐÅ·¢ËÍ£º

<?php

namespace appcontroller;

use AlibabaCloudClientAlibabaCloud;
use AlibabaCloudClientExceptionClientException;
use AlibabaCloudClientExceptionServerException;
use thinkacadeConfig;

class Sms
{
    /**
     * ·¢ËͶÌÐÅÑéÖ¤Âë
     * @param string $mobile ÊÖ»úºÅÂë
     * @param string $code ÑéÖ¤Âë
     * @return bool ÊÇ·ñ·¢ËÍÀÖ³É
     */
    public function sendVerifySms($mobile, $code)
    {
        //»ñÈ¡ÉèÖÃÐÅÏ¢
        $config = Config::get('sms.aliyun');
        //ÉèÖöÌÐÅÄ£°å²ÎÊý
        $templateParam = [
            'code' => $code
        ];
        try {
            //ŲÓð¢ÀïÔƶÌÐÅ·¢ËͽӿÚ
            $result = AlibabaCloud::rpc()
                ->product('Dysmsapi')
                //¿Éƾ֤ÏÖÕæÏàÐÎÑ¡Ôñ²î±ðµÄЧÀ͵ØÇø
                ->regionId('cn-hangzhou')
                ->version('2017-05-25')
                ->action('SendSms')
                ->method('POST')
                ->host('dysmsapi.aliyuncs.com')
                ->options([
                    'query' => [
                        'RegionId' => 'cn-hangzhou',
                        'PhoneNumbers' => $mobile,
                        'SignName' => $config['sign_name'],
                        'TemplateCode' => $config['template_code']['verify'],
                        'TemplateParam' => json_encode($templateParam),
                    ],
                ])
                ->request();
            //Åж϶ÌÐÅ·¢ËÍ״̬
            if ($result->toArray()['Code'] == 'OK') {
                return true;
            } else {
                return false;
            }
        } catch (ClientException $e) {
            return false;
        } catch (ServerException $e) {
            return false;
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬Ê×ÏÈÎÒÃÇ´ÓÉèÖÃÎļþ¶ÁÈ¡¶ÌÐÅƽ̨µÄÉèÖÃÐÅÏ¢£¬È»ºóÉèÖöÌÐÅÄ£°å²ÎÊý£¬×îºóŲÓð¢ÀïÔƶÌÐÅ·¢ËͽӿÚ¡£ÔÚ½Ó¿ÚŲÓõÄÀú³ÌÖУ¬ÎÒÃÇÐèÒªÉèÖÃÊÖ»úºÅÂë¡¢¶ÌÐÅÊðÃû¡¢¶ÌÐÅÄ£°åCODEºÍ¶ÌÐÅÄ£°å²ÎÊýµÈÐÅÏ¢¡£½Ó¿ÚŲÓÃÀֳɺó£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÅжϷµ»ØµÄ״̬ÂëÀ´È·¶¨¶ÌÐÅÊÇ·ñ·¢ËÍÀֳɡ£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

×ܽáÀ´Ëµ£¬ThinkPHP6¿ò¼ÜÖÐʵÏÖ¶ÌÐÅ·¢Ë͹¦Ð§Ïà¶ÔÀ´Ëµ½ÏÁ¿¼òÆÓ£¬Ö»Ðè¾ÙÐмòÆÓµÄÉèÖúÍŲÓü´¿É¡£ÔÚʹÓÃÀú³ÌÖУ¬ÐèҪעÖر £»¤ºÃAccessKeyºÍAccessKey SecretµÈÒþ˽ÐÅÏ¢¡£Í¬Ê±£¬ÔÚŲÓýӿÚʱ£¬Ò²ÐèҪעÖØÒì³£µÄ´¦Àí£¬×èÖ¹Òò½Ó¿ÚŲÓÃʧ°Ü¶ø·ºÆð³ÌÐòÒì³£¡£

ÒÔÉϾÍÊÇThinkPHP6ÖÐÔõÑù¾ÙÐжÌÐÅ·¢ËͲÙ×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ