PHP发送短信验证码

短信费用:0.04/条

下载alidayu的SDK加入到项目

示例代码:

//发送短信验证码
//tel 手机号
//code 验证码
//shop_name 商户名
//type 短信模板
 public function sendSMS($tel,$code,$shop_name,$type) {
        require_once './Application/alidayu/TopSdk.php';
        $msgType = C('ALIDAYU.Type');
  
        $c = new \TopClient();
        $c->appkey = C('ALIDAYU.AppKey');
        $c->secretKey = C('ALIDAYU.AppSecret');
        $req = new \AlibabaAliqinFcSmsNumSendRequest();
        $req->setExtend("");
        $req->setSmsType("normal");
        $req->setSmsFreeSignName($msgType[$type]['sign']);
        $req->setSmsParam(json_encode(array(
            'code' => $code,
            'product' => $shop_name,
        )));
        $req->setRecNum($tel);
        $req->setSmsTemplateCode($msgType[$type]['tpl']);
        $res = $c->execute($req);
        if ($res->result->success) {
            return true;
        } else {
            //记录短信发送失败原因
            A("Home/ErrorLog")->sms(json_encode($res));
            return false;
        }
    }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值