封装一个灵活的短信发送

/**
 * 发送短信
 */
public static function sendSms($telephone , $extend = [] , $type = 1)
{
    $log = [];
    $log['tel'] = $telephone;
    $log['extend'] = $extend;
    $log['time'] = date('Y-m-d H:i:s');
    switch($type) {
        case 1:
            $smsConf = array(
                'key'       => C('SMS_KEY'),     //您申请的APPKEY
                'mobile'    => $telephone,                              //接受短信的用户手机号码
                'tpl_id'    => C('SMS_TPL_CANCEL_ORDER'),                   //您申请的短信模板ID,根据实际情况修改
                'tpl_value' =>'#order_num#='.$extend['order_num'].'&#address#='.$extend['address'],  //#code#=1234&#company#=聚合数据
                'platform'  => 'xxx',
            );
            break;
    }
    $sendUrl = 'xxx';
    $result = Http::doPost($sendUrl, $smsConf);
    $result = json_decode($result,true);
    setlog($log,$result,'短信','sms.log');
    if(!$result['error_code']){
        return true;
    }else{
        return false;
    }
}

通过变量extend,和type可以支持多种模板短信发送。

posted @ 2020-04-13 14:30  TBHacker  阅读(260)  评论(0编辑  收藏  举报