阿里云短信接入 PHP

 $accessKeyId,
            // 您的 AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = $endpoint;
        return new Dysmsapi($config);
    }
 
    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient($args['access_key_id'], $args['access_key_secret'],$args['endpoint']);
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $args['phone'],  //发送的手机号码
            "signName" => $args['sign_name'],  //签名
            "templateCode" => $args['template'],  //模板CODE
            "templateParam" => json_encode($args['info'])  //这个根据你的模板信息来
        ]);
 
        $result = $client->sendSms($sendSmsRequest);
        if ($result->body->message == 'OK' && $result->body->code == 'OK') {
            return ['code' => 200,'msg'=>'success'];
        }
        if ($result->body->code == 'isv.MOBILE_NUMBER_ILLEGAL') {
            return ['code' => 0, 'msg' => '手机号码格式不正确'];
        }
        return ['code' => 0, 'msg' => '短信发送失败,网络繁忙'];
    }
}

你可能感兴趣的:(php,阿里云,php)