关于利用google 生成二维码的代码,求优化
参考了论坛中某位的代码(sorry,忘了原作者是谁了……)
稍微修改了一下
求助:1. 增加超时限制,允许设置超过***秒后若无法生成,则返回-1
2. %2B表示+是怎么转换的?Func _QRcode($sPath, $sWH, $sString)
If StringRegExp($sString, '[^\x00-\xff]') Then
SetError(1)
Return False
EndIf;检测是否为全单字节
$sString = StringReplace($sString,'+','%2B')
$sString = StringReplace($sString,'%','%25')
$sString = StringReplace($sString,@CR,'%0D')
$sString = StringReplace($sString,@LF,'%0A')
$sString = StringReplace($sString,'?','%3F')
$sString = StringReplace($sString,'(','%28')
$sString = StringReplace($sString,')','%29')
$sString = StringReplace($sString,'!','%21')
$sString = StringReplace($sString,'@','%40')
$sString = StringReplace($sString,'+','%2B')
$sString = StringReplace($sString,'=','%3D')
$sString = StringReplace($sString,'#','%23')
$sString = StringReplace($sString,','%24')
$sString = StringReplace($sString,'&','%26')
$sString = StringReplace($sString,' ','+')
If StringLen($sString) +stringlen("http://chart.apis.google.com/chart?cht=qr&chs=" & $sWH & 'x' & $sWH & "&chl=" ) > 2048 Then
SetError(2)
Return False
EndIf;字符超限
FileDelete($sPath)
;开始发送数据,并获取二维码了
InetGet("http://chart.apis.google.com/chart?cht=qr&chs=" & $sWH & 'x' & $sWH & "&chl=" & $sString, $sPath, 1, 0)
If @error Then
SetError(3)
Return False
EndIf;网络故障
Return True
EndFunc
|