diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 27dd557..2856525 100755 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -147,4 +147,23 @@ class Index extends Base exit(); // return $this->renderSuccess('请求成功', $user_base ); } + + + public function generate_urllinks() + { + $userId = request()->param('userId/d', 0); + $wxServer = new \app\common\server\Wx($this->app); + $user_base = $wxServer->generateUrlLinks($userId); + $autoload = new \app\common\server\autoload(); + $imageData = $autoload->generatePosterWithQR('/www/wwwroot/testbaji.onelight.vip/public/img_poster.jpg', $user_base); + if ($imageData) { + header('Content-Type: image/png'); + header('Content-Length: ' . strlen($imageData)); // 设置图像长度,帮助浏览器处理流式内容 + echo $imageData; + exit(); + } + return $this->renderSuccess('请求成功', $user_base); + } + + } diff --git a/app/api/route/app.php b/app/api/route/app.php index 14ddcc1..fc853ac 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -153,6 +153,8 @@ Route::any('seckill_order_logistics','Seckill/seckill_order_logistics'); Route::any('sign','UserSign/index'); //签到页面 Route::any('sign_add','UserSign/sign_add'); //签到 //generate_urllink -Route::any('generate_urllink','Index/generate_urllink'); //签到 +Route::any('generate_urllink','Index/generate_urllink'); + +Route::any('generate_urllinks','Index/generate_urllinks'); diff --git a/app/common/server/Wx.php b/app/common/server/Wx.php index 868d804..c5606bf 100755 --- a/app/common/server/Wx.php +++ b/app/common/server/Wx.php @@ -89,6 +89,30 @@ class Wx extends MyController } + + /** + * + * @param string $code + * @return int|mixed|\think\response\Json + */ + public function generateUrlLinks($userId) + { + $access_token = $this->get_access_token(); + $request_url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" . $access_token; + $param = '{ + "path": "/pages/shouye/index", + "query": "pid=' . $userId . '" + }'; + $res = curlPost($request_url, $param); + $res = json_decode($res, true); + if ($res['errcode'] == 0 && $res['errmsg'] == 'ok') { + return $res['url_link']; + } else { + return ''; + } + } + + /** * 获得小程序二维码 diff --git a/app/common/server/autoload.php b/app/common/server/autoload.php new file mode 100644 index 0000000..0f7037c --- /dev/null +++ b/app/common/server/autoload.php @@ -0,0 +1,53 @@ +setSize($qrSize); + $writer = new PngWriter(); + $qrImage = $writer->write($qrCode); + + // 将二维码转换为 GD 图像资源 + $qrImageResource = imagecreatefromstring($qrImage->getString()); + + // 计算二维码的放置位置 + $qrX = ($backgroundWidth - $qrSize) / 2; + $qrY = ($backgroundHeight - $qrSize) * 0.73; + + // 将二维码绘制到背景图上 + imagecopy($backgroundImage, $qrImageResource, $qrX, $qrY, 0, 0, $qrSize, $qrSize); + + // 创建一个临时的内存文件,保存合成后的图片 + ob_start(); + imagepng($backgroundImage); // 输出图像为PNG格式 + $imageData = ob_get_contents(); + ob_end_clean(); + + // 释放图像资源 + imagedestroy($backgroundImage); + imagedestroy($qrImageResource); + + // 返回合成后的图片的字节数据 + return $imageData; + + } + +} \ No newline at end of file