💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
​ 获取Accesstoken ~~~php public function getAccessToken() { $appId = Config('wxinfo.appId'); $secretId = Config('wxinfo.secretId'); $accessUrl = Config('wxinfo.accessUrl'); $url = sprintf($accessUrl,$appId,$secretId); $result = https_request($url); $Result = json_decode($result,true); return $Result['access_token']; } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 生成二维码: ~~~php /*分享带参数小程序二维码*/ public function share() { $base_url=request()->domain(); if (!input('?post.spcode')) { $ret['code'] = 400; $ret['message'] = "缺少参数,请参照接口文档,规范传参"; $ret['data'] = null; return json($ret); } $spcode=request()->param('spcode'); $code=Db::name('newuser')->where('spcode',$spcode)->value('qrcode'); if($code!=''){ return code(200,'获取数据成功'.$base_url.$code); } $res=$this->getAccessToken(); $url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$res"; $page= 'pages/index/index'; //TODO 这个路径太长会报错,所以要注意了 $processData = [ 'page'=>$page, 'scene'=> $spcode //二维码id,二维码类型 ]; $qrData = json_encode($processData); $data=https_request($url,$qrData); $tmp = json_decode($data,true); if($tmp['errcode'] == 45009 || $tmp['errcode'] == 41030){ return (['code' => $tmp['errcode'], 'msg' => $tmp['errmsg']]); } $filename = date('YmdHis').rand(10000,999999).'.jpg'; $dir = ROOT_PATH.'public/uploads/qr'; if(!is_dir($dir)){ @mkdir($dir,0777,true); } $file = $dir.'/'.$filename; file_put_contents($file,$data); // return $file; $retFile ='/uploads/qr/'.$filename; return request()->domain().$retFile; //到这里就可以了,后面是用来上传到三方存储的 // if($retFile){ // $cos=new Upload(); // $cos->upload($file,$retFile); // } // unlink('.'.$retFile); // Db::name('newuser')->where('spcode',$spcode)->update(['qrcode'=>$retFile]); return code(200,'获取数据成功',$this->base_url.$retFile); } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") 官方地址: [wxacode.getUnlimited | 微信开放文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html "wxacode.getUnlimited | 微信开放文档") 方案2 微信官方文档:[获取小程序码 | 微信开放文档](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/qr-code.html "获取小程序码 | 微信开放文档") ~~~php #curl请求 if(!function_exists('https_request')){ function https_request($url,$data = null){ if(function_exists('curl_init')){ $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }else{ return false; } } } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "点击并拖拽以移动") ​