PHP code example of xiaosongshu / message

1. Go to this page and download the library: Download xiaosongshu/message library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xiaosongshu / message example snippets

 

use Xiaosongshu\Message\AliEmail;
use Xiaosongshu\Message\TencentEmail;
use Xiaosongshu\Message\TencentSms;
use Xiaosongshu\Message\MessageClient;
use Xiaosongshu\Message\AliSms;


        /** 阿里云短信发送配置 */
        $configASMS=[
            'accessKeyId'=>'',
            'accessKeySecret'=>'',
            'signName'=>'',
            'sdkAppId'=>""
        ];
        $res=(new MessageClient($configASMS))->Asms->setTemplate("SMS_154950909")->setConTent(['code' => rand(100000,999999)])->sendTo([''])->send();
        $res = AliSms::config($configASMS)->setTemplate("SMS_154950909")->setConTent(['code' => rand(100000,999999)])->sendTo([''])->send();
        $res = MessageClient::Asms()->config($configASMS)->setTemplate("SMS_154950909")->setConTent(['code' => rand(100000,999999)])->sendTo([''])->send();

        
        /** 阿里云邮件发送配置 */
        $configAEmail=[
            'accessKeyId'=>'',
            'accessKeySecret'=>'',
            'fromAddress'=>''
        ];
        $res = (new MessageClient($configAEmail))->Aemail->setTitle('标题')->setContent(['你好呀'])->sendTo([''])->send();
        $res = AliEmail::config($configAEmail)->setTitle('标题')->setContent(['你好呀'])->sendTo([''])->send();
        $res = MessageClient::Aemail()->config($configAEmail)->setTitle('标题')->setContent(['你好呀'])->sendTo([''])->send();


        /** 腾讯短信发送配置 */
        $config=[
            'accessKeyId'=>'',
            'accessKeySecret'=>'',
            'signName'=>"",
            'sdkAppId'=>""
        ];
        $res=(new MessageClient($config))->Tsms->setTemplate("1430565")->setConTent(['code' => rand(100000,999999)])->sendTo([''])->send();
        $res=TencentSms::config($config)->setTemplate("1430565")->setConTent(['code' => rand(100000,999999)])->sendTo([''])->send();
        $res=MessageClient::Tsms()->config($config)->setTemplate("1430565")->setConTent(['code' => rand(100000,999999)])->sendTo([''])->send();
        /** 腾讯邮件发送配置 */
        $config= [
            'accessKeyId'=>'',
            'accessKeySecret'=>'',
            'fromAddress'=>''
        ];
        $res=(new MessageClient($config))->Temail->setTemplate()->setTitle('恭喜发财')->setConTent(['username' => '牡丹花'])->sendTo([''])->send();
        $res = TencentEmail::config($config)->setTemplate()->setTitle('恭喜发财')->setConTent(['username' => '牡丹花'])->sendTo([''])->send();
        $res=MessageClient::Temail()->config($config)->setTemplate()->setTitle('恭喜发财')->setConTent(['username' => '躺不平,摆不烂'])->sendTo([''])->send();
      
 
        $config= [
            'accessKeyId'=>'',
            'accessKeySecret'=>'',
            'fromAddress'=>''
        ];
       /** 对服务进行扩展:只在程序当前生命周期内有效。 */
        $factory = new MessageClient();
        /** 注册其他的消息服务类 例如Email第三方发送邮件服务,当然Email必须继承接口 Xiaosongshu\Message\provider\MessageProviderInterface */
        $factory->bind('other',Email::class);
        /** 调用已注册的服务 */
        $factory->other->config($config)->setTemplate()->setTitle('测试')->setConTent(['content' => '对服务进行扩展呢'])->sendTo(['[email protected]'])->send();

        /** 静态注册  */
        MessageClient::register('other',Email::class);
        /** 静态调用 */
        MessageClient::other()->config($config)->setTemplate()->setTitle('恭喜发财')->setConTent(['username' => '躺不平,摆不烂'])->sendTo([''])->send();