PHP code example of singka / singka-hwsms
1. Go to this page and download the library: Download singka/singka-hwsms 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/ */
singka / singka-hwsms example snippets
// +----------------------------------------------------------------------
// | 胜家云 [ SingKa Cloud ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.singka.net All rights reserved.
// +----------------------------------------------------------------------
// | 宁波晟嘉网络科技有限公司
// +----------------------------------------------------------------------
// | Author: ShyComet <[email protected]>
// +----------------------------------------------------------------------
namespace app\home\controller;
use SingKa\HwSms\HwSms;
class Index
{
/**
* 短信发送示例
*
* @url 华为云短信APP接入地址+接口访问URI
* @appKey 华为云短信appKey
* @appSecret 华为云短信appSecret
* @sender 国内短信签名通道号或国际/港澳台短信通道号
* @signature 华为云短信签名
* @statusCallback 短信发送状态返回接收地址,可以为空
*/
public function smsDemo()
{
$config['url'] = 'https://rtcsms.cn-north-1.myhuaweicloud.com:10743';
$config['appKey'] = 'PkT889B*************wM0GAi';
$config['appSecret'] = 'U58fd****************0o4N';
$config['sender'] = 'csms12345678';
$config['signature'] = '短信签名';
$config['statusCallback'] = '短信发送状态返回接收地址,可以为空';
$sms = new HwSms($config);
$result = $sms->send('模板ID', '手机号码(多个号码可以用英文逗号隔开)', '短信变量数组');
if ($result['code'] == '000000') {
echo '发送成功';
} else {
echo $result['msg'];
}
}
}