今天接到一个需求,生成一个vcard电子名片,文件格式还必须是.vcf格式的
第一步:由于我用的是laravel框架,所以得安装扩展包
安装 : jeroendesloovere/vcard
第二布:不用任何配置
public function makeVcard(Request $request)
{
$agent = Agent::find($request->admin->agent_id);
$language_name = AgentSlogan::where('agent_id',$agent->id)->where('slogan_type',$request->slogan_type)->select('first_name','last_name')->first();
$vcard = new VCard();
$lastname = $language_name->last_name;
$firstname = $language_name->first_name;
$additional = '';
$prefix = '';
$suffix = '';
// 这里可以不要,默认UTF-8,导出来windows可能会中文乱码,但是手机上不影响
$vcard->setCharset = "GB2312";
$vcard->addName($lastname, $firstname, $additional, $prefix, $suffix);
$vcard->addCompany($agent->brokerage);
$vcard->addJobtitle('');
$vcard->addRole('Data Protection Officer');
$vcard->addEmail($agent->email);
$vcard->addPhoneNumber((int) $agent->phone, 'PREF;WORK');
$vcard->addPhoneNumber((int) $agent->company_tel, 'WORK');
$vcard->addAddress(null, null, $agent->street, $agent->city, null, $agent->postal_code, $agent->country);
$vcard->addLabel($agent->street.$agent->city.$agent->postal_code.$agent->country);
$vcard->addURL('http://www.jeroendesloovere.be');
//下载vcf文件
return $vcard->download();
//打印vcf文件的内容
// return $vcard->getOutput();
}