小程序生成代码优化
This commit is contained in:
@@ -27,34 +27,32 @@ class PosterWeChatMiniProgram extends Controller
|
||||
|
||||
$taskId = request()->param('id');
|
||||
|
||||
$app = Factory::miniProgram(self::MINI_PROGRAM_CONFIG);
|
||||
|
||||
// scene参数长度限制为32位
|
||||
// $scene = 'taskId=' . $taskId;
|
||||
$scene = 'id=' . $taskId;
|
||||
|
||||
// 调用接口生成小程序码
|
||||
$response = $app->app_code->getUnlimit($scene, [
|
||||
'page' => 'pages/poster/index', // 必须是已经发布的小程序页面
|
||||
'width' => 430, // 二维码的宽度,默认430
|
||||
// 'auto_color' => false, // 自动配置线条颜色
|
||||
// 'line_color' => ['r' => 0, 'g' => 0, 'b' => 0], // 颜色设置
|
||||
// 'is_hyaline' => false, // 是否需要透明底色
|
||||
]);
|
||||
|
||||
// 保存小程序码到文件
|
||||
if ($response instanceof StreamResponse) {
|
||||
// $filename = 'minicode_' . $taskId . '.png';
|
||||
// $response->saveAs('path/to/codes', $filename);
|
||||
// return 'path/to/codes/' . $filename;
|
||||
try {
|
||||
$app = Factory::miniProgram(self::MINI_PROGRAM_CONFIG);
|
||||
// scene参数长度限制为32位
|
||||
// $scene = 'taskId=' . $taskId;
|
||||
$scene = 'id=' . $taskId;
|
||||
// 调用接口生成小程序码
|
||||
$response = $app->app_code->getUnlimit($scene, [
|
||||
'page' => 'pages/poster/index', // 必须是已经发布的小程序页面
|
||||
'width' => 430, // 二维码的宽度,默认430
|
||||
// 'auto_color' => false, // 自动配置线条颜色
|
||||
// 'line_color' => ['r' => 0, 'g' => 0, 'b' => 0], // 颜色设置
|
||||
// 'is_hyaline' => false, // 是否需要透明底色
|
||||
]);
|
||||
// 保存小程序码到文件
|
||||
if ($response instanceof StreamResponse) {
|
||||
// $filename = 'minicode_' . $taskId . '.png';
|
||||
// $response->saveAs('path/to/codes', $filename);
|
||||
// return 'path/to/codes/' . $filename;
|
||||
|
||||
$img = $response->getBody()->getContents();//获取图片二进制流
|
||||
$img_base64 = 'data:image/png;base64,' .base64_encode($img);//转化base64
|
||||
return $img_base64;
|
||||
$img = $response->getBody()->getContents();//获取图片二进制流
|
||||
$img_base64 = 'data:image/png;base64,' . base64_encode($img);//转化base64
|
||||
return json_encode(['code' => 200, 'data' => $img_base64]);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
return json_encode(['code' => 500,'data' => '','msg' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
// return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
// getPhoneNumber
|
||||
|
||||
Reference in New Issue
Block a user