tp5生成小程序带参二维码
tp5⽣成⼩程序带参⼆维码深圳旅游景点介绍
class Wechatqrcode extends Controller
{
//调⽤接⼝查看是否存在⼆维码
public function GenerateCodeImg(Request $request)
{
$param=$request->param();
if(!isset($param['id'])||empty($param['id']))return return_msg('210','参数');
if(!isset($param['brand'])||empty($param['brand']))return return_msg('210','参数');
$PhotoLikesTask=model('PhotoLikesTask');
$codeimg=$PhotoLikesTask->where('id',$param['id'])->value('qrcode');
/
/存在直接输出⼆维码存放在七⽜云空间的路径
陈奕迅不要说话if(!empty($codeimg)){
return return_msg('200','⼆维码已经存在',$data['info']=''.config('qiniu')['domain'].'/'.$codeimg);
}
$token=json_decode($this->curl_get(),true);
//获取凭证出错
if(empty($token['access_token'])){
return false;
}
$url='api.weixin.qq/wxa/getwxacodeunlimit?access_token='.$token['access_token'];
$data=json_encode([
'width'=>400,
//            'auto_color'=>false,
'scene'=>$param['id'].'*'.$param['brand'],
'page'=>'pages/c-profile/activity/goDowning/goDownding',
]);
$header=[
'Content-type: application/json;charset=utf-8',
橙子是热性还是凉性'Content-Length:'.strlen($data)
];
$result=self::httpPost($url,$data,'',$header);
if(!$result){
return return_msg('400','获取⽂件流失败');
}
//⽣成转化为base64⽂件流
//        $base64String = 'data:image/png' . ';base64,' . base64_encode($result);
//        return $base64String;
$name=$param['id'].rand(1111,9999);
国庆高速免费时间2022最新通知
$key=$this->QiniuUpload($name,$result);
if(!is_string($key))return$key;
小车违章记录查询$res=$PhotoLikesTask->where('id',$param['id'])->update(['qrcode'=>$key]);
return$res===1?return_msg('200','成功',''.config('qiniu')['domain'].'/'.$key): return_msg('400','失败'); }
//php get请求⽹络的⽅法
function curl_get(&$httpCode=0){
$appid=config('wechat')['appid'];
//⼩程序秘钥
$secret=config('wechat')['appSecret'];
$url="api.weixin.qq/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//不做证书校验,部署在linux环境下请改为true
//不做证书校验,部署在linux环境下请改为true
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
$file_contents=curl_exec($ch);
$httpCode=curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
return$file_contents;
}
public static function httpPost($url,$post_data,$cookieDir='',$header=[]){
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_HEADER,false);
if($header)curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($curl,CURLOPT_REFERER,$url);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
if($cookieDir)curl_setopt($curl,CURLOPT_COOKIEJAR,$cookieDir);林冲的性格特点
$UserAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36';
curl_setopt($curl,CURLOPT_USERAGENT,$UserAgent);
$data=curl_exec($curl);
return$data;
}
function QiniuUpload($name,$result)
{
// 七⽜鉴权账号
$accessKey=config("qiniu")['accessKey'];
$secretKey=config("qiniu")['secretKey'];
$key=md5($name.time()).'.png';
// 构建鉴权对象
$auth=new Auth($accessKey,$secretKey);
/
/ 要上传的空间
$bucket=config("qiniu")['bucket'];
$token=$auth->uploadToken($bucket);
$uploadMgr=new UploadManager();
list($ret,$err)=$uploadMgr->put($token,$key,$result);
if($err!==null){
return return_msg('400',$err);
}
return$key;
}
}

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