PHP code example of niceyo / xhy-sms

1. Go to this page and download the library: Download niceyo/xhy-sms 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/ */

    

niceyo / xhy-sms example snippets


return [ 
    'gateways' => [  //需要使用那个配置那个
        'aliyun' => [ 
            'access_key_id' => env('ALIYUN_API_KEY'),
            'access_key_secret' => env('ALIYUN_API_KEY_SECRET'),
            'sign_name' => env('SIGN_NAME'),
        ],
        'qcloud' => [
            'sdk_app_id' => '', // SDK APP ID
            'app_key' => '', // APP KEY
            'sign_name' => '',
        ],
    ],
];

    use Nice\XhySms\XhySms;    
    /*
        扩展包已经自己绑定一个单例到容器中 所以你也可以这样 
        app('XhySms')->send();
    */
    public function show(XhySms $Sms) {  //阿里云 
        $Sms->send('185****4076', [
            'template' => 'SMS_******34', 
            'data' => [
              'code' => 123456   //变量名
            ]
        ],'aliyun');
    }
    
    public function show(XhySms $Sms) {  //腾讯云
            $Sms->send('185****4076', [
            'template' => '6***9', 
            'data' => [
                123456, 555555
            ]
        ],'qcloud');
    }
        

    $config =  [
        'gateways' => [
            'aliyun' => [ 
                'access_key_id' => '',
                'access_key_secret' => '',
                'sign_name' => '',
            ],
            'qcloud' => [
                'sdk_app_id' => '', // SDK APP ID
                'app_key' => '', // APP KEY
                'sign_name' => '',
            ],
        ],
    ];
    
    $Sms = new XhySms($config);
    
    $Sms->send('185****4076', [
       'template' => 'SMS_******34', 
       'data' => [
          'code' => 123456   
       ]
    ],'aliyun');
    
shell
touch config/xhysms.php