配置修改

This commit is contained in:
2026-04-17 20:19:43 +08:00
parent 298b31c77d
commit 40e4937b93
5 changed files with 83 additions and 76 deletions

View File

@ -43,10 +43,7 @@ class Statistics extends AdminBase
return view();
}
public function test(){
$result = StatisticsLogic::makeMpWechatQrcode();
var_dump($result);
}
//交易分析
public function trading()
{

View File

@ -226,4 +226,9 @@ class Basic extends AdminBase
return JsonServer::success('操作成功');
}
}
public function qrCode(){
$result = BasicLogic::makeMpWechatQrcode();
return JsonServer::success('操作成功',$result);
}
}

View File

@ -309,69 +309,6 @@ class StatisticsLogic extends Logic
return ['count' => $goods_count, 'lists' => $goods_list];
}
public static function makeMpWechatQrcode( string $type = 'url', array $extra = [])
{
try {
$width = 430;
// 'env_version' => 'trial',
$envVersion = 'develop';
// $envVersion = 'release';
$page = "bundle/pages/user_spread/user_spread";
$save_dir = public_path() . 'uploads/wxqrcode/';
// 确保目录存在
if (!is_dir($save_dir)) {
mkdir($save_dir, 0755, true);
}
$file_name = time() . '.png';
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->app_code->getUnlimit('type=1', [
// 'scene' => 'type=1',
'page' => $page,
'width' => $width,
'auto_color' => false,
'line_color' => ['r' => 0, 'g' => 0, 'b' => 0],
'is_hyaline' => false,
'env_version' => $envVersion,
'check_path' => false,
]);
if(is_array($response) && 41030 === $response['errcode']){
//开启错误提示,小程序未发布和页面不存在,返回提示
if (41030 === $response['errcode']) {
return '所传page页面不存在或者小程序没有发布';
}
return $response['errmsg'];
}
$contents = $response->getBody()->getContents();
switch ($type){
case 'file':
if ($response instanceof StreamResponse) {
$file_name = $response->saveAs($save_dir, $file_name);
$contents = $save_dir . $file_name;
}
break;
case 'url': // 保存并返回完整URL
$full_path = $save_dir . $file_name;
file_put_contents($full_path, $contents);
// 生成完整的可访问URL根据实际域名调整
$contents = request()->domain() . '/uploads/wxqrcode/' . $file_name;
break;
case 'base64':
$mp_base64 = chunk_split(base64_encode($contents));
$contents = 'data:image/png;base64,' . $mp_base64;
break;
}
return data_success('',['qr_code'=>$contents, 'extra' => $extra]);
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e){
return data_error($e->getMessage());
}
}
}

View File

@ -6,6 +6,9 @@ use app\common\basics\Logic;
use app\common\server\ConfigServer;
use app\common\server\FileServer;
use app\common\server\UrlServer;
use app\common\server\WeChatServer;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Http\StreamResponse;
/**
* 网站基础设置
@ -166,4 +169,69 @@ class BasicLogic extends Logic
return true;
}
public static function makeMpWechatQrcode( string $type = 'url', array $extra = [])
{
try {
$width = 430;
// 'env_version' => 'trial',
$envVersion = 'develop';
// $envVersion = 'release';
$page = "bundle/pages/user_spread/user_spread";
$save_dir = public_path() . 'uploads/wxqrcode/';
// 确保目录存在
if (!is_dir($save_dir)) {
mkdir($save_dir, 0755, true);
}
$file_name = time() . '.png';
$config = WeChatServer::getMnpConfig();
$app = Factory::miniProgram($config);
$response = $app->app_code->getUnlimit('type=1', [
// 'scene' => 'type=1',
'page' => $page,
'width' => $width,
'auto_color' => false,
'line_color' => ['r' => 0, 'g' => 0, 'b' => 0],
'is_hyaline' => false,
'env_version' => $envVersion,
'check_path' => false,
]);
if(is_array($response) && 41030 === $response['errcode']){
//开启错误提示,小程序未发布和页面不存在,返回提示
if (41030 === $response['errcode']) {
return '所传page页面不存在或者小程序没有发布';
}
return $response['errmsg'];
}
$contents = $response->getBody()->getContents();
switch ($type){
case 'file':
if ($response instanceof StreamResponse) {
$file_name = $response->saveAs($save_dir, $file_name);
$contents = $save_dir . $file_name;
}
break;
case 'url': // 保存并返回完整URL
$full_path = $save_dir . $file_name;
file_put_contents($full_path, $contents);
// 生成完整的可访问URL根据实际域名调整
$contents = request()->domain() . '/uploads/wxqrcode/' . $file_name;
break;
case 'base64':
$mp_base64 = chunk_split(base64_encode($contents));
$contents = 'data:image/png;base64,' . $mp_base64;
break;
}
return data_success('',['qr_code'=>$contents, 'extra' => $extra]);
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e){
return data_error($e->getMessage());
}
}
}

View File

@ -36,18 +36,18 @@
</div>
<!--商城微信二维码-->
<div class="layui-form-item">
<label class="layui-form-label">商城logo</label>
<div class="layui-input-inline">
<div class="like-upload-image">
{if !empty($config.client_login_logo)}
<div class="upload-image-div">
<img src="{$config.file_url}{$config.wxcode}" alt="img" style="background-color:#EEEEEE;height: 80px;width:auto">
<input name="client_login_logo" type="hidden" value="{$config.wxcode}">
<label class="layui-form-label">商城微信二维码</label>
<div class="layui-input-inline" style="width:300px;height: 300px">
<div class="like-upload-image" style="width:300px;height: 300px">
{if !empty($config.wxcode)}
<div class="upload-image-div" style="width:300px;height: 300px">
<img src="{$config.file_url}{$config.wxcode}" alt="img" style="background-color:#EEEEEE;height: 300px;width:100%">
<input name="wxcode" type="hidden" value="{$config.wxcode}">
<div class="del-upload-btn">x</div>
</div>
<div class="upload-image-elem" style="display:none;"><a class="add-upload-image client_login_logo"> + 添加图片</a></div>
<div class="upload-image-elem" style="display:none;"><a class="add-upload-image wxcode"> + 添加图片</a></div>
{else}
<div class="upload-image-elem"><a class="add-upload-image client_login_logo"> + 添加图片</a></div>
<div class="upload-image-elem"><a class="add-upload-image wxcode"> + 添加图片</a></div>
{/if}
</div>
</div>