feat: 优化腾讯地图地址选点插件,完善订单管理与分销服务

这个提交包含在:
2026-10-26 10:01:40 +08:00
父节点 d871e73d23
当前提交 7b58952cd4
共有 19 个文件被更改,包括 1045 次插入 和 201 次删除

查看文件

@@ -207,6 +207,60 @@ class WxMini
return isset($token['access_token']) ? (string)$token['access_token'] : '';
}
/**
* 生成并缓存不限次数微信小程序码(wxacode.getUnlimited)
* 若未配置小程序或线上尚未发布正式版,静默返回空字符串以便前端自动回退至普通二维码
*
* @param string $scene 场景值(最长32个可见字符,如 ic_ABCD12)
* @param string $page 小程序页面路径(不带前导 /,如 pages/index/index)
* @param int $width 二维码宽度(px)
* @return string 成功返回相对 URL(如 /uploads/wxacode/xxx.png),失败返回空字符串
*/
public static function wxacodeUnlimit($scene, $page = 'pages/index/index', $width = 280)
{
$scene = substr(trim((string)$scene), 0, 32);
$page = ltrim(trim((string)$page), '/');
if ($scene === '' || !self::isConfigured()) {
return '';
}
$hash = md5($scene . '|' . $page . '|' . (int)$width);
$relDir = '/uploads/wxacode';
$absDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'wxacode';
$relUrl = $relDir . '/' . $hash . '.png';
$absFile = $absDir . DS . $hash . '.png';
if (is_file($absFile) && filesize($absFile) > 200) {
return $relUrl;
}
try {
$response = self::app()->app_code->getUnlimit($scene, [
'page' => $page !== '' ? $page : 'pages/index/index',
'width' => max(280, min(1280, (int)$width)),
'check_path' => false,
]);
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
$body = $response->getBody()->getContents();
// 校验 PNG (\x89PNG) 或 JPEG (\xFF\xD8) 魔数,避免把微信返回的 JSON 错误当图片落盘
if (strlen($body) > 200 && (substr($body, 0, 4) === "\x89PNG" || substr($body, 0, 2) === "\xFF\xD8")) {
if (!is_dir($absDir)) {
@mkdir($absDir, 0755, true);
}
@file_put_contents($absFile, $body);
if (is_file($absFile) && filesize($absFile) > 200) {
return $relUrl;
}
}
}
} catch (\Throwable $e) {
// 静默降级:小程序未发布或网络受限时由前端自动回退绘制二维码
}
return '';
}
/* ==================== 内部工具 ==================== */
/** SDK 返回 Collection / array / object 统一转数组 */