当前位置:网站首页>Crmeb second open SMS function tutorial

Crmeb second open SMS function tutorial

2022-06-23 13:39:00 CRMEB

The knowledge payment SMS function supports both Alibaba cloud SMS and crmeb SMS , When we use it, we only need to choose one of two .

So how can we turn on the SMS function of Alibaba cloud ?

First step : First, enter the Alibaba cloud console , In Alibaba cloud SMS module , The application requires a new SMS template

The second step : In the general background of knowledge payment -> system maintenance -> Development configuration -> Configuration classification -> Add a new SMS template under SMS configuration id Save configuration

 Insert picture description here

Click on “ SMS configuration ” name , Enter the sub configuration under SMS configuration

 Insert picture description here

Click Add configuration , choice ‘ The text box ’ type , Fill in the configuration below , Submit configuration

 Insert picture description here

After submission , Get into “ System settings -> System settings -> Alicloud configuration -> SMS configuration ”, Here we can see our new SMS template id To configure .

 Insert picture description here

The third step : Call alicloud SMS interface , Send a text message

The root directory of knowledge payment source code ”extend/service/AliMessageService” Under the sendmsg The method is the sending method of Alibaba cloud SMS ;

$tel: Receive phone number

$setTemplateCode : SMS template ID

$setTemplateParam : Content of short message Parameters are arrays

$setOutId : Can be null

/**
 *  Send a text message 
 * @param string $tel  SMS number 
 * @param string $setSignName  SMS signature 
 * @param string $setTemplateCode  SMS template ID
 * @param array $setTemplateParam  Content of short message 
 * @param string $setOutId  External pipeline extension field 
 */
public static function sendmsg($tel = '', $setTemplateCode = '', $setTemplateParam = [], $setOutId = '')
{
    
    try {
    
        self::init();
        $result = AlibabaCloud::rpc()
            ->product('Dysmsapi')
            ->version('2017-05-25')
            ->action('SendSms')
            ->method('POST')
            ->host('dysmsapi.aliyuncs.com')
            ->options([
                'query' => [
                    'RegionId' => "cn-hangzhou",
                    'PhoneNumbers' => $tel,
                    'SignName' => SystemConfigService::get('smsSignName'),
                    'TemplateCode' => $setTemplateCode,
                    'TemplateParam' => json_encode(is_array($setTemplateParam) ? $setTemplateParam : ['code' => $setTemplateParam]),
                ],
            ])->request()->toArray();
        return $result;
    } catch (ClientException $e) {
    
        return false;
    } catch (ServerException $e) {
    
        return false;
    }
}

What if you send text messages ?

AliMessageService::sendmsg( t e l , tel, tel,setTemplateCode,$setTemplateParam);

For example, the sending of our login verification code

 Insert picture description here

p h o n e yes Pick up closed Of hand machine Number , phone Is the received mobile number , phone yes Pick up closed Of hand machine Number ,smsTemplateCode Is the SMS template ID ,[‘code’ => $code] This is the content of the SMS ; In this way, the transmission is successful .

The source code attachment has been packaged and uploaded to Baidu cloud , You can download it yourself ~

link : https://pan.baidu.com/s/14G-bpVthImHD4eosZUNSFA?pwd=yu27
Extraction code : yu27
Baidu cloud link is unstable , It may fail at any time , Let's keep it tight .

If Baidu cloud link fails , Please leave me a message , When I see it, I will update it in time ~

Open source address
Code cloud address :
http://github.crmeb.net/u/defu

Github Address :
http://github.crmeb.net/u/defu

原网站

版权声明
本文为[CRMEB]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231254160237.html

随机推荐