'wxcacf6eb6e7478e29', 'appSecret' => '3722c3f95df0569498a0e32ae6e85153', ]; } /** * 获取二维码 * 20211229 * wj */ public function getqrcode($data, $filename = '', $dirname = "qrcode") { if (empty($data) || !is_array($data)) { return backarr(0, "请求失败"); } $filename = empty($filename) || !is_string($filename) ? time() : $filename; $dirname = empty($dirname) || !is_string($dirname) ? "qrcode" : $dirname; $qr_path = "./Uploads/" . $dirname; if (!file_exists($qr_path)) { mkdir($qr_path, 0700, true); //判断保存目录是否存在,不存在自动生成文件目录 } $filepath = $dirname . "/" . $filename . '.png'; $filename = $filename . '.png'; $file = $qr_path . "/" . $filename; $access = $this->getAccessToken(); $access_token = $access['access_token']; $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $access_token; $data = array( 'scene' => $data['scene'], //二维码所带参数 'width' => 200, 'page' => $data['page'], //二维码跳转路径(要已发布小程序) 'auto_color' => true, //'is_hyaline' => true, //透明底色 ); $result = requestCurl($url, "post", json_encode($data)); //请求微信接口 $resultJson = json_decode($result, true); if (!empty($resultJson) && isset($resultJson['errcode'])) { $errcode = $resultJson['errcode']; $errmsg = $resultJson['errmsg']; return backarr(0, $errmsg); } $domainpath = 'https://app.tjzhxx.cn:11443/Uploads/'; $res = file_put_contents($file, $result); //将微信返回的图片数据流写入文件 if ($res === false) { return backarr(0, '生成二维码失败'); } $data = [ 'qrcode' => $domainpath . $filepath, ]; return backarr(1, 'success', $data); } public function getAccessToken() { $config = $this->getconfig(); $appid = 'wxcacf6eb6e7478e29'; $appSecret = '3722c3f95df0569498a0e32ae6e85153'; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appSecret; $result = requestCurl($url); $wxResult = json_decode($result, true); return $wxResult; } }