1首先呢,去官方下载demo 把该删的删了,该改的改了。最后改名aliyun文件夹就好了。
2.然后呢,去你的阿里后台设置发送的模板(设置完你就知道怎么填下面的值了)
3.再然后呢,把aliyun文件放vendor下面
4.最后呢,加我qq 备注 阿里大于 找我要aliyun 扩展类,O(∩_∩)O哈哈~
把下面的代码放Controller
/**
* @name 发送短信
* @author cq <just_leaf@foxmail.com>
* @copyright vikily 2018-07-19
*/
public function sendsms() {
#接收人手机号码
$mobile = I('mobile');
#验证码
$signcode = I('signcode');
header('Content-Type: text/plain; charset=utf-8');
vendor('aliyun.api_demo.SmsDemo');
#实例化
$demo = new \SmsDemo('你的key','你的Sec');
# 短信接收者
$phone = $mobile;
# 短信签名
$sign = '注册验证';
# 短信模板编号
$code = 'SMS_33650273';
# 短信模板中字段的值
$data = array(
'code' => $signcode,
'product' => '威京利'
);
#发送短信
$response = $demo->sendSms($phone,$sign,$code,$data);
$Code = $response -> Code;
$Msg = $response -> Message;
if($Code == 'OK'){
returnApiSuccess('ok');
}else{
returnApiError($Msg);
}
}