This commit is contained in:
zpc 2026-02-08 01:18:53 +08:00
parent 9541224f46
commit 408c17af6c
2 changed files with 27 additions and 3 deletions

View File

@ -222,13 +222,35 @@
console.log("v.scene:", v.scene); console.log("v.scene:", v.scene);
console.log("当前存储的 pid:", uni.getStorageSync("pid")); console.log("当前存储的 pid:", uni.getStorageSync("pid"));
// pid
if (v.pid) { if (v.pid) {
console.log("设置 pid 到 storage:", v.pid); console.log("设置 pid 到 storage:", v.pid);
uni.setStorageSync("pid", v.pid); uni.setStorageSync("pid", v.pid);
} }
// scene
// scene "pid=25498"
if (v.scene) { if (v.scene) {
console.log("设置 scene 作为 pid 到 storage:", v.scene); console.log("收到 scene 参数:", v.scene);
uni.setStorageSync("pid", v.scene); // scene encodeURIComponent
const decodedScene = decodeURIComponent(v.scene);
console.log("解码后的 scene:", decodedScene);
// scene "pid=xxx"
const sceneParams = {};
decodedScene.split('&').forEach(item => {
const [key, value] = item.split('=');
if (key && value) {
sceneParams[key] = value;
}
});
console.log("解析后的 scene 参数:", JSON.stringify(sceneParams));
// scene pid storage
if (sceneParams.pid) {
console.log("从 scene 中提取 pid:", sceneParams.pid);
uni.setStorageSync("pid", sceneParams.pid);
}
} }
console.log("设置后存储的 pid:", uni.getStorageSync("pid")); console.log("设置后存储的 pid:", uni.getStorageSync("pid"));

View File

@ -87,8 +87,10 @@ public class PosterService : IPosterService
if (platform.Equals("MP-WEIXIN", StringComparison.OrdinalIgnoreCase)) if (platform.Equals("MP-WEIXIN", StringComparison.OrdinalIgnoreCase))
{ {
// 小程序调用微信API生成小程序码 // 小程序调用微信API生成小程序码
// 注意未发布的小程序不能指定page参数否则会报错41030
// scene参数会在小程序onLoad中通过options.scene获取
var scene = $"pid={userId}"; var scene = $"pid={userId}";
qrCodeBytes = await _wechatService.GetWxaCodeUnlimitAsync(scene, "pages/shouye/index", posterConfig.QrCodeSize ?? DefaultQrCodeSize); qrCodeBytes = await _wechatService.GetWxaCodeUnlimitAsync(scene, null, posterConfig.QrCodeSize ?? DefaultQrCodeSize);
if (qrCodeBytes == null) if (qrCodeBytes == null)
{ {
return new PosterResult { Success = false, Message = "生成小程序码失败" }; return new PosterResult { Success = false, Message = "生成小程序码失败" };