php带参数二维码生成
php带参数⼆维码⽣成
TP5带参数⼆维码⽣成
php代码⽰例(已测试):
//⼆维码type
public function qrcode($id,$type='1'){
if($type == 1){
$para='uid,'.$id;
}else{
$para='container,'.$id;
退休人员死亡抚恤金}
$arr=['action_name'=>'QR_LIMIT_STR_SCENE','action_info'=>['scene'=>['scene_str'=>$para]]];
$data=json_encode($arr);
$url='api.weixin.qq/cgi-bin/qrcode/create?access_token='.getAccessToken();
$result=CURLSend($url,'post',$data);
$results=json_decode($result,true);
$qecodeUrl='mp.weixin.qq/cgi-bin/showqrcode?ticket='.UrlEncode($results['ticket']);        $res = $this->uploadImg($qecodeUrl);
return $res;
}
public function uploadImg($img){
$path = DOC_ROOT.'upload/qrcode';
if(!file_exists($path)) {
mkdir($path, 0777, true);
}
ob_clean();
ob_start();
$ext="/".time().".png";
readfile($img);    //读取图⽚
$img=ob_get_contents(); //得到缓冲区中保存的图⽚
ob_end_clean();    //清空缓冲区
$fp = fopen($path.$ext,'w');    //写⼊图⽚
会计 打一成语if(fwrite($fp,$img)){
fclose($fp);
return IMGS.'upload/qrcode'.$ext;
}
return false;
}学瑜伽
//获取access_token,调⽤接⼝凭据(使⽤接⼝需要⽤到)
//access_token获取频次2000/天,2⼩时内有效
function getAccessToken(){
$config=db('public_wx_config')->field('appid,appsecret,expires_in,access_token')->where('id',1)->find();
$appid=$config['appid'];全国高温前十名是哪些城市?
汉语国际教育就业方向及前景
$secret=$config['appsecret'];
if($config['expires_in']< time()){
$url="api.weixin.qq/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;        $tmp=CURLSend($url,'get');
$obj=json_decode($tmp);
$dty=(time()+$obj->expires_in);
$data['access_token']=$obj->access_token;
血精灵适合什么职业$data['expires_in']=$dty;
db('public_wx_config')->where('id',1)->update($data);
return $obj->access_token;
}else {
return  $config['access_token'];
}
}
/*
*模拟浏览器发送
*/
function CURLSend($url,$method = 'get', $data = ''){
$ch = curl_init();//初始化
$headers = array('Accept-Charset: utf-8');
//设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, $url);//指定请求的URL
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));//提交⽅式
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//不验证SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);//不验证SSL
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置HTTP头字段的数组
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible;MSIE5.01;Windows NT 5.0)');//头的字符串
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);//⾃动设置header中的Referer:信息
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//提交数值
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//是否输出到屏幕上,true不直接输出
$temp = curl_exec($ch);//执⾏并获取结果
curl_close($ch);
return $temp;//return 返回值
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。