[PHP] code
- /*
- * php generate QR code business card
- * api Google
- * google api QR code generation [QRcode can store up to 4296 alphanumeric types of arbitrary text, specific You can view the QR code data format】
- * @param string $chl The information contained in the QR code can be numbers, characters, binary information, or Chinese characters. Data types cannot be mixed, and the data must be UTF-8 URL-encoded. If the information that needs to be transmitted exceeds 2K bytes, please use the POST method
- * @param int $widhtHeight The size setting of the generated QR code
- * @param string $ EC_level optional error correction level, QR code supports four levels of error correction, used to recover lost, misread, ambiguous, and data.
- * L-Default: Can identify 7% of data that has been lost
- * M-Can identify 15% of data that has been lost
- * Q-Can identify 25% of data that has been lost
- * H-Can identify 30% of data that has been lost Data
- * @param int $margin The distance between the generated QR code and the picture border
- * The format of the QR code business card---vcard
- * The format reference is as follows:
- BEGIN: VCARD
- VERSION: 3.0
- FN: Username
- TEL;CELL;VOICE:15201280000
- TEL;WORK;VOICE:010-62100000
- TEL;WORK;FAX:010-62100001
- EMAIL;PREF;INTERNET:lzw#lzw.me
- URL: http://lzw.me
- orG: Zhiwen Studio
- ROLE: Product Department
- TITLE: CTO
- ADR; WORK; POSTAL: No. 35, North Fourth Ring Middle Road, Chaoyang District, Beijing; 100101
- REV: 2012-12-27T08:30:02Z
- END: VCARD
-
- If you want to customize the required format in more detail, you need to understand the vcard format standard in detail.
- */
- $vcard = array(
- 'vname' => 'username',
- 'vtel' => '13700000000',
- 'vemail' => 'playby@163.com',
- 'vaddress ' => 'Chaoyang District, Beijing',
- );
-
- generateQRfromGoogle($vcard);
- function generateQRfromGoogle($vcard,$widhtHeight ='150',$EC_level='L',$margin='0')
- {
- if($vcard){
- $chl = "BEGIN:VCARDnVERSION:3.0". //vcard header information
- "nFN:'".$vcard['vname'].
- "nTEL:".$vcard[ 'vtel'].
- "nEMAIL:".$vcard['vemail'].
- "nADR:".$vcard['vaddress'].
- "nEND:VCARD"; //vcard tail information
- echo '< img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.' &chl='.urlencode($chl).'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>';
- }
- }
- ?> ;
Copy code
|