Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
0aaf4918
Commit
0aaf4918
authored
May 23, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分享调试
parent
8da5c178
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
27 deletions
+26
-27
Wechat.php
addons/shopro/controller/third/Wechat.php
+26
-27
No files found.
addons/shopro/controller/third/Wechat.php
View file @
0aaf4918
...
@@ -163,6 +163,7 @@ class Wechat extends Common
...
@@ -163,6 +163,7 @@ class Wechat extends Common
$this
->
success
(
'jssdkApi'
,
$data
);
$this
->
success
(
'jssdkApi'
,
$data
);
}
}
/**
/**
* 微信小程序码接口
* 微信小程序码接口
*/
*/
...
@@ -171,54 +172,53 @@ class Wechat extends Common
...
@@ -171,54 +172,53 @@ class Wechat extends Common
try
{
try
{
$mp
=
$this
->
wechat
->
getApp
();
$mp
=
$this
->
wechat
->
getApp
();
$path
=
$this
->
payload
[
'path'
]
??
''
;
$path
=
$this
->
payload
[
'path'
]
??
''
;
list
(
$page
,
$scene
)
=
array_pad
(
explode
(
'?'
,
$path
,
2
),
2
,
''
);
// 验证路径
// 根据域名或配置动态选择环境版本
if
(
empty
(
$path
))
{
$envVersion
=
'release'
;
$this
->
error
(
'页面路径不能为空'
);
}
//
安全处理:使用 array_pad 确保变量存在
//
缓存键:使用 scene 参数作为唯一标识,支持缓存不同场景的二维码
$
parts
=
explode
(
'?'
,
$path
,
2
);
$
cacheKey
=
'wxacode_'
.
md5
(
$scene
.
'_'
.
$envVersion
);
list
(
$page
,
$scene
)
=
array_pad
(
$parts
,
2
,
''
);
$cacheTtl
=
7
*
24
*
60
*
60
;
// 7天
// 确保路径以 / 开头
// 尝试从缓存获取
if
(
$page
[
0
]
!==
'/'
)
{
$cachedImage
=
cache
(
$cacheKey
);
$page
=
'/'
.
$page
;
if
(
$cachedImage
)
{
custom_log
(
'[微信小程序码] 从缓存获取成功: scene='
.
$scene
,
'wechat'
);
return
response
(
$cachedImage
,
200
,
[
'Content-Length'
=>
strlen
(
$cachedImage
)])
->
contentType
(
'image/png'
);
}
}
// 根据域名或配置动态选择环境版本
$envVersion
=
'develop'
;
$inputParams
=
[
$inputParams
=
[
'platform'
=>
$this
->
platform
,
'platform'
=>
$this
->
platform
,
'payload'
=>
$this
->
payload
,
'payload'
=>
$this
->
payload
,
'path'
=>
$path
,
'path'
=>
$path
,
'page'
=>
$page
,
'scene'
=>
$scene
,
'scene'
=>
$scene
,
'env_version'
=>
$envVersion
,
'env_version'
=>
$envVersion
'request_page'
=>
substr
(
$page
,
1
)
];
];
custom_log
(
json_encode
(
$inputParams
,
JSON_UNESCAPED_UNICODE
),
'wechat'
);
custom_log
(
json_encode
(
$inputParams
,
JSON_UNESCAPED_UNICODE
),
'wechat'
);
// 去掉 page 参数,使用小程序默认页
$content
=
$mp
->
app_code
->
getUnlimit
(
$scene
,
[
$content
=
$mp
->
app_code
->
getUnlimit
(
$scene
,
[
'page'
=>
substr
(
$page
,
1
),
// 微信接口要求不带开头的 /
'is_hyaline'
=>
true
,
'is_hyaline'
=>
true
,
'env_version'
=>
$envVersion
'env_version'
=>
$envVersion
]);
]);
if
(
$content
instanceof
\EasyWeChat\Kernel\Http\StreamResponse
)
{
if
(
$content
instanceof
\EasyWeChat\Kernel\Http\StreamResponse
)
{
// 成功返回图片
// 成功返回图片
$imageContent
=
$content
->
getBodyContents
();
$outputParams
=
[
$outputParams
=
[
'success'
=>
true
,
'success'
=>
true
,
'type'
=>
'StreamResponse'
,
'type'
=>
'StreamResponse'
,
'content_length'
=>
strlen
(
$
content
->
getBodyContents
()
),
'content_length'
=>
strlen
(
$
imageContent
),
'content_type'
=>
'image/png'
'content_type'
=>
'image/png'
];
];
custom_log
(
'[微信小程序码]获取成功 : pag'
.
json_encode
(
$outputParams
),
'wechat'
);
custom_log
(
'[微信小程序码]获取成功 : '
.
json_encode
(
$outputParams
),
'wechat'
);
// 缓存图片
cache
(
$cacheKey
,
$imageContent
,
$cacheTtl
);
custom_log
(
'[微信小程序码] 已缓存: '
.
$cacheKey
,
'wechat'
);
return
response
(
$
content
->
getBody
(),
200
,
[
'Content-Length'
=>
strlen
(
$content
->
getBodyContents
()
)])
->
contentType
(
'image/png'
);
return
response
(
$
imageContent
,
200
,
[
'Content-Length'
=>
strlen
(
$imageContent
)])
->
contentType
(
'image/png'
);
}
else
{
}
else
{
// 记录详细日志
// 记录详细日志
$errcode
=
$content
[
'errcode'
]
??
'-'
;
$errcode
=
$content
[
'errcode'
]
??
'-'
;
...
@@ -227,17 +227,16 @@ class Wechat extends Common
...
@@ -227,17 +227,16 @@ class Wechat extends Common
'success'
=>
false
,
'success'
=>
false
,
'errcode'
=>
$errcode
,
'errcode'
=>
$errcode
,
'errmsg'
=>
$errmsg
,
'errmsg'
=>
$errmsg
,
'page'
=>
$page
,
'scene'
=>
$scene
,
'scene'
=>
$scene
,
'env_version'
=>
$envVersion
'env_version'
=>
$envVersion
];
];
custom_log
(
'[微信小程序码] 获取失败:
'
.
json_encode
(
$outputParams
),
'wechat'
);
custom_log
(
'[微信小程序码] 获取失败:
'
.
json_encode
(
$outputParams
),
'wechat'
);
$this
->
error
(
'获取小程序码失败: ['
.
$errcode
.
'] '
.
$errmsg
);
return
response
(
'获取小程序码失败: ['
.
$errcode
.
'] '
.
$errmsg
,
200
,
[
'Content-Type'
=>
'application/json; charset=utf-8'
]
);
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
custom_log
(
'[微信小程序码]异常: '
.
$e
->
getMessage
()
.
' | '
.
$e
->
getTraceAsString
()
,
'wechat'
);
format_log_error_custom_name
(
$e
,
'[微信小程序码异常]'
,
''
,
'wechat'
);
$this
->
error
(
'获取小程序码异常'
);
return
response
(
'获取小程序码异常'
,
200
,
[
'Content-Type'
=>
'application/json; charset=utf-8'
]
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment